Skip to content

Commit

Permalink
Pass guiData to MultiblockUIFactory#createFlexButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorbatron committed Jan 30, 2025
1 parent 12ad632 commit 901c7b6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkM
protected MultiblockUIFactory createUIFactory() {
IntSyncValue recipeMapValue = new IntSyncValue(this::getRecipeMapIndex, this::setRecipeMapIndex);
return super.createUIFactory()
.createFlexButton((panel, syncManager) -> {
.createFlexButton((panel, syncManager, guiData) -> {
if (getAvailableRecipeMaps() == null || getAvailableRecipeMaps().length <= 1)
return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import gregtech.api.util.JsonUtils;
import gregtech.api.util.KeyUtil;
import gregtech.api.util.TextFormattingUtil;
import gregtech.api.util.function.TriFunction;
import gregtech.common.ConfigHolder;

import net.minecraft.network.PacketBuffer;
Expand Down Expand Up @@ -46,15 +47,15 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class MultiblockUIFactory {

private final MultiblockWithDisplayBase mte;
protected Consumer<Builder> displayText, warningText, errorText;
protected BiFunction<ModularPanel, PanelSyncManager, IWidget> flexButton = (panel, syncManager) -> null;
protected TriFunction<ModularPanel, PanelSyncManager, PosGuiData, IWidget> flexButton = (panel, syncManager,
posGuiData) -> null;
private int width = 198, height = 202;
private int screenHeight = 109;
private Supplier<IWidget> customScreen;
Expand Down Expand Up @@ -94,7 +95,7 @@ public MultiblockUIFactory(@NotNull MultiblockWithDisplayBase mte) {
.margin(4, 0)
.child(SlotGroupWidget.playerInventory(0)
.alignX(0f))
.child(createButtons(panel, panelSyncManager)));
.child(createButtons(panel, panelSyncManager, guiData)));
}

private Widget<?> createIndicator(PanelSyncManager syncManager) {
Expand Down Expand Up @@ -196,7 +197,7 @@ public MultiblockUIFactory configureDisplayText(Consumer<Builder> displayText) {
* <br>
* Size will be 18x18.
*/
public MultiblockUIFactory createFlexButton(BiFunction<ModularPanel, PanelSyncManager, IWidget> flexButton) {
public MultiblockUIFactory createFlexButton(TriFunction<ModularPanel, PanelSyncManager, PosGuiData, IWidget> flexButton) {
this.flexButton = flexButton;
return this;
}
Expand Down Expand Up @@ -293,8 +294,9 @@ protected Widget<?> createScreen(PanelSyncManager syncManager) {
}

@NotNull
protected Flow createButtons(@NotNull ModularPanel mainPanel, @NotNull PanelSyncManager panelSyncManager) {
IWidget flexButton = this.flexButton.apply(mainPanel, panelSyncManager);
protected Flow createButtons(@NotNull ModularPanel mainPanel, @NotNull PanelSyncManager panelSyncManager,
PosGuiData guiData) {
IWidget flexButton = this.flexButton.apply(mainPanel, panelSyncManager, guiData);
if (flexButton == null) {
flexButton = GTGuiTextures.BUTTON_NO_FLEX.asWidget()
.size(18)
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/gregtech/api/util/function/TriFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gregtech.api.util.function;

@FunctionalInterface
public interface TriFunction<T, U, Z, R> {

R apply(T t, U u, Z z);
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected void configureWarningText(MultiblockUIFactory.Builder builder) {
@Override
protected MultiblockUIFactory createUIFactory() {
return super.createUIFactory()
.createFlexButton((panel, syncManager) -> {
.createFlexButton((panel, syncManager, guiData) -> {
PanelSyncHandler throttle = (PanelSyncHandler) syncManager.panel("throttle_panel",
this::makeThrottlePanel, true);

Expand Down

0 comments on commit 901c7b6

Please sign in to comment.