Skip to content

Commit

Permalink
add UIBuildContext to getGUI method
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWeabo committed Dec 27, 2023
1 parent 8090cad commit a32ee83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/main/java/gregtech/api/gui/GUIHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.annotation.Nonnull;

import com.gtnewhorizons.modularui.api.math.Size;
import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
Expand All @@ -13,10 +14,14 @@ public interface GUIHost extends ITileWithModularUI {
@Nonnull
@Override
default ModularWindow createWindow(UIBuildContext uiContext) {
GUIProvider<?> gui = getGUI();
return gui.openGUI(Objects.requireNonNull(uiContext));
Objects.requireNonNull(uiContext);
GUIProvider<?> gui = getGUI(uiContext);
return gui.openGUI(uiContext);
}

/**
* Width of the GUI when its being displayed
*/
default int getWidth() {
return 170;
}
Expand All @@ -26,6 +31,6 @@ default int getHeight() {
}

@Nonnull
GUIProvider<?> getGUI();
GUIProvider<?> getGUI(@Nonnull UIBuildContext uiContext);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable;
import com.gtnewhorizons.modularui.api.forge.ItemStackHandler;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -785,7 +786,7 @@ protected GUIProvider<?> createGUIProvider() {
}

@Nonnull
public GUIProvider<?> getGUI() {
public GUIProvider<?> getGUI(@Nonnull UIBuildContext uiContext) {
return guiProvider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -668,13 +668,11 @@ public String getInventoryName() {
if (modeSelected(ITEM_IN, ITEM_OUT)) {
InventoryType type = modeSelected(ITEM_IN) ? InventoryType.Input : InventoryType.Output;
ItemInventoryLogic itemLogic = controller.getItemLogic(type, lockedInventory);
if (itemLogic == null) return "";
return itemLogic.getDisplayName();
}
if (modeSelected(FLUID_IN, FLUID_OUT)) {
InventoryType type = modeSelected(FLUID_IN) ? InventoryType.Input : InventoryType.Output;
FluidInventoryLogic fluidLogic = controller.getFluidLogic(type, lockedInventory);
if (fluidLogic == null) return "";
return fluidLogic.getDisplayName();
}
return "";
Expand All @@ -694,12 +692,13 @@ protected GUIProvider<?> createGUIProvider() {

@Override
@Nonnull
public GUIProvider<?> getGUI() {
public GUIProvider<?> getGUI(@Nonnull UIBuildContext uiContext) {
IMultiBlockController controller = getTarget(false);
if (controller == null) return guiProvider;
if (!modeSelected(NOTHING, ENERGY_IN, ENERGY_OUT)) return guiProvider;
if (!canOpenControllerGui()) return guiProvider;
GUIProvider<?> controllerGUI = controller.getGUI();
if (uiContext.getPlayer().isSneaking()) return guiProvider;
GUIProvider<?> controllerGUI = controller.getGUI(uiContext);
return controllerGUI;
}

Expand Down

0 comments on commit a32ee83

Please sign in to comment.