mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 10:46:05 +03:00
197 lines
9.2 KiB
Diff
197 lines
9.2 KiB
Diff
--- ../src-base/minecraft/net/minecraft/tileentity/TileEntityHopper.java
|
|
+++ ../src-work/minecraft/net/minecraft/tileentity/TileEntityHopper.java
|
|
@@ -27,12 +27,49 @@
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.MathHelper;
|
|
import net.minecraft.world.World;
|
|
+import luohuayu.CatServer.tileentity.CBTileEntityLockableLoot;
|
|
|
|
-public class TileEntityHopper extends TileEntityLockableLoot implements IHopper, ITickable
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
+import org.bukkit.entity.HumanEntity;
|
|
+
|
|
+//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
|
|
+
|
|
+public class TileEntityHopper extends CBTileEntityLockableLoot implements IHopper, ITickable
|
|
{
|
|
private ItemStack[] inventory = new ItemStack[5];
|
|
private String customName;
|
|
private int transferCooldown = -1;
|
|
+ // CraftBukkit start - add fields and methods
|
|
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
|
+ private int maxStack = MAX_STACK;
|
|
+
|
|
+ public ItemStack[] getContents() {
|
|
+ return this.inventory;
|
|
+ }
|
|
+
|
|
+ public void onOpen(CraftHumanEntity who) {
|
|
+ transaction.add(who);
|
|
+ }
|
|
+
|
|
+ public void onClose(CraftHumanEntity who) {
|
|
+ transaction.remove(who);
|
|
+ }
|
|
+
|
|
+ public List<HumanEntity> getViewers() {
|
|
+ return transaction;
|
|
+ }
|
|
+
|
|
+ public void setMaxStackSize(int size) {
|
|
+ maxStack = size;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
public static void registerFixesHopper(DataFixer fixer)
|
|
{
|
|
@@ -154,7 +191,7 @@
|
|
|
|
public int getInventoryStackLimit()
|
|
{
|
|
- return 64;
|
|
+ return maxStack; // CraftBukkit
|
|
}
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer player)
|
|
@@ -209,7 +246,7 @@
|
|
|
|
if (flag)
|
|
{
|
|
- this.setTransferCooldown(8);
|
|
+ this.setTransferCooldown(worldObj.spigotConfig.hopperTransfer); // Spigot
|
|
this.markDirty();
|
|
return true;
|
|
}
|
|
@@ -273,14 +310,40 @@
|
|
if (this.getStackInSlot(i) != null)
|
|
{
|
|
ItemStack itemstack = this.getStackInSlot(i).copy();
|
|
- ItemStack itemstack1 = putStackInInventoryAllSlots(iinventory, this.decrStackSize(i, 1), enumfacing);
|
|
+ // ItemStack itemstack1 = putStackInInventoryAllSlots(iinventory, this.decrStackSize(i, 1), enumfacing);
|
|
|
|
+ // CraftBukkit start - Call event when pushing items into other inventories
|
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(this.decrStackSize(i, worldObj.spigotConfig.hopperAmount)); // Spigot
|
|
+
|
|
+ Inventory destinationInventory;
|
|
+ // Have to special case large chests as they work oddly
|
|
+ if (iinventory instanceof net.minecraft.inventory.InventoryLargeChest) {
|
|
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((net.minecraft.inventory.InventoryLargeChest) iinventory);
|
|
+ } else {
|
|
+ destinationInventory = iinventory.getOwner() != null ? iinventory.getOwner().getInventory() : null;
|
|
+ }
|
|
+
|
|
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(this.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true);
|
|
+ if (destinationInventory != null) this.getWorld().getServer().getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ this.setInventorySlotContents(i, itemstack);
|
|
+ this.setTransferCooldown(worldObj.spigotConfig.hopperTransfer); // Spigot
|
|
+ return false;
|
|
+ }
|
|
+ int origCount = event.getItem().getAmount(); // Spigot
|
|
+ ItemStack itemstack1 = putStackInInventoryAllSlots(iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumfacing);
|
|
+
|
|
if (itemstack1 == null || itemstack1.stackSize == 0)
|
|
{
|
|
- iinventory.markDirty();
|
|
+ if (event.getItem().equals(oitemstack)) {
|
|
+ iinventory.markDirty();
|
|
+ } else {
|
|
+ this.setInventorySlotContents(i, itemstack);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
return true;
|
|
}
|
|
-
|
|
+ itemstack.stackSize -= origCount - itemstack1.stackSize; // Spigot
|
|
this.setInventorySlotContents(i, itemstack);
|
|
}
|
|
}
|
|
@@ -418,14 +481,46 @@
|
|
if (itemstack != null && canExtractItemFromSlot(inventoryIn, itemstack, index, direction))
|
|
{
|
|
ItemStack itemstack1 = itemstack.copy();
|
|
- ItemStack itemstack2 = putStackInInventoryAllSlots(hopper, inventoryIn.decrStackSize(index, 1), (EnumFacing)null);
|
|
+ //ItemStack itemstack2 = putStackInInventoryAllSlots(hopper, inventoryIn.decrStackSize(index, 1), (EnumFacing)null);
|
|
+ // CraftBukkit start - Call event on collection of items from inventories into the hopper
|
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(inventoryIn.decrStackSize(index, hopper.getWorld().spigotConfig.hopperAmount)); // Spigot
|
|
|
|
+ Inventory sourceInventory;
|
|
+ // Have to special case large chests as they work oddly
|
|
+ if (inventoryIn instanceof net.minecraft.inventory.InventoryLargeChest) {
|
|
+ sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((net.minecraft.inventory.InventoryLargeChest) inventoryIn);
|
|
+ } else {
|
|
+ sourceInventory = inventoryIn.getOwner() != null ? inventoryIn.getOwner().getInventory() : null;
|
|
+ }
|
|
+
|
|
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, oitemstack.clone(), hopper.getOwner().getInventory(), false);
|
|
+
|
|
+ if (sourceInventory != null) hopper.getWorld().getServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ inventoryIn.setInventorySlotContents(index, itemstack1);
|
|
+
|
|
+ if (hopper instanceof TileEntityHopper) {
|
|
+ ((TileEntityHopper) hopper).setTransferCooldown(hopper.getWorld().spigotConfig.hopperTransfer); // Spigot
|
|
+ } else if (hopper instanceof net.minecraft.entity.item.EntityMinecartHopper) {
|
|
+ ((net.minecraft.entity.item.EntityMinecartHopper) hopper).setTransferTicker(hopper.getWorld().spigotConfig.hopperTransfer / 2); // Spigot
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+ int origCount = event.getItem().getAmount(); // Spigot
|
|
+ ItemStack itemstack2 = putStackInInventoryAllSlots(hopper, CraftItemStack.asNMSCopy(event.getItem()), null);
|
|
+
|
|
if (itemstack2 == null || itemstack2.stackSize == 0)
|
|
{
|
|
- inventoryIn.markDirty();
|
|
+ if (event.getItem().equals(oitemstack)) {
|
|
+ inventoryIn.markDirty();
|
|
+ } else {
|
|
+ inventoryIn.setInventorySlotContents(index, itemstack1);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
return true;
|
|
}
|
|
-
|
|
+ itemstack1.stackSize -= origCount - itemstack2.stackSize; // Spigot
|
|
inventoryIn.setInventorySlotContents(index, itemstack1);
|
|
}
|
|
|
|
@@ -442,6 +537,13 @@
|
|
}
|
|
else
|
|
{
|
|
+ // CraftBukkit start
|
|
+ InventoryPickupItemEvent event = new InventoryPickupItemEvent(p_145898_0_.getOwner().getInventory(), (org.bukkit.entity.Item)itemIn.getBukkitEntity());
|
|
+ itemIn.worldObj.getServer().getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ return false;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
ItemStack itemstack = itemIn.getEntityItem().copy();
|
|
ItemStack itemstack1 = putStackInInventoryAllSlots(p_145898_0_, itemstack, (EnumFacing)null);
|
|
|
|
@@ -544,7 +646,7 @@
|
|
|
|
if (tileentityhopper.mayTransfer())
|
|
{
|
|
- tileentityhopper.setTransferCooldown(8);
|
|
+ tileentityhopper.setTransferCooldown(tileentityhopper.worldObj.spigotConfig.hopperTransfer); // Spigot
|
|
}
|
|
|
|
inventoryIn.markDirty();
|
|
@@ -580,6 +682,7 @@
|
|
int j = MathHelper.floor_double(y);
|
|
int k = MathHelper.floor_double(z);
|
|
BlockPos blockpos = new BlockPos(i, j, k);
|
|
+ if (!worldIn.isBlockLoaded(blockpos)) return null; // Spigot
|
|
Block block = worldIn.getBlockState(blockpos).getBlock();
|
|
|
|
if (block.hasTileEntity())
|