Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/com/cleanroommc/modularui/api/UIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* An interface for UI factories. They are responsible for opening synced GUIs and syncing necessary data.
Expand All @@ -41,7 +42,7 @@ public interface UIFactory<D extends GuiData> {
* @return new main panel
*/
@ApiStatus.OverrideOnly
ModularPanel createPanel(D guiData, PanelSyncManager syncManager, UISettings settings);
@Nullable ModularPanel createPanel(D guiData, PanelSyncManager syncManager, UISettings settings);

/**
* Creates the screen for the GUI. Is only called on client side.
Expand All @@ -52,7 +53,7 @@ public interface UIFactory<D extends GuiData> {
*/
@SideOnly(Side.CLIENT)
@ApiStatus.OverrideOnly
ModularScreen createScreen(D guiData, ModularPanel mainPanel);
@Nullable ModularScreen createScreen(D guiData, ModularPanel mainPanel);

/**
* Creates the screen wrapper for the GUI. Is only called on client side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.entity.player.EntityPlayerMP;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

Expand Down Expand Up @@ -40,19 +41,18 @@ protected AbstractUIFactory(String name) {
return this.name;
}

@NotNull
public abstract IGuiHolder<T> getGuiHolder(T data);
public abstract @Nullable IGuiHolder<T> getGuiHolder(T data);

@Override
public ModularPanel createPanel(T guiData, PanelSyncManager syncManager, UISettings settings) {
IGuiHolder<T> guiHolder = Objects.requireNonNull(getGuiHolder(guiData), "Gui holder must not be null!");
return guiHolder.buildUI(guiData, syncManager, settings);
public @Nullable ModularPanel createPanel(T guiData, PanelSyncManager syncManager, UISettings settings) {
IGuiHolder<T> guiHolder = getGuiHolder(guiData);
return guiHolder == null ? null : guiHolder.buildUI(guiData, syncManager, settings);
}

@Override
public ModularScreen createScreen(T guiData, ModularPanel mainPanel) {
IGuiHolder<T> guiHolder = Objects.requireNonNull(getGuiHolder(guiData), "Gui holder must not be null!");
return guiHolder.createScreen(guiData, mainPanel);
public @Nullable ModularScreen createScreen(T guiData, ModularPanel mainPanel) {
IGuiHolder<T> guiHolder = getGuiHolder(guiData);
return guiHolder == null ? null : guiHolder.createScreen(guiData, mainPanel);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static <T extends GuiData> void open(@NotNull UIFactory<T> factory, @NotN
ModularSyncManager msm = new ModularSyncManager(false);
PanelSyncManager syncManager = new PanelSyncManager(msm, true);
ModularPanel panel = factory.createPanel(guiData, syncManager, settings);
if (panel == null) return;
WidgetTree.collectSyncValues(syncManager, panel);
ModularContainer container = settings.hasCustomContainer() ? settings.createContainer() : factory.createContainer();
container.construct(player, msm, settings, panel.getName(), guiData);
Expand Down Expand Up @@ -106,8 +107,10 @@ public static <T extends GuiData> void openFromClient(int windowId, int networkI
ModularSyncManager msm = new ModularSyncManager(true);
PanelSyncManager syncManager = new PanelSyncManager(msm, true);
ModularPanel panel = factory.createPanel(guiData, syncManager, settings);
if (panel == null) throw new IllegalStateException("Panel must not be null on Client when Panel was not null on Server!");
WidgetTree.collectSyncValues(syncManager, panel);
ModularScreen screen = factory.createScreen(guiData, panel);
if (screen == null) throw new IllegalStateException("Screen must not be null on Client when Screen was not null on Server!");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically server doesnt have a screen. Its just the panel

screen.getContext().setSettings(settings);
ModularContainer container = settings.hasCustomContainer() ? settings.createContainer() : factory.createContainer();
container.construct(player, msm, settings, panel.getName(), guiData);
Expand Down