From 8b8acbb89804923654e072aa5f0411258ab0ea89 Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:17:12 +0200 Subject: [PATCH] Add recipeBrewTime == AT == public net.minecraft.world.inventory.BrewingStandMenu brewingStandData --- .../inventory/BrewingStandMenu.java.patch | 35 ++++++++---- .../entity/BrewingStandBlockEntity.java.patch | 54 ++++++++++++++++--- .../inventory/BrewingSimpleContainerData.java | 11 ++++ .../craftbukkit/block/CraftBrewingStand.java | 13 +++++ .../craftbukkit/inventory/CraftContainer.java | 2 +- .../inventory/view/CraftBrewingStandView.java | 13 +++++ 6 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 paper-server/src/main/java/io/papermc/paper/inventory/BrewingSimpleContainerData.java diff --git a/paper-server/patches/sources/net/minecraft/world/inventory/BrewingStandMenu.java.patch b/paper-server/patches/sources/net/minecraft/world/inventory/BrewingStandMenu.java.patch index 5649df7a88..36dcdb7277 100644 --- a/paper-server/patches/sources/net/minecraft/world/inventory/BrewingStandMenu.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/inventory/BrewingStandMenu.java.patch @@ -11,7 +11,7 @@ public class BrewingStandMenu extends AbstractContainerMenu { -@@ -35,21 +39,29 @@ +@@ -35,29 +39,51 @@ public final ContainerData brewingStandData; private final Slot ingredientSlot; @@ -21,14 +21,16 @@ + // CraftBukkit end + public BrewingStandMenu(int syncId, Inventory playerInventory) { - this(syncId, playerInventory, new SimpleContainer(5), new SimpleContainerData(2)); +- this(syncId, playerInventory, new SimpleContainer(5), new SimpleContainerData(2)); ++ this(syncId, playerInventory, new SimpleContainer(5), new io.papermc.paper.inventory.BrewingSimpleContainerData()); // Paper - Add totalBrewTime } public BrewingStandMenu(int syncId, Inventory playerInventory, Container inventory, ContainerData propertyDelegate) { super(MenuType.BREWING_STAND, syncId); + this.player = playerInventory; // CraftBukkit checkContainerSize(inventory, 5); - checkContainerDataCount(propertyDelegate, 2); +- checkContainerDataCount(propertyDelegate, 2); ++ checkContainerDataCount(propertyDelegate, 3); // Paper - Add recipeBrewTime this.brewingStand = inventory; this.brewingStandData = propertyDelegate; PotionBrewing potionbrewer = playerInventory.player.level().potionBrewing(); @@ -43,8 +45,23 @@ + // Paper end - custom potion mixes this.ingredientSlot = this.addSlot(new BrewingStandMenu.IngredientsSlot(potionbrewer, inventory, 3, 79, 17)); this.addSlot(new BrewingStandMenu.FuelSlot(inventory, 4, 17, 17)); - this.addDataSlots(propertyDelegate); -@@ -58,6 +70,7 @@ +- this.addDataSlots(propertyDelegate); ++ // Paper start - Add recipeBrewTime ++ this.addDataSlots(new SimpleContainerData(2) { ++ @Override ++ public int get(final int index) { ++ if (index == 0) return 400 * propertyDelegate.get(index) / propertyDelegate.get(2); ++ return propertyDelegate.get(index); ++ } ++ ++ @Override ++ public void set(final int index, final int value) { ++ propertyDelegate.set(index, value); ++ } ++ }); ++ // Paper end - Add recipeBrewTime + this.addStandardInventorySlots(playerInventory, 8, 84); + } @Override public boolean stillValid(Player player) { @@ -52,7 +69,7 @@ return this.brewingStand.stillValid(player); } -@@ -79,7 +92,7 @@ +@@ -79,7 +105,7 @@ if (!this.moveItemStackTo(itemstack1, 3, 4, false)) { return ItemStack.EMPTY; } @@ -61,7 +78,7 @@ if (!this.moveItemStackTo(itemstack1, 0, 3, false)) { return ItemStack.EMPTY; } -@@ -128,13 +141,15 @@ +@@ -128,13 +154,15 @@ private static class PotionSlot extends Slot { @@ -79,7 +96,7 @@ } @Override -@@ -153,8 +168,8 @@ +@@ -153,8 +181,8 @@ super.onTake(player, stack); } @@ -90,7 +107,7 @@ } @Override -@@ -198,4 +213,17 @@ +@@ -198,4 +226,17 @@ return BrewingStandMenu.EMPTY_SLOT_FUEL; } } diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java.patch index 380ffa3d40..39dec9ecc2 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java.patch @@ -29,7 +29,12 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer { -@@ -41,7 +54,37 @@ +@@ -37,11 +50,42 @@ + public static final int NUM_DATA_VALUES = 2; + private NonNullList items; + public int brewTime; ++ public int recipeBrewTime = 400; // Paper - Add recipeBrewTime + private boolean[] lastPotionCount; private Item ingredient; public int fuel; protected final ContainerData dataAccess; @@ -67,7 +72,39 @@ public BrewingStandBlockEntity(BlockPos pos, BlockState state) { super(BlockEntityType.BREWING_STAND, pos, state); this.items = NonNullList.withSize(5, ItemStack.EMPTY); -@@ -107,8 +150,19 @@ +@@ -57,6 +101,11 @@ + case 1: + j = BrewingStandBlockEntity.this.fuel; + break; ++ // Paper start - Add recipeBrewTime ++ case 2: ++ j = BrewingStandBlockEntity.this.recipeBrewTime; ++ break; ++ // Paper end - Add recipeBrewTime + default: + j = 0; + } +@@ -72,13 +121,18 @@ + break; + case 1: + BrewingStandBlockEntity.this.fuel = value; ++ // Paper start - Add recipeBrewTime ++ case 2: ++ BrewingStandBlockEntity.this.recipeBrewTime = value; ++ break; ++ // Paper end - Add recipeBrewTime + } + + } + + @Override + public int getCount() { +- return 2; ++ return 3; // Paper - Add recipeBrewTime + } + }; + } +@@ -107,8 +161,19 @@ ItemStack itemstack = (ItemStack) blockEntity.items.get(4); if (blockEntity.fuel <= 0 && itemstack.is(ItemTags.BREWING_FUEL)) { @@ -89,7 +126,7 @@ setChanged(world, pos, state); } -@@ -116,12 +170,15 @@ +@@ -116,12 +181,15 @@ boolean flag1 = blockEntity.brewTime > 0; ItemStack itemstack1 = (ItemStack) blockEntity.items.get(3); @@ -108,7 +145,7 @@ } else if (!flag || !itemstack1.is(blockEntity.ingredient)) { blockEntity.brewTime = 0; } -@@ -129,7 +186,11 @@ +@@ -129,7 +197,12 @@ setChanged(world, pos, state); } else if (flag && blockEntity.fuel > 0) { --blockEntity.fuel; @@ -116,12 +153,13 @@ + // CraftBukkit start + BrewingStartEvent event = new BrewingStartEvent(CraftBlock.at(world, pos), CraftItemStack.asCraftMirror(itemstack1), 400); + world.getCraftServer().getPluginManager().callEvent(event); -+ blockEntity.brewTime = event.getTotalBrewTime(); // 400 -> event.getTotalBrewTime() ++ blockEntity.recipeBrewTime = event.getRecipeBrewTime(); // Paper - use recipe brew time from event ++ blockEntity.brewTime = event.getBrewingTime(); // 400 -> event.getTotalBrewTime() // Paper - use brewing time from event + // CraftBukkit end blockEntity.ingredient = itemstack1.getItem(); setChanged(world, pos, state); } -@@ -185,14 +246,36 @@ +@@ -185,14 +258,36 @@ } } @@ -161,7 +199,7 @@ itemstack.shrink(1); ItemStack itemstack1 = itemstack.getItem().getCraftingRemainder(); -@@ -200,12 +283,12 @@ +@@ -200,12 +295,12 @@ if (itemstack.isEmpty()) { itemstack = itemstack1; } else { @@ -177,7 +215,7 @@ } @Override -@@ -231,12 +314,12 @@ +@@ -231,12 +326,12 @@ @Override public boolean canPlaceItem(int slot, ItemStack stack) { diff --git a/paper-server/src/main/java/io/papermc/paper/inventory/BrewingSimpleContainerData.java b/paper-server/src/main/java/io/papermc/paper/inventory/BrewingSimpleContainerData.java new file mode 100644 index 0000000000..84dead7519 --- /dev/null +++ b/paper-server/src/main/java/io/papermc/paper/inventory/BrewingSimpleContainerData.java @@ -0,0 +1,11 @@ +package io.papermc.paper.inventory; + +import net.minecraft.world.inventory.SimpleContainerData; + +public class BrewingSimpleContainerData extends SimpleContainerData { + + public BrewingSimpleContainerData() { + super(3); + this.set(2, 400); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java index e9f55c898d..f330c17b11 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java @@ -41,6 +41,19 @@ public class CraftBrewingStand extends CraftContainer i this.getSnapshot().brewTime = brewTime; } + // Paper start - Add recipeBrewTime + @Override + public void setRecipeBrewTime(int recipeBrewTime) { + com.google.common.base.Preconditions.checkArgument(recipeBrewTime > 0, "recipeBrewTime must be positive"); + this.getSnapshot().recipeBrewTime = recipeBrewTime; + } + + @Override + public int getRecipeBrewTime() { + return this.getSnapshot().recipeBrewTime; + } + // Paper end - Add recipeBrewTime + @Override public int getFuelLevel() { return this.getSnapshot().fuel; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java index 674e3a827f..6d3f9d5dab 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java @@ -163,7 +163,7 @@ public class CraftContainer extends AbstractContainerMenu { this.delegate = new EnchantmentMenu(windowId, bottom); break; case BREWING: - this.delegate = new BrewingStandMenu(windowId, bottom, top, new SimpleContainerData(2)); + this.delegate = new BrewingStandMenu(windowId, bottom, top, new io.papermc.paper.inventory.BrewingSimpleContainerData()); // Paper - Add recipeBrewTime break; case HOPPER: this.delegate = new HopperMenu(windowId, bottom, top); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftBrewingStandView.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftBrewingStandView.java index aeb5a9c996..6e88347d74 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftBrewingStandView.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftBrewingStandView.java @@ -35,4 +35,17 @@ public class CraftBrewingStandView extends CraftInventoryView 0, "The given brewing ticks must be greater than 0"); this.container.setData(BrewingStandBlockEntity.DATA_BREW_TIME, brewingTicks); } + + // Paper start - Add recipeBrewTime + @Override + public void setRecipeBrewTime(int recipeBrewTime) { + com.google.common.base.Preconditions.checkArgument(recipeBrewTime > 0, "recipeBrewTime must be positive"); + this.container.brewingStandData.set(2, recipeBrewTime); + } + + @Override + public int getRecipeBrewTime() { + return this.container.brewingStandData.get(2); + } + // Paper end - Add recipeBrewTime }