mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2024-11-22 10:06:16 +00:00
59 lines
3.5 KiB
Diff
59 lines
3.5 KiB
Diff
--- a/net/minecraft/world/level/block/BlockDropper.java
|
|
+++ b/net/minecraft/world/level/block/BlockDropper.java
|
|
@@ -20,11 +20,17 @@
|
|
import net.minecraft.world.level.block.state.IBlockData;
|
|
import org.slf4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import net.minecraft.world.InventoryLargeChest;
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public class BlockDropper extends BlockDispenser {
|
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
public static final MapCodec<BlockDropper> CODEC = simpleCodec(BlockDropper::new);
|
|
- private static final IDispenseBehavior DISPENSE_BEHAVIOUR = new DispenseBehaviorItem();
|
|
+ private static final IDispenseBehavior DISPENSE_BEHAVIOUR = new DispenseBehaviorItem(true); // CraftBukkit
|
|
|
|
@Override
|
|
public MapCodec<BlockDropper> codec() {
|
|
@@ -47,7 +53,7 @@
|
|
|
|
@Override
|
|
public void dispenseFrom(WorldServer worldserver, IBlockData iblockdata, BlockPosition blockposition) {
|
|
- TileEntityDispenser tileentitydispenser = (TileEntityDispenser) worldserver.getBlockEntity(blockposition, TileEntityTypes.DROPPER).orElse((Object) null);
|
|
+ TileEntityDispenser tileentitydispenser = (TileEntityDispenser) worldserver.getBlockEntity(blockposition, TileEntityTypes.DROPPER).orElse(null); // CraftBukkit - decompile error
|
|
|
|
if (tileentitydispenser == null) {
|
|
BlockDropper.LOGGER.warn("Ignoring dispensing attempt for Dropper without matching block entity at {}", blockposition);
|
|
@@ -68,8 +74,25 @@
|
|
if (iinventory == null) {
|
|
itemstack1 = BlockDropper.DISPENSE_BEHAVIOUR.dispense(sourceblock, itemstack);
|
|
} else {
|
|
- itemstack1 = TileEntityHopper.addItem(tileentitydispenser, iinventory, itemstack.copyWithCount(1), enumdirection.getOpposite());
|
|
- if (itemstack1.isEmpty()) {
|
|
+ // CraftBukkit start - Fire event when pushing items into other inventories
|
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.copyWithCount(1));
|
|
+
|
|
+ org.bukkit.inventory.Inventory destinationInventory;
|
|
+ // Have to special case large chests as they work oddly
|
|
+ if (iinventory instanceof InventoryLargeChest) {
|
|
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
|
|
+ } else {
|
|
+ destinationInventory = iinventory.getOwner().getInventory();
|
|
+ }
|
|
+
|
|
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentitydispenser.getOwner().getInventory(), oitemstack, destinationInventory, true);
|
|
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ itemstack1 = TileEntityHopper.addItem(tileentitydispenser, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection.getOpposite());
|
|
+ if (event.getItem().equals(oitemstack) && itemstack1.isEmpty()) {
|
|
+ // CraftBukkit end
|
|
itemstack1 = itemstack.copy();
|
|
itemstack1.shrink(1);
|
|
} else {
|