CraftBukkit/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch
2022-12-08 03:00:00 +11:00

73 lines
2.9 KiB
Diff

--- a/net/minecraft/world/inventory/ContainerWorkbench.java
+++ b/net/minecraft/world/inventory/ContainerWorkbench.java
@@ -14,6 +14,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<InventoryCrafting> {
public static final int RESULT_SLOT = 0;
@@ -27,6 +33,9 @@
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);
@@ -34,8 +43,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.addSlot(new SlotResult(playerinventory.player, this.craftSlots, this.resultSlots, 0, 124, 35));
@@ -78,6 +90,7 @@
}
}
}
+ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), optional.orElse(null) instanceof RecipeRepair); // CraftBukkit
inventorycraftresult.setItem(0, itemstack);
container.setRemoteSlot(0, itemstack);
@@ -118,6 +131,7 @@
@Override
public boolean stillValid(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return stillValid(this.access, entityhuman, Blocks.CRAFTING_TABLE);
}
@@ -206,4 +220,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
}