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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
package gregtech.common.tileentities.machines.multi;
import static gregtech.api.enums.GTValues.VN;
import static gregtech.api.enums.HatchElement.Energy;
import static gregtech.api.enums.HatchElement.InputBus;
import static gregtech.api.enums.HatchElement.InputHatch;
import static gregtech.api.enums.HatchElement.Maintenance;
import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.IFluidBlock;
import com.google.common.collect.ImmutableList;
import com.gtnewhorizons.modularui.api.NumberFormatMUI;
import com.gtnewhorizons.modularui.api.drawable.IDrawable;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.api.math.Pos2d;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.Materials;
import gregtech.api.gui.modularui.GTUITextures;
import gregtech.api.gui.widgets.LockedWhileActiveButton;
import gregtech.api.interfaces.IHatchElement;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.api.util.shutdown.ShutDownReasonRegistry;
public abstract class MTEConcreteBackfillerBase extends MTEDrillerBase {
private int mLastXOff = 0, mLastZOff = 0;
/** Used to drive the readout in the GUI for the backfiller's current y-level. */
private int clientYHead;
protected boolean mLiquidEnabled = true;
private static boolean isWater(Block aBlock) {
return aBlock == Blocks.water || aBlock == Blocks.flowing_water;
}
private static boolean isLava(Block aBlock) {
return aBlock == Blocks.lava || aBlock == Blocks.flowing_lava;
}
private static boolean isFluid(Block aBlock) {
return isWater(aBlock) || isLava(aBlock) || aBlock instanceof IFluidBlock;
}
public MTEConcreteBackfillerBase(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
initRecipeResults();
}
public MTEConcreteBackfillerBase(String aName) {
super(aName);
initRecipeResults();
}
private void initRecipeResults() {
addResultMessage(STATE_UPWARD, true, "backfiller_working");
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setBoolean("liquidenabled", mLiquidEnabled);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
if (aNBT.hasKey("liquidenabled")) mLiquidEnabled = aNBT.getBoolean("liquidenabled");
}
protected MultiblockTooltipBuilder createTooltip(String aStructureName) {
String casings = getCasingBlockItem().get(0)
.getDisplayName();
final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder();
tt.addMachineType("Concrete Backfiller")
.addInfo("Will fill in areas below it with light concrete. This goes through walls")
.addInfo("Use it to remove any spawning locations beneath your base to reduce lag")
.addInfo("Will pull back the pipes after it finishes that layer")
.addInfo("Radius is " + getRadius() + " blocks")
.beginStructureBlock(3, 7, 3, false)
.addController("Front bottom")
.addOtherStructurePart(casings, "form the 3x1x3 Base")
.addOtherStructurePart(casings, "1x3x1 pillar above the center of the base (2 minimum total)")
.addOtherStructurePart(getFrameMaterial().mName + " Frame Boxes", "Each pillar's side and 1x3x1 on top")
.addEnergyHatch("1x " + VN[getMinTier()] + "+, Any base casing", 1)
.addMaintenanceHatch("Any base casing", 1)
.addInputBus("Mining Pipes, optional, any base casing", 1)
.addInputHatch("GT Concrete, any base casing", 1)
.addOutputBus("Mining Pipes, optional, any base casing", 1)
.toolTipFinisher();
return tt;
}
protected abstract int getRadius();
@Override
protected boolean checkHatches() {
return !mMaintenanceHatches.isEmpty() && !mInputHatches.isEmpty() && mEnergyHatches.size() == 1;
}
@Override
protected List<IHatchElement<? super MTEDrillerBase>> getAllowedHatches() {
return ImmutableList.of(InputHatch, InputBus, Maintenance, Energy);
}
@Override
protected void setElectricityStats() {
this.mEfficiency = getCurrentEfficiency(null);
this.mEfficiencyIncrease = 10000;
int tier = Math.max(1, GTUtility.getTier(getMaxInputVoltage()));
this.mEUt = -6 * (1 << (tier << 1));
this.mMaxProgresstime = (workState == STATE_UPWARD ? 240 : 80) / (1 << tier);
this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
}
@Override
protected boolean workingUpward(ItemStack aStack, int xDrill, int yDrill, int zDrill, int xPipe, int zPipe,
int yHead, int oldYHead) {
if (isRefillableBlock(xPipe, yHead - 1, zPipe)) return tryRefillBlock(xPipe, yHead - 1, zPipe);
int radius = getRadius();
if (mLastXOff == 0 && mLastZOff == 0) {
mLastXOff = -radius;
mLastZOff = -radius;
}
if (yHead != yDrill) {
for (int i = mLastXOff; i <= radius; i++) {
for (int j = (i == mLastXOff ? mLastZOff : -radius); j <= radius; j++) {
if (isRefillableBlock(xPipe + i, yHead, zPipe + j)) {
mLastXOff = i;
mLastZOff = j;
return tryRefillBlock(xPipe + i, yHead, zPipe + j);
}
}
}
}
if (tryPickPipe()) {
mLastXOff = 0;
mLastZOff = 0;
return true;
} else {
workState = STATE_DOWNWARD;
stopMachine(ShutDownReasonRegistry.NONE);
setShutdownReason(StatCollector.translateToLocal("GT5U.gui.text.backfiller_finished"));
return false;
}
}
private boolean isRefillableBlock(int aX, int aY, int aZ) {
IGregTechTileEntity aBaseTile = getBaseMetaTileEntity();
Block aBlock = aBaseTile.getBlock(aX, aY, aZ);
if (!aBlock.isAir(aBaseTile.getWorld(), aX, aY, aZ)) {
if (mLiquidEnabled) {
if (!isFluid(aBlock)) {
return false;
}
} else {
return false;
}
}
if (aBlock.getMaterial()
.isSolid()) {
return false;
}
return GTUtility
.setBlockByFakePlayer(getFakePlayer(aBaseTile), aX, aY, aZ, GregTechAPI.sBlockConcretes, 8, true);
}
private boolean tryRefillBlock(int aX, int aY, int aZ) {
if (!tryConsumeFluid()) {
setRuntimeFailureReason(CheckRecipeResultRegistry.BACKFILLER_NO_CONCRETE);
return false;
}
getBaseMetaTileEntity().getWorld()
.setBlock(aX, aY, aZ, GregTechAPI.sBlockConcretes, 8, 3);
return true;
}
private boolean tryConsumeFluid() {
if (!depleteInput(Materials.Concrete.getMolten(144L))) {
mMaxProgresstime = 0;
return false;
}
return true;
}
protected static final NumberFormatMUI numberFormat = new NumberFormatMUI();
@Override
protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) {
super.drawTexts(screenElements, inventorySlot);
screenElements
.widget(
TextWidget
.dynamicString(
() -> StatCollector.translateToLocalFormatted(
"GT5U.gui.text.backfiller_current_area",
numberFormat.format(clientYHead)))
.setSynced(false)
.setTextAlignment(Alignment.CenterLeft)
.setEnabled(widget -> getBaseMetaTileEntity().isActive() && workState == STATE_UPWARD))
.widget(new FakeSyncWidget.IntegerSyncer(this::getYHead, newInt -> clientYHead = newInt))
.widget(new FakeSyncWidget.IntegerSyncer(() -> workState, newInt -> workState = newInt));
}
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
super.addUIWidgets(builder, buildContext);
final int BUTTON_Y_LEVEL = 91;
builder.widget(
new LockedWhileActiveButton(this.getBaseMetaTileEntity(), builder)
.setOnClick((clickData, widget) -> mLiquidEnabled = !mLiquidEnabled)
.setPlayClickSound(true)
.setBackground(() -> {
if (mLiquidEnabled) {
return new IDrawable[] { GTUITextures.BUTTON_STANDARD_PRESSED,
GTUITextures.OVERLAY_BUTTON_LIQUIDMODE };
}
return new IDrawable[] { GTUITextures.BUTTON_STANDARD, GTUITextures.OVERLAY_BUTTON_LIQUIDMODE_OFF };
})
.attachSyncer(
new FakeSyncWidget.BooleanSyncer(() -> mLiquidEnabled, newBoolean -> mLiquidEnabled = newBoolean),
builder,
(widget, val) -> widget.notifyTooltipChange())
.dynamicTooltip(
() -> ImmutableList.of(
StatCollector.translateToLocal(
mLiquidEnabled ? "GT5U.gui.button.liquid_filling_ON"
: "GT5U.gui.button.liquid_filling_OFF")))
.setTooltipShowUpDelay(TOOLTIP_DELAY)
.setPos(new Pos2d(100, BUTTON_Y_LEVEL))
.setSize(16, 16));
int left = 98;
for (ButtonWidget button : getAdditionalButtons(builder, buildContext)) {
button.setPos(new Pos2d(left, BUTTON_Y_LEVEL))
.setSize(16, 16);
builder.widget(button);
left += 18;
}
}
}
|