Skip to content

Commit ad2bfe4

Browse files
committed
fix issue when client player is null
1 parent 9f446e6 commit ad2bfe4

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public void onGuiOpen(GuiOpenEvent event) {
118118
lastChar = null;
119119
}
120120
currentScreen = muiScreen.getScreen();
121+
currentScreen.getContext().setParentScreen(Minecraft.getMinecraft().currentScreen);
121122
fpsCounter.reset();
122123
}
123124
} else if (hasScreen() && getMCScreen() != null && newGui != getMCScreen()) {
@@ -194,7 +195,7 @@ public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Pre event) {
194195
}
195196

196197
@SubscribeEvent(priority = EventPriority.HIGH)
197-
public static void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Post event) {
198+
public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Post event) {
198199
OverlayStack.draw(event.getMouseX(), event.getMouseY(), event.getRenderPartialTicks());
199200
Platform.setupDrawTex(); // jei and other mods may expect this state
200201
}

src/main/java/com/cleanroommc/modularui/screen/ModularPanel.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.cleanroommc.modularui.animation.Animator;
55
import com.cleanroommc.modularui.api.IPanelHandler;
66
import com.cleanroommc.modularui.api.ITheme;
7+
import com.cleanroommc.modularui.api.MCHelper;
78
import com.cleanroommc.modularui.api.drawable.IDrawable;
89
import com.cleanroommc.modularui.api.layout.IViewport;
910
import com.cleanroommc.modularui.api.layout.IViewportStack;
@@ -29,10 +30,10 @@
2930
import com.cleanroommc.modularui.widget.WidgetTree;
3031
import com.cleanroommc.modularui.widget.sizer.Area;
3132
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
32-
3333
import com.cleanroommc.neverenoughanimations.NEAConfig;
3434

3535
import net.minecraft.client.Minecraft;
36+
import net.minecraft.entity.player.EntityPlayer;
3637

3738
import mezz.jei.gui.ghost.GhostIngredientDrag;
3839
import org.jetbrains.annotations.ApiStatus;
@@ -129,7 +130,13 @@ public void closeIfOpen() {
129130
closeSubPanels();
130131
if (isMainPanel()) {
131132
// close screen and let NEA animation
132-
Minecraft.getMinecraft().player.closeScreen();
133+
EntityPlayer player = MCHelper.getPlayer();
134+
if (player != null) {
135+
player.closeScreen();
136+
} else {
137+
// we are currently not in a world and want to display the previous screen
138+
Minecraft.getMinecraft().displayGuiScreen(getContext().getParentScreen());
139+
}
133140
return;
134141
}
135142
if (!shouldAnimate()) {

src/main/java/com/cleanroommc/modularui/screen/viewport/ModularGuiContext.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
import com.cleanroommc.modularui.ClientProxy;
44
import com.cleanroommc.modularui.api.ITheme;
55
import com.cleanroommc.modularui.api.MCHelper;
6-
import com.cleanroommc.modularui.api.widget.*;
7-
import com.cleanroommc.modularui.screen.*;
6+
import com.cleanroommc.modularui.api.widget.IDraggable;
7+
import com.cleanroommc.modularui.api.widget.IFocusedWidget;
8+
import com.cleanroommc.modularui.api.widget.IGuiElement;
9+
import com.cleanroommc.modularui.api.widget.IVanillaSlot;
10+
import com.cleanroommc.modularui.api.widget.IWidget;
11+
import com.cleanroommc.modularui.api.widget.ResizeDragArea;
12+
import com.cleanroommc.modularui.screen.DraggablePanelWrapper;
13+
import com.cleanroommc.modularui.screen.JeiSettingsImpl;
14+
import com.cleanroommc.modularui.screen.ModularPanel;
15+
import com.cleanroommc.modularui.screen.ModularScreen;
16+
import com.cleanroommc.modularui.screen.PanelManager;
17+
import com.cleanroommc.modularui.screen.UISettings;
818

919
import net.minecraft.client.Minecraft;
1020
import net.minecraft.client.entity.EntityPlayerSP;
21+
import net.minecraft.client.gui.GuiScreen;
1122

1223
import org.jetbrains.annotations.ApiStatus;
1324
import org.jetbrains.annotations.NotNull;
@@ -26,12 +37,10 @@
2637
*/
2738
public class ModularGuiContext extends GuiContext {
2839

29-
/* GUI elements */
30-
@Deprecated
31-
public final ModularScreen screen;
40+
private final ModularScreen screen;
41+
private @Nullable GuiScreen parent;
3242
private LocatedWidget focusedWidget = LocatedWidget.EMPTY;
33-
@Nullable
34-
private LocatedWidget hovered;
43+
private @Nullable LocatedWidget hovered;
3544
private int timeHovered = 0;
3645
private final HoveredIterable hoveredWidgets;
3746

@@ -53,6 +62,18 @@ public ModularScreen getScreen() {
5362
return screen;
5463
}
5564

65+
/**
66+
* @return the screen that was open before when this screen was opened or null of none was open
67+
*/
68+
public @Nullable GuiScreen getParentScreen() {
69+
return parent;
70+
}
71+
72+
@ApiStatus.Internal
73+
public void setParentScreen(@Nullable GuiScreen parent) {
74+
this.parent = parent;
75+
}
76+
5677
/**
5778
* @return true if any widget is being hovered
5879
*/
@@ -428,4 +449,4 @@ public IGuiElement next() {
428449
};
429450
}
430451
}
431-
}
452+
}

0 commit comments

Comments
 (0)