0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-22 05:26:17 +00:00
craftbukkit/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch
2024-10-23 02:15:00 +11:00

76 lines
3.0 KiB
Diff

--- a/net/minecraft/world/inventory/ContainerWorkbench.java
+++ b/net/minecraft/world/inventory/ContainerWorkbench.java
@@ -16,6 +16,12 @@
import net.minecraft.world.item.crafting.Recipes;
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 AbstractCraftingMenu {
private static final int CRAFTING_GRID_WIDTH = 3;
@@ -31,13 +37,16 @@
public final ContainerAccess access;
private final EntityHuman player;
private boolean placingRecipe;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ // CraftBukkit end
public ContainerWorkbench(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.NULL);
}
public ContainerWorkbench(int i, PlayerInventory playerinventory, ContainerAccess containeraccess) {
- super(Containers.CRAFTING, i, 3, 3);
+ super(Containers.CRAFTING, i, 3, 3, playerinventory); // CraftBukkit - pass player
this.access = containeraccess;
this.player = playerinventory.player;
this.addResultSlot(this.player, 124, 35);
@@ -50,6 +59,7 @@
EntityPlayer entityplayer = (EntityPlayer) entityhuman;
ItemStack itemstack = ItemStack.EMPTY;
Optional<RecipeHolder<RecipeCrafting>> optional = worldserver.getServer().getRecipeManager().getRecipeFor(Recipes.CRAFTING, craftinginput, worldserver, recipeholder);
+ inventorycrafting.setCurrentRecipe(optional.orElse(null)); // CraftBukkit
if (optional.isPresent()) {
RecipeHolder<RecipeCrafting> recipeholder1 = (RecipeHolder) optional.get();
@@ -63,6 +73,7 @@
}
}
}
+ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), optional.map(RecipeHolder::value).orElse(null) instanceof RecipeRepair); // CraftBukkit
inventorycraftresult.setItem(0, itemstack);
container.setRemoteSlot(0, itemstack);
@@ -103,6 +114,7 @@
@Override
public boolean stillValid(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return stillValid(this.access, entityhuman, Blocks.CRAFTING_TABLE);
}
@@ -181,4 +193,17 @@
protected EntityHuman owner() {
return this.player;
}
+
+ // 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
}