From d47c47ee59e7d3fa3f70fdf8ad1eef389bfaf0b2 Mon Sep 17 00:00:00 2001 From: Parker Hawke Date: Tue, 30 Jun 2020 12:18:39 +1000 Subject: [PATCH] SPIGOT-5889: Villager using composter should call EntityChangeBlockEvent --- nms-patches/BehaviorWork.patch | 26 ++++++++++++++ nms-patches/BehaviorWorkComposter.patch | 20 +++++++++++ nms-patches/BlockComposter.patch | 35 +++++++++++++++---- .../util/DummyGeneratorAccess.java | 8 +++-- 4 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 nms-patches/BehaviorWork.patch create mode 100644 nms-patches/BehaviorWorkComposter.patch diff --git a/nms-patches/BehaviorWork.patch b/nms-patches/BehaviorWork.patch new file mode 100644 index 0000000000..b2973100e2 --- /dev/null +++ b/nms-patches/BehaviorWork.patch @@ -0,0 +1,26 @@ +--- a/net/minecraft/server/BehaviorWork.java ++++ b/net/minecraft/server/BehaviorWork.java +@@ -27,19 +27,19 @@ + protected void a(WorldServer worldserver, EntityVillager entityvillager, long i) { + BehaviorController behaviorcontroller = entityvillager.getBehaviorController(); + +- behaviorcontroller.setMemory(MemoryModuleType.LAST_WORKED_AT_POI, (Object) i); ++ behaviorcontroller.setMemory(MemoryModuleType.LAST_WORKED_AT_POI, i); // CraftBukkit - decompile error + behaviorcontroller.getMemory(MemoryModuleType.JOB_SITE).ifPresent((globalpos) -> { +- behaviorcontroller.setMemory(MemoryModuleType.LOOK_TARGET, (Object) (new BehaviorTarget(globalpos.getBlockPosition()))); ++ behaviorcontroller.setMemory(MemoryModuleType.LOOK_TARGET, (new BehaviorTarget(globalpos.getBlockPosition()))); // CraftBukkit - decompile error + }); + entityvillager.fd(); +- this.a(worldserver, entityvillager); ++ this.doWork(worldserver, entityvillager); // PAIL + if (entityvillager.fc()) { + entityvillager.fb(); + } + + } + +- protected void a(WorldServer worldserver, EntityVillager entityvillager) {} ++ protected void doWork(WorldServer worldserver, EntityVillager entityvillager) {} // PAIL + + protected boolean b(WorldServer worldserver, EntityVillager entityvillager, long i) { + Optional optional = entityvillager.getBehaviorController().getMemory(MemoryModuleType.JOB_SITE); diff --git a/nms-patches/BehaviorWorkComposter.patch b/nms-patches/BehaviorWorkComposter.patch new file mode 100644 index 0000000000..0c6c71b884 --- /dev/null +++ b/nms-patches/BehaviorWorkComposter.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/server/BehaviorWorkComposter.java ++++ b/net/minecraft/server/BehaviorWorkComposter.java +@@ -11,7 +11,7 @@ + public BehaviorWorkComposter() {} + + @Override +- protected void a(WorldServer worldserver, EntityVillager entityvillager) { ++ protected void doWork(WorldServer worldserver, EntityVillager entityvillager) { // PAIL + Optional optional = entityvillager.getBehaviorController().getMemory(MemoryModuleType.JOB_SITE); + + if (optional.isPresent()) { +@@ -52,7 +52,7 @@ + i -= k1; + + for (int l1 = 0; l1 < k1; ++l1) { +- iblockdata = BlockComposter.a(iblockdata, worldserver, itemstack, globalpos.getBlockPosition()); ++ iblockdata = BlockComposter.a(iblockdata, worldserver, itemstack, globalpos.getBlockPosition(), entityvillager); // CraftBukkit + if ((Integer) iblockdata.get(BlockComposter.a) == 7) { + return; + } diff --git a/nms-patches/BlockComposter.patch b/nms-patches/BlockComposter.patch index c46e7761a2..83229e808e 100644 --- a/nms-patches/BlockComposter.patch +++ b/nms-patches/BlockComposter.patch @@ -1,10 +1,13 @@ --- a/net/minecraft/server/BlockComposter.java +++ b/net/minecraft/server/BlockComposter.java -@@ -4,13 +4,14 @@ +@@ -4,13 +4,17 @@ import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; import java.util.Random; import javax.annotation.Nullable; -+import org.bukkit.craftbukkit.inventory.CraftBlockInventoryHolder; // CraftBukkit ++// CraftBukkit start ++import org.bukkit.craftbukkit.inventory.CraftBlockInventoryHolder; ++import org.bukkit.craftbukkit.util.DummyGeneratorAccess; ++// CraftBukkit end public class BlockComposter extends Block implements IInventoryHolder { @@ -16,7 +19,27 @@ 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); } -@@ -254,7 +255,8 @@ +@@ -163,11 +167,17 @@ + } + } + +- 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 + int i = (Integer) iblockdata.get(BlockComposter.a); + + if (i < 7 && BlockComposter.b.containsKey(itemstack.getItem())) { +- IBlockData iblockdata1 = b(iblockdata, (GeneratorAccess) worldserver, blockposition, itemstack); ++ // CraftBukkit start ++ IBlockData iblockdata1 = b(iblockdata, DummyGeneratorAccess.INSTANCE, blockposition, itemstack); ++ if (iblockdata == iblockdata1 || org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata1).isCancelled()) { ++ return iblockdata; ++ } ++ iblockdata1 = b(iblockdata, (GeneratorAccess) worldserver, blockposition, itemstack); ++ // CraftBukkit end + + itemstack.subtract(1); + worldserver.triggerEffect(1500, blockposition, iblockdata != iblockdata1 ? 1 : 0); +@@ -254,7 +264,8 @@ public IWorldInventory a(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) { int i = (Integer) iblockdata.get(BlockComposter.a); @@ -26,7 +49,7 @@ } static class ContainerInput extends InventorySubcontainer implements IWorldInventory { -@@ -266,6 +268,7 @@ +@@ -266,6 +277,7 @@ public ContainerInput(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) { super(1); @@ -34,7 +57,7 @@ this.a = iblockdata; this.b = generatoraccess; this.c = blockposition; -@@ -318,6 +321,7 @@ +@@ -318,6 +330,7 @@ this.blockData = iblockdata; this.generatorAccess = generatoraccess; this.blockPosition = blockposition; @@ -42,7 +65,7 @@ } @Override -@@ -342,15 +346,23 @@ +@@ -342,15 +355,23 @@ @Override public void update() { diff --git a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java index 254bc29d71..99a49ae136 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java +++ b/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java @@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.util; import java.util.List; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import java.util.function.Predicate; import net.minecraft.server.AxisAlignedBB; import net.minecraft.server.BiomeBase; @@ -25,6 +26,7 @@ import net.minecraft.server.ParticleParam; import net.minecraft.server.SoundCategory; import net.minecraft.server.SoundEffect; import net.minecraft.server.TickList; +import net.minecraft.server.TickListEmpty; import net.minecraft.server.TileEntity; import net.minecraft.server.World; import net.minecraft.server.WorldBorder; @@ -39,12 +41,12 @@ public class DummyGeneratorAccess implements GeneratorAccess { @Override public TickList getBlockTickList() { - throw new UnsupportedOperationException("Not supported yet."); + return TickListEmpty.b(); } @Override public TickList getFluidTickList() { - throw new UnsupportedOperationException("Not supported yet."); + return TickListEmpty.b(); } @Override @@ -69,7 +71,7 @@ public class DummyGeneratorAccess implements GeneratorAccess { @Override public Random getRandom() { - throw new UnsupportedOperationException("Not supported yet."); + return ThreadLocalRandom.current(); } @Override