3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00
Paper/nms-patches/DispenseBehaviorItem.patch

77 Zeilen
3.4 KiB
Diff

2015-02-26 23:41:06 +01:00
--- /home/matt/mc-dev-private//net/minecraft/server/DispenseBehaviorItem.java 2015-02-26 22:40:22.447608141 +0000
+++ src/main/java/net/minecraft/server/DispenseBehaviorItem.java 2015-02-26 22:40:22.447608141 +0000
@@ -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 DispenseBehaviorItem implements IDispenseBehavior {
public DispenseBehaviorItem() {}
@@ -17,11 +22,18 @@
IPosition iposition = BlockDispenser.a(isourceblock);
ItemStack itemstack1 = itemstack.a(1);
- a(isourceblock.i(), itemstack1, 6, enumdirection, iposition);
+ // CraftBukkit start
+ if (!a(isourceblock.i(), itemstack1, 6, enumdirection, isourceblock)) {
+ itemstack.count++;
+ }
+ // CraftBukkit end
return itemstack;
}
- public static void a(World world, ItemStack itemstack, int i, EnumDirection enumdirection, IPosition iposition) {
+ // CraftBukkit start - void -> boolean return, IPosition -> ISourceBlock last argument
+ public static boolean a(World world, ItemStack itemstack, int i, EnumDirection enumdirection, ISourceBlock isourceblock) {
+ IPosition iposition = BlockDispenser.a(isourceblock);
+ // CraftBukkit end
double d0 = iposition.getX();
double d1 = iposition.getY();
double d2 = iposition.getZ();
@@ -41,7 +53,41 @@
entityitem.motX += world.random.nextGaussian() * 0.007499999832361937D * (double) i;
entityitem.motY += world.random.nextGaussian() * 0.007499999832361937D * (double) i;
entityitem.motZ += world.random.nextGaussian() * 0.007499999832361937D * (double) i;
+
+ // CraftBukkit start
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(entityitem.motX, entityitem.motY, entityitem.motZ));
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
+ return false;
+ }
+
+ entityitem.setItemStack(CraftItemStack.asNMSCopy(event.getItem()));
+ entityitem.motX = event.getVelocity().getX();
+ entityitem.motY = event.getVelocity().getY();
+ entityitem.motZ = event.getVelocity().getZ();
+
+ if (!event.getItem().getType().equals(craftItem.getType())) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-02-26 23:41:06 +01:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.N.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.a && idispensebehavior.getClass() != DispenseBehaviorItem.class) {
+ idispensebehavior.a(isourceblock, eventStack);
+ } else {
+ world.addEntity(entityitem);
+ }
+ return false;
+ }
+
world.addEntity(entityitem);
2015-02-26 23:41:06 +01:00
+
+ return true;
+ // CraftBukkit end
}
protected void a(ISourceBlock isourceblock) {