CraftBukkit/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch
2021-11-22 09:00:00 +11:00

59 lines
2.5 KiB
Diff

--- a/net/minecraft/world/level/block/entity/ContainerOpenersCounter.java
+++ b/net/minecraft/world/level/block/entity/ContainerOpenersCounter.java
@@ -13,6 +13,7 @@
private static final int CHECK_TICK_DELAY = 5;
private int openCount;
+ public boolean opened; // CraftBukkit
public ContainerOpenersCounter() {}
@@ -25,8 +26,19 @@
protected abstract boolean isOwnContainer(EntityHuman entityhuman);
public void incrementOpeners(EntityHuman entityhuman, World world, BlockPosition blockposition, IBlockData iblockdata) {
+ int oldPower = Math.max(0, Math.min(15, this.openCount)); // CraftBukkit - Get power before new viewer is added
int i = this.openCount++;
+ // CraftBukkit start - Call redstone event
+ if (world.getBlockState(blockposition).is(net.minecraft.world.level.block.Blocks.TRAPPED_CHEST)) {
+ int newPower = Math.max(0, Math.min(15, this.openCount));
+
+ if (oldPower != newPower) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, blockposition, oldPower, newPower);
+ }
+ }
+ // CraftBukkit end
+
if (i == 0) {
this.onOpen(world, blockposition, iblockdata);
world.gameEvent(entityhuman, GameEvent.CONTAINER_OPEN, blockposition);
@@ -37,8 +49,19 @@
}
public void decrementOpeners(EntityHuman entityhuman, World world, BlockPosition blockposition, IBlockData iblockdata) {
+ int oldPower = Math.max(0, Math.min(15, this.openCount)); // CraftBukkit - Get power before new viewer is added
int i = this.openCount--;
+ // CraftBukkit start - Call redstone event
+ if (world.getBlockState(blockposition).is(net.minecraft.world.level.block.Blocks.TRAPPED_CHEST)) {
+ int newPower = Math.max(0, Math.min(15, this.openCount));
+
+ if (oldPower != newPower) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(world, blockposition, oldPower, newPower);
+ }
+ }
+ // CraftBukkit end
+
if (this.openCount == 0) {
this.onClose(world, blockposition, iblockdata);
world.gameEvent(entityhuman, GameEvent.CONTAINER_CLOSE, blockposition);
@@ -59,6 +82,7 @@
public void recheckOpeners(World world, BlockPosition blockposition, IBlockData iblockdata) {
int i = this.getOpenCount(world, blockposition);
+ if (opened) i++; // CraftBukkit - add dummy count from API
int j = this.openCount;
if (j != i) {