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

77 Zeilen
3.4 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/DispenseBehaviorItem.java
+++ b/net/minecraft/server/DispenseBehaviorItem.java
2019-04-23 04:00:00 +02:00
@@ -1,5 +1,11 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
2019-04-23 04:00:00 +02:00
+import org.bukkit.craftbukkit.util.CraftVector;
+import org.bukkit.event.block.BlockDispenseEvent;
+// CraftBukkit end
+
public class DispenseBehaviorItem implements IDispenseBehavior {
public DispenseBehaviorItem() {}
2019-04-23 04:00:00 +02:00
@@ -18,11 +24,19 @@
IPosition iposition = BlockDispenser.a(isourceblock);
2015-07-30 08:56:52 +02:00
ItemStack itemstack1 = itemstack.cloneAndSubtract(1);
2015-07-30 08:56:52 +02:00
- a(isourceblock.getWorld(), itemstack1, 6, enumdirection, iposition);
+ // CraftBukkit start
2015-07-30 08:56:52 +02:00
+ if (!a(isourceblock.getWorld(), itemstack1, 6, enumdirection, isourceblock)) {
2016-11-17 02:41:03 +01:00
+ itemstack.add(1);
+ }
+ // 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) {
2018-07-15 02:00:00 +02:00
+ if (itemstack.isEmpty()) return true;
+ IPosition iposition = BlockDispenser.a(isourceblock);
+ // CraftBukkit end
double d0 = iposition.getX();
double d1 = iposition.getY();
double d2 = iposition.getZ();
2019-04-23 04:00:00 +02:00
@@ -37,7 +51,39 @@
double d3 = world.random.nextDouble() * 0.1D + 0.2D;
entityitem.setMot(world.random.nextGaussian() * 0.007499999832361937D * (double) i + (double) enumdirection.getAdjacentX() * d3, world.random.nextGaussian() * 0.007499999832361937D * (double) i + 0.20000000298023224D, world.random.nextGaussian() * 0.007499999832361937D * (double) i + (double) enumdirection.getAdjacentZ() * d3);
+
+ // CraftBukkit start
+ org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack);
+
2019-04-23 04:00:00 +02:00
+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), CraftVector.toBukkit(entityitem.getMot()));
+ if (!BlockDispenser.eventFired) {
+ world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (event.isCancelled()) {
+ return false;
+ }
+
+ entityitem.setItemStack(CraftItemStack.asNMSCopy(event.getItem()));
2019-04-23 04:00:00 +02:00
+ entityitem.setMot(CraftVector.toNMS(event.getVelocity()));
+
+ if (!event.getItem().getType().equals(craftItem.getType())) {
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
2015-07-30 08:56:52 +02:00
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.REGISTRY.get(eventStack.getItem());
+ if (idispensebehavior != IDispenseBehavior.NONE && idispensebehavior.getClass() != DispenseBehaviorItem.class) {
2018-07-15 02:00:00 +02:00
+ idispensebehavior.dispense(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) {