Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startingBrewTime #11406

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions patches/api/0490-Add-totalBrewTime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tamion <[email protected]>
Date: Fri, 20 Sep 2024 17:39:22 +0200
Subject: [PATCH] Add totalBrewTime


diff --git a/src/main/java/org/bukkit/block/BrewingStand.java b/src/main/java/org/bukkit/block/BrewingStand.java
index fe155f14de7f7efb519f0585897ef43ee6c16bb9..d22775556da2a8872115eb113dffb646cbdcb1da 100644
--- a/src/main/java/org/bukkit/block/BrewingStand.java
+++ b/src/main/java/org/bukkit/block/BrewingStand.java
@@ -22,6 +22,24 @@ public interface BrewingStand extends Container {
*/
void setBrewingTime(int brewTime);

+ // Paper start - Add totalBrewTime
+ /**
+ * Sets the total time the brewing process started with.
+ * This only affects the visual progress on the client.
+ *
+ * @param totalBrewTime Total Brew time
+ */
+ void setTotalBrewTime(int totalBrewTime);
+
+ /**
+ * Gets the total time the brewing process started with.
+ * This only affects the visual progress on the client.
+ *
+ * @return Total Brew time
+ */
+ int getTotalBrewTime();
+ // Paper end - Add totalBrewTime
+
/**
* Get the level of current fuel for brewing.
*
diff --git a/src/main/java/org/bukkit/inventory/view/BrewingStandView.java b/src/main/java/org/bukkit/inventory/view/BrewingStandView.java
index 206e9befae9863f99f44ac0e1629c2af1905787a..f3587506ebb1aa832ae326c990d0a19074ffd6bc 100644
--- a/src/main/java/org/bukkit/inventory/view/BrewingStandView.java
+++ b/src/main/java/org/bukkit/inventory/view/BrewingStandView.java
@@ -39,4 +39,22 @@ public interface BrewingStandView extends InventoryView {
* @throws IllegalArgumentException if the ticks are less than 0
*/
void setBrewingTicks(final int ticks) throws IllegalArgumentException;
+
+ // Paper start - Add totalBrewTime
+ /**
+ * Sets the total time the brewing process started with.
+ * This only affects the visual progress on the client.
+ *
+ * @param totalBrewTime Total Brew time
+ */
+ void setTotalBrewTime(int totalBrewTime);
+
+ /**
+ * Gets the total time the brewing process started with.
+ * This only affects the visual progress on the client.
+ *
+ * @return Total Brew time
+ */
+ int getTotalBrewTime();
+ // Paper end - Add totalBrewTime
}
184 changes: 184 additions & 0 deletions patches/server/1058-Add-totalBrewTime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tamion <[email protected]>
Date: Sun, 15 Sep 2024 19:17:12 +0200
Subject: [PATCH] Add totalBrewTime

== AT ==
public net.minecraft.world.inventory.BrewingStandMenu brewingStandData

diff --git a/src/main/java/io/papermc/paper/inventory/BrewingSimpleContainerData.java b/src/main/java/io/papermc/paper/inventory/BrewingSimpleContainerData.java
new file mode 100644
index 0000000000000000000000000000000000000000..84dead75191634c3aa6031781a2ff3087171793b
--- /dev/null
+++ b/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/src/main/java/net/minecraft/world/inventory/BrewingStandMenu.java b/src/main/java/net/minecraft/world/inventory/BrewingStandMenu.java
index 68c529cb38d61cd3a0f39bef0f666057fc219c9b..fa6d867212e3818263a3d5060b4b08d80acb2ad6 100644
--- a/src/main/java/net/minecraft/world/inventory/BrewingStandMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/BrewingStandMenu.java
@@ -41,14 +41,14 @@ public class BrewingStandMenu extends AbstractContainerMenu {
// CraftBukkit end

public BrewingStandMenu(int syncId, Inventory playerInventory) {
- 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, 3); // Paper - Add totalBrewTime
this.brewingStand = inventory;
this.brewingStandData = propertyDelegate;
PotionBrewing potionbrewer = playerInventory.player.level().potionBrewing();
@@ -60,7 +60,20 @@ public class BrewingStandMenu extends AbstractContainerMenu {
// 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);
+ // Paper start - Add totalBrewTime
+ 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 totalBrewTime

int j;

diff --git a/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
index bf2c303a314205590a2839e0f729af3a9ff40a86..dd740c289825a2c120555eb441517b4e0c8d9328 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
@@ -49,6 +49,7 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements
public static final int NUM_DATA_VALUES = 2;
private NonNullList<ItemStack> items;
public int brewTime;
+ public int totalBrewTime = 400; // Paper - Add totalBrewTime
private boolean[] lastPotionCount;
private Item ingredient;
public int fuel;
@@ -99,6 +100,11 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements
case 1:
j = BrewingStandBlockEntity.this.fuel;
break;
+ // Paper start - Add totalBrewTime
+ case 2:
+ j = BrewingStandBlockEntity.this.totalBrewTime;
+ break;
+ // Paper end - Add totalBrewTime
default:
j = 0;
}
@@ -114,13 +120,18 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements
break;
case 1:
BrewingStandBlockEntity.this.fuel = value;
+ // Paper start - Add totalBrewTime
+ case 2:
+ BrewingStandBlockEntity.this.totalBrewTime = value;
+ break;
+ // Paper end - Add totalBrewTime
}

}

