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
|
package de.hysky.skyblocker.skyblock.item;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;
import java.util.Arrays;
public class SkyblockCraftingTableScreenHandler extends GenericContainerScreenHandler {
private static final int[] normalSlots = new int[]{
10, 11, 12, 16,
19, 20, 21, 23, 25,
28, 29, 30, 34
};
public SkyblockCraftingTableScreenHandler(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, Inventory inventory, int rows) {
super(type, syncId, playerInventory, inventory, rows);
for (int i = 0; i < rows * 9; i++) {
Slot originalSlot = slots.get(i);
if (Arrays.binarySearch(normalSlots, i) >= 0) {
int[] coords = getCoords(i);
Slot slot = new Slot(originalSlot.inventory, originalSlot.getIndex(), coords[0], coords[1]);
slot.id = i;
slots.set(i, slot);
} else {
DisabledSlot slot = new DisabledSlot(originalSlot.inventory, originalSlot.getIndex(), originalSlot.x, originalSlot.y);
slot.id = i;
slots.set(i, slot);
}
}
int yOffset = (rows - 4) * 18 + 19;
for (int i = rows * 9; i < slots.size(); i++) {
Slot originalSlot = slots.get(i);
Slot slot = new Slot(originalSlot.inventory, originalSlot.getIndex(), originalSlot.x, originalSlot.y - yOffset);
slot.id = i;
slots.set(i, slot);
}
}
public SkyblockCraftingTableScreenHandler(GenericContainerScreenHandler handler, PlayerInventory playerInventory) {
this(handler.getType(), handler.syncId, playerInventory, handler.getInventory(), handler.getRows());
}
private int[] getCoords(int slot) {
if (slot == 23) return new int[]{124, 35};
if (slot == 16 || slot == 25 || slot == 34) {
int y = (slot / 9 - 1) * 18 + 8;
return new int[]{174, y};
}
int gridX = slot % 9 - 1;
int gridY = slot / 9 - 1;
return new int[]{30 + gridX * 18, 17 + gridY * 18};
}
public static class DisabledSlot extends Slot {
public DisabledSlot(Inventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
}
@Override
public boolean isEnabled() {
return false;
}
}
}
|