Paper/nms-patches/DispenseBehaviorBoat.patch

58 lines
2.4 KiB
Diff
Raw Normal View History

2019-04-23 04:00:00 +02:00
--- a/net/minecraft/server/DispenseBehaviorBoat.java
+++ b/net/minecraft/server/DispenseBehaviorBoat.java
@@ -1,5 +1,10 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.block.BlockDispenseEvent;
+// CraftBukkit end
+
public class DispenseBehaviorBoat extends DispenseBehaviorItem {
private final DispenseBehaviorItem b = new DispenseBehaviorItem();
@@ -29,12 +34,40 @@
d3 = 0.0D;
}
2020-08-11 23:00:00 +02:00
- EntityBoat entityboat = new EntityBoat(worldserver, d0, d1 + d3, d2);
+ // EntityBoat entityboat = new EntityBoat(worldserver, d0, d1 + d3, d2);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2020-08-11 23:00:00 +02:00
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
2019-04-23 04:00:00 +02:00
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d0, d1 + d3, d2));
+ if (!BlockDispenser.eventFired) {
2020-08-11 23:00:00 +02:00
+ worldserver.getServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (event.isCancelled()) {
+ itemstack.add(1);
+ return itemstack;
+ }
+
+ if (!event.getItem().equals(craftItem)) {
+ itemstack.add(1);
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior != this) {
+ idispensebehavior.dispense(isourceblock, eventStack);
+ return itemstack;
+ }
+ }
+
2020-08-11 23:00:00 +02:00
+ EntityBoat entityboat = new EntityBoat(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
entityboat.setType(this.c);
2020-06-25 02:00:00 +02:00
entityboat.yaw = enumdirection.o();
2020-08-11 23:00:00 +02:00
- worldserver.addEntity(entityboat);
2019-04-23 04:00:00 +02:00
- itemstack.subtract(1);
2020-08-11 23:00:00 +02:00
+ if (!worldserver.addEntity(entityboat)) itemstack.add(1); // CraftBukkit
2019-04-23 04:00:00 +02:00
+ // itemstack.subtract(1); // CraftBukkit - handled during event processing
return itemstack;
}