Fix fake players not being able to respawn for exiting the end (#1664)

* Allow fake players to respawn (to return from the end)
* Fixes #1645 (Fake players get stuck in the end exit portal)

* fix up some imports
This commit is contained in:
James McCulloch authored and GitHub committed 2023-03-14 17:07:27 +01:00
1 parent 8c09946bef
commit 8307794f19
2 files changed
+35 -2

No files matched your search

@@ -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;
}
}