Skip to content

Commit

Permalink
Fix crash when player with potion effect changes dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Feb 3, 2025
1 parent bcda45d commit cf55d60
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Worldthreader 2.0.4 for Minecraft 1.21.4 fixes a minor thread safety issue.
Worldthreader 2.0.4 for Minecraft 1.21.4 fixes a crash and a minor thread safety issue.
Please report any issues you encounter to the [issue tracker of worldthreader](https://github.com/2No2Name/worldthreader/issues). As worldthreader likely comes with massive mod compatibility issues, please do not report crashes and issues to other mods' issue trackers before confirming the issue without worldthreader.

## Fixes:

- Fix crash when player with potion effect changes dimension
- Add thread-safety to iron golem, snow golem, end portal and wither block patterns used in spawning

## Known issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public abstract class PlayerListMixin implements ServerPlayerInstanceSwapper {
//Create the player with a null level, which is set a bit later. The constructor uses the level to adjust the spawn position etc., which is not needed when copying the player.
//noinspection DataFlowIssue
ServerPlayer newPlayer = new ServerPlayer(this.server, null, previousPlayer.getGameProfile(), previousPlayer.clientInformation());
newPlayer.setServerLevel(newLevel);

newPlayer.connection = previousPlayer.connection;
newPlayer.restoreFrom(previousPlayer, true);
Expand All @@ -51,10 +52,7 @@ public abstract class PlayerListMixin implements ServerPlayerInstanceSwapper {
this.playersByUUID.put(newPlayer.getUUID(), newPlayer);
}

//Loot context or so needs the minecraft server and the random instance from the level
newPlayer.setServerLevel(newLevel);
newPlayer.initInventoryMenu();
newPlayer.setServerLevel(null);

newPlayer.setHealth(newPlayer.getHealth());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private void swapPlayerWithNewInstance(TeleportTransition teleportTransition, Ca
throw new AssertionError("Worldthreader: Ordinals of Local Capture are incorrect!");
}

if (WorldThreadingManager.isWrongThreadForWorld(newLevel)) {
throw new IllegalStateException("Worldthreader: Must create new player on destination world thread!");
}

//Swap the player with a new instance, what could go wrong?
ServerPlayer serverPlayer = ((ServerPlayerInstanceSwapper) this.connection).worldthreader$swapRemovedPlayerWithNewCopy((ServerPlayer) (Object) this, newLevel);
newPlayerRef.set(serverPlayer);
Expand Down

0 comments on commit cf55d60

Please sign in to comment.