Paper/nms-patches/TileEntityChest.patch

117 lines
4.0 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/TileEntityChest.java
+++ b/net/minecraft/server/TileEntityChest.java
2016-05-10 13:47:39 +02:00
@@ -4,6 +4,11 @@
import java.util.List;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
2016-02-29 22:32:46 +01:00
public class TileEntityChest extends TileEntityLootable implements ITickable, IInventory {
private ItemStack[] items = new ItemStack[27];
2016-05-10 13:47:39 +02:00
@@ -21,6 +26,31 @@
public TileEntityChest() {}
2015-02-26 23:41:06 +01:00
+ // 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.items;
+ }
+
+ 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
2015-02-26 23:41:06 +01:00
+
2016-02-29 22:32:46 +01:00
public TileEntityChest(BlockChest.Type blockchest_type) {
this.q = blockchest_type;
2015-02-26 23:41:06 +01:00
}
2016-05-10 13:47:39 +02:00
@@ -123,10 +153,11 @@
}
public int getMaxStackSize() {
- return 64;
+ return maxStack; // CraftBukkit
}
public boolean a(EntityHuman entityhuman) {
+ if (this.world == null) return true; // CraftBukkit
return this.world.getTileEntity(this.position) != this ? false : entityhuman.e((double) this.position.getX() + 0.5D, (double) this.position.getY() + 0.5D, (double) this.position.getZ() + 0.5D) <= 64.0D;
}
2016-05-10 13:47:39 +02:00
@@ -303,9 +334,21 @@
if (this.l < 0) {
this.l = 0;
}
+ int oldPower = Math.max(0, Math.min(15, this.l)); // CraftBukkit - Get power before new viewer is added
++this.l;
+ if (this.world == null) return; // CraftBukkit
2016-02-29 22:32:46 +01:00
this.world.playBlockAction(this.position, this.getBlock(), 1, this.l);
+
+ // CraftBukkit start - Call redstone event
2016-02-29 22:32:46 +01:00
+ if (this.getBlock() == Blocks.TRAPPED_CHEST) {
+ int newPower = Math.max(0, Math.min(15, this.l));
+
+ if (oldPower != newPower) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, position.getX(), position.getY(), position.getZ(), oldPower, newPower);
+ }
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.world.applyPhysics(this.position, this.getBlock());
this.world.applyPhysics(this.position.down(), this.getBlock());
}
2016-05-10 13:47:39 +02:00
@@ -314,8 +357,20 @@
public void closeContainer(EntityHuman entityhuman) {
2016-02-29 22:32:46 +01:00
if (!entityhuman.isSpectator() && this.getBlock() instanceof BlockChest) {
+ int oldPower = Math.max(0, Math.min(15, this.l)); // CraftBukkit - Get power before new viewer is added
--this.l;
+ if (this.world == null) return; // CraftBukkit
2016-02-29 22:32:46 +01:00
this.world.playBlockAction(this.position, this.getBlock(), 1, this.l);
2015-02-26 23:41:06 +01:00
+
+ // CraftBukkit start - Call redstone event
2016-02-29 22:32:46 +01:00
+ if (this.getBlock() == Blocks.TRAPPED_CHEST) {
+ int newPower = Math.max(0, Math.min(15, this.l));
+
+ if (oldPower != newPower) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, position.getX(), position.getY(), position.getZ(), oldPower, newPower);
+ }
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.world.applyPhysics(this.position, this.getBlock());
this.world.applyPhysics(this.position.down(), this.getBlock());
}
2016-05-10 13:47:39 +02:00
@@ -372,6 +427,13 @@
2016-03-30 21:50:59 +02:00
}
+ // CraftBukkit start
+ @Override
2016-02-29 22:32:46 +01:00
+ public boolean isFilteredNBT() {
+ return true;
+ }
+ // CraftBukkit end
+
static class SyntheticClass_1 {
static final int[] a = new int[EnumDirection.values().length];