From 7c44152eba07cb9dae98974a36677a7057fe8e4a Mon Sep 17 00:00:00 2001 From: FreeSoccerHDX Date: Sun, 5 Feb 2023 11:06:25 +1100 Subject: [PATCH] SPIGOT-7224: Add events for brewing stands and campfires starting their actions --- .../block/entity/TileEntityBrewingStand.patch | 24 +++++++++++++++---- .../block/entity/TileEntityCampfire.patch | 19 +++++++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch b/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch index 19d99fef9..7c920860c 100644 --- a/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch +++ b/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java +++ b/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java -@@ -24,6 +24,19 @@ +@@ -24,6 +24,20 @@ import net.minecraft.world.level.block.BlockBrewingStand; import net.minecraft.world.level.block.state.IBlockData; @@ -12,6 +12,7 @@ +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.entity.HumanEntity; ++import org.bukkit.event.block.BrewingStartEvent; +import org.bukkit.event.inventory.BrewEvent; +import org.bukkit.event.inventory.BrewingStandFuelEvent; +import org.bukkit.inventory.InventoryHolder; @@ -20,7 +21,7 @@ public class TileEntityBrewingStand extends TileEntityContainer implements IWorldInventory { private static final int INGREDIENT_SLOT = 3; -@@ -41,6 +54,36 @@ +@@ -41,6 +55,36 @@ private Item ingredient; public int fuel; protected final IContainerProperties dataAccess; @@ -57,7 +58,7 @@ public TileEntityBrewingStand(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.BREWING_STAND, blockposition, iblockdata); -@@ -108,8 +151,19 @@ +@@ -108,8 +152,19 @@ ItemStack itemstack = (ItemStack) tileentitybrewingstand.items.get(4); if (tileentitybrewingstand.fuel <= 0 && itemstack.is(Items.BLAZE_POWDER)) { @@ -79,7 +80,7 @@ setChanged(world, blockposition, iblockdata); } -@@ -117,12 +171,17 @@ +@@ -117,12 +172,17 @@ boolean flag1 = tileentitybrewingstand.brewTime > 0; ItemStack itemstack1 = (ItemStack) tileentitybrewingstand.items.get(3); @@ -100,7 +101,20 @@ setChanged(world, blockposition, iblockdata); } else if (!flag || !itemstack1.is(tileentitybrewingstand.ingredient)) { tileentitybrewingstand.brewTime = 0; -@@ -186,11 +245,33 @@ +@@ -130,7 +190,11 @@ + } + } else if (flag && tileentitybrewingstand.fuel > 0) { + --tileentitybrewingstand.fuel; +- tileentitybrewingstand.brewTime = 400; ++ // CraftBukkit start ++ BrewingStartEvent event = new BrewingStartEvent(CraftBlock.at(world, blockposition), CraftItemStack.asCraftMirror(itemstack1), 400); ++ world.getCraftServer().getPluginManager().callEvent(event); ++ tileentitybrewingstand.brewTime = event.getTotalBrewTime(); // 400 -> event.getTotalBrewTime() ++ // CraftBukkit end + tileentitybrewingstand.ingredient = itemstack1.getItem(); + setChanged(world, blockposition, iblockdata); + } +@@ -186,11 +250,33 @@ } } diff --git a/nms-patches/net/minecraft/world/level/block/entity/TileEntityCampfire.patch b/nms-patches/net/minecraft/world/level/block/entity/TileEntityCampfire.patch index 4be4c3530..fa7e0db83 100644 --- a/nms-patches/net/minecraft/world/level/block/entity/TileEntityCampfire.patch +++ b/nms-patches/net/minecraft/world/level/block/entity/TileEntityCampfire.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityCampfire.java +++ b/net/minecraft/world/level/block/entity/TileEntityCampfire.java -@@ -25,6 +25,12 @@ +@@ -25,6 +25,14 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.gameevent.GameEvent; @@ -8,12 +8,14 @@ +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.block.BlockCookEvent; ++import org.bukkit.event.block.CampfireStartEvent; ++import org.bukkit.inventory.CampfireRecipe; +// CraftBukkit end + public class TileEntityCampfire extends TileEntity implements Clearable { private static final int BURN_COOL_SPEED = 2; -@@ -59,6 +65,20 @@ +@@ -59,6 +67,20 @@ }).orElse(itemstack); if (itemstack1.isItemEnabled(world.enabledFeatures())) { @@ -34,3 +36,16 @@ InventoryUtils.dropItemStack(world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack1); tileentitycampfire.items.set(i, ItemStack.EMPTY); world.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3); +@@ -171,7 +193,11 @@ + ItemStack itemstack1 = (ItemStack) this.items.get(j); + + if (itemstack1.isEmpty()) { +- this.cookingTime[j] = i; ++ // CraftBukkit start ++ CampfireStartEvent event = new CampfireStartEvent(CraftBlock.at(this.level,this.worldPosition), CraftItemStack.asCraftMirror(itemstack), (CampfireRecipe) getCookableRecipe(itemstack).get().toBukkitRecipe()); ++ this.level.getCraftServer().getPluginManager().callEvent(event); ++ this.cookingTime[j] = event.getTotalCookTime(); // i -> event.getTotalCookTime() ++ // CraftBukkit end + this.cookingProgress[j] = 0; + this.items.set(j, itemstack.split(1)); + this.level.gameEvent(GameEvent.BLOCK_CHANGE, this.getBlockPos(), GameEvent.a.of(entity, this.getBlockState()));