@Override
public int getCount() {
- return 2;
+ return 3;
}
};
}
@@ -188,6 +199,7 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements
// CraftBukkit start
BrewingStartEvent event = new BrewingStartEvent(CraftBlock.at(world, pos), CraftItemStack.asCraftMirror(itemstack1), 400);
world.getCraftServer().getPluginManager().callEvent(event);
+ blockEntity.totalBrewTime = event.getTotalBrewTime(); // Paper - Add totalBrewTime
blockEntity.brewTime = event.getTotalBrewTime(); // 400 -> event.getTotalBrewTime()
// CraftBukkit end
blockEntity.ingredient = itemstack1.getItem();
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java
index e9f55c898de827afe6c9f951cbe1b46eea5f4149..76f808fa7dee001ff596a23017a450c56c9f50fe 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java
@@ -39,8 +39,21 @@ public class CraftBrewingStand extends CraftContainer<BrewingStandBlockEntity> i
@Override
public void setBrewingTime(int brewTime) {
this.getSnapshot().brewTime = brewTime;
+ // Paper start - Add totalBrewTime
+ if (brewTime > this.getSnapshot().totalBrewTime) this.getSnapshot().totalBrewTime = brewTime;
}

+ @Override
+ public void setTotalBrewTime(int totalBrewTime) {
+ this.getSnapshot().totalBrewTime = totalBrewTime;
+ }
+
+ @Override
+ public int getTotalBrewTime() {
+ return this.getSnapshot().totalBrewTime;
+ }
+ // Paper end - Add totalBrewTime
+
@Override
public int getFuelLevel() {
return this.getSnapshot().fuel;
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
index 674e3a827f8fb64e5c0beefb3c1874d6e8aee4e5..b8cd8d442d9e3fe223e920e420b19551783002d1 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
+++ b/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 totalBrewTime
break;
case HOPPER:
this.delegate = new HopperMenu(windowId, bottom, top);
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftBrewingStandView.java b/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftBrewingStandView.java
index c92e51227cf2c0046a558b012c078c46582aed44..804d71d277b64c012b0a87f4295b858c11c6863a 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftBrewingStandView.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftBrewingStandView.java
@@ -33,6 +33,19 @@ public class CraftBrewingStandView extends CraftInventoryView<BrewingStandMenu>
@Override
public void setBrewingTicks(final int brewingTicks) {
Preconditions.checkArgument(brewingTicks > 0, "The given brewing ticks must be greater than 0");
- this.container.setData(BrewingStandBlockEntity.DATA_BREW_TIME, brewingTicks);
+ // Paper start - Add totalBrewTime
+ this.container.brewingStandData.set(BrewingStandBlockEntity.DATA_BREW_TIME, brewingTicks);
+ if (brewingTicks > this.container.brewingStandData.get(2)) this.container.brewingStandData.set(2, brewingTicks);
}
+
+ @Override
+ public void setTotalBrewTime(int totalBrewTime) {
+ this.container.brewingStandData.set(2, totalBrewTime);
+ }
+
+ @Override
+ public int getTotalBrewTime() {
+ return this.container.brewingStandData.get(2);
+ }
+ // Paper end - Add totalBrewTime
}
Loading