CraftBukkit/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch
2021-06-11 15:00:00 +10:00

76 lines
3.1 KiB
Diff

--- a/net/minecraft/world/inventory/ContainerWorkbench.java
+++ b/net/minecraft/world/inventory/ContainerWorkbench.java
@@ -14,6 +14,11 @@
import net.minecraft.world.level.World;
import net.minecraft.world.level.block.Blocks;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerWorkbench extends ContainerRecipeBook<InventoryCrafting> {
public static final int RESULT_SLOT = 0;
@@ -27,6 +32,9 @@
private final InventoryCraftResult resultSlots;
public final ContainerAccess access;
private final EntityHuman player;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ // CraftBukkit end
public ContainerWorkbench(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.NULL);
@@ -34,8 +42,11 @@
public ContainerWorkbench(int i, PlayerInventory playerinventory, ContainerAccess containeraccess) {
super(Containers.CRAFTING, i);
- this.craftSlots = new InventoryCrafting(this, 3, 3);
+ // CraftBukkit start - Switched order of IInventory construction and stored player
this.resultSlots = new InventoryCraftResult();
+ this.craftSlots = new InventoryCrafting(this, 3, 3, playerinventory.player); // CraftBukkit - pass player
+ this.craftSlots.resultInventory = this.resultSlots;
+ // CraftBukkit end
this.access = containeraccess;
this.player = playerinventory.player;
this.a((Slot) (new SlotResult(playerinventory.player, this.craftSlots, this.resultSlots, 0, 124, 35)));
@@ -71,9 +82,10 @@
RecipeCrafting recipecrafting = (RecipeCrafting) optional.get();
if (inventorycraftresult.setRecipeUsed(world, entityplayer, recipecrafting)) {
- itemstack = recipecrafting.a((IInventory) inventorycrafting);
+ itemstack = recipecrafting.a(inventorycrafting); // CraftBukkit - decompile error
}
}
+ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), false); // CraftBukkit
inventorycraftresult.setItem(0, itemstack);
container.a(0, itemstack);
@@ -114,6 +126,7 @@
@Override
public boolean canUse(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return a(this.access, entityhuman, Blocks.CRAFTING_TABLE);
}
@@ -202,4 +215,17 @@
public boolean d(int i) {
return i != this.j();
}
+
+ // CraftBukkit start
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots);
+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}