--- a/net/minecraft/world/inventory/ContainerWorkbench.java +++ b/net/minecraft/world/inventory/ContainerWorkbench.java @@ -15,6 +15,12 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.block.Blocks; +// CraftBukkit start +import net.minecraft.world.item.crafting.RecipeRepair; +import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; +import org.bukkit.craftbukkit.inventory.CraftInventoryView; +// CraftBukkit end + public class ContainerWorkbench extends ContainerRecipeBook { public static final int RESULT_SLOT = 0; @@ -24,10 +30,13 @@ private static final int INV_SLOT_END = 37; private static final int USE_ROW_SLOT_START = 37; private static final int USE_ROW_SLOT_END = 46; - public final InventoryCrafting craftSlots; + public final TransientCraftingContainer craftSlots; // CraftBukkit public 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); @@ -35,8 +44,11 @@ public ContainerWorkbench(int i, PlayerInventory playerinventory, ContainerAccess containeraccess) { super(Containers.CRAFTING, i); - this.craftSlots = new TransientCraftingContainer(this, 3, 3); + // CraftBukkit start - Switched order of IInventory construction and stored player this.resultSlots = new InventoryCraftResult(); + this.craftSlots = new TransientCraftingContainer(this, 3, 3, playerinventory.player); // CraftBukkit - pass player + this.craftSlots.resultInventory = this.resultSlots; + // CraftBukkit end this.access = containeraccess; this.player = playerinventory.player; this.addSlot(new SlotResult(playerinventory.player, this.craftSlots, this.resultSlots, 0, 124, 35)); @@ -80,6 +92,7 @@ } } } + itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), optional.map(RecipeHolder::toBukkitRecipe).orElse(null) instanceof RecipeRepair); // CraftBukkit inventorycraftresult.setItem(0, itemstack); container.setRemoteSlot(0, itemstack); @@ -120,6 +133,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { + if (!this.checkReachable) return true; // CraftBukkit return stillValid(this.access, entityhuman, Blocks.CRAFTING_TABLE); } @@ -208,4 +222,17 @@ public boolean shouldMoveToInventory(int i) { return i != this.getResultSlotIndex(); } + + // 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 }