67 lines
3.3 KiB
Java
67 lines
3.3 KiB
Java
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.ClientInformation;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.server.network.CommonListenerCookie;
|
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
|
import net.minecraft.server.players.PlayerList;
|
|
import net.minecraft.util.ProblemReporter;
|
|
import net.minecraft.world.level.storage.ValueInput;
|
|
import org.spongepowered.asm.mixin.Final;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
import carpet.patches.NetHandlerPlayServerFake;
|
|
import carpet.patches.EntityPlayerMPFake;
|
|
|
|
import java.util.Optional;
|
|
|
|
@Mixin(PlayerList.class)
|
|
public abstract class PlayerList_fakePlayersMixin
|
|
{
|
|
@Shadow
|
|
@Final
|
|
private MinecraftServer server;
|
|
|
|
// may need to be invoked in the configuration phase on prepareSpawn Task
|
|
@Inject(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;level()Lnet/minecraft/server/level/ServerLevel;"))
|
|
private void fixStartingPos(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci)
|
|
{
|
|
if (serverPlayer instanceof EntityPlayerMPFake)
|
|
{
|
|
((EntityPlayerMPFake) serverPlayer).fixStartingPosition.run();
|
|
}
|
|
}
|
|
|
|
@Redirect(method = "placeNewPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/server/network/CommonListenerCookie;)Lnet/minecraft/server/network/ServerGamePacketListenerImpl;"))
|
|
private ServerGamePacketListenerImpl replaceNetworkHandler(MinecraftServer server, Connection clientConnection, ServerPlayer playerIn, CommonListenerCookie cookie)
|
|
{
|
|
if (playerIn instanceof EntityPlayerMPFake fake)
|
|
{
|
|
return new NetHandlerPlayServerFake(this.server, clientConnection, fake, cookie);
|
|
}
|
|
else
|
|
{
|
|
return new ServerGamePacketListenerImpl(this.server, clientConnection, playerIn, cookie);
|
|
}
|
|
}
|
|
|
|
@Redirect(method = "respawn", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/server/level/ServerLevel;Lcom/mojang/authlib/GameProfile;Lnet/minecraft/server/level/ClientInformation;)Lnet/minecraft/server/level/ServerPlayer;"))
|
|
public ServerPlayer makePlayerForRespawn(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation cli, ServerPlayer serverPlayer, boolean i)
|
|
{
|
|
if (serverPlayer instanceof EntityPlayerMPFake) {
|
|
return EntityPlayerMPFake.respawnFake(minecraftServer, serverLevel, gameProfile, cli);
|
|
}
|
|
return new ServerPlayer(minecraftServer, serverLevel, gameProfile, cli);
|
|
}
|
|
}
|