diff --git a/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java b/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java index 9b9d6cc2..0792a728 100644 --- a/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java +++ b/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java @@ -1,8 +1,10 @@ package carpet.mixins; +import com.mojang.authlib.GameProfile; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.Connection; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.server.players.PlayerList; @@ -44,4 +46,13 @@ public abstract class PlayerList_fakePlayersMixin return new ServerGamePacketListenerImpl(this.server, clientConnection, playerIn); } } -} \ No newline at end of file + + @Redirect(method = "respawn", at = @At(value = "NEW", target = "net/minecraft/server/level/ServerPlayer")) + public ServerPlayer makePlayerForRespawn(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ServerPlayer serverPlayer, boolean bl) + { + if (serverPlayer instanceof EntityPlayerMPFake) { + return EntityPlayerMPFake.respawnFake(minecraftServer, serverLevel, gameProfile); + } + return new ServerPlayer(minecraftServer, serverLevel, gameProfile); + } +} diff --git a/src/main/java/carpet/patches/EntityPlayerMPFake.java b/src/main/java/carpet/patches/EntityPlayerMPFake.java index 10962c04..f66d1b73 100644 --- a/src/main/java/carpet/patches/EntityPlayerMPFake.java +++ b/src/main/java/carpet/patches/EntityPlayerMPFake.java @@ -9,6 +9,7 @@ import net.minecraft.network.protocol.PacketFlow; import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; +import net.minecraft.network.protocol.game.ServerboundClientCommandPacket; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.TickTask; @@ -104,6 +105,11 @@ public class EntityPlayerMPFake extends ServerPlayer return playerShadow; } + public static EntityPlayerMPFake respawnFake(MinecraftServer server, ServerLevel level, GameProfile profile) + { + return new EntityPlayerMPFake(server, level, profile, false); + } + private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, boolean shadow) { super(server, worldIn, profile); @@ -137,7 +143,6 @@ public class EntityPlayerMPFake extends ServerPlayer { this.connection.resetPosition(); this.getLevel().getChunkSource().move(this); - hasChangedDimension(); //<- causes hard crash but would need to be done to enable portals // not as of 1.17 } try { @@ -182,4 +187,21 @@ public class EntityPlayerMPFake extends ServerPlayer protected void checkFallDamage(double y, boolean onGround, BlockState state, BlockPos pos) { doCheckFallDamage(y, onGround); } + + @Override + public Entity changeDimension(ServerLevel serverLevel) + { + super.changeDimension(serverLevel); + if (wonGame) { + ServerboundClientCommandPacket p = new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN); + connection.handleClientCommand(p); + } + + // If above branch was taken, *this* has been removed and replaced, the new instance has been set + // on 'our' connection (which is now theirs, but we still have a ref). + if (connection.player.isChangingDimension()) { + connection.player.hasChangedDimension(); + } + return connection.player; + } }