From 5209a4f731f22dbe87a7e90a2f6f0dbbaae1a9c0 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 5 Jul 2020 08:53:26 +1000 Subject: [PATCH] SPIGOT-5940: EntityChangeBlockEvent is not called for villager emptying composter --- nms-patches/BehaviorWorkComposter.patch | 9 ++++++ nms-patches/BlockComposter.patch | 39 ++++++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/nms-patches/BehaviorWorkComposter.patch b/nms-patches/BehaviorWorkComposter.patch index 0c6c71b884..1c02031df3 100644 --- a/nms-patches/BehaviorWorkComposter.patch +++ b/nms-patches/BehaviorWorkComposter.patch @@ -9,6 +9,15 @@ Optional optional = entityvillager.getBehaviorController().getMemory(MemoryModuleType.JOB_SITE); if (optional.isPresent()) { +@@ -28,7 +28,7 @@ + + private void a(WorldServer worldserver, EntityVillager entityvillager, GlobalPos globalpos, IBlockData iblockdata) { + if ((Integer) iblockdata.get(BlockComposter.a) == 8) { +- iblockdata = BlockComposter.d(iblockdata, (World) worldserver, globalpos.getBlockPosition()); ++ iblockdata = BlockComposter.d(iblockdata, (World) worldserver, globalpos.getBlockPosition(), entityvillager); // CraftBukkit + } + + int i = 20; @@ -52,7 +52,7 @@ i -= k1; diff --git a/nms-patches/BlockComposter.patch b/nms-patches/BlockComposter.patch index af395f26a3..02af604e98 100644 --- a/nms-patches/BlockComposter.patch +++ b/nms-patches/BlockComposter.patch @@ -19,12 +19,20 @@ for (int i = 0; i < 8; ++i) { avoxelshape[i] = VoxelShapes.a(BlockComposter.c, Block.a(2.0D, (double) Math.max(2, 1 + i * 2), 2.0D, 14.0D, 16.0D, 14.0D), OperatorBoolean.ONLY_FIRST); } -@@ -163,11 +167,18 @@ +@@ -156,18 +160,25 @@ + + return EnumInteractionResult.a(world.isClientSide); + } else if (i == 8) { +- d(iblockdata, world, blockposition); ++ d(iblockdata, world, blockposition, (Entity) null); // CraftBukkit - no event for players + return EnumInteractionResult.a(world.isClientSide); + } else { + return EnumInteractionResult.PASS; } } - public static IBlockData a(IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition) { -+ public static IBlockData a(IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition, EntityVillager entity) { // CraftBukkit ++ public static IBlockData a(IBlockData iblockdata, WorldServer worldserver, ItemStack itemstack, BlockPosition blockposition, Entity entity) { // CraftBukkit int i = (Integer) iblockdata.get(BlockComposter.a); if (i < 7 && BlockComposter.b.containsKey(itemstack.getItem())) { @@ -40,7 +48,24 @@ itemstack.subtract(1); worldserver.triggerEffect(1500, blockposition, iblockdata != iblockdata1 ? 1 : 0); -@@ -203,10 +214,16 @@ +@@ -177,7 +188,15 @@ + } + } + +- public static IBlockData d(IBlockData iblockdata, World world, BlockPosition blockposition) { ++ // CraftBukkit start ++ public static IBlockData d(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { ++ if (entity != null) { ++ IBlockData iblockdata1 = d(iblockdata, DummyGeneratorAccess.INSTANCE, blockposition); ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1).isCancelled()) { ++ return iblockdata; ++ } ++ } ++ // CraftBukkit end + if (!world.isClientSide) { + float f = 0.7F; + double d0 = (double) (world.random.nextFloat() * 0.7F) + 0.15000000596046448D; +@@ -203,10 +222,16 @@ } private static IBlockData b(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack) { @@ -58,7 +83,7 @@ return iblockdata; } else { int j = i + 1; -@@ -254,7 +271,8 @@ +@@ -254,7 +279,8 @@ public IWorldInventory a(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) { int i = (Integer) iblockdata.get(BlockComposter.a); @@ -68,7 +93,7 @@ } static class ContainerInput extends InventorySubcontainer implements IWorldInventory { -@@ -266,6 +284,7 @@ +@@ -266,6 +292,7 @@ public ContainerInput(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) { super(1); @@ -76,7 +101,7 @@ this.a = iblockdata; this.b = generatoraccess; this.c = blockposition; -@@ -318,6 +337,7 @@ +@@ -318,6 +345,7 @@ this.blockData = iblockdata; this.generatorAccess = generatoraccess; this.blockPosition = blockposition; @@ -84,7 +109,7 @@ } @Override -@@ -342,15 +362,23 @@ +@@ -342,15 +370,23 @@ @Override public void update() {