Hi,
I'm playing around with different screens to display information with pure server side code. (MC 1.21.11, yarn mapping (I want to make this work before transitioning to mojang mapping for 26.1 update) )
I've got most of it working except for switching back to a screen.
The flow of screens that causes issues:
Main screen (generic 9x6 inventory) -> Merchant screen (overriden to be mostly Read Only) <--------- this works fine
Merchant Screen -> to Main screen <-------- this causes issues
- Overrides onClosed(PlayerEntity) to return to the main screen (new Screenhandler and factories are used, so no lingering / cached values)
I know that Screenhandlers are not thread safe, so I try to separate the opening of the new Main Screenhandler to the next tick with
// server is retrieved from the onClosed(PlayerEntity player with
if (/*some other checks*/ && player instanceof ServerPlayerEntity serverPlayer) {
MinecraftServer server = serverPlayer.getEntityWorld().getServer();
// from everything i read, executeSync is supposedly queing it on the Main thread, effectively the next tick, but doesn't seem to work
server.executeSync(this::returnToMainScreenOnClose);
}
private void returnToMainScreenOnClose() {
if (returnInfo != null && returnInfo.player().isAlive() && !returnInfo.player().isDisconnected()) {
returnInfo.view().openMainPage(returnInfo.player(), returnInfo.page());
}
}
But this doesn't seem to work.
The returned to Main Screen still is bugged (as in acting like a normal inventory instead of my custom logic on slots clicked. leading me to believe that the opening happens on the same tick as the closing of the previous screenhandler, causing issues with the interaction handling.)
Is there any method on the server class or elsewhere to queue something the next tick reliably or do i have to inject a tick counter in some "tick()" method and call it there?