|
33 | 33 | import net.minecraft.world.item.Items; |
34 | 34 |
|
35 | 35 | import com.mojang.blaze3d.platform.InputConstants; |
| 36 | +import it.unimi.dsi.fastutil.booleans.BooleanConsumer; |
| 37 | + |
| 38 | +import java.util.function.BooleanSupplier; |
36 | 39 |
|
37 | 40 | public class GTMuiWidgets { |
38 | 41 |
|
@@ -75,20 +78,27 @@ public static Flow createTitleBar(MachineDefinition definition, int panelWidth, |
75 | 78 | .size(Math.min(minPanelWidth, textTitleWidth), textHeight)); |
76 | 79 | } |
77 | 80 |
|
78 | | - public static ToggleButton createPowerButton(IRecipeLogicMachine recipeLogicMachine, PanelSyncManager syncManager) { |
79 | | - BooleanSyncValue power = new BooleanSyncValue(() -> recipeLogicMachine.getRecipeLogic().isWorkingEnabled(), |
80 | | - recipeLogicMachine::setWorkingEnabled); |
| 81 | + public static ToggleButton createPowerButton(BooleanSupplier getter, BooleanConsumer setter, |
| 82 | + PanelSyncManager syncManager) { |
| 83 | + BooleanSyncValue power = new BooleanSyncValue(getter, setter); |
81 | 84 | syncManager.syncValue("working_enabled", power); |
82 | 85 | return new ToggleButton() |
83 | 86 | .value(new BoolValue.Dynamic(power::getBoolValue, power::setBoolValue)) |
84 | 87 | .selectedBackground(GTGuiTextures.BUTTON_POWER[1]) |
85 | 88 | .background(GTGuiTextures.BUTTON_POWER[0]) |
86 | 89 | .tooltipAutoUpdate(true) |
87 | 90 | .tooltipBuilder((r) -> r.addLine(IKey.lang(Component.translatable( |
88 | | - recipeLogicMachine.getRecipeLogic().isWorkingEnabled() ? "behaviour.soft_hammer.enabled" : |
| 91 | + power.getBoolValue() ? "behaviour.soft_hammer.enabled" : |
89 | 92 | "behaviour.soft_hammer.disabled")))); |
90 | 93 | } |
91 | 94 |
|
| 95 | + public static ToggleButton createPowerButton(IRecipeLogicMachine recipeLogicMachine, PanelSyncManager syncManager) { |
| 96 | + return createPowerButton( |
| 97 | + () -> recipeLogicMachine.getRecipeLogic().isWorkingEnabled(), |
| 98 | + recipeLogicMachine::setWorkingEnabled, |
| 99 | + syncManager); |
| 100 | + } |
| 101 | + |
92 | 102 | public static ProgressWidget createProgressBar(IRecipeLogicMachine workableMachine, UITexture texture, int size) { |
93 | 103 | return new ProgressWidget() |
94 | 104 | .texture(texture, size) |
|
0 commit comments