mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 07:19:56 +03:00
133 lines
4.6 KiB
Diff
133 lines
4.6 KiB
Diff
--- ../src-base/minecraft/net/minecraft/tileentity/TileEntityChest.java
|
|
+++ ../src-work/minecraft/net/minecraft/tileentity/TileEntityChest.java
|
|
@@ -1,10 +1,15 @@
|
|
package net.minecraft.tileentity;
|
|
|
|
import javax.annotation.Nullable;
|
|
+
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
+import org.bukkit.entity.HumanEntity;
|
|
+
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockChest;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
+import net.minecraft.init.Blocks;
|
|
import net.minecraft.init.SoundEvents;
|
|
import net.minecraft.inventory.Container;
|
|
import net.minecraft.inventory.ContainerChest;
|
|
@@ -23,6 +28,8 @@
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
+import java.util.List;
|
|
+
|
|
public class TileEntityChest extends TileEntityLockableLoot implements ITickable
|
|
{
|
|
private NonNullList<ItemStack> chestContents = NonNullList.<ItemStack>withSize(27, ItemStack.EMPTY);
|
|
@@ -36,7 +43,30 @@
|
|
public int numPlayersUsing;
|
|
private int ticksSinceSync;
|
|
private BlockChest.Type cachedChestType;
|
|
-
|
|
+ // CraftBukkit start - add fields and methods
|
|
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
|
+ private int maxStack = MAX_STACK;
|
|
+
|
|
+ public List<ItemStack> getContents() {
|
|
+ return this.chestContents;
|
|
+ }
|
|
+
|
|
+ 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 TileEntityChest()
|
|
{
|
|
}
|
|
@@ -109,13 +139,14 @@
|
|
|
|
public int getInventoryStackLimit()
|
|
{
|
|
- return 64;
|
|
+ return maxStack;
|
|
}
|
|
|
|
public void updateContainingBlockInfo()
|
|
{
|
|
super.updateContainingBlockInfo();
|
|
this.adjacentChestChecked = false;
|
|
+ doubleChestHandler = null;
|
|
}
|
|
|
|
@SuppressWarnings("incomplete-switch")
|
|
@@ -167,6 +198,7 @@
|
|
{
|
|
if (!this.adjacentChestChecked)
|
|
{
|
|
+ if (this.world == null || !this.world.isAreaLoaded(this.pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbors
|
|
this.adjacentChestChecked = true;
|
|
this.adjacentChestXNeg = this.getAdjacentChest(EnumFacing.WEST);
|
|
this.adjacentChestXPos = this.getAdjacentChest(EnumFacing.EAST);
|
|
@@ -323,8 +355,18 @@
|
|
this.numPlayersUsing = 0;
|
|
}
|
|
|
|
+ int oldPower = Math.max(0, Math.min(15, this.numPlayersUsing)); // CraftBukkit - Get power before new viewer is added
|
|
+
|
|
++this.numPlayersUsing;
|
|
+ if (this.world == null) return;
|
|
this.world.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing);
|
|
+ if (this.getBlockType() == Blocks.TRAPPED_CHEST) {
|
|
+ int newPower = Math.max(0, Math.min(15, this.numPlayersUsing));
|
|
+
|
|
+ if (oldPower != newPower) {
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, pos.getX(), pos.getY(), pos.getZ(), oldPower, newPower);
|
|
+ }
|
|
+ }
|
|
this.world.notifyNeighborsOfStateChange(this.pos, this.getBlockType(), false);
|
|
|
|
if (this.getChestType() == BlockChest.Type.TRAP)
|
|
@@ -349,6 +391,29 @@
|
|
}
|
|
}
|
|
|
|
+ public net.minecraftforge.items.VanillaDoubleChestItemHandler doubleChestHandler;
|
|
+
|
|
+ @SuppressWarnings("unchecked")
|
|
+ @Override
|
|
+ @Nullable
|
|
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable EnumFacing facing)
|
|
+ {
|
|
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
|
+ {
|
|
+ if(doubleChestHandler == null || doubleChestHandler.needsRefresh())
|
|
+ doubleChestHandler = net.minecraftforge.items.VanillaDoubleChestItemHandler.get(this);
|
|
+ if (doubleChestHandler != null && doubleChestHandler != net.minecraftforge.items.VanillaDoubleChestItemHandler.NO_ADJACENT_CHESTS_INSTANCE)
|
|
+ return (T) doubleChestHandler;
|
|
+ }
|
|
+ return super.getCapability(capability, facing);
|
|
+ }
|
|
+
|
|
+ public net.minecraftforge.items.IItemHandler getSingleChestHandler()
|
|
+ {
|
|
+ return super.getCapability(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
|
+ }
|
|
+
|
|
+
|
|
public void invalidate()
|
|
{
|
|
super.invalidate();
|