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:
1 parent
8c09946bef
commit
8307794f19
2 files changed
+35
-2
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user