Skip to content

Commit e3cd152

Browse files
authored
Fix #822: Show overclock status for steam multiblocks (#880)
1 parent 75891f4 commit e3cd152

File tree

6 files changed

+60
-29
lines changed

6 files changed

+60
-29
lines changed

src/client/java/aztech/modern_industrialization/machines/guicomponents/CraftingMultiblockGuiClient.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class CraftingMultiblockGuiClient implements GuiComponentClient {
4343
int maxEfficiencyTicks;
4444
long currentRecipeEu;
4545
long baseRecipeEu;
46+
int remainingOverclockTicks;
4647

4748
public CraftingMultiblockGuiClient(RegistryFriendlyByteBuf buf) {
4849
readCurrentData(buf);
@@ -61,6 +62,7 @@ public void readCurrentData(RegistryFriendlyByteBuf buf) {
6162
baseRecipeEu = buf.readLong();
6263
}
6364
}
65+
remainingOverclockTicks = buf.readVarInt();
6466
}
6567

6668
@Override
@@ -79,16 +81,17 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
7981
CraftingMultiblockGui.W, CraftingMultiblockGui.H, CraftingMultiblockGui.W, CraftingMultiblockGui.H);
8082
Font font = minecraftClient.font;
8183

82-
guiGraphics.drawString(font, isShapeValid ? MIText.MultiblockShapeValid.text() : MIText.MultiblockShapeInvalid.text(), x + 9, y + 23,
84+
int deltaY = 23;
85+
86+
guiGraphics.drawString(font, isShapeValid ? MIText.MultiblockShapeValid.text() : MIText.MultiblockShapeInvalid.text(), x + 9, y + deltaY,
8387
isShapeValid ? 0xFFFFFF : 0xFF0000, false);
84-
if (isShapeValid) {
85-
// TODO: what is this weird check?
86-
guiGraphics.drawString(font, hasActiveRecipe ? MIText.MultiblockStatusActive.text() : MIText.MultiblockStatusActive.text(), x + 9,
87-
y + 34, 0xFFFFFF, false);
88-
if (hasActiveRecipe) {
88+
deltaY += 11;
8989

90-
int deltaY = 45;
90+
if (isShapeValid) {
91+
guiGraphics.drawString(font, MIText.MultiblockStatusActive.text(), x + 9, y + deltaY, 0xFFFFFF, false);
92+
deltaY += 11;
9193

94+
if (hasActiveRecipe) {
9295
guiGraphics.drawString(font, MIText.Progress.text(String.format("%.1f", progress * 100) + " %"), x + 9, y + deltaY, 0xFFFFFF,
9396
false);
9497
deltaY += 11;
@@ -105,8 +108,14 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
105108

106109
guiGraphics.drawString(font, MIText.CurrentEuRecipe.text(TextHelper.getEuTextTick(currentRecipeEu)), x + 9, y + deltaY, 0xFFFFFF,
107110
false);
111+
deltaY += 11;
108112
}
109113
}
114+
115+
if (remainingOverclockTicks > 0) {
116+
guiGraphics.drawString(font, GunpowderOverclockGuiClient.Renderer.formatOverclock(remainingOverclockTicks), x + 9, y + deltaY,
117+
0xFFFFFF, false);
118+
}
110119
}
111120

112121
}

src/client/java/aztech/modern_industrialization/machines/guicomponents/GunpowderOverclockGuiClient.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.minecraft.client.gui.Font;
3232
import net.minecraft.client.gui.GuiGraphics;
3333
import net.minecraft.network.RegistryFriendlyByteBuf;
34+
import net.minecraft.network.chat.Component;
3435

3536
public class GunpowderOverclockGuiClient implements GuiComponentClient {
3637
final GunpowderOverclockGui.Parameters params;
@@ -66,21 +67,25 @@ public void renderBackground(GuiGraphics guiGraphics, int x, int y) {
6667
public void renderTooltip(MachineScreen screen, Font font, GuiGraphics guiGraphics, int x, int y, int cursorX, int cursorY) {
6768
if (remTick > 0) {
6869
if (RenderHelper.isPointWithinRectangle(params.renderX, params.renderY, 20, 20, cursorX - x, cursorY - y)) {
69-
int seconds = remTick / 20;
70-
int hours = seconds / 3600;
71-
int minutes = (seconds % 3600) / 60;
70+
guiGraphics.renderTooltip(font, formatOverclock(remTick), cursorX, cursorY);
71+
}
72+
}
73+
}
7274

73-
String time = String.format("%d", seconds);
75+
public static Component formatOverclock(int remTick) {
76+
int seconds = remTick / 20;
77+
int hours = seconds / 3600;
78+
int minutes = (seconds % 3600) / 60;
7479

75-
if (hours > 0) {
76-
time = String.format("%d:%02d:%02d", hours, minutes, seconds % 60);
77-
} else if (minutes > 0) {
78-
time = String.format("%d:%02d", minutes, seconds % 60);
79-
}
80+
String time = String.format("%d", seconds);
8081

81-
guiGraphics.renderTooltip(font, MIText.GunpowderTime.text(time), cursorX, cursorY);
82-
}
82+
if (hours > 0) {
83+
time = String.format("%d:%02d:%02d", hours, minutes, seconds % 60);
84+
} else if (minutes > 0) {
85+
time = String.format("%d:%02d", minutes, seconds % 60);
8386
}
87+
88+
return MIText.GunpowderTime.text(time);
8489
}
8590
}
8691
}

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import aztech.modern_industrialization.machines.BEP;
3030
import aztech.modern_industrialization.machines.components.*;
3131
import aztech.modern_industrialization.machines.gui.MachineGuiParameters;
32-
import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui;
3332
import aztech.modern_industrialization.machines.guicomponents.ReiSlotLocking;
3433
import aztech.modern_industrialization.machines.models.MachineModelClientData;
3534
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
@@ -48,7 +47,6 @@ public AbstractCraftingMultiblockBlockEntity(BEP bep, String name, OrientationCo
4847
this.inventory = new MultiblockInventoryComponent();
4948
this.crafter = new CrafterComponent(this, inventory, getBehavior());
5049
this.isActive = new IsActiveComponent();
51-
registerGuiComponent(new CraftingMultiblockGui.Server(() -> shapeValid.shapeValid, crafter::getProgress, crafter));
5250
registerGuiComponent(new ReiSlotLocking.Server(crafter::lockRecipe, () -> operatingState != OperatingState.NOT_MATCHED));
5351
registerComponents(activeShape, crafter, isActive);
5452
}

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import aztech.modern_industrialization.api.machine.holder.EnergyListComponentHolder;
2727
import aztech.modern_industrialization.machines.BEP;
2828
import aztech.modern_industrialization.machines.components.*;
29+
import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui;
2930
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
3031
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
3132
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
@@ -48,6 +49,7 @@ public AbstractElectricCraftingMultiblockBlockEntity(BEP bep, String name, Orien
4849
super(bep, name, orientationParams, shapeTemplates);
4950

5051
this.redstoneControl = new RedstoneControlComponent();
52+
registerGuiComponent(new CraftingMultiblockGui.Server(() -> shapeValid.shapeValid, crafter::getProgress, crafter, () -> 0));
5153
registerComponents(redstoneControl);
5254
}
5355

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import aztech.modern_industrialization.machines.components.CrafterComponent;
2828
import aztech.modern_industrialization.machines.components.OrientationComponent;
2929
import aztech.modern_industrialization.machines.components.OverclockComponent;
30+
import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui;
3031
import aztech.modern_industrialization.machines.helper.SteamHelper;
3132
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
3233
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
@@ -53,6 +54,8 @@ public SteamCraftingMultiblockBlockEntity(BEP bep, String name, ShapeTemplate sh
5354

5455
this.overclockComponent = new OverclockComponent(overclockCatalysts);
5556
this.recipeType = recipeType;
57+
registerGuiComponent(
58+
new CraftingMultiblockGui.Server(() -> shapeValid.shapeValid, crafter::getProgress, crafter, overclockComponent::getTicks));
5659
this.registerComponents(overclockComponent);
5760
}
5861

