2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/TileEntityHopper.java
|
|
|
|
+++ b/net/minecraft/server/TileEntityHopper.java
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -7,12 +7,51 @@
|
|
|
|
import java.util.stream.IntStream;
|
2016-05-10 13:47:39 +02:00
|
|
|
import javax.annotation.Nullable;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
|
|
+import org.bukkit.entity.HumanEntity;
|
|
|
|
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
|
|
|
+import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
|
|
|
+import org.bukkit.inventory.Inventory;
|
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
public class TileEntityHopper extends TileEntityLootable implements IHopper, ITickable {
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
private NonNullList<ItemStack> items;
|
2019-04-23 04:00:00 +02:00
|
|
|
private int j;
|
|
|
|
private long k;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - add fields and methods
|
|
|
|
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
|
|
|
+ private int maxStack = MAX_STACK;
|
|
|
|
+
|
2016-11-17 02:41:03 +01:00
|
|
|
+ public List<ItemStack> getContents() {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return this.items;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void onOpen(CraftHumanEntity who) {
|
|
|
|
+ transaction.add(who);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void onClose(CraftHumanEntity who) {
|
|
|
|
+ transaction.remove(who);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<HumanEntity> getViewers() {
|
|
|
|
+ return transaction;
|
|
|
|
+ }
|
|
|
|
+
|
2019-04-23 04:00:00 +02:00
|
|
|
+ @Override
|
|
|
|
+ public int getMaxStackSize() {
|
|
|
|
+ return maxStack;
|
|
|
|
+ }
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public void setMaxStackSize(int size) {
|
|
|
|
+ maxStack = size;
|
|
|
|
+ }
|
2015-02-26 23:41:06 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
+
|
2016-11-17 02:41:03 +01:00
|
|
|
public TileEntityHopper() {
|
2018-08-26 04:00:00 +02:00
|
|
|
super(TileEntityTypes.HOPPER);
|
2016-11-17 02:41:03 +01:00
|
|
|
this.items = NonNullList.a(5, ItemStack.a);
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -159,7 +198,28 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
for (int i = 0; i < this.getSize(); ++i) {
|
2016-11-17 02:41:03 +01:00
|
|
|
if (!this.getItem(i).isEmpty()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
ItemStack itemstack = this.getItem(i).cloneItemStack();
|
2016-11-17 02:41:03 +01:00
|
|
|
- ItemStack itemstack1 = addItem(this, iinventory, this.splitStack(i, 1), enumdirection);
|
|
|
|
+ // ItemStack itemstack1 = addItem(this, iinventory, this.splitStack(i, 1), enumdirection);
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - Call event when pushing items into other inventories
|
|
|
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(this.splitStack(i, 1));
|
|
|
|
+
|
|
|
|
+ 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(this.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true);
|
|
|
|
+ this.getWorld().getServer().getPluginManager().callEvent(event);
|
|
|
|
+ if (event.isCancelled()) {
|
|
|
|
+ this.setItem(i, itemstack);
|
2017-01-26 04:08:04 +01:00
|
|
|
+ this.setCooldown(8); // Delay hopper checks
|
|
|
|
+ return false;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2016-11-17 02:41:03 +01:00
|
|
|
+ ItemStack itemstack1 = addItem(this, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection);
|
2018-11-19 10:59:37 +01:00
|
|
|
+ // CraftBukkit end
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
if (itemstack1.isEmpty()) {
|
2018-11-19 10:59:37 +01:00
|
|
|
iinventory.update();
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -224,7 +284,34 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
if (!itemstack.isEmpty() && b(iinventory, itemstack, i, enumdirection)) {
|
2014-11-25 22:32:16 +01:00
|
|
|
ItemStack itemstack1 = itemstack.cloneItemStack();
|
2016-11-17 02:41:03 +01:00
|
|
|
- ItemStack itemstack2 = addItem(iinventory, ihopper, iinventory.splitStack(i, 1), (EnumDirection) null);
|
|
|
|
+ // ItemStack itemstack2 = addItem(iinventory, ihopper, iinventory.splitStack(i, 1), (EnumDirection) null);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - Call event on collection of items from inventories into the hopper
|
|
|
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.splitStack(i, 1));
|
|
|
|
+
|
|
|
|
+ Inventory sourceInventory;
|
|
|
|
+ // Have to special case large chests as they work oddly
|
|
|
|
+ if (iinventory instanceof InventoryLargeChest) {
|
|
|
|
+ sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
|
|
|
|
+ } else {
|
|
|
|
+ sourceInventory = iinventory.getOwner().getInventory();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, oitemstack.clone(), ihopper.getOwner().getInventory(), false);
|
|
|
|
+
|
|
|
|
+ ihopper.getWorld().getServer().getPluginManager().callEvent(event);
|
|
|
|
+ if (event.isCancelled()) {
|
|
|
|
+ iinventory.setItem(i, itemstack1);
|
|
|
|
+
|
|
|
|
+ if (ihopper instanceof TileEntityHopper) {
|
2016-02-29 22:32:46 +01:00
|
|
|
+ ((TileEntityHopper) ihopper).setCooldown(8); // Delay hopper checks
|
2014-11-25 22:32:16 +01:00
|
|
|
+ } else if (ihopper instanceof EntityMinecartHopper) {
|
2016-02-29 22:32:46 +01:00
|
|
|
+ ((EntityMinecartHopper) ihopper).setCooldown(4); // Delay hopper minecart checks
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
2016-11-17 02:41:03 +01:00
|
|
|
+ ItemStack itemstack2 = addItem(iinventory, ihopper, CraftItemStack.asNMSCopy(event.getItem()), null);
|
2018-11-19 10:59:37 +01:00
|
|
|
+ // CraftBukkit end
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
if (itemstack2.isEmpty()) {
|
2018-11-19 10:59:37 +01:00
|
|
|
iinventory.update();
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -239,6 +326,13 @@
|
2018-07-15 02:00:00 +02:00
|
|
|
|
|
|
|
public static boolean a(IInventory iinventory, EntityItem entityitem) {
|
|
|
|
boolean flag = false;
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ InventoryPickupItemEvent event = new InventoryPickupItemEvent(iinventory.getOwner().getInventory(), (org.bukkit.entity.Item) entityitem.getBukkitEntity());
|
|
|
|
+ entityitem.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
+ if (event.isCancelled()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
ItemStack itemstack = entityitem.getItemStack().cloneItemStack();
|
|
|
|
ItemStack itemstack1 = addItem((IInventory) null, iinventory, itemstack, (EnumDirection) null);
|
2014-11-25 22:32:16 +01:00
|
|
|
|