diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch index fc6223fe0f..dfb1293593 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch @@ -8,7 +8,24 @@ public ContainerOpenersCounter() {} -@@ -25,8 +26,19 @@ +@@ -22,11 +23,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) { @@ -28,7 +45,7 @@ if (i == 0) { this.onOpen(world, blockposition, iblockdata); world.gameEvent((Entity) entityhuman, GameEvent.CONTAINER_OPEN, blockposition); -@@ -37,8 +49,19 @@ +@@ -37,8 +63,19 @@ } public void decrementOpeners(EntityHuman entityhuman, World world, BlockPosition blockposition, IBlockData iblockdata) { @@ -48,7 +65,7 @@ if (this.openCount == 0) { this.onClose(world, blockposition, iblockdata); world.gameEvent((Entity) entityhuman, GameEvent.CONTAINER_CLOSE, blockposition); -@@ -59,6 +82,7 @@ +@@ -59,6 +96,7 @@ public void recheckOpeners(World world, BlockPosition blockposition, IBlockData iblockdata) { int i = this.getOpenCount(world, blockposition); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityEnderChest.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityEnderChest.patch new file mode 100644 index 0000000000..38712ba9b9 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityEnderChest.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/level/block/entity/TileEntityEnderChest.java ++++ b/net/minecraft/world/level/block/entity/TileEntityEnderChest.java +@@ -11,7 +11,7 @@ + public class TileEntityEnderChest extends TileEntity implements LidBlockEntity { + + private final ChestLidController chestLidController = new ChestLidController(); +- private final ContainerOpenersCounter openersCounter = new ContainerOpenersCounter() { ++ public final ContainerOpenersCounter openersCounter = new ContainerOpenersCounter() { + @Override + protected void onOpen(World world, BlockPosition blockposition, IBlockData iblockdata) { + world.playSound((EntityHuman) null, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, SoundEffects.ENDER_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java index 9ec58bc1b7..dcb38cbbb9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java @@ -1,6 +1,5 @@ package org.bukkit.craftbukkit.block; -import net.minecraft.sounds.SoundEffects; import net.minecraft.world.ITileInventory; import net.minecraft.world.level.block.BlockChest; import net.minecraft.world.level.block.Blocks; @@ -58,8 +57,10 @@ public class CraftChest extends CraftLootable implements Chest requirePlaced(); if (!getTileEntity().openersCounter.opened && getWorldHandle() instanceof net.minecraft.world.level.World) { IBlockData block = getTileEntity().getBlockState(); - getTileEntity().getLevel().blockEvent(getPosition(), block.getBlock(), 1, getTileEntity().openersCounter.getOpenerCount() + 1); - TileEntityChest.playSound(getTileEntity().getLevel(), getPosition(), block, SoundEffects.CHEST_OPEN); + int openCount = getTileEntity().openersCounter.getOpenerCount(); + + getTileEntity().openersCounter.onAPIOpen((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block); + getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block, openCount, openCount + 1); } getTileEntity().openersCounter.opened = true; } @@ -69,8 +70,10 @@ public class CraftChest extends CraftLootable implements Chest requirePlaced(); if (getTileEntity().openersCounter.opened && getWorldHandle() instanceof net.minecraft.world.level.World) { IBlockData block = getTileEntity().getBlockState(); - getTileEntity().getLevel().blockEvent(getPosition(), block.getBlock(), 1, 0); - TileEntityChest.playSound(getTileEntity().getLevel(), getPosition(), block, SoundEffects.CHEST_CLOSE); + int openCount = getTileEntity().openersCounter.getOpenerCount(); + + getTileEntity().openersCounter.onAPIClose((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block); + getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block, openCount, 0); } getTileEntity().openersCounter.opened = false; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftEnderChest.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftEnderChest.java index c0cd734ca4..9e65fc72ef 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftEnderChest.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftEnderChest.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.block; import net.minecraft.world.level.block.entity.TileEntityEnderChest; +import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.World; import org.bukkit.block.EnderChest; @@ -9,4 +10,30 @@ public class CraftEnderChest extends CraftBlockEntityState public CraftEnderChest(World world, TileEntityEnderChest tileEntity) { super(world, tileEntity); } + + @Override + public void open() { + requirePlaced(); + if (!getTileEntity().openersCounter.opened && getWorldHandle() instanceof net.minecraft.world.level.World) { + IBlockData block = getTileEntity().getBlockState(); + int openCount = getTileEntity().openersCounter.getOpenerCount(); + + getTileEntity().openersCounter.onAPIOpen((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block); + getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block, openCount, openCount + 1); + } + getTileEntity().openersCounter.opened = true; + } + + @Override + public void close() { + requirePlaced(); + if (getTileEntity().openersCounter.opened && getWorldHandle() instanceof net.minecraft.world.level.World) { + IBlockData block = getTileEntity().getBlockState(); + int openCount = getTileEntity().openersCounter.getOpenerCount(); + + getTileEntity().openersCounter.onAPIClose((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block); + getTileEntity().openersCounter.openerAPICountChanged((net.minecraft.world.level.World) getWorldHandle(), getPosition(), block, openCount, 0); + } + getTileEntity().openersCounter.opened = false; + } }