src/main/java/aztech/modern_industrialization/machines/guicomponents/CraftingMultiblockGui.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import aztech.modern_industrialization.machines.GuiComponents;
2727
import aztech.modern_industrialization.machines.components.CrafterComponent;
2828
import aztech.modern_industrialization.machines.gui.GuiComponent;
29+
import java.util.function.IntSupplier;
2930
import java.util.function.Supplier;
3031
import net.minecraft.network.RegistryFriendlyByteBuf;
3132
import net.minecraft.resources.ResourceLocation;
@@ -36,24 +37,32 @@ public static class Server implements GuiComponent.Server<Data> {
3637
private final CrafterComponent crafter;
3738
private final Supplier<Boolean> isShapeValid;
3839
private final Supplier<Float> progressSupplier;
40+
private final IntSupplier remainingOverclockTicks;
3941

42+
@Deprecated(forRemoval = true)
4043
public Server(Supplier<Boolean> isShapeValid, Supplier<Float> progressSupplier, CrafterComponent crafter) {
44+
this(isShapeValid, progressSupplier, crafter, () -> 0);
45+
}
46+
47+
public Server(Supplier<Boolean> isShapeValid, Supplier<Float> progressSupplier, CrafterComponent crafter,
48+
IntSupplier remainingOverclockTicks) {
4149
this.isShapeValid = isShapeValid;
4250
this.crafter = crafter;
4351
this.progressSupplier = progressSupplier;
52+
this.remainingOverclockTicks = remainingOverclockTicks;
4453
}
4554

4655
@Override
4756
public Data copyData() {
4857
if (isShapeValid.get()) {
4958
if (crafter.hasActiveRecipe()) {
5059
return new Data(progressSupplier.get(), crafter.getEfficiencyTicks(), crafter.getMaxEfficiencyTicks(),
51-
crafter.getCurrentRecipeEu(), crafter.getBaseRecipeEu());
60+
crafter.getCurrentRecipeEu(), crafter.getBaseRecipeEu(), remainingOverclockTicks.getAsInt());
5261
} else {
53-
return new Data(true);
62+
return new Data(true, remainingOverclockTicks.getAsInt());
5463
}
5564
} else {
56-
return new Data();
65+
return new Data(remainingOverclockTicks.getAsInt());
5766
}
5867
}
5968

