diff --git a/build.gradle b/build.gradle index 4397120..8c6a10f 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation include("net.kyori:adventure-platform-fabric:5.8.0") // for Minecraft 1.19.4 + modImplementation include("net.kyori:adventure-platform-fabric:5.10.0") // for Minecraft 1.20.2 modImplementation include("net.kyori:adventure-text-serializer-legacy:4.13.1") diff --git a/gradle.properties b/gradle.properties index 0399033..0412a2b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20.1 - yarn_mappings=1.20.1+build.9 - loader_version=0.14.21 + minecraft_version=1.20.2 + yarn_mappings=1.20.2+build.1 + loader_version=0.14.22 # Mod Properties mod_version = 1.0.0 @@ -14,6 +14,6 @@ org.gradle.parallel=true archives_base_name = chipmunkmod # Dependencies - fabric_version=0.84.0+1.20.1 + fabric_version=0.89.2+1.20.2 diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java index 59d9078..a085c7b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java @@ -11,14 +11,15 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ConnectScreen; import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen; import net.minecraft.client.network.ServerInfo; import net.minecraft.client.network.ServerAddress; -import net.minecraft.client.util.Session; +import net.minecraft.client.session.Session; import net.minecraft.text.Text; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import java.util.Optional; +import java.util.UUID; + import land.chipmunk.chipmunkmod.mixin.MinecraftClientAccessor; public class UsernameCommand { @@ -45,7 +46,7 @@ public class UsernameCommand { public static int updateUsername (CommandContext context) throws CommandSyntaxException { final String username = getString(context, "username"); if (username.length() > 16) throw USERNAME_TOO_LONG.create(); - final Session session = new Session(username, "", "", Optional.empty(), Optional.empty(), Session.AccountType.MOJANG); + final Session session = new Session(username, new UUID(0L, 0L), "", Optional.empty(), Optional.empty(), Session.AccountType.MOJANG); return updateSession(context, session); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java index 6608a03..c01f236 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java @@ -16,9 +16,6 @@ public interface ClientPlayNetworkHandlerAccessor { @Accessor("CHAT_VALIDATION_FAILED_TEXT") static Text chatValidationFailedText () { throw new AssertionError(); } - @Accessor("connection") - ClientConnection connection(); - @Accessor("playerListEntries") Map playerListEntries(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index b62cfd9..e5d6c84 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -1,6 +1,5 @@ package land.chipmunk.chipmunkmod.mixin; -import com.mojang.authlib.GameProfile; import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.listeners.Listener; @@ -8,26 +7,21 @@ import land.chipmunk.chipmunkmod.listeners.ListenerManager; import land.chipmunk.chipmunkmod.modules.*; import net.kyori.adventure.text.TextComponent; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.network.ClientDynamicRegistryType; -import net.minecraft.client.network.ServerInfo; -import net.minecraft.client.util.telemetry.WorldSession; import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.network.ClientConnection; import net.minecraft.network.encryption.NetworkEncryptionUtils; import net.minecraft.network.message.LastSeenMessagesCollector; import net.minecraft.network.message.MessageBody; import net.minecraft.network.message.MessageChain; import net.minecraft.network.message.MessageSignatureData; -import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket; -import net.minecraft.registry.CombinedDynamicRegistries; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.resource.featuretoggle.FeatureSet; import net.minecraft.text.Text; import net.minecraft.text.TranslatableTextContent; +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; @@ -38,22 +32,16 @@ import java.time.Instant; @Mixin(value = net.minecraft.client.network.ClientPlayNetworkHandler.class, priority = 1001) public class ClientPlayNetworkHandlerMixin { + @Final @Shadow private FeatureSet enabledFeatures; - @Shadow private CombinedDynamicRegistries combinedDynamicRegistries; + @Final + @Shadow private DynamicRegistryManager.Immutable combinedDynamicRegistries; @Shadow private LastSeenMessagesCollector lastSeenMessagesCollector; @Shadow private MessageChain.Packer messagePacker; - @Shadow - public void sendPacket(Packet packet) {} - - @Inject(method = "", at = @At("TAIL")) - private void init (MinecraftClient client, Screen screen, ClientConnection connection, ServerInfo serverInfo, GameProfile profile, WorldSession worldSession, CallbackInfo ci) { - - } - @Inject(method = "onGameJoin", at = @At("TAIL")) private void onGameJoin (GameJoinS2CPacket packet, CallbackInfo ci) { - final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries.getCombinedRegistryManager(), this.enabledFeatures); + final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures); KaboomCheck.INSTANCE.onJoin(); CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess); @@ -69,7 +57,6 @@ public class ClientPlayNetworkHandlerMixin { @Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true) private void onPlayerRemove (PlayerRemoveS2CPacket packet, CallbackInfo ci) { ci.cancel(); } - @Inject(method = "onGameMessage", at = @At("HEAD"), cancellable = true) private void onGameMessage (GameMessageS2CPacket packet, CallbackInfo ci) { final Text message = packet.content(); @@ -129,7 +116,7 @@ public class ClientPlayNetworkHandlerMixin { long l = NetworkEncryptionUtils.SecureRandomUtil.nextLong(); LastSeenMessagesCollector.LastSeenMessages lastSeenMessages = this.lastSeenMessagesCollector.collect(); MessageSignatureData messageSignatureData = this.messagePacker.pack(new MessageBody(content, instant, l, lastSeenMessages.lastSeen())); - this.sendPacket(new ChatMessageC2SPacket(content, instant, l, messageSignatureData, lastSeenMessages.update())); + MinecraftClient.getInstance().getNetworkHandler().sendPacket(new ChatMessageC2SPacket(content, instant, l, messageSignatureData, lastSeenMessages.update())); ci.cancel(); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoderHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoderHandlerMixin.java deleted file mode 100644 index 687ae6c..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoderHandlerMixin.java +++ /dev/null @@ -1,46 +0,0 @@ -package land.chipmunk.chipmunkmod.mixin; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import net.minecraft.network.*; -import net.minecraft.network.packet.Packet; -import net.minecraft.util.profiling.jfr.FlightProfiler; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -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.callback.CallbackInfo; - -import java.util.List; - -import static land.chipmunk.chipmunkmod.ChipmunkMod.LOGGER; - -@Mixin(DecoderHandler.class) -public class DecoderHandlerMixin { - @Final @Mutable @Shadow private final NetworkSide side; - - public DecoderHandlerMixin(NetworkSide side) { - this.side = side; - } - - @Inject(method = "decode", at = @At("HEAD"), cancellable = true) - private void decode (ChannelHandlerContext ctx, ByteBuf buf, List objects, CallbackInfo ci) { - int i = buf.readableBytes(); - if (i != 0) { - PacketByteBuf packetByteBuf = new PacketByteBuf(buf); - int j = packetByteBuf.readVarInt(); - Packet packet = ctx.channel().attr(ClientConnection.PROTOCOL_ATTRIBUTE_KEY).get().getPacketHandler(this.side, j, packetByteBuf); - if (packet != null) { - int k = ctx.channel().attr(ClientConnection.PROTOCOL_ATTRIBUTE_KEY).get().getId(); - FlightProfiler.INSTANCE.onPacketReceived(k, j, ctx.channel().remoteAddress(), i); - objects.add(packet); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(ClientConnection.PACKET_RECEIVED_MARKER, " IN: [{}:{}] {}", ctx.channel().attr(ClientConnection.PROTOCOL_ATTRIBUTE_KEY).get(), j, packet.getClass().getName()); - } - } - } - ci.cancel(); - } -} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java index cb5b5ac..f38b4bf 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; // https://github.com/LunaWasFlaggedAgain/Mojang-ResourceLocation-Challenge/blob/main/src/main/java/com/github/lunawasflaggedagain/mojangresourcelocationchallenge/mixin/DecoratedPotBlockEntitySherdsMixin.java @Mixin(DecoratedPotBlockEntity.Sherds.class) public class DecoratedPotBlockEntitySherdsMixin { - @Inject(method = "getSherd(Lnet/minecraft/nbt/NbtList;I)Lnet/minecraft/item/Item;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Identifier;(Ljava/lang/String;)V"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + @Inject(method = "getSherd", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Identifier;tryParse(Ljava/lang/String;)Lnet/minecraft/util/Identifier;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) private static void getSherd(NbtList list, int index, CallbackInfoReturnable cir, NbtElement nbtElement) { if (!Identifier.isValid(nbtElement.asString())) cir.setReturnValue(Items.BRICK); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java index 4a45e34..04f2cb8 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java @@ -1,9 +1,9 @@ package land.chipmunk.chipmunkmod.mixin; +import net.minecraft.client.session.Session; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; -import net.minecraft.client.util.Session; @Mixin(net.minecraft.client.MinecraftClient.class) public interface MinecraftClientAccessor { diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoMixin.java deleted file mode 100644 index aa775f0..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/NbtIoMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package land.chipmunk.chipmunkmod.mixin; - -import net.minecraft.nbt.*; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.io.DataInput; -import java.io.IOException; - -@Mixin(NbtIo.class) -public class NbtIoMixin { - @Inject(method = "read(Ljava/io/DataInput;ILnet/minecraft/nbt/NbtTagSizeTracker;)Lnet/minecraft/nbt/NbtElement;", at = @At("HEAD"), cancellable = true) - private static void read(DataInput input, int depth, NbtTagSizeTracker tracker, CallbackInfoReturnable cir) { - try { - byte b = input.readByte(); - if (b == 0) { - cir.setReturnValue(NbtEnd.INSTANCE); - } - - NbtString.skip(input); - cir.setReturnValue(NbtTypes.byId(b).read(input, depth, tracker)); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java index 0485559..32de7a5 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java @@ -131,7 +131,7 @@ public class SelfCare extends Listener { } public void packetReceived(GameJoinS2CPacket packet) { - gameMode = packet.gameMode().getId(); + gameMode = packet.commonPlayerSpawnInfo().gameMode().getId(); } public void packetReceived(GameStateChangeS2CPacket packet) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index a4f01f7..7605f92 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -1,8 +1,5 @@ package land.chipmunk.chipmunkmod.modules; -import land.chipmunk.chipmunkmod.mixin.ClientConnectionAccessor; -import land.chipmunk.chipmunkmod.mixin.ClientConnectionInvoker; -import land.chipmunk.chipmunkmod.mixin.ClientPlayNetworkHandlerAccessor; import land.chipmunk.chipmunkmod.song.Note; import land.chipmunk.chipmunkmod.song.Song; import land.chipmunk.chipmunkmod.song.SongLoaderException; @@ -14,13 +11,10 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; -import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import net.minecraft.util.math.random.Random; import java.io.File; import java.net.URL; @@ -220,23 +214,16 @@ public class SongPlayer { if (thing[1] == null) return; // idk if this can be null but ill just protect it for now i guess - final ClientPlayNetworkHandlerAccessor networkHandlerAccessor = (ClientPlayNetworkHandlerAccessor) client.getNetworkHandler(); - - final ClientConnectionAccessor clientConnectionAccessor = (ClientConnectionAccessor) networkHandlerAccessor.connection(); - - ClientConnectionInvoker.handlePacket( - new PlaySoundS2CPacket( - RegistryEntry.of(SoundEvent.of(Identifier.of(thing[0], thing[1]))), - SoundCategory.RECORDS, - client.player.getX(), - client.player.getY(), - client.player.getZ(), - note.volume, - floatingPitch, - Random.create().nextLong() - ), - clientConnectionAccessor.packetListener() - ); + client.submit(() -> client.world.playSound( + client.player.getX(), + client.player.getY(), + client.player.getZ(), + SoundEvent.of(Identifier.of(thing[0], thing[1])), + SoundCategory.RECORDS, + note.volume, + floatingPitch, + true + )); } else { final float floatingPitch = MathUtilities.clamp((float) (0.5 * (Math.pow(2, ((note.pitch + (pitch / 10)) / 12)))), 0F, 2F); diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 991e584..b52bc7c 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -11,9 +11,7 @@ "ClientPlayNetworkHandlerAccessor", "ClientPlayNetworkHandlerMixin", "MinecraftClientAccessor", - "DecoderHandlerMixin", "StringHelperMixin", - "NbtIoMixin", "ElderGuardianAppearanceParticleMixin", "IdentifierMixin", "DecoratedPotBlockEntitySherdsMixin",