CraftBukkit/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch
2021-07-22 11:37:22 +10:00

83 lines
3.5 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;
@@ -23,10 +29,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;
- private final InventoryCrafting craftSlots;
- private final InventoryCraftResult resultSlots;
+ public final InventoryCrafting craftSlots; // PAIL private -> public
+ public final InventoryCraftResult resultSlots; // PAIL private -> public
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.a((Slot) (new SlotResult(playerinventory.player, this.craftSlots, this.resultSlots, 0, 124, 35)));
@@ -71,9 +83,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(), optional.orElse(null) instanceof RecipeRepair); // CraftBukkit
inventorycraftresult.setItem(0, itemstack);
container.a(0, itemstack);
@@ -114,6 +127,7 @@
@Override
public boolean canUse(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return a(this.access, entityhuman, Blocks.CRAFTING_TABLE);
}
@@ -202,4 +216,17 @@
public boolean d(int i) {
return i != this.m();
}
+
+ // 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
}