aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower-stripped/net/minecraft/world/inventory/LoomMenu.java.patch
blob: 0fa04cefb8e1a760d670c0f463327bc8548dec67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--- a/net/minecraft/world/inventory/LoomMenu.java
+++ b/net/minecraft/world/inventory/LoomMenu.java
@@ -24,8 +22,30 @@
 import net.minecraft.world.level.block.Blocks;
 import net.minecraft.world.level.block.entity.BannerPattern;
 import net.minecraft.world.level.block.entity.BlockEntityType;
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.inventory.CraftInventoryLoom;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+import org.bukkit.entity.Player;
+// CraftBukkit end
 
 public class LoomMenu extends AbstractContainerMenu {
+
+    // CraftBukkit start
+    private CraftInventoryView bukkitEntity = null;
+    private Player player;
+
+    @Override
+    public CraftInventoryView getBukkitView() {
+        if (bukkitEntity != null) {
+            return bukkitEntity;
+        }
+
+        CraftInventoryLoom inventory = new CraftInventoryLoom(this.inputContainer, this.outputContainer);
+        bukkitEntity = new CraftInventoryView(this.player, inventory, this);
+        return bukkitEntity;
+    }
+    // CraftBukkit end
     private static final int PATTERN_NOT_SET = -1;
     private static final int INV_SLOT_START = 4;
     private static final int INV_SLOT_END = 31;
@@ -63,6 +69,39 @@
 
     public LoomMenu(int containerId, Inventory playerInventory, final ContainerLevelAccess access) {
         super(MenuType.LOOM, containerId);
+        this.selectedBannerPatternIndex = DataSlot.standalone();
+        this.selectablePatterns = List.of();
+        this.slotUpdateListener = () -> {
+        };
+        this.inputContainer = new SimpleContainer(3) {
+            @Override
+            public void setChanged() {
+                super.setChanged();
+                LoomMenu.this.slotsChanged(this);
+                LoomMenu.this.slotUpdateListener.run();
+            }
+
+            // CraftBukkit start
+            @Override
+            public Location getLocation() {
+                return access.getLocation();
+            }
+            // CraftBukkit end
+        };
+        this.outputContainer = new SimpleContainer(1) {
+            @Override
+            public void setChanged() {
+                super.setChanged();
+                LoomMenu.this.slotUpdateListener.run();
+            }
+
+            // CraftBukkit start
+            @Override
+            public Location getLocation() {
+                return access.getLocation();
+            }
+            // CraftBukkit end
+        };
         this.access = access;
         this.bannerSlot = this.addSlot(new Slot(this.inputContainer, 0, 13, 26) {
             @Override
@@ -118,10 +161,12 @@
         }
 
         this.addDataSlot(this.selectedBannerPatternIndex);
+        player = (Player) playerInventory.player.getBukkitEntity(); // CraftBukkit
     }
 
     @Override
-    public boolean stillValid(Player player) {
+    public boolean stillValid(net.minecraft.world.entity.player.Player player) {
+        if (!this.checkReachable) return true; // CraftBukkit
         return stillValid(this.access, player, Blocks.LOOM);
     }
 
@@ -275,16 +332,23 @@
     }
 
     private void setupResultSlot(Holder<BannerPattern> pattern) {
-        ItemStack item = this.bannerSlot.getItem();
-        ItemStack item1 = this.dyeSlot.getItem();
-        ItemStack itemStack = ItemStack.EMPTY;
-        if (!item.isEmpty() && !item1.isEmpty()) {
-            itemStack = item.copyWithCount(1);
-            DyeColor dyeColor = ((DyeItem)item1.getItem()).getDyeColor();
-            CompoundTag blockEntityData = BlockItem.getBlockEntityData(itemStack);
-            ListTag list;
-            if (blockEntityData != null && blockEntityData.contains("Patterns", 9)) {
-                list = blockEntityData.getList("Patterns", 10);
+        ItemStack itemstack = this.bannerSlot.getItem();
+        ItemStack itemstack1 = this.dyeSlot.getItem();
+        ItemStack itemstack2 = ItemStack.EMPTY;
+
+        if (!itemstack.isEmpty() && !itemstack1.isEmpty()) {
+            itemstack2 = itemstack.copyWithCount(1);
+            DyeColor enumcolor = ((DyeItem) itemstack1.getItem()).getDyeColor();
+            CompoundTag nbttagcompound = BlockItem.getBlockEntityData(itemstack2);
+            ListTag nbttaglist;
+
+            if (nbttagcompound != null && nbttagcompound.contains("Patterns", 9)) {
+                nbttaglist = nbttagcompound.getList("Patterns", 10);
+                // CraftBukkit start
+                while (nbttaglist.size() > 20) {
+                    nbttaglist.remove(20);
+                }
+                // CraftBukkit end
             } else {
                 list = new ListTag();
                 if (blockEntityData == null) {