3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 20:40:07 +01:00
Paper/nms-patches/TileEntityBrewingStand.patch
2019-12-11 09:00:00 +11:00

113 Zeilen
3.8 KiB
Diff

--- a/net/minecraft/server/TileEntityBrewingStand.java
+++ b/net/minecraft/server/TileEntityBrewingStand.java
@@ -4,6 +4,16 @@
import java.util.Iterator;
import javax.annotation.Nullable;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.HumanEntity;
+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, ITickable {
private static final int[] b = new int[]{3};
@@ -15,6 +25,36 @@
private Item k;
public int fuelLevel;
protected final IContainerProperties a;
+ // CraftBukkit start - add fields and methods
+ private int lastTick = MinecraftServer.currentTick;
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = 64;
+
+ 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() {
super(TileEntityTypes.BREWING_STAND);
@@ -83,8 +123,19 @@
ItemStack itemstack = (ItemStack) this.items.get(4);
if (this.fuelLevel <= 0 && itemstack.getItem() == Items.BLAZE_POWDER) {
- this.fuelLevel = 20;
- itemstack.subtract(1);
+ // CraftBukkit start
+ BrewingStandFuelEvent event = new BrewingStandFuelEvent(world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), CraftItemStack.asCraftMirror(itemstack), 20);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+
+ this.fuelLevel = event.getFuelPower();
+ if (this.fuelLevel > 0 && event.isConsuming()) {
+ itemstack.subtract(1);
+ }
+ // CraftBukkit end
this.update();
}
@@ -92,9 +143,14 @@
boolean flag1 = this.brewTime > 0;
ItemStack itemstack1 = (ItemStack) this.items.get(3);
+ // CraftBukkit start - Use wall time instead of ticks for brewing
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
+ this.lastTick = MinecraftServer.currentTick;
+
if (flag1) {
- --this.brewTime;
- boolean flag2 = this.brewTime == 0;
+ this.brewTime -= elapsedTicks;
+ boolean flag2 = this.brewTime <= 0; // == -> <=
+ // CraftBukkit end
if (flag2 && flag) {
this.j();
@@ -168,6 +224,16 @@
private void j() {
ItemStack itemstack = (ItemStack) this.items.get(3);
+ // CraftBukkit start
+ InventoryHolder owner = this.getOwner();
+ if (owner != null) {
+ BrewEvent event = new BrewEvent(world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), (org.bukkit.inventory.BrewerInventory) owner.getInventory(), this.fuelLevel);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
for (int i = 0; i < 3; ++i) {
this.items.set(i, PotionBrewer.d(itemstack, (ItemStack) this.items.get(i)));