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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
--- a/net/minecraft/world/inventory/CrafterMenu.java
+++ b/net/minecraft/world/inventory/CrafterMenu.java
@@ -5,11 +5,30 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
-import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.CrafterBlock;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafter;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class CrafterMenu extends AbstractContainerMenu implements ContainerListener {
+
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventoryCrafter inventory = new CraftInventoryCrafter(this.container, this.resultContainer);
+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
protected static final int SLOT_COUNT = 9;
private static final int INV_SLOT_START = 9;
private static final int INV_SLOT_END = 36;
@@ -18,43 +37,47 @@
private final ResultContainer resultContainer = new ResultContainer();
private final ContainerData containerData;
private final Player player;
- private final CraftingContainer container;
+ private final InventoryCrafting container;
- public CrafterMenu(int containerId, Inventory inventory) {
- super(MenuType.CRAFTER_3x3, containerId);
- this.player = inventory.player;
+ public CrafterMenu(int i, Inventory playerinventory) {
+ super(MenuType.CRAFTER_3x3, i);
+ this.player = playerinventory.player;
this.containerData = new SimpleContainerData(10);
this.container = new TransientCraftingContainer(this, 3, 3);
- this.addSlots(inventory);
+ this.addSlots(playerinventory);
}
- public CrafterMenu(int containerId, Inventory inventory, CraftingContainer craftingContainer, ContainerData containerData) {
- super(MenuType.CRAFTER_3x3, containerId);
- this.player = inventory.player;
- this.containerData = containerData;
- this.container = craftingContainer;
- checkContainerSize(craftingContainer, 9);
- craftingContainer.startOpen(inventory.player);
- this.addSlots(inventory);
+ public CrafterMenu(int i, Inventory playerinventory, InventoryCrafting inventorycrafting, ContainerData icontainerproperties) {
+ super(MenuType.CRAFTER_3x3, i);
+ this.player = playerinventory.player;
+ this.containerData = icontainerproperties;
+ this.container = inventorycrafting;
+ checkContainerSize(inventorycrafting, 9);
+ inventorycrafting.startOpen(playerinventory.player);
+ this.addSlots(playerinventory);
this.addSlotListener(this);
}
- private void addSlots(Inventory inventory) {
- for (int i = 0; i < 3; i++) {
- for (int i1 = 0; i1 < 3; i1++) {
- int i2 = i1 + i * 3;
- this.addSlot(new CrafterSlot(this.container, i2, 26 + i1 * 18, 17 + i * 18, this));
+ private void addSlots(Inventory playerinventory) {
+ int i;
+ int j;
+
+ for (j = 0; j < 3; ++j) {
+ for (i = 0; i < 3; ++i) {
+ int k = i + j * 3;
+
+ this.addSlot(new CrafterSlot(this.container, k, 26 + i * 18, 17 + j * 18, this));
}
}
- for (int i = 0; i < 3; i++) {
- for (int i1 = 0; i1 < 9; i1++) {
- this.addSlot(new Slot(inventory, i1 + i * 9 + 9, 8 + i1 * 18, 84 + i * 18));
+ for (j = 0; j < 3; ++j) {
+ for (i = 0; i < 9; ++i) {
+ this.addSlot(new Slot(playerinventory, i + j * 9 + 9, 8 + i * 18, 84 + j * 18));
}
}
- for (int i = 0; i < 9; i++) {
- this.addSlot(new Slot(inventory, i, 8 + i * 18, 142));
+ for (j = 0; j < 9; ++j) {
+ this.addSlot(new Slot(playerinventory, j, 8 + j * 18, 142));
}
this.addSlot(new NonInteractiveResultSlot(this.resultContainer, 0, 134, 35));
@@ -63,13 +86,14 @@
}
public void setSlotState(int i, boolean flag) {
- CrafterSlot crafterSlot = (CrafterSlot)this.getSlot(i);
- this.containerData.set(crafterSlot.index, flag ? 0 : 1);
+ CrafterSlot crafterslot = (CrafterSlot) this.getSlot(i);
+
+ this.containerData.set(crafterslot.index, flag ? 0 : 1);
this.broadcastChanges();
}
public boolean isSlotDisabled(int i) {
- return i > -1 && i < 9 && this.containerData.get(i) == 1;
+ return i > -1 && i < 9 ? this.containerData.get(i) == 1 : false;
}
public boolean isPowered() {
@@ -78,48 +102,56 @@
@Override
public ItemStack quickMoveStack(Player player, int index) {
- ItemStack itemStack = ItemStack.EMPTY;
- Slot slot = this.slots.get(index);
+ ItemStack itemstack = ItemStack.EMPTY;
+ Slot slot = (Slot) this.slots.get(index);
+
if (slot != null && slot.hasItem()) {
- ItemStack item = slot.getItem();
- itemStack = item.copy();
+ ItemStack itemstack1 = slot.getItem();
+
+ itemstack = itemstack1.copy();
if (index < 9) {
- if (!this.moveItemStackTo(item, 9, 45, true)) {
+ if (!this.moveItemStackTo(itemstack1, 9, 45, true)) {
return ItemStack.EMPTY;
}
- } else if (!this.moveItemStackTo(item, 0, 9, false)) {
+ } else if (!this.moveItemStackTo(itemstack1, 0, 9, false)) {
return ItemStack.EMPTY;
}
- if (item.isEmpty()) {
+ if (itemstack1.isEmpty()) {
slot.set(ItemStack.EMPTY);
} else {
slot.setChanged();
}
- if (item.getCount() == itemStack.getCount()) {
+ if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.EMPTY;
}
- slot.onTake(player, item);
+ slot.onTake(player, itemstack1);
}
- return itemStack;
+ return itemstack;
}
@Override
public boolean stillValid(Player player) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.container.stillValid(player);
}
private void refreshRecipeResult() {
- if (this.player instanceof ServerPlayer serverPlayer) {
- Level level = serverPlayer.level();
- ItemStack itemStack = CrafterBlock.getPotentialResults(level, this.container)
- .map(craftingRecipe -> craftingRecipe.assemble(this.container, level.registryAccess()))
- .orElse(ItemStack.EMPTY);
- this.resultContainer.setItem(0, itemStack);
+ Player entityhuman = this.player;
+
+ if (entityhuman instanceof ServerPlayer) {
+ ServerPlayer entityplayer = (ServerPlayer) entityhuman;
+ Level world = entityplayer.level();
+ ItemStack itemstack = (ItemStack) CrafterBlock.getPotentialResults(world, this.container).map((recipecrafting) -> {
+ return recipecrafting.assemble(this.container, world.registryAccess());
+ }).orElse(ItemStack.EMPTY);
+
+ this.resultContainer.setItem(0, itemstack);
}
+
}
public Container getContainer() {
@@ -132,6 +164,5 @@
}
@Override
- public void dataChanged(AbstractContainerMenu containerMenu, int dataSlotIndex, int value) {
- }
+ public void dataChanged(AbstractContainerMenu containerMenu, int dataSlotIndex, int value) {}
}
|