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 gtPlusPlus.xmod.gregtech.common.covers;
import java.util.concurrent.atomic.AtomicBoolean;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.common.widget.TextWidget;
import gregtech.api.gui.modularui.CoverUIBuildContext;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.util.CoverBehavior;
import gregtech.api.util.GTUtility;
import gregtech.api.util.ISerializableObject;
import gregtech.common.gui.modularui.widget.CoverDataControllerWidget;
import gregtech.common.gui.modularui.widget.CoverDataFollowerNumericWidget;
public class CoverOverflow extends CoverBehavior {
public final int mTransferRate;
public final int mInitialTransferRate;
public final int mMaxTransferRate;
public CoverOverflow(int aTransferRate) {
this.mTransferRate = aTransferRate * 1000 / 10;
this.mInitialTransferRate = aTransferRate;
this.mMaxTransferRate = aTransferRate * 1000;
}
public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable,
ICoverable aTileEntity, long aTimer) {
if (aCoverVariable == 0) {
return aCoverVariable;
}
if ((aTileEntity instanceof IFluidHandler)) {
// Logger.INFO("Trying to Void via Overflow.");
IFluidHandler tTank1;
ForgeDirection directionFrom;
directionFrom = ForgeDirection.UNKNOWN;
tTank1 = (IFluidHandler) aTileEntity;
if (tTank1 != null) {
FluidStack aTankStack = tTank1.getTankInfo(directionFrom)[0].fluid;
if (aTankStack != null) {
// Logger.INFO("Found Fluid inside self - "+aTankStack.getLocalizedName()+", overflow point set at
// "+aCoverVariable+"L and we have "+aTankStack.amount+"L inside.");
if (aTankStack.amount > aCoverVariable) {
int aAmountToDrain = aTankStack.amount - aCoverVariable;
// Logger.INFO("There is "+aAmountToDrain+" more fluid in the tank than we would like.");
if (aAmountToDrain > 0) {
FluidStack tLiquid = tTank1.drain(directionFrom, Math.abs(aAmountToDrain), true);
if (tLiquid != null) {
// Logger.INFO("Drained "+aAmountToDrain+"L.");
}
}
}
} else {
// Logger.INFO("Could not simulate drain on self.");
}
}
}
return aCoverVariable;
}
public int onCoverScrewdriverclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity,
EntityPlayer aPlayer, float aX, float aY, float aZ) {
if (GTUtility.getClickedFacingCoords(side, aX, aY, aZ)[0] >= 0.5F) {
aCoverVariable += (mMaxTransferRate * (aPlayer.isSneaking() ? 0.1f : 0.01f));
} else {
aCoverVariable -= (mMaxTransferRate * (aPlayer.isSneaking() ? 0.1f : 0.01f));
}
if (aCoverVariable > mMaxTransferRate) {
aCoverVariable = mInitialTransferRate;
}
if (aCoverVariable <= 0) {
aCoverVariable = mMaxTransferRate;
}
GTUtility.sendChatToPlayer(
aPlayer,
GTUtility.trans("322", "Overflow point: ") + aCoverVariable + GTUtility.trans("323", "L"));
return aCoverVariable;
}
public boolean onCoverRightclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity,
EntityPlayer aPlayer, float aX, float aY, float aZ) {
boolean aShift = aPlayer.isSneaking();
int aAmount = aShift ? 128 : 8;
if (GTUtility.getClickedFacingCoords(side, aX, aY, aZ)[0] >= 0.5F) {
aCoverVariable += aAmount;
} else {
aCoverVariable -= aAmount;
}
if (aCoverVariable > mMaxTransferRate) {
aCoverVariable = mInitialTransferRate;
}
if (aCoverVariable <= 0) {
aCoverVariable = mMaxTransferRate;
}
GTUtility.sendChatToPlayer(
aPlayer,
GTUtility.trans("322", "Overflow point: ") + aCoverVariable + GTUtility.trans("323", "L"));
aTileEntity.setCoverDataAtSide(side, new ISerializableObject.LegacyCoverData(aCoverVariable));
return true;
}
public boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public boolean letsItemsIn(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot,
ICoverable aTileEntity) {
return true;
}
public boolean letsItemsOut(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot,
ICoverable aTileEntity) {
return true;
}
public boolean letsFluidIn(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid,
ICoverable aTileEntity) {
return false;
}
public boolean letsFluidOut(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid,
ICoverable aTileEntity) {
return true;
}
public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return true;
}
public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
return 5;
}
// GUI
@Override
public boolean hasCoverGUI() {
return true;
}
@Override
public ModularWindow createWindow(CoverUIBuildContext buildContext) {
return new OverflowUIFactory(buildContext).createWindow();
}
private class OverflowUIFactory extends UIFactory {
private static final int startX = 10;
private static final int startY = 25;
private static final int spaceX = 18;
private static final int spaceY = 18;
public OverflowUIFactory(CoverUIBuildContext buildContext) {
super(buildContext);
}
@SuppressWarnings("PointlessArithmeticExpression")
@Override
protected void addUIWidgets(ModularWindow.Builder builder) {
AtomicBoolean warn = new AtomicBoolean(false);
builder
.widget(
new CoverDataControllerWidget<>(this::getCoverData, this::setCoverData, CoverOverflow.this)
.addFollower(
new CoverDataFollowerNumericWidget<>(),
coverData -> (double) convert(coverData),
(coverData, state) -> new ISerializableObject.LegacyCoverData(state.intValue()),
widget -> widget.setBounds(0, mMaxTransferRate)
.setScrollValues(1000, 144, 100000)
.setFocusOnGuiOpen(true)
.setPos(startX + spaceX * 0, startY + spaceY * 1 + 8)
.setSize(spaceX * 4 - 3, 12)))
.widget(
new TextWidget(GTUtility.trans("322", "Overflow point: ")).setDefaultColor(COLOR_TEXT_GRAY.get())
.setPos(startX, 4 + startY + spaceY * 0 + 8));
}
}
}
|