3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 23:00:08 +01:00
Paper/nms-patches/TileEntityBrewingStand.patch

115 Zeilen
3.8 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/TileEntityBrewingStand.java
+++ b/net/minecraft/server/TileEntityBrewingStand.java
@@ -3,6 +3,15 @@
import java.util.Arrays;
2016-11-17 02:41:03 +01:00
import java.util.Iterator;
+// CraftBukkit start
2016-02-29 22:32:46 +01:00
+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;
+// CraftBukkit end
+
2016-02-29 22:32:46 +01:00
public class TileEntityBrewingStand extends TileEntityContainer implements ITickable, IWorldInventory {
private static final int[] a = new int[] { 3};
@@ -14,6 +23,31 @@
2016-02-29 22:32:46 +01:00
private Item k;
private String l;
private int m;
+ // CraftBukkit start - add fields and methods
2016-11-17 02:41:03 +01:00
+ 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;
+ }
+
2016-11-17 02:41:03 +01:00
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
public TileEntityBrewingStand() {
this.items = NonNullList.a(5, ItemStack.a);
@@ -55,8 +89,19 @@
ItemStack itemstack = (ItemStack) this.items.get(4);
if (this.m <= 0 && itemstack.getItem() == Items.BLAZE_POWDER) {
- this.m = 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.m = event.getFuelPower(); // PAIL fuelLevel
+ if (this.m > 0 && event.isConsuming()) {
+ itemstack.subtract(1);
+ }
+ // CraftBukkit end
this.update();
}
@@ -64,9 +109,14 @@
2016-02-29 22:32:46 +01:00
boolean flag1 = this.brewTime > 0;
2016-11-17 02:41:03 +01:00
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;
+
2016-02-29 22:32:46 +01:00
if (flag1) {
- --this.brewTime;
2016-02-29 22:32:46 +01:00
- boolean flag2 = this.brewTime == 0;
+ this.brewTime -= elapsedTicks;
2016-02-29 22:32:46 +01:00
+ boolean flag2 = this.brewTime <= 0; // == -> <=
+ // CraftBukkit end
if (flag2 && flag) {
2016-11-17 02:41:03 +01:00
this.p();
@@ -140,6 +190,15 @@
2015-02-26 23:41:06 +01:00
2016-11-17 02:41:03 +01:00
private void p() {
ItemStack itemstack = (ItemStack) this.items.get(3);
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start
+ if (getOwner() != null) {
+ BrewEvent event = new BrewEvent(world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), (org.bukkit.inventory.BrewerInventory) this.getOwner().getInventory(), this.m);
2016-02-29 22:32:46 +01:00
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
2016-02-29 22:32:46 +01:00
+ }
+ // CraftBukkit end
for (int i = 0; i < 3; ++i) {
2016-11-17 02:41:03 +01:00
this.items.set(i, PotionBrewer.d(itemstack, (ItemStack) this.items.get(i)));
@@ -210,7 +269,7 @@
}
public int getMaxStackSize() {
- return 64;
+ return this.maxStack; // CraftBukkit
}
public boolean a(EntityHuman entityhuman) {