-
Notifications
You must be signed in to change notification settings - Fork 497
/
ContainerEmzuliPipe.java
177 lines (153 loc) · 5.51 KB
/
ContainerEmzuliPipe.java
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
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.gui;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.EnumColor;
import buildcraft.core.lib.gui.BuildCraftContainer;
import buildcraft.core.lib.gui.GuiBuildCraft;
import buildcraft.core.lib.gui.slots.SlotPhantom;
import buildcraft.core.lib.gui.tooltips.ToolTip;
import buildcraft.core.lib.gui.tooltips.ToolTipLine;
import buildcraft.core.lib.gui.widgets.ButtonWidget;
import buildcraft.core.lib.network.PacketGuiReturn;
import buildcraft.core.lib.utils.RevolvingList;
import buildcraft.core.lib.utils.StringUtils;
import buildcraft.transport.pipes.PipeItemsEmzuli;
public class ContainerEmzuliPipe extends BuildCraftContainer {
private final PipeItemsEmzuli pipe;
private final IInventory filterInv;
private final byte[] prevSlotColors = new byte[4];
private final PaintWidget[] paintWidgets = new PaintWidget[4];
public ContainerEmzuliPipe(IInventory playerInventory, PipeItemsEmzuli pipe) {
super(pipe.getFilters().getSizeInventory());
this.pipe = pipe;
filterInv = pipe.getFilters();
addWidget(paintWidgets[0] = new PaintWidget(0, 51, 19));
addWidget(paintWidgets[1] = new PaintWidget(1, 104, 19));
addWidget(paintWidgets[2] = new PaintWidget(2, 51, 47));
addWidget(paintWidgets[3] = new PaintWidget(3, 104, 47));
addSlot(new SlotPhantom(filterInv, 0, 25, 21));
addSlot(new SlotPhantom(filterInv, 1, 134, 21));
addSlot(new SlotPhantom(filterInv, 2, 25, 49));
addSlot(new SlotPhantom(filterInv, 3, 134, 49));
for (int l = 0; l < 3; l++) {
for (int k1 = 0; k1 < 9; k1++) {
addSlotToContainer(new Slot(playerInventory, k1 + l * 9 + 9, 8 + k1 * 18, 84 + l * 18));
}
}
for (int i1 = 0; i1 < 9; i1++) {
addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 142));
}
}
@Override
public void addCraftingToCrafters(ICrafting player) {
super.addCraftingToCrafters(player);
for (int slot = 0; slot < pipe.slotColors.length; slot++) {
prevSlotColors[slot] = pipe.slotColors[slot];
player.sendProgressBarUpdate(this, slot, pipe.slotColors[slot]);
}
}
/**
* Updates crafting matrix; called from onCraftMatrixChanged. Args: none
*/
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); ++i) {
ICrafting player = (ICrafting) crafters.get(i);
for (int slot = 0; slot < pipe.slotColors.length; slot++) {
if (prevSlotColors[slot] != pipe.slotColors[slot]) {
player.sendProgressBarUpdate(this, slot, pipe.slotColors[slot]);
}
}
}
System.arraycopy(pipe.slotColors, 0, prevSlotColors, 0, pipe.slotColors.length);
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data) {
paintWidgets[id].colors.setCurrent(data == 0 ? null : EnumColor.fromId(data - 1));
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return pipe.container.isUseableByPlayer(entityplayer);
}
private class PaintWidget extends ButtonWidget {
private final int slot;
private RevolvingList<EnumColor> colors = new RevolvingList<EnumColor>();
private ToolTip toolTip = new ToolTip(500) {
@Override
public void refresh() {
toolTip.clear();
EnumColor color = colors.getCurrent();
if (color != null) {
toolTip.add(new ToolTipLine(String.format(StringUtils.localize("gui.pipes.emzuli.paint"), color.getLocalizedName())));
} else {
toolTip.add(new ToolTipLine(StringUtils.localize("gui.pipes.emzuli.nopaint")));
}
}
};
public PaintWidget(int slot, int x, int y) {
super(x, y, 176, 0, 20, 20);
this.slot = slot;
colors.add(null);
colors.addAll(Arrays.asList(EnumColor.VALUES));
}
@Override
public void draw(GuiBuildCraft gui, int guiX, int guiY, int mouseX, int mouseY) {
super.draw(gui, guiX, guiY, mouseX, mouseY);
EnumColor color = colors.getCurrent();
if (color != null) {
gui.bindTexture(TextureMap.locationItemsTexture);
gui.drawTexturedModelRectFromIcon(guiX + x + 2, guiY + y + 2, BuildCraftTransport.actionPipeColor[color.ordinal()].getIcon(), 16, 16);
} else {
gui.drawTexturedModalRect(guiX + x + 2, guiY + y + 2, u, v + h + h, 16, 16);
}
}
@Override
public void onRelease(int mouseButton) {
switch (mouseButton) {
case 0:
colors.rotateLeft();
break;
case 1:
colors.rotateRight();
break;
case 2:
colors.setCurrent(null);
break;
}
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
data.writeByte(slot);
EnumColor color = colors.getCurrent();
data.writeByte(color == null ? 0 : color.ordinal() + 1);
PacketGuiReturn pkt = new PacketGuiReturn(pipe.getContainer(), bytes.toByteArray());
pkt.sendPacket();
} catch (IOException ex) {
}
}
@Override
public ToolTip getToolTip() {
return toolTip;
}
}
}