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
|
package gregtech.api.gui;
import gregtech.api.enums.GT_Values;
import gregtech.api.gui.widgets.GT_GuiIcon;
import gregtech.api.gui.widgets.GT_GuiTabLine.GT_GuiTabIconSet;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine_Bronze;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine_Steel;
import gregtech.api.net.GT_Packet_SetConfigurationCircuit;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static gregtech.api.enums.GT_Values.RES_PATH_GUI;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
* <p/>
* The GUI-Container I use for all my Basic Machines
* <p/>
* As the NEI-RecipeTransferRect Handler can't handle one GUI-Class for all GUIs I needed to produce some dummy-classes which extend this class
*/
public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machine {
private static final List<String> GHOST_CIRCUIT_TOOLTIP = Arrays.asList(
"GT5U.machines.select_circuit.tooltip",
"GT5U.machines.select_circuit.tooltip.1",
"GT5U.machines.select_circuit.tooltip.2",
"GT5U.machines.select_circuit.tooltip.3"
);
private final static GT_GuiTabIconSet TAB_ICONSET_BRONZE = new GT_GuiTabIconSet(
GT_GuiIcon.TAB_NORMAL_BRONZE,
GT_GuiIcon.TAB_HIGHLIGHT_BRONZE,
GT_GuiIcon.TAB_DISABLED_BRONZE);
private final static GT_GuiTabIconSet TAB_ICONSET_STEEL = new GT_GuiTabIconSet(
GT_GuiIcon.TAB_NORMAL_STEEL,
GT_GuiIcon.TAB_HIGHLIGHT_STEEL,
GT_GuiIcon.TAB_DISABLED_STEEL);
public final String
mName,
mNEI;
public final byte
mProgressBarDirection,
mProgressBarAmount;
public final boolean
mRenderAutoOutputSlots;
public GT_GUIContainer_BasicMachine(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName, String aTextureFile, String aNEI) {
this(aInventoryPlayer, aTileEntity, aName, aTextureFile, aNEI, (byte) 0, (byte) 1);
}
public GT_GUIContainer_BasicMachine(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName, String aTextureFile, String aNEI, byte aProgressBarDirection, byte aProgressBarAmount) {
super(new GT_Container_BasicMachine(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "basicmachines/" + aTextureFile);
getContainer().setCircuitSlotClickCallback(this::openSelectCircuitDialog);
mProgressBarDirection = aProgressBarDirection;
mProgressBarAmount = (byte) Math.max(1, aProgressBarAmount);
mName = aName;
mNEI = aNEI;
mRenderAutoOutputSlots = !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_BasicMachine_Bronze);
}
private void openSelectCircuitDialog() {
mc.displayGuiScreen(new GT_GUIDialogSelectItem(
StatCollector.translateToLocal("GT5U.machines.select_circuit"),
mContainer.mTileEntity.getMetaTileEntity().getStackForm(0),
this,
this::onCircuitSelected,
getMachine().getConfigurationCircuits(),
GT_Utility.findMatchingStackInList(getMachine().getConfigurationCircuits(), getMachine().getStackInSlot(getMachine().getCircuitSlot()))));
}
private void onCircuitSelected(ItemStack selected) {
GT_Values.NW.sendToServer(new GT_Packet_SetConfigurationCircuit(mContainer.mTileEntity, selected));
// we will not do any validation on client side
// it doesn't get to actually decide what inventory contains anyway
mContainer.mTileEntity.setInventorySlotContents(getMachine().getCircuitSlot(), selected);
}
private GT_MetaTileEntity_BasicMachine getMachine() {
return (GT_MetaTileEntity_BasicMachine) mContainer.mTileEntity.getMetaTileEntity();
}
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
if (mRenderAutoOutputSlots){
drawTooltip(par1, par2);
}
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
fontRendererObj.drawString(mName, 8, 4, 4210752);
}
private void drawTooltip(int x2, int y2) {
int xStart = (width - xSize) / 2;
int yStart = (height - ySize) / 2;
int x = x2 - xStart;
int y = y2 - yStart + 5;
if (y >= 67 && y <= 84) {
if (mRenderAutoOutputSlots && x >= 7 && x <= 24) {
drawHoveringText(Collections.singletonList("Fluid Auto-Output"), x2, y2, fontRendererObj);
}
if (mRenderAutoOutputSlots && x >= 25 && x <= 42) {
drawHoveringText(Collections.singletonList("Item Auto-Output"), x2, y2, fontRendererObj);
}
if (getMachine().allowSelectCircuit() && getMachine().getStackInSlot(getMachine().getCircuitSlot()) == null && x >= 153 && x <= 171) {
drawHoveringText(GHOST_CIRCUIT_TOOLTIP.stream().map(StatCollector::translateToLocal).collect(Collectors.toList()), x2, y2, fontRendererObj);
}
}
}
@Override
protected void onMouseWheel(int mx, int my, int delta) {
GT_Slot_Render slotCircuit = getContainer().slotCircuit;
if (slotCircuit != null && func_146978_c(slotCircuit.xDisplayPosition, slotCircuit.yDisplayPosition, 16, 16, mx, my)) {
// emulate click
handleMouseClick(slotCircuit, -1, delta > 0 ? 1 : 0, 0);
return;
}
super.onMouseWheel(mx, my, delta);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
if (mContainer != null) {
if (mRenderAutoOutputSlots){
if (getContainer().mFluidTransfer)
drawTexturedModalRect(x + 7, y + 62, 176, 18, 18, 18);
if (getContainer().mItemTransfer)
drawTexturedModalRect(x + 25, y + 62, 176, 36, 18, 18);
}
if (getContainer().mStuttering)
drawTexturedModalRect(x + 79, y + 44, 176, 54, 18, 18);
if (mContainer.mMaxProgressTime > 0) {
int tSize = mProgressBarDirection < 2 ? 20 : 18, tProgress = Math.max(1, Math.min(tSize * mProgressBarAmount, (mContainer.mProgressTime > 0 ? 1 : 0) + mContainer.mProgressTime * tSize * mProgressBarAmount / mContainer.mMaxProgressTime)) % (tSize + 1);
switch (mProgressBarDirection) { // yes, my OCD was mad at me before I did the Tabs.
case 0:
drawTexturedModalRect(x + 78, y + 24, 176, 0, tProgress, 18);
break;
case 1:
drawTexturedModalRect(x + 78 + 20 - tProgress, y + 24, 176 + 20 - tProgress, 0, tProgress, 18);
break;
case 2:
drawTexturedModalRect(x + 78, y + 24, 176, 0, 20, tProgress);
break;
case 3:
drawTexturedModalRect(x + 78, y + 24 + 18 - tProgress, 176, 18 - tProgress, 20, tProgress);
break;
case 4:
tProgress = 20 - tProgress;
drawTexturedModalRect(x + 78, y + 24, 176, 0, tProgress, 18);
break;
case 5:
tProgress = 20 - tProgress;
drawTexturedModalRect(x + 78 + 20 - tProgress, y + 24, 176 + 20 - tProgress, 0, tProgress, 18);
break;
case 6:
tProgress = 18 - tProgress;
drawTexturedModalRect(x + 78, y + 24, 176, 0, 20, tProgress);
break;
case 7:
tProgress = 18 - tProgress;
drawTexturedModalRect(x + 78, y + 24 + 18 - tProgress, 176, 18 - tProgress, 20, tProgress);
break;
}
}
}
}
@Override
protected GT_GuiTabIconSet getTabBackground() {
if (getMachine().isSteampowered()) {
return getMachine() instanceof GT_MetaTileEntity_BasicMachine_Steel
? TAB_ICONSET_STEEL : TAB_ICONSET_BRONZE;
}
return super.getTabBackground();
}
private GT_Container_BasicMachine getContainer() {
return (GT_Container_BasicMachine) mContainer;
}
}
|