mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2024-11-25 22:06:15 +00:00
76 lines
3.2 KiB
Diff
76 lines
3.2 KiB
Diff
--- a/net/minecraft/world/level/block/entity/ContainerOpenersCounter.java
|
|
+++ b/net/minecraft/world/level/block/entity/ContainerOpenersCounter.java
|
|
@@ -17,6 +17,7 @@
|
|
private static final int CHECK_TICK_DELAY = 5;
|
|
private int openCount;
|
|
private double maxInteractionRange;
|
|
+ public boolean opened; // CraftBukkit
|
|
|
|
public ContainerOpenersCounter() {}
|
|
|
|
@@ -26,11 +27,36 @@
|
|
|
|
protected abstract void openerCountChanged(World world, BlockPosition blockposition, IBlockData iblockdata, int i, int j);
|
|
|
|
+ // CraftBukkit start
|
|
+ public void onAPIOpen(World world, BlockPosition blockposition, IBlockData iblockdata) {
|
|
+ onOpen(world, blockposition, iblockdata);
|
|
+ }
|
|
+
|
|
+ public void onAPIClose(World world, BlockPosition blockposition, IBlockData iblockdata) {
|
|
+ onClose(world, blockposition, iblockdata);
|
|
+ }
|
|
+
|
|
+ public void openerAPICountChanged(World world, BlockPosition blockposition, IBlockData iblockdata, int i, int j) {
|
|
+ openerCountChanged(world, blockposition, iblockdata, i, j);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
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((Entity) entityhuman, (Holder) GameEvent.CONTAINER_OPEN, blockposition);
|
|
@@ -42,8 +68,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((Entity) entityhuman, (Holder) GameEvent.CONTAINER_CLOSE, blockposition);
|
|
@@ -72,6 +109,7 @@
|
|
}
|
|
|
|
int i = list.size();
|
|
+ if (opened) i++; // CraftBukkit - add dummy count from API
|
|
int j = this.openCount;
|
|
|
|
if (j != i) {
|