0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-22 14:46:16 +00:00
craftbukkit/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch
2024-10-23 02:15:00 +11:00

154 lines
6.4 KiB
Diff

--- a/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java
+++ b/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java
@@ -24,6 +24,20 @@
import net.minecraft.world.level.block.BlockBrewingStand;
import net.minecraft.world.level.block.state.IBlockData;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.craftbukkit.block.CraftBlock;
+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;
+// CraftBukkit end
+
public class TileEntityBrewingStand extends TileEntityContainer implements IWorldInventory {
private static final int INGREDIENT_SLOT = 3;
@@ -41,6 +55,36 @@
private Item ingredient;
public int fuel;
protected final IContainerProperties dataAccess;
+ // CraftBukkit start - add fields and methods
+ private int lastTick = MinecraftServer.currentTick;
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
public TileEntityBrewingStand(BlockPosition blockposition, IBlockData iblockdata) {
super(TileEntityTypes.BREWING_STAND, blockposition, iblockdata);
@@ -107,8 +151,19 @@
ItemStack itemstack = (ItemStack) tileentitybrewingstand.items.get(4);
if (tileentitybrewingstand.fuel <= 0 && itemstack.is(TagsItem.BREWING_FUEL)) {
- tileentitybrewingstand.fuel = 20;
- itemstack.shrink(1);
+ // CraftBukkit start
+ BrewingStandFuelEvent event = new BrewingStandFuelEvent(CraftBlock.at(world, blockposition), CraftItemStack.asCraftMirror(itemstack), 20);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ tileentitybrewingstand.fuel = event.getFuelPower();
+ if (tileentitybrewingstand.fuel > 0 && event.isConsuming()) {
+ itemstack.shrink(1);
+ }
+ // CraftBukkit end
setChanged(world, blockposition, iblockdata);
}
@@ -116,12 +171,17 @@
boolean flag1 = tileentitybrewingstand.brewTime > 0;
ItemStack itemstack1 = (ItemStack) tileentitybrewingstand.items.get(3);
+ // CraftBukkit start - Use wall time instead of ticks for brewing
+ int elapsedTicks = MinecraftServer.currentTick - tileentitybrewingstand.lastTick;
+ tileentitybrewingstand.lastTick = MinecraftServer.currentTick;
+
if (flag1) {
- --tileentitybrewingstand.brewTime;
- boolean flag2 = tileentitybrewingstand.brewTime == 0;
+ tileentitybrewingstand.brewTime -= elapsedTicks;
+ boolean flag2 = tileentitybrewingstand.brewTime <= 0; // == -> <=
+ // CraftBukkit end
if (flag2 && flag) {
- doBrew(world, blockposition, tileentitybrewingstand.items);
+ doBrew(world, blockposition, tileentitybrewingstand.items, tileentitybrewingstand); // CraftBukkit
} else if (!flag || !itemstack1.is(tileentitybrewingstand.ingredient)) {
tileentitybrewingstand.brewTime = 0;
}
@@ -129,7 +189,11 @@
setChanged(world, blockposition, iblockdata);
} 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);
}
@@ -185,12 +249,34 @@
}
}
- private static void doBrew(World world, BlockPosition blockposition, NonNullList<ItemStack> nonnulllist) {
+ private static void doBrew(World world, BlockPosition blockposition, NonNullList<ItemStack> nonnulllist, TileEntityBrewingStand tileentitybrewingstand) { // CraftBukkit
ItemStack itemstack = (ItemStack) nonnulllist.get(3);
PotionBrewer potionbrewer = world.potionBrewing();
+ // CraftBukkit start
+ InventoryHolder owner = tileentitybrewingstand.getOwner();
+ List<org.bukkit.inventory.ItemStack> brewResults = new ArrayList<>(3);
for (int i = 0; i < 3; ++i) {
- nonnulllist.set(i, potionbrewer.mix(itemstack, (ItemStack) nonnulllist.get(i)));
+ brewResults.add(i, CraftItemStack.asCraftMirror(potionbrewer.mix(itemstack, (ItemStack) nonnulllist.get(i))));
+ }
+
+ if (owner != null) {
+ BrewEvent event = new BrewEvent(CraftBlock.at(world, blockposition), (org.bukkit.inventory.BrewerInventory) owner.getInventory(), brewResults, tileentitybrewingstand.fuel);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
+
+ for (int i = 0; i < 3; ++i) {
+ // CraftBukkit start - validate index in case it is cleared by plugins
+ if (i < brewResults.size()) {
+ nonnulllist.set(i, CraftItemStack.asNMSCopy(brewResults.get(i)));
+ } else {
+ nonnulllist.set(i, ItemStack.EMPTY);
+ }
+ // CraftBukkit end
}
itemstack.shrink(1);