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
|
package gregtech.common.tileentities.machines.multi.purification;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.api.math.Color;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import com.gtnewhorizons.modularui.common.widget.TextWidget;
import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget;
import gregtech.api.enums.Textures;
import gregtech.api.gui.modularui.GTUIInfos;
import gregtech.api.gui.modularui.GTUITextures;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.MTEHatch;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTUtility;
import gregtech.common.gui.modularui.widget.CoverCycleButtonWidget;
public class MTEHatchPHSensor extends MTEHatch {
// This implementation was largely copied from the neutron sensor hatch
protected float threshold = 0;
protected boolean inverted = false;
private boolean isOn = false;
private static final IIconContainer textureFont = Textures.BlockIcons.OVERLAY_HATCH_PH_SENSOR;
private static final IIconContainer textureFont_Glow = Textures.BlockIcons.OVERLAY_HATCH_PH_SENSOR_GLOW;
public MTEHatchPHSensor(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 0, "Detects pH value.");
}
public MTEHatchPHSensor(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 0, aDescription, aTextures);
}
@Override
public boolean isValidSlot(int aIndex) {
return false;
}
@Override
public boolean isSimpleMachine() {
return true;
}
@Override
public boolean isFacingValid(ForgeDirection facing) {
return true;
}
@Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
@Override
public boolean allowGeneralRedstoneOutput() {
return true;
}
@Override
public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection Side,
ItemStack aStack) {
return false;
}
@Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
return false;
}
@Override
public void initDefaultModes(NBTTagCompound aNBT) {
getBaseMetaTileEntity().setActive(true);
}
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
float aX, float aY, float aZ) {
GTUIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer);
return true;
}
@Override
public String[] getDescription() {
return new String[] { "Can be installed in the pH Neutralization Purification Unit.",
"Outputs Redstone Signal according to the current pH value.",
"Right click to open the GUI and change settings." };
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
threshold = aNBT.getFloat("mThreshold");
inverted = aNBT.getBoolean("mInverted");
super.loadNBTData(aNBT);
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setFloat("mThreshold", threshold);
aNBT.setBoolean("mInverted", inverted);
super.saveNBTData(aNBT);
}
/**
* Updates redstone output strength based on the pH of the multiblock.
*/
public void updateRedstoneOutput(float pH) {
isOn = (pH > threshold) ^ inverted;
}
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (isOn) {
for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
aBaseMetaTileEntity.setStrongOutputRedstoneSignal(side, (byte) 15);
}
} else {
for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
aBaseMetaTileEntity.setStrongOutputRedstoneSignal(side, (byte) 0);
}
}
super.onPostTick(aBaseMetaTileEntity, aTick);
}
@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTEHatchPHSensor(mName, mTier, mDescriptionArray, mTextures);
}
@Override
public ITexture[] getTexturesActive(ITexture aBaseTexture) {
return new ITexture[] { aBaseTexture, TextureFactory.of(textureFont), TextureFactory.builder()
.addIcon(textureFont_Glow)
.glow()
.build() };
}
@Override
public ITexture[] getTexturesInactive(ITexture aBaseTexture) {
return new ITexture[] { aBaseTexture, TextureFactory.of(textureFont) };
}
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
final String INVERTED = GTUtility.trans("INVERTED", "Inverted");
final String NORMAL = GTUtility.trans("NORMAL", "Normal");
builder.widget(
new CoverCycleButtonWidget().setToggle(() -> inverted, (val) -> inverted = val)
.setTextureGetter(
(state) -> state == 1 ? GTUITextures.OVERLAY_BUTTON_REDSTONE_ON
: GTUITextures.OVERLAY_BUTTON_REDSTONE_OFF)
.addTooltip(0, NORMAL)
.addTooltip(1, INVERTED)
.setPos(10, 8))
.widget(
new TextWidget().setStringSupplier(() -> inverted ? INVERTED : NORMAL)
.setDefaultColor(COLOR_TEXT_GRAY.get())
.setTextAlignment(Alignment.CenterLeft)
.setPos(28, 12))
.widget(
new NumericWidget().setBounds(0, 14.0)
.setIntegerOnly(false)
.setGetter(() -> (double) threshold)
.setSetter((value) -> threshold = (float) Math.round(value * 100.0) / 100.0f)
.setScrollValues(0.1, 0.01, 1.0)
.setMaximumFractionDigits(2)
.setTextColor(Color.WHITE.dark(1))
.setTextAlignment(Alignment.CenterLeft)
.setFocusOnGuiOpen(true)
.setBackground(GTUITextures.BACKGROUND_TEXT_FIELD.withOffset(-1, -1, 2, 2))
.setPos(10, 28)
.setSize(77, 12))
.widget(
new TextWidget(StatCollector.translateToLocal("GT5U.gui.text.ph_sensor"))
.setDefaultColor(COLOR_TEXT_GRAY.get())
.setTextAlignment(Alignment.CenterLeft)
.setPos(90, 30));
}
}
|