Fix inventory not appearing after changing dimension

This commit is contained in:
themode 2021-03-07 23:18:32 +01:00
parent b8e987f556
commit 2e17c8a8e1

View File

@ -633,11 +633,10 @@ public class Player extends LivingEntity implements CommandSender {
final boolean firstSpawn = this.instance == null; // TODO: Handle player reconnections, must be false in that case too final boolean firstSpawn = this.instance == null; // TODO: Handle player reconnections, must be false in that case too
// Send the new dimension if player isn't in any instance or if the dimension is different // Send the new dimension if player isn't in any instance or if the dimension is different
{ final DimensionType instanceDimensionType = instance.getDimensionType();
final DimensionType instanceDimensionType = instance.getDimensionType(); final boolean dimensionChange = dimensionType != instanceDimensionType;
if (dimensionType != instanceDimensionType) { if (dimensionChange) {
sendDimension(instanceDimensionType); sendDimension(instanceDimensionType);
}
} }
// Load all the required chunks // Load all the required chunks
@ -656,7 +655,7 @@ public class Player extends LivingEntity implements CommandSender {
final ChunkCallback endCallback = chunk -> { final ChunkCallback endCallback = chunk -> {
// This is the last chunk to be loaded , spawn player // This is the last chunk to be loaded , spawn player
spawnPlayer(instance, spawnPosition, firstSpawn, true); spawnPlayer(instance, spawnPosition, firstSpawn, true, dimensionChange);
}; };
// Chunk 0;0 always needs to be loaded // Chunk 0;0 always needs to be loaded
@ -667,7 +666,7 @@ public class Player extends LivingEntity implements CommandSender {
} else { } else {
// The player already has the good version of all the chunks. // The player already has the good version of all the chunks.
// We just need to refresh his entity viewing list and add him to the instance // We just need to refresh his entity viewing list and add him to the instance
spawnPlayer(instance, spawnPosition, false, false); spawnPlayer(instance, spawnPosition, false, false, false);
} }
} }
@ -694,7 +693,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param firstSpawn true if this is the player first spawn * @param firstSpawn true if this is the player first spawn
*/ */
private void spawnPlayer(@NotNull Instance instance, @NotNull Position spawnPosition, private void spawnPlayer(@NotNull Instance instance, @NotNull Position spawnPosition,
boolean firstSpawn, boolean updateChunks) { boolean firstSpawn, boolean updateChunks, boolean dimensionChange) {
// Clear previous instance elements // Clear previous instance elements
if (!firstSpawn) { if (!firstSpawn) {
this.viewableChunks.forEach(chunk -> chunk.removeViewer(this)); this.viewableChunks.forEach(chunk -> chunk.removeViewer(this));
@ -712,7 +711,11 @@ public class Player extends LivingEntity implements CommandSender {
if (chunk != null) { if (chunk != null) {
refreshVisibleChunks(chunk); refreshVisibleChunks(chunk);
} }
updatePlayerPosition(); // So the player doesn't get stuck when changing dimension }
if (dimensionChange) {
updatePlayerPosition(); // So the player doesn't get stuck
this.inventory.update();
} }
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn); PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn);