diff --git a/gradle.properties b/gradle.properties index 1a45b9de..07454d15 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check https://fabricmc.net/develop/ - minecraft_version=23w35a + minecraft_version=1.20.2-pre1 loader_version=0.14.22 jsr305_version=3.0.2 - fabric_version=0.87.1+1.20.2 + fabric_version=0.88.2+1.20.2 # Mod Properties mod_version = 1.4.115 diff --git a/src/main/java/carpet/fakes/ServerPlayerInterface.java b/src/main/java/carpet/fakes/ServerPlayerInterface.java index 06fea590..96c8e09a 100644 --- a/src/main/java/carpet/fakes/ServerPlayerInterface.java +++ b/src/main/java/carpet/fakes/ServerPlayerInterface.java @@ -7,5 +7,4 @@ public interface ServerPlayerInterface EntityPlayerActionPack getActionPack(); void invalidateEntityObjectReference(); boolean isInvalidEntityObject(); - String getLanguage(); } diff --git a/src/main/java/carpet/mixins/PlayerList_coreMixin.java b/src/main/java/carpet/mixins/PlayerList_coreMixin.java index d52e0c40..fec5c66c 100644 --- a/src/main/java/carpet/mixins/PlayerList_coreMixin.java +++ b/src/main/java/carpet/mixins/PlayerList_coreMixin.java @@ -5,6 +5,7 @@ import carpet.network.ServerNetworkHandler; import net.minecraft.network.Connection; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; import net.minecraft.server.players.PlayerList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -16,7 +17,7 @@ public class PlayerList_coreMixin { @Inject(method = "placeNewPlayer", at = @At("RETURN")) - private void onPlayerConnected(Connection connection, ServerPlayer player, int i, CallbackInfo ci) + private void onPlayerConnected(Connection connection, ServerPlayer player, CommonListenerCookie i, CallbackInfo ci) { CarpetServer.onPlayerLoggedIn(player); } diff --git a/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java b/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java index 2cfdae22..3cd54ed3 100644 --- a/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java +++ b/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java @@ -4,8 +4,10 @@ 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 org.spongepowered.asm.mixin.Final; @@ -34,25 +36,25 @@ public abstract class PlayerList_fakePlayersMixin } } - @Redirect(method = "placeNewPlayer", at = @At(value = "NEW", target = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;I)Lnet/minecraft/server/network/ServerGamePacketListenerImpl;")) - private ServerGamePacketListenerImpl replaceNetworkHandler( MinecraftServer server, Connection clientConnection, ServerPlayer playerIn, int i) + @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, i); + return new NetHandlerPlayServerFake(this.server, clientConnection, fake, cookie); } else { - return new ServerGamePacketListenerImpl(this.server, clientConnection, playerIn, i); + 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/ServerPlayer;")) - public ServerPlayer makePlayerForRespawn(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ServerPlayer serverPlayer, boolean i) + @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); + return EntityPlayerMPFake.respawnFake(minecraftServer, serverLevel, gameProfile, cli); } - return new ServerPlayer(minecraftServer, serverLevel, gameProfile); + return new ServerPlayer(minecraftServer, serverLevel, gameProfile, cli); } } diff --git a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_antiCheatDisabledMixin.java b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_antiCheatDisabledMixin.java index 0b0ac162..3aed9172 100644 --- a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_antiCheatDisabledMixin.java +++ b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_antiCheatDisabledMixin.java @@ -4,6 +4,7 @@ import carpet.CarpetSettings; import net.minecraft.network.Connection; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; import net.minecraft.server.network.ServerCommonPacketListenerImpl; import net.minecraft.server.network.ServerGamePacketListenerImpl; import org.spongepowered.asm.mixin.Mixin; @@ -20,9 +21,9 @@ public abstract class ServerGamePacketListenerImpl_antiCheatDisabledMixin extend @Shadow private int aboveGroundVehicleTickCount; - public ServerGamePacketListenerImpl_antiCheatDisabledMixin(final MinecraftServer minecraftServer, final Connection connection, final int i) + public ServerGamePacketListenerImpl_antiCheatDisabledMixin(final MinecraftServer minecraftServer, final Connection connection, CommonListenerCookie cci) { - super(minecraftServer, connection, i); + super(minecraftServer, connection, cci); } //@Shadow protected abstract boolean isSingleplayerOwner(); diff --git a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java index 3d23a71c..4935d30e 100644 --- a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java +++ b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java @@ -6,9 +6,9 @@ import net.minecraft.network.Connection; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; import net.minecraft.server.network.ServerCommonPacketListenerImpl; import net.minecraft.server.network.ServerGamePacketListenerImpl; -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; @@ -20,7 +20,7 @@ public abstract class ServerGamePacketListenerImpl_coreMixin extends ServerCommo @Shadow public ServerPlayer player; - public ServerGamePacketListenerImpl_coreMixin(final MinecraftServer minecraftServer, final Connection connection, final int i) + public ServerGamePacketListenerImpl_coreMixin(final MinecraftServer minecraftServer, final Connection connection, final CommonListenerCookie i) { super(minecraftServer, connection, i); } diff --git a/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java b/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java index 6eda0884..9f7a39f0 100644 --- a/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayer_actionPackMixin.java @@ -4,6 +4,7 @@ import carpet.fakes.ServerPlayerInterface; import carpet.helpers.EntityPlayerActionPack; import com.mojang.authlib.GameProfile; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ClientInformation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import org.spongepowered.asm.mixin.Mixin; @@ -24,7 +25,7 @@ public abstract class ServerPlayer_actionPackMixin implements ServerPlayerInterf } @Inject(method = "", at = @At(value = "RETURN")) - private void onServerPlayerEntityContructor(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, CallbackInfo ci) + private void onServerPlayerEntityContructor(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation cli, CallbackInfo ci) { this.actionPack = new EntityPlayerActionPack((ServerPlayer) (Object) this); } diff --git a/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java b/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java index 4f41fc06..afba6cde 100644 --- a/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayer_scarpetEventMixin.java @@ -5,7 +5,6 @@ import carpet.fakes.ServerPlayerInterface; import carpet.script.EntityEventsGroup; import com.mojang.authlib.GameProfile; import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ServerboundClientInformationPacket; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; @@ -129,20 +128,4 @@ public abstract class ServerPlayer_scarpetEventMixin extends Player implements S { return isInvalidReference; } - - //getting player language - @Unique - private String language; - - @Override - public String getLanguage() - { - return this.language; - } - - @Inject(method = "updateOptions", at = @At("HEAD")) - public void setLanguage(ServerboundClientInformationPacket packet, CallbackInfo ci) - { - this.language = packet.language(); - } } diff --git a/src/main/java/carpet/patches/EntityPlayerMPFake.java b/src/main/java/carpet/patches/EntityPlayerMPFake.java index db022230..62cffb72 100644 --- a/src/main/java/carpet/patches/EntityPlayerMPFake.java +++ b/src/main/java/carpet/patches/EntityPlayerMPFake.java @@ -14,8 +14,10 @@ import net.minecraft.network.protocol.game.ServerboundClientCommandPacket; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.TickTask; +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.players.GameProfileCache; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; @@ -69,9 +71,9 @@ public class EntityPlayerMPFake extends ServerPlayer { current = p.get(); } - EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, false); + EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, ClientInformation.createDefault(), false); instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch); - server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, 0); + server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(current, 0, instance.clientInformation())); instance.teleportTo(worldIn, pos.x, pos.y, pos.z, (float) yaw, (float) pitch); instance.setHealth(20.0F); instance.unsetRemoved(); @@ -95,9 +97,9 @@ public class EntityPlayerMPFake extends ServerPlayer player.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login")); ServerLevel worldIn = player.serverLevel();//.getWorld(player.dimension); GameProfile gameprofile = player.getGameProfile(); - EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, true); + EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, player.clientInformation(), true); playerShadow.setChatSession(player.getChatSession()); - server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, 0); + server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, new CommonListenerCookie(gameprofile, 0, player.clientInformation())); playerShadow.setHealth(player.getHealth()); playerShadow.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot()); @@ -114,14 +116,14 @@ public class EntityPlayerMPFake extends ServerPlayer return playerShadow; } - public static EntityPlayerMPFake respawnFake(MinecraftServer server, ServerLevel level, GameProfile profile) + public static EntityPlayerMPFake respawnFake(MinecraftServer server, ServerLevel level, GameProfile profile, ClientInformation cli) { - return new EntityPlayerMPFake(server, level, profile, false); + return new EntityPlayerMPFake(server, level, profile, cli, false); } - private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, boolean shadow) + private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, ClientInformation cli, boolean shadow) { - super(server, worldIn, profile); + super(server, worldIn, profile, cli); isAShadow = shadow; } diff --git a/src/main/java/carpet/patches/NetHandlerPlayServerFake.java b/src/main/java/carpet/patches/NetHandlerPlayServerFake.java index 7eee43fe..bfdd7f45 100644 --- a/src/main/java/carpet/patches/NetHandlerPlayServerFake.java +++ b/src/main/java/carpet/patches/NetHandlerPlayServerFake.java @@ -6,13 +6,14 @@ import net.minecraft.network.chat.contents.TranslatableContents; import net.minecraft.network.protocol.Packet; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.world.entity.RelativeMovement; import java.util.Set; public class NetHandlerPlayServerFake extends ServerGamePacketListenerImpl { - public NetHandlerPlayServerFake(final MinecraftServer minecraftServer, final Connection connection, final ServerPlayer serverPlayer, final int i) + public NetHandlerPlayServerFake(final MinecraftServer minecraftServer, final Connection connection, final ServerPlayer serverPlayer, final CommonListenerCookie i) { super(minecraftServer, connection, serverPlayer, i); } diff --git a/src/main/java/carpet/script/external/Vanilla.java b/src/main/java/carpet/script/external/Vanilla.java index 67470b4d..9e30a738 100644 --- a/src/main/java/carpet/script/external/Vanilla.java +++ b/src/main/java/carpet/script/external/Vanilla.java @@ -230,7 +230,7 @@ public class Vanilla public static String ServerPlayer_getLanguage(ServerPlayer player) { - return ((ServerPlayerInterface) player).getLanguage(); + return player.clientInformation().language(); } public static GoalSelector Mob_getAI(Mob mob, boolean target) diff --git a/src/main/java/carpet/script/utils/SnoopyCommandSource.java b/src/main/java/carpet/script/utils/SnoopyCommandSource.java index 4fe3d8d5..adc181d7 100644 --- a/src/main/java/carpet/script/utils/SnoopyCommandSource.java +++ b/src/main/java/carpet/script/utils/SnoopyCommandSource.java @@ -41,6 +41,8 @@ public class SnoopyCommandSource extends CommandSourceStack private final List chatOutput; private final CommandSigningContext signingContext; + private final TaskChainer taskChainer; + public SnoopyCommandSource(CommandSourceStack original, Component[] error, List chatOutput) { super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), Vanilla.MinecraftServer_getRunPermissionLevel(original.getServer()), @@ -62,6 +64,7 @@ public class SnoopyCommandSource extends CommandSourceStack this.error = error; this.chatOutput = chatOutput; this.signingContext = original.getSigningContext(); + this.taskChainer = TaskChainer.immediate(original.getServer()); } public SnoopyCommandSource(ServerPlayer player, Component[] error, List output) @@ -85,15 +88,16 @@ public class SnoopyCommandSource extends CommandSourceStack this.error = error; this.chatOutput = output; this.signingContext = CommandSigningContext.ANONYMOUS; + this.taskChainer = TaskChainer.immediate(player.server); } - private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, ResultConsumer consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, + private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, ResultConsumer consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer, Component[] error, List chatOutput ) { super(output, pos, rot, world, level, simpleName, name, server, entity, false, - consumer, entityAnchor, context, TaskChainer.immediate(server), i -> {}); + consumer, entityAnchor, context, chainer, i -> {}); this.output = output; this.position = pos; this.rotation = rot; @@ -108,30 +112,31 @@ public class SnoopyCommandSource extends CommandSourceStack this.error = error; this.chatOutput = chatOutput; this.signingContext = context; + this.taskChainer = chainer; } @Override public CommandSourceStack withEntity(Entity entity) { - return new SnoopyCommandSource(output, position, rotation, world, level, entity.getName().getString(), entity.getDisplayName(), server, entity, resultConsumer, entityAnchor, signingContext, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, entity.getName().getString(), entity.getDisplayName(), server, entity, resultConsumer, entityAnchor, signingContext, taskChainer, error, chatOutput); } @Override public CommandSourceStack withPosition(Vec3 position) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, taskChainer, error, chatOutput); } @Override public CommandSourceStack withRotation(Vec2 rotation) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, taskChainer, error, chatOutput); } @Override public CommandSourceStack withCallback(ResultConsumer consumer) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, signingContext, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, signingContext, taskChainer, error, chatOutput); } @Override @@ -160,13 +165,13 @@ public class SnoopyCommandSource extends CommandSourceStack @Override public CommandSourceStack withAnchor(EntityAnchorArgument.Anchor anchor) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, anchor, signingContext, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, anchor, signingContext, taskChainer, error, chatOutput); } @Override - public CommandSourceStack withSigningContext(CommandSigningContext commandSigningContext) + public CommandSourceStack withSigningContext(CommandSigningContext commandSigningContext, TaskChainer taskChainer) { - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, commandSigningContext, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, commandSigningContext, taskChainer, error, chatOutput); } @Override @@ -174,7 +179,7 @@ public class SnoopyCommandSource extends CommandSourceStack { double d = DimensionType.getTeleportationScale(this.world.dimensionType(), world.dimensionType()); Vec3 position = new Vec3(this.position.x * d, this.position.y, this.position.z * d); - return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, error, chatOutput); + return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, signingContext, taskChainer, error, chatOutput); } @Override