2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/TileEntityBrewingStand.java
|
|
|
|
+++ b/net/minecraft/server/TileEntityBrewingStand.java
|
2018-07-15 02:00:00 +02:00
|
|
|
@@ -4,6 +4,16 @@
|
2016-11-17 02:41:03 +01:00
|
|
|
import java.util.Iterator;
|
2018-07-15 02:00:00 +02:00
|
|
|
import javax.annotation.Nullable;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
2016-02-29 22:32:46 +01:00
|
|
|
+import java.util.List;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
2016-11-24 18:03:48 +01:00
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.entity.HumanEntity;
|
|
|
|
+import org.bukkit.event.inventory.BrewEvent;
|
2016-11-24 18:03:48 +01:00
|
|
|
+import org.bukkit.event.inventory.BrewingStandFuelEvent;
|
Improvements to BlockStates
* Actually capture all the data of TileEntities. This is done by creating a copy of the TileEntity. The methods of BlockState which currently directly access the TileEntity reference will modify the data of that TileEntity-snapshot instead.
* With the call to BlockState.update, the captured TileEntity data gets applied to the current TileEntity in the world.
* Methods which trigger block specific actions will use the current TileEntity from the world.
* CraftBlockState does not hand out the wrapped or the snapshot TileEntity directly. Instead, it provides an applyTo method to copy the data to a given TileEntity and a method to directly get a copy of the TileEntity NBT data represented by the BlockState. CraftMetaBlockState was updated to make use of that.
* Added #getSnapshotInventory() to bukkit which allows modifiying the captured inventory snapshots of containers.
* Tried to clarify which methods only work if the BlockState is placed, which methods require the block in the world to still be of the same type (methods which trigger actions), and that .getInventory() directly modifies the inventory of the block in the world if the BlockState is placed and becomes invalid if the block type is changed.
Backwards compatibility
* If the BlockState acts as InventoryHolder, getInventory() will still return the inventory directly backed by the TileEntity in the world (like before), and not the snapshot inventory. This compromise should reduce the potential of these changes to break existing plugins, or craftbukkit's own use of BlockState.
* The snapshot's inventory can be accessed by a new method getSnapshotInventory()
* In case the BlockState is not placed (if it was retrieved from the MetaBlockState of an item), the getInventory() method will however return the snapshot inventory. So that when the BlockState gets applied back to the item, the inventory changes are properly included.
* With the changes to CraftMetaBlockState it is no longer required to call the update method before passing a modified BlockState to the CraftMetaBlockState. For backwards compatibility the update method will simply return true for a non-placed BlockState, without actually doing anything.
Impact on plugins
* Restoring blocks now actually works as expected, properly restoring the TileEntity data, reglardless if the block changed its type in the meantime.
* Plugins are now consistently required to call the update method in order to apply changes to blocks. Though, regarding the Javadoc they should have been required to do so anyways.
* New feature: Plugins can take and modify inventory snapshots.
* Breaking change: If a plugin gets the BlockState of a block in the world, modifies the inventory returned by .getInventory(), and then tries to use the same BlockState to apply the TileEntity data to an ItemStack block meta, the ItemStack will use the snapshot inventory, disregarding the changes made to the inventory returned by .getInventory(). This is the compromise of .getInventory() returning the inventory directly backed by the TileEntity in the world.
Other fixes related to BlockState:
* TileEntityContainer#getLocation() will run into a NPE if the TileEntity is non-placed (ex. when getting the BlockState from a CraftMetaBlockState).
* Beacon.getEntitiesInRange() would previously throw a NPE if called for a non-placed BlockState. It was changed to now require to be placed and use the current TileEntity in the world. If the TileEntity in the world is no longer a beacon, it will return an empty list.
* EndGateway now supports setting and getting the exit location even for non-placed EndGateways (inside BlockStateMeta) by using / returning a location with world being null.
2017-08-05 06:37:19 +02:00
|
|
|
+import org.bukkit.inventory.InventoryHolder;
|
2014-11-25 22:32:16 +01:00
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
2018-07-15 02:00:00 +02:00
|
|
|
public class TileEntityBrewingStand extends TileEntityContainer implements IWorldInventory, ITickable {
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-05-27 22:30:00 +02:00
|
|
|
private static final int[] b = new int[]{3};
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -15,6 +25,36 @@
|
|
|
|
private Item k;
|
|
|
|
public int fuelLevel;
|
|
|
|
protected final IContainerProperties a;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - add fields and methods
|
2016-11-17 02:41:03 +01:00
|
|
|
+ private int lastTick = MinecraftServer.currentTick;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ 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() {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return this.items;
|
|
|
|
+ }
|
|
|
|
+
|
2019-04-23 04:00:00 +02:00
|
|
|
+ @Override
|
|
|
|
+ public int getMaxStackSize() {
|
|
|
|
+ return maxStack;
|
|
|
|
+ }
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ public void setMaxStackSize(int size) {
|
|
|
|
+ maxStack = size;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2016-11-17 02:41:03 +01:00
|
|
|
|
|
|
|
public TileEntityBrewingStand() {
|
2018-08-26 04:00:00 +02:00
|
|
|
super(TileEntityTypes.BREWING_STAND);
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -83,8 +123,19 @@
|
2016-11-24 18:03:48 +01:00
|
|
|
ItemStack itemstack = (ItemStack) this.items.get(4);
|
|
|
|
|
2017-05-14 04:00:00 +02:00
|
|
|
if (this.fuelLevel <= 0 && itemstack.getItem() == Items.BLAZE_POWDER) {
|
|
|
|
- this.fuelLevel = 20;
|
2016-11-24 18:03:48 +01:00
|
|
|
- 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;
|
|
|
|
+ }
|
|
|
|
+
|
2018-12-06 00:00:00 +01:00
|
|
|
+ this.fuelLevel = event.getFuelPower();
|
2017-05-14 04:00:00 +02:00
|
|
|
+ if (this.fuelLevel > 0 && event.isConsuming()) {
|
2016-11-24 18:03:48 +01:00
|
|
|
+ itemstack.subtract(1);
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -92,9 +143,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);
|
2014-11-25 22:32:16 +01:00
|
|
|
|
|
|
|
+ // 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) {
|
2014-11-25 22:32:16 +01:00
|
|
|
- --this.brewTime;
|
2016-02-29 22:32:46 +01:00
|
|
|
- boolean flag2 = this.brewTime == 0;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ this.brewTime -= elapsedTicks;
|
2016-02-29 22:32:46 +01:00
|
|
|
+ boolean flag2 = this.brewTime <= 0; // == -> <=
|
|
|
|
+ // CraftBukkit end
|
|
|
|
|
|
|
|
if (flag2 && flag) {
|
2019-12-10 23:00:00 +01:00
|
|
|
this.j();
|
2019-04-23 04:00:00 +02:00
|
|
|
@@ -168,6 +224,16 @@
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2019-12-10 23:00:00 +01:00
|
|
|
private void j() {
|
2016-11-17 02:41:03 +01:00
|
|
|
ItemStack itemstack = (ItemStack) this.items.get(3);
|
2016-02-29 22:32:46 +01:00
|
|
|
+ // CraftBukkit start
|
Improvements to BlockStates
* Actually capture all the data of TileEntities. This is done by creating a copy of the TileEntity. The methods of BlockState which currently directly access the TileEntity reference will modify the data of that TileEntity-snapshot instead.
* With the call to BlockState.update, the captured TileEntity data gets applied to the current TileEntity in the world.
* Methods which trigger block specific actions will use the current TileEntity from the world.
* CraftBlockState does not hand out the wrapped or the snapshot TileEntity directly. Instead, it provides an applyTo method to copy the data to a given TileEntity and a method to directly get a copy of the TileEntity NBT data represented by the BlockState. CraftMetaBlockState was updated to make use of that.
* Added #getSnapshotInventory() to bukkit which allows modifiying the captured inventory snapshots of containers.
* Tried to clarify which methods only work if the BlockState is placed, which methods require the block in the world to still be of the same type (methods which trigger actions), and that .getInventory() directly modifies the inventory of the block in the world if the BlockState is placed and becomes invalid if the block type is changed.
Backwards compatibility
* If the BlockState acts as InventoryHolder, getInventory() will still return the inventory directly backed by the TileEntity in the world (like before), and not the snapshot inventory. This compromise should reduce the potential of these changes to break existing plugins, or craftbukkit's own use of BlockState.
* The snapshot's inventory can be accessed by a new method getSnapshotInventory()
* In case the BlockState is not placed (if it was retrieved from the MetaBlockState of an item), the getInventory() method will however return the snapshot inventory. So that when the BlockState gets applied back to the item, the inventory changes are properly included.
* With the changes to CraftMetaBlockState it is no longer required to call the update method before passing a modified BlockState to the CraftMetaBlockState. For backwards compatibility the update method will simply return true for a non-placed BlockState, without actually doing anything.
Impact on plugins
* Restoring blocks now actually works as expected, properly restoring the TileEntity data, reglardless if the block changed its type in the meantime.
* Plugins are now consistently required to call the update method in order to apply changes to blocks. Though, regarding the Javadoc they should have been required to do so anyways.
* New feature: Plugins can take and modify inventory snapshots.
* Breaking change: If a plugin gets the BlockState of a block in the world, modifies the inventory returned by .getInventory(), and then tries to use the same BlockState to apply the TileEntity data to an ItemStack block meta, the ItemStack will use the snapshot inventory, disregarding the changes made to the inventory returned by .getInventory(). This is the compromise of .getInventory() returning the inventory directly backed by the TileEntity in the world.
Other fixes related to BlockState:
* TileEntityContainer#getLocation() will run into a NPE if the TileEntity is non-placed (ex. when getting the BlockState from a CraftMetaBlockState).
* Beacon.getEntitiesInRange() would previously throw a NPE if called for a non-placed BlockState. It was changed to now require to be placed and use the current TileEntity in the world. If the TileEntity in the world is no longer a beacon, it will return an empty list.
* EndGateway now supports setting and getting the exit location even for non-placed EndGateways (inside BlockStateMeta) by using / returning a location with world being null.
2017-08-05 06:37:19 +02:00
|
|
|
+ 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);
|
2016-02-29 22:32:46 +01:00
|
|
|
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
|
|
|
|
+ if (event.isCancelled()) {
|
|
|
|
+ return;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
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)));
|