Skip to content

Commit 8307794

Browse files
authored
Fix fake players not being able to respawn for exiting the end (gnembon#1664)
* Allow fake players to respawn (to return from the end) * Fixes gnembon#1645 (Fake players get stuck in the end exit portal) * fix up some imports
1 parent 8c09946 commit 8307794

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package carpet.mixins;
22

3+
import com.mojang.authlib.GameProfile;
34
import net.minecraft.nbt.CompoundTag;
45
import net.minecraft.network.Connection;
56
import net.minecraft.server.MinecraftServer;
7+
import net.minecraft.server.level.ServerLevel;
68
import net.minecraft.server.level.ServerPlayer;
79
import net.minecraft.server.network.ServerGamePacketListenerImpl;
810
import net.minecraft.server.players.PlayerList;
@@ -44,4 +46,13 @@ private ServerGamePacketListenerImpl replaceNetworkHandler(MinecraftServer serve
4446
return new ServerGamePacketListenerImpl(this.server, clientConnection, playerIn);
4547
}
4648
}
47-
}
49+
50+
@Redirect(method = "respawn", at = @At(value = "NEW", target = "net/minecraft/server/level/ServerPlayer"))
51+
public ServerPlayer makePlayerForRespawn(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ServerPlayer serverPlayer, boolean bl)
52+
{
53+
if (serverPlayer instanceof EntityPlayerMPFake) {
54+
return EntityPlayerMPFake.respawnFake(minecraftServer, serverLevel, gameProfile);
55+
}
56+
return new ServerPlayer(minecraftServer, serverLevel, gameProfile);
57+
}
58+
}

src/main/java/carpet/patches/EntityPlayerMPFake.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
1010
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
1111
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
12+
import net.minecraft.network.protocol.game.ServerboundClientCommandPacket;
1213
import net.minecraft.resources.ResourceKey;
1314
import net.minecraft.server.MinecraftServer;
1415
import net.minecraft.server.TickTask;
@@ -104,6 +105,11 @@ public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlay
104105
return playerShadow;
105106
}
106107

108+
public static EntityPlayerMPFake respawnFake(MinecraftServer server, ServerLevel level, GameProfile profile)
109+
{
110+
return new EntityPlayerMPFake(server, level, profile, false);
111+
}
112+
107113
private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, boolean shadow)
108114
{
109115
super(server, worldIn, profile);
@@ -137,7 +143,6 @@ public void tick()
137143
{
138144
this.connection.resetPosition();
139145
this.getLevel().getChunkSource().move(this);
140-
hasChangedDimension(); //<- causes hard crash but would need to be done to enable portals // not as of 1.17
141146
}
142147
try
143148
{
@@ -182,4 +187,21 @@ public String getIpAddress()
182187
protected void checkFallDamage(double y, boolean onGround, BlockState state, BlockPos pos) {
183188
doCheckFallDamage(y, onGround);
184189
}
190+
191+
@Override
192+
public Entity changeDimension(ServerLevel serverLevel)
193+
{
194+
super.changeDimension(serverLevel);
195+
if (wonGame) {
196+
ServerboundClientCommandPacket p = new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN);
197+
connection.handleClientCommand(p);
198+
}
199+
200+
// If above branch was taken, *this* has been removed and replaced, the new instance has been set
201+
// on 'our' connection (which is now theirs, but we still have a ref).
202+
if (connection.player.isChangingDimension()) {
203+
connection.player.hasChangedDimension();
204+
}
205+
return connection.player;
206+
}
185207
}

0 commit comments

Comments
 (0)