@@ -66,7 +75,8 @@ public boolean needsSync(Data cachedData) {
6675
}
6776
return cachedData.isShapeValid != isShapeValid.get() || cachedData.hasActiveRecipe != crafter.hasActiveRecipe()
6877
|| cachedData.progress != progressSupplier.get() || crafter.getEfficiencyTicks() != cachedData.efficiencyTicks
69-
|| crafter.getMaxEfficiencyTicks() != cachedData.maxEfficiencyTicks || recipe;
78+
|| crafter.getMaxEfficiencyTicks() != cachedData.maxEfficiencyTicks || recipe
79+
|| cachedData.remainingOverclockTicks != remainingOverclockTicks.getAsInt();
7080

7181
}
7282

@@ -92,7 +102,7 @@ public void writeCurrentData(RegistryFriendlyByteBuf buf) {
92102
} else {
93103
buf.writeBoolean(false);
94104
}
95-
105+
buf.writeVarInt(remainingOverclockTicks.getAsInt());
96106
}
97107

98108
@Override
@@ -109,29 +119,33 @@ private static class Data {
109119
final int maxEfficiencyTicks;
110120
final long currentRecipeEu;
111121
final long baseRecipeEu;
122+
final int remainingOverclockTicks;
112123

113-
private Data() {
114-
this(false);
124+
private Data(int remainingOverclockTicks) {
125+
this(false, remainingOverclockTicks);
115126
}
116127

117-
private Data(boolean isShapeValid) {
128+
private Data(boolean isShapeValid, int remainingOverclockTicks) {
118129
this.isShapeValid = isShapeValid;
119130
this.hasActiveRecipe = false;
120131
this.efficiencyTicks = 0;
121132
this.progress = 0;
122133
this.maxEfficiencyTicks = 0;
123134
this.currentRecipeEu = 0;
124135
this.baseRecipeEu = 0;
136+
this.remainingOverclockTicks = remainingOverclockTicks;
125137
}
126138

127-
private Data(float progress, int efficiencyTicks, int maxEfficiencyTicks, long currentRecipeEu, long baseRecipeEu) {
139+
private Data(float progress, int efficiencyTicks, int maxEfficiencyTicks, long currentRecipeEu, long baseRecipeEu,
140+
int remainingOverclockTicks) {
128141
this.efficiencyTicks = efficiencyTicks;
129142
this.progress = progress;
130143
this.maxEfficiencyTicks = maxEfficiencyTicks;
131144
this.isShapeValid = true;
132145
this.hasActiveRecipe = true;
133146
this.currentRecipeEu = currentRecipeEu;
134147
this.baseRecipeEu = baseRecipeEu;
148+
this.remainingOverclockTicks = remainingOverclockTicks;
135149
}
136150
}
137151

0 commit comments

Comments
 (0)