craftbukkit/nms-patches/net/minecraft/world/inventory/TransientCraftingContainer.patch

89 lines
2.6 KiB
Diff
Raw Normal View History

2023-06-08 01:30:00 +10:00
--- a/net/minecraft/world/inventory/TransientCraftingContainer.java
+++ b/net/minecraft/world/inventory/TransientCraftingContainer.java
@@ -8,6 +8,16 @@
2021-03-16 09:00:00 +11:00
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.item.ItemStack;
2021-03-09 08:47:33 +11:00
+// CraftBukkit start
+import java.util.List;
2023-06-08 01:30:00 +10:00
+import net.minecraft.world.IInventory;
2023-09-22 02:40:00 +10:00
+import net.minecraft.world.item.crafting.RecipeHolder;
2016-03-01 08:32:46 +11:00
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.inventory.InventoryType;
+// CraftBukkit end
2021-03-09 08:47:33 +11:00
+
2023-06-08 01:30:00 +10:00
public class TransientCraftingContainer implements InventoryCrafting {
2021-03-09 08:47:33 +11:00
private final NonNullList<ItemStack> items;
2023-06-08 01:30:00 +10:00
@@ -15,6 +25,68 @@
2021-06-11 15:00:00 +10:00
private final int height;
2023-06-08 01:30:00 +10:00
private final Container menu;
2015-02-26 22:41:06 +00:00
+ // CraftBukkit start - add fields
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
2023-09-22 02:40:00 +10:00
+ private RecipeHolder<?> currentRecipe;
+ public IInventory resultInventory;
+ private EntityHuman owner;
+ private int maxStack = MAX_STACK;
+
2016-11-17 12:41:03 +11:00
+ public List<ItemStack> getContents() {
+ return this.items;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public InventoryType getInvType() {
2016-11-17 12:41:03 +11:00
+ return items.size() == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH;
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ return (owner == null) ? null : owner.getBukkitEntity();
+ }
+
2019-04-23 12:00:00 +10:00
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ resultInventory.setMaxStackSize(size);
+ }
+
2016-03-01 08:32:46 +11:00
+ @Override
+ public Location getLocation() {
2021-06-11 15:00:00 +10:00
+ return menu instanceof ContainerWorkbench ? ((ContainerWorkbench) menu).access.getLocation() : owner.getBukkitEntity().getLocation();
2016-03-01 08:32:46 +11:00
+ }
+
2018-07-15 10:00:00 +10:00
+ @Override
2023-09-22 02:40:00 +10:00
+ public RecipeHolder<?> getCurrentRecipe() {
2018-07-15 10:00:00 +10:00
+ return currentRecipe;
+ }
+
+ @Override
2023-09-22 02:40:00 +10:00
+ public void setCurrentRecipe(RecipeHolder<?> currentRecipe) {
2018-07-15 10:00:00 +10:00
+ this.currentRecipe = currentRecipe;
+ }
+
2023-06-08 01:30:00 +10:00
+ public TransientCraftingContainer(Container container, int i, int j, EntityHuman player) {
+ this(container, i, j);
+ this.owner = player;
+ }
2015-02-26 22:41:06 +00:00
+ // CraftBukkit end
+
2023-06-08 01:30:00 +10:00
public TransientCraftingContainer(Container container, int i, int j) {
this(container, i, j, NonNullList.withSize(i * j, ItemStack.EMPTY));
}