-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathCraftingStationInputWidgetGroup.java
More file actions
68 lines (57 loc) · 2.62 KB
/
CraftingStationInputWidgetGroup.java
File metadata and controls
68 lines (57 loc) · 2.62 KB
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
package gregtech.api.gui.widgets;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.IRenderContext;
import gregtech.api.gui.Widget;
import gregtech.api.util.Position;
import gregtech.common.metatileentities.storage.CraftingRecipeLogic;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.ItemStackHandler;
public class CraftingStationInputWidgetGroup extends AbstractWidgetGroup {
protected CraftingRecipeLogic recipeResolver;
protected short tintLocations;
public static final int LIGHT_RED = 0x66FF0000;
public CraftingStationInputWidgetGroup(int x, int y, ItemStackHandler craftingGrid,
CraftingRecipeLogic recipeResolver) {
super(new Position(x, y));
// crafting grid
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
this.addWidget(new PhantomSlotWidget(craftingGrid, j + i * 3, x + j * 18, y + i * 18)
.setBackgroundTexture(GuiTextures.SLOT));
}
}
this.recipeResolver = recipeResolver;
}
@Override
public void drawInBackground(int mouseX, int mouseY, float partialTicks, IRenderContext context) {
super.drawInBackground(mouseX, mouseY, partialTicks, context);
if (this.widgets.size() == 9) { // In case someone added more...
for (int i = 0; i < 9; i++) {
Widget widget = widgets.get(i);
if (widget instanceof PhantomSlotWidget && ((tintLocations >> i) & 1) == 0) { // In other words, is this
// slot usable?
int color = LIGHT_RED;
PhantomSlotWidget phantomSlotWidget = (PhantomSlotWidget) widget;
drawSolidRect(phantomSlotWidget.getPosition().x + 1, phantomSlotWidget.getPosition().y + 1,
phantomSlotWidget.getSize().getWidth() - 2, phantomSlotWidget.getSize().getWidth() - 2,
color);
}
}
}
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
short newTintLocations = recipeResolver.getTintLocations();
if (tintLocations != newTintLocations) {
this.tintLocations = newTintLocations;
writeUpdateInfo(2, buffer -> buffer.writeShort(tintLocations));
}
}
public void readUpdateInfo(int id, PacketBuffer buffer) {
super.readUpdateInfo(id, buffer);
if (id == 2) {
tintLocations = buffer.readShort();
}
}
}