Skip to content

Commit a5b9e82

Browse files
authored
Remove uses of lang keys from dynamic keys causing crashes server side (#2898)
1 parent 3bdc441 commit a5b9e82

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

src/main/java/gregtech/api/cover/CoverWithUI.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import com.cleanroommc.modularui.widgets.ToggleButton;
3434
import com.cleanroommc.modularui.widgets.layout.Flow;
3535
import org.jetbrains.annotations.ApiStatus;
36+
import org.jetbrains.annotations.NotNull;
37+
38+
import java.util.function.BooleanSupplier;
3639

3740
public interface CoverWithUI extends Cover, IUIHolder, IGuiHolder<SidedPosGuiData> {
3841

@@ -117,6 +120,18 @@ default ParentWidget<?> createSettingsRow() {
117120
return new ParentWidget<>().height(16).widthRel(1.0f).marginBottom(2);
118121
}
119122

123+
/**
124+
* Create a dynamic lang key that switches between {@code cover.generic.enabled} and {@code cover.generic.disabled}
125+
* depending on the result of the given boolean supplier. <br/>
126+
*
127+
* @param keyBase the base of the lang key to use. {@code .enabled} and {@code .disabled} will be appended.
128+
*/
129+
default IKey createEnabledKey(@NotNull String keyBase, @NotNull BooleanSupplier enabledState) {
130+
String enabled = keyBase + ".enabled";
131+
String disabled = keyBase + ".disabled";
132+
return IKey.lang(() -> enabledState.getAsBoolean() ? enabled : disabled);
133+
}
134+
120135
default int getIncrementValue(MouseData data) {
121136
int adjust = 1;
122137
if (data.shift) adjust *= 4;

src/main/java/gregtech/common/covers/CoverFluidFilter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
166166
.coverChildrenHeight()
167167
.setEnabledIf(b -> getFilterMode() != FluidFilterMode.FILTER_BOTH)
168168
.child(new ToggleButton()
169-
.overlay(IKey.dynamic(() -> IKey.lang(allowFlow ?
170-
"cover.generic.enabled" :
171-
"cover.generic.disabled").get())
172-
.color(Color.WHITE.main).shadow(false))
169+
.overlay(createEnabledKey("cover.generic", () -> this.allowFlow)
170+
.color(Color.WHITE.main)
171+
.shadow(false))
173172
.tooltip(tooltip -> tooltip
174173
.addLine(IKey.lang("cover.filter.allow_flow.tooltip")))
175174
.size(72, 18)

src/main/java/gregtech/common/covers/CoverFluidVoiding.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import codechicken.lib.render.pipeline.IVertexOperation;
2525
import codechicken.lib.vec.Cuboid6;
2626
import codechicken.lib.vec.Matrix4;
27-
import com.cleanroommc.modularui.api.drawable.IKey;
2827
import com.cleanroommc.modularui.factory.GuiData;
2928
import com.cleanroommc.modularui.factory.SidedPosGuiData;
3029
import com.cleanroommc.modularui.screen.ModularPanel;
@@ -79,16 +78,14 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
7978

8079
@Override
8180
protected ParentWidget<?> createUI(GuiData data, PanelSyncManager syncManager) {
82-
var isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
81+
BooleanSyncValue isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
8382

8483
return super.createUI(data, syncManager)
8584
.child(Flow.row().height(18).widthRel(1f)
8685
.marginBottom(2)
8786
.child(new ToggleButton()
8887
.value(isWorking)
89-
.overlay(IKey.dynamic(() -> IKey.lang(this.isWorkingAllowed ?
90-
"behaviour.soft_hammer.enabled" :
91-
"behaviour.soft_hammer.disabled").get())
88+
.overlay(createEnabledKey("behaviour.soft_hammer", () -> this.isWorkingAllowed)
9289
.color(Color.WHITE.darker(1)))
9390
.widthRel(0.6f)
9491
.left(0)));

src/main/java/gregtech/common/covers/CoverItemFilter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,9 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
168168
.coverChildrenHeight()
169169
.setEnabledIf(b -> getFilterMode() != ItemFilterMode.FILTER_BOTH)
170170
.child(new ToggleButton()
171-
.overlay(IKey.dynamic(() -> IKey.lang(allowFlow ?
172-
"cover.generic.enabled" :
173-
"cover.generic.disabled").get())
174-
.color(Color.WHITE.main).shadow(false))
171+
.overlay(createEnabledKey("cover.generic", () -> this.allowFlow)
172+
.color(Color.WHITE.main)
173+
.shadow(false))
175174
.tooltip(tooltip -> tooltip
176175
.addLine(IKey.lang("cover.filter.allow_flow.tooltip")))
177176
.size(72, 18)

src/main/java/gregtech/common/covers/CoverItemVoiding.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import codechicken.lib.render.pipeline.IVertexOperation;
2222
import codechicken.lib.vec.Cuboid6;
2323
import codechicken.lib.vec.Matrix4;
24-
import com.cleanroommc.modularui.api.drawable.IKey;
2524
import com.cleanroommc.modularui.factory.GuiData;
2625
import com.cleanroommc.modularui.factory.SidedPosGuiData;
2726
import com.cleanroommc.modularui.screen.ModularPanel;
@@ -80,16 +79,14 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
8079

8180
@Override
8281
protected ParentWidget<Flow> createUI(GuiData data, PanelSyncManager guiSyncManager) {
83-
var isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
82+
BooleanSyncValue isWorking = new BooleanSyncValue(this::isWorkingEnabled, this::setWorkingEnabled);
8483

8584
return super.createUI(data, guiSyncManager)
8685
.child(Flow.row().height(18).widthRel(1f)
8786
.marginBottom(2)
8887
.child(new ToggleButton()
8988
.value(isWorking)
90-
.overlay(IKey.dynamic(() -> IKey.lang(this.isWorkingAllowed ?
91-
"behaviour.soft_hammer.enabled" :
92-
"behaviour.soft_hammer.disabled").get())
89+
.overlay(createEnabledKey("behaviour.soft_hammer", () -> this.isWorkingAllowed)
9390
.color(Color.WHITE.darker(1)))
9491
.widthRel(0.6f)
9592
.left(0)));

0 commit comments

Comments
 (0)