Mod crashing on server, when gui is opened

Started by Fresfries on

Topic category: Help with modding (Java Edition)

Last seen on 23:08, 1. Dec 2021
Joined Nov 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mod crashing on server, when gui is opened
Sun, 11/21/2021 - 15:12 (edited)

So my mod works perfectly if you run it in singleplayer but as soon as you run it on a server and open a gui it crashes.
I know it's because the server is trying to execute code that is client side, or something like that.
 

Minecraft version:  1.17.1

MCreator version: 2021.3 EAP (47317)

 

Crash log:

https://pastebin.com/BpJjumMN

 

The part that crashes the server:

@SubscribeEvent
	public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
		Player entity = event.player;
		if (event.phase == TickEvent.Phase.END && entity.containerMenu instanceof ScreenMenu) {
			Level world = entity.level;
			double x = entity.getX();
			double y = entity.getY();
			double z = entity.getZ();
			HashMap<String, Object> guistate = ChiselScreen.guistate;

			CloseGuiProcedure.execute(entity);
		}
	}

 

Edited by Fresfries on Sun, 11/21/2021 - 15:12
Last seen on 23:08, 1. Dec 2021
Joined Nov 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is there a easy solution on…
Sun, 11/21/2021 - 15:24

Is there a easy solution on fixing this? Because I don't think I can fix it through MCreator if I understand correctly.
The part of code I posted is this tick event.
screenshot
 

Or is it the procedure itself?

CloseGuiProcedure.execute(entity);

But even if I comment it out it still crashes, so it can't be this part.

Last seen on 23:08, 1. Dec 2021
Joined Nov 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I still just can't get it to…
Tue, 11/23/2021 - 22:15

I still just can't get it to work/not crash.

If I do this, it crashes on the server

@SubscribeEvent
	public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
		Player entity = event.player;
		if (event.phase == TickEvent.Phase.END && entity.containerMenu instanceof ScreenMenu) {
			Level world = entity.level;
			double x = entity.getX();
			double y = entity.getY();
			double z = entity.getZ();
			HashMap<String, Object> guistate = Screen.guistate;

			CloseGuiProcedure.execute(entity);
		}
	}

And if I put this at the beginning

@OnlyIn(Dist.CLIENT)

or this

if (world.isClientSide()) {


}

it doesn't crash, but also doesn't run the procedure on the server.