craftbukkit/nms-patches/ContainerWorkbench.patch

91 lines
3.8 KiB
Diff
Raw Normal View History

2015-05-25 20:37:24 +10:00
--- a/net/minecraft/server/ContainerWorkbench.java
+++ b/net/minecraft/server/ContainerWorkbench.java
2021-03-09 08:47:33 +11:00
@@ -2,12 +2,21 @@
2019-04-23 12:00:00 +10:00
import java.util.Optional;
2021-03-09 08:47:33 +11:00
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
2021-03-09 08:47:33 +11:00
+
2019-04-23 12:00:00 +10:00
public class ContainerWorkbench extends ContainerRecipeBook<InventoryCrafting> {
2021-03-09 08:47:33 +11:00
private final InventoryCrafting craftInventory;
2019-04-23 12:00:00 +10:00
private final InventoryCraftResult resultInventory;
2019-05-28 06:30:00 +10:00
public final ContainerAccess containerAccess;
2019-04-23 12:00:00 +10:00
private final EntityHuman f;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
2019-04-23 12:00:00 +10:00
public ContainerWorkbench(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.a);
2021-03-09 08:47:33 +11:00
@@ -15,8 +24,12 @@
2019-04-23 12:00:00 +10:00
public ContainerWorkbench(int i, PlayerInventory playerinventory, ContainerAccess containeraccess) {
super(Containers.CRAFTING, i);
- this.craftInventory = new InventoryCrafting(this, 3, 3);
+ // CraftBukkit start - Switched order of IInventory construction and stored player
2019-04-23 12:00:00 +10:00
this.resultInventory = new InventoryCraftResult();
+ this.craftInventory = new InventoryCrafting(this, 3, 3, playerinventory.player); // CraftBukkit - pass player
+ this.craftInventory.resultInventory = this.resultInventory;
+ this.player = playerinventory;
+ // CraftBukkit end
2019-05-28 06:30:00 +10:00
this.containerAccess = containeraccess;
2019-04-23 12:00:00 +10:00
this.f = playerinventory.player;
this.a((Slot) (new SlotResult(playerinventory.player, this.craftInventory, this.resultInventory, 0, 124, 35)));
2021-03-09 08:47:33 +11:00
@@ -42,7 +55,7 @@
2019-04-23 12:00:00 +10:00
}
2019-04-23 12:00:00 +10:00
- protected static void a(int i, World world, EntityHuman entityhuman, InventoryCrafting inventorycrafting, InventoryCraftResult inventorycraftresult) {
+ protected static void a(int i, World world, EntityHuman entityhuman, InventoryCrafting inventorycrafting, InventoryCraftResult inventorycraftresult, Container container) { // CraftBukkit
if (!world.isClientSide) {
EntityPlayer entityplayer = (EntityPlayer) entityhuman;
2020-06-25 10:00:00 +10:00
ItemStack itemstack = ItemStack.b;
2021-03-09 08:47:33 +11:00
@@ -55,6 +68,7 @@
2019-04-23 12:00:00 +10:00
itemstack = recipecrafting.a(inventorycrafting);
}
}
+ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), false); // CraftBukkit
inventorycraftresult.setItem(0, itemstack);
entityplayer.playerConnection.sendPacket(new PacketPlayOutSetSlot(i, 0, itemstack));
2021-03-09 08:47:33 +11:00
@@ -64,7 +78,7 @@
2019-04-23 12:00:00 +10:00
@Override
public void a(IInventory iinventory) {
2019-05-28 06:30:00 +10:00
this.containerAccess.a((world, blockposition) -> {
2019-04-23 12:00:00 +10:00
- a(this.windowId, world, this.f, this.craftInventory, this.resultInventory);
+ a(this.windowId, world, this.f, this.craftInventory, this.resultInventory, this); // CraftBukkit
});
}
2021-03-09 08:47:33 +11:00
@@ -94,6 +108,7 @@
2019-04-23 12:00:00 +10:00
@Override
2017-09-18 20:00:00 +10:00
public boolean canUse(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
2019-05-28 06:30:00 +10:00
return a(this.containerAccess, entityhuman, Blocks.CRAFTING_TABLE);
}
2021-03-09 08:47:33 +11:00
@@ -168,4 +183,17 @@
2019-04-23 12:00:00 +10:00
public int h() {
return this.craftInventory.f();
}
+
+ // CraftBukkit start
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftInventory, this.resultInventory);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}