diff --git a/build.gradle b/build.gradle index 8c6a10f..af42abc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'fabric-loom' version '1.0-SNAPSHOT' + id 'fabric-loom' version '1.7-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name version = project.mod_version @@ -20,6 +20,13 @@ repositories { mavenCentral() } +// https://github.com/MeteorDevelopment/meteor-client/blob/master/build.gradle#L46 +configurations { + implementation.extendsFrom(library) + shadow.extendsFrom(library) + include.extendsFrom(library) +} + dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -29,11 +36,13 @@ 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.10.0") // for Minecraft 1.20.2 + library "net.kyori:adventure-platform-fabric:5.14.1" // for Minecraft 1.21-1.21.1 - modImplementation include("net.kyori:adventure-text-serializer-legacy:4.13.1") + library "net.kyori:adventure-text-serializer-gson:4.17.0" - modImplementation include("org.luaj:luaj-jse:3.0.1") + library "net.kyori:adventure-text-serializer-legacy:4.17.0" + + library "org.luaj:luaj-jse:3.0.1" // Uncomment the following line to enable the deprecated Fabric API modules. // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. @@ -51,7 +60,7 @@ processResources { tasks.withType(JavaCompile).configureEach { // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release = 17 + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index 0412a2b..3ae78b1 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.2 - yarn_mappings=1.20.2+build.1 - loader_version=0.14.22 + minecraft_version=1.21.1 + yarn_mappings=1.21.1+build.3 + loader_version=0.16.5 # Mod Properties mod_version = 1.0.0 @@ -14,6 +14,6 @@ org.gradle.parallel=true archives_base_name = chipmunkmod # Dependencies - fabric_version=0.89.2+1.20.2 + fabric_version=0.105.0+1.21.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a363877..2617362 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index aeb74cb..7cd6e60 100755 --- a/gradlew +++ b/gradlew @@ -122,6 +122,7 @@ if [ -n "$JAVA_HOME" ] ; then else JAVACMD=$JAVA_HOME/bin/java fi + JAVACMD=/usr/bin/java if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME diff --git a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java index 5861999..0781d47 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java +++ b/src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java @@ -5,7 +5,6 @@ import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.CommandException; import net.minecraft.text.ClickEvent; import net.minecraft.text.Text; import net.minecraft.text.Texts; @@ -52,8 +51,6 @@ public class CommandManager { commandSource.sendError(Texts.toText(e.getRawMessage())); final Text context = getContext(e); if (context != null) commandSource.sendError(context); - } catch (CommandException e) { - commandSource.sendError(e.getTextMessage()); } catch (Exception e) { commandSource.sendError(Text.of(e.getMessage())); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java index c0c52cf..2efdc8a 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java @@ -1,5 +1,6 @@ package land.chipmunk.chipmunkmod.commands; +import com.google.common.base.Suppliers; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; @@ -10,6 +11,8 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.literal; import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; import static com.mojang.brigadier.arguments.StringArgumentType.getString; + +import land.chipmunk.chipmunkmod.util.TextUtilities; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.text.Text; import net.minecraft.nbt.NbtCompound; @@ -64,8 +67,9 @@ public class CoreCommand { future.thenApply(tag -> { try { final String output = tag.getString("LastOutput"); - if (output != null) source.sendFeedback(Text.Serializer.fromJson(output)); - } catch (Exception ignored) { + if (output != null) source.sendFeedback(TextUtilities.fromJson(output)); + } catch (Exception e) { + e.printStackTrace(); } return tag; diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java index 40deb98..5327deb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java @@ -8,6 +8,7 @@ import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.modules.SongPlayer; import land.chipmunk.chipmunkmod.song.Song; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.event.ClickEvent; @@ -219,7 +220,7 @@ public class MusicCommand { mergedList.addAll(files); final Component component = Component.translatable("Songs - %s", Component.join(JoinConfiguration.separator(Component.space()), mergedList)).color(NamedTextColor.GREEN); - MinecraftClient.getInstance().player.sendMessage(component); + ((Audience) MinecraftClient.getInstance().player).sendMessage(component); return 1; } diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java index a085c7b..feecd37 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java @@ -9,8 +9,8 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.literal; import static land.chipmunk.chipmunkmod.command.CommandManager.argument; 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.ConnectScreen; import net.minecraft.client.network.ServerInfo; import net.minecraft.client.network.ServerAddress; import net.minecraft.client.session.Session; @@ -61,7 +61,7 @@ public class UsernameCommand { final ServerInfo info = client.getCurrentServerEntry(); client.world.disconnect(); client.disconnect(); - ConnectScreen.connect(new TitleScreen(), client, ServerAddress.parse(info.address), info, false); + ConnectScreen.connect(new TitleScreen(), client, ServerAddress.parse(info.address), info, false, null); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java index 01cd34a..fe23281 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java @@ -6,18 +6,13 @@ import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand; import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions; import land.chipmunk.chipmunkmod.util.BotValidationUtilities; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ChatInputSuggestor; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.text.MutableText; import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import javax.net.ssl.HttpsURLConnection; import java.io.IOException; @@ -36,7 +31,7 @@ public class ChatScreenMixin extends Screen { } @Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true) - private void sendMessage (String chatText, boolean addToHistory, CallbackInfoReturnable cir) { + private void sendMessage (String chatText, boolean addToHistory, CallbackInfo cir) { final MinecraftClient client = MinecraftClient.getInstance(); if (addToHistory) { @@ -96,7 +91,6 @@ public class ChatScreenMixin extends Screen { try { BotValidationUtilities.chomens(chatText.substring(prefixLength)); - cir.setReturnValue(true); cir.cancel(); return; @@ -112,8 +106,6 @@ public class ChatScreenMixin extends Screen { client.player.networkHandler.sendChatMessage(chatText); } - cir.setReturnValue(true); - cir.cancel(); } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java index 8c03bf9..a81600f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java @@ -76,7 +76,7 @@ public class ClientConnectionMixin { if (world == null) return; // huge mess - final SoundEvent newSound = SoundEvent.of(new Identifier(sound.getNamespace(), sound.getPath().substring(0, sound.getPath().length() - (".pitch." + stringPitch).length()))); + final SoundEvent newSound = SoundEvent.of(Identifier.of(sound.getNamespace(), sound.getPath().substring(0, sound.getPath().length() - (".pitch." + stringPitch).length()))); client.executeSync(() -> world.playSound(client.player, t_packet.getX(), t_packet.getY(), t_packet.getZ(), newSound, t_packet.getCategory(), t_packet.getVolume(), pitch, t_packet.getSeed())); diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index e5d6c84..461c713 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -5,6 +5,8 @@ import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.listeners.Listener; import land.chipmunk.chipmunkmod.listeners.ListenerManager; import land.chipmunk.chipmunkmod.modules.*; +import net.kyori.adventure.platform.fabric.FabricAudiences; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandRegistryAccess; @@ -19,6 +21,7 @@ import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.resource.featuretoggle.FeatureSet; +import net.minecraft.text.PlainTextContent; import net.minecraft.text.Text; import net.minecraft.text.TranslatableTextContent; import org.spongepowered.asm.mixin.Final; @@ -81,16 +84,14 @@ public class ClientPlayNetworkHandlerMixin { } try { - final TextComponent suggestionId = ((TextComponent) message.asComponent().children().get(0)); - final TextComponent authId = (TextComponent) message.asComponent(); + final String suggestionId = message.getSiblings().getFirst().getString(); + final String authId = ((PlainTextContent) message.getContent()).string(); - if (suggestionId.content().equals(ChomeNSBotCommandSuggestions.ID) || authId.content().equals(ChomeNSAuth.INSTANCE.id)) { + if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID) || authId.equals(ChomeNSAuth.INSTANCE.id)) { ci.cancel(); } } catch (Exception ignored) {} - } catch (Exception e) { - e.printStackTrace(); - } + } catch (Exception ignored) {} } @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java deleted file mode 100644 index f38b4bf..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package land.chipmunk.chipmunkmod.mixin; - -import net.minecraft.block.entity.DecoratedPotBlockEntity; -import net.minecraft.item.Item; -import net.minecraft.item.Items; -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtList; -import net.minecraft.util.Identifier; -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 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", 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/ElderGuardianAppearanceParticleMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ElderGuardianAppearanceParticleMixin.java index e729f6d..ac46a1f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ElderGuardianAppearanceParticleMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ElderGuardianAppearanceParticleMixin.java @@ -3,7 +3,7 @@ package land.chipmunk.chipmunkmod.mixin; import net.minecraft.client.particle.ElderGuardianAppearanceParticle; import net.minecraft.client.particle.Particle; import net.minecraft.client.world.ClientWorld; -import net.minecraft.particle.DefaultParticleType; +import net.minecraft.particle.SimpleParticleType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -11,8 +11,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ElderGuardianAppearanceParticle.Factory.class) public class ElderGuardianAppearanceParticleMixin { - @Inject(method = "createParticle(Lnet/minecraft/particle/DefaultParticleType;Lnet/minecraft/client/world/ClientWorld;DDDDDD)Lnet/minecraft/client/particle/Particle;", at = @At("HEAD"), cancellable = true) - private void createParticle (DefaultParticleType defaultParticleType, ClientWorld clientWorld, double d, double e, double f, double g, double h, double i, CallbackInfoReturnable cir) { + @Inject(method = "createParticle(Lnet/minecraft/particle/SimpleParticleType;Lnet/minecraft/client/world/ClientWorld;DDDDDD)Lnet/minecraft/client/particle/Particle;", at = @At("HEAD")) + private void createParticle (SimpleParticleType simpleParticleType, ClientWorld clientWorld, double d, double e, double f, double g, double h, double i, CallbackInfoReturnable cir) { if (cir.isCancelled() || !cir.isCancellable()) return; cir.cancel(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/SharedConstantsMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/SharedConstantsMixin.java deleted file mode 100644 index ac5e810..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/SharedConstantsMixin.java +++ /dev/null @@ -1,16 +0,0 @@ -package land.chipmunk.chipmunkmod.mixin; - -import net.minecraft.SharedConstants; -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; - -@Mixin(SharedConstants.class) -public class SharedConstantsMixin { - @Inject(method = "isValidChar", at = @At("HEAD"), cancellable = true) - private static void isValidChar (char chr, CallbackInfoReturnable cir) { - cir.setReturnValue(chr >= ' ' && chr != '\u007f'); - cir.cancel(); - } -} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/StringHelperMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/StringHelperMixin.java index 716f38f..c3fb817 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/StringHelperMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/StringHelperMixin.java @@ -19,4 +19,10 @@ public class StringHelperMixin { cir.setReturnValue(text); cir.cancel(); } + + @Inject(method = "isValidChar", at = @At("HEAD"), cancellable = true) + private static void isValidChar (char chr, CallbackInfoReturnable cir) { + cir.setReturnValue(chr >= ' ' && chr != '\u007f'); + cir.cancel(); + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSAuth.java b/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSAuth.java index 264ea4d..8eafe49 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSAuth.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSAuth.java @@ -5,9 +5,10 @@ import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.listeners.Listener; import land.chipmunk.chipmunkmod.listeners.ListenerManager; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.text.PlainTextContent; import net.minecraft.text.Text; +import net.minecraft.text.TextContent; import java.nio.charset.StandardCharsets; import java.util.List; @@ -24,26 +25,26 @@ public class ChomeNSAuth extends Listener { public void init () {} @Override - public void chatMessageReceived(Text message) { + public void chatMessageReceived(Text text) { final String authKey = ChipmunkMod.CONFIG.bots.chomens.authKey; if (authKey == null) return; - final Component component = message.asComponent(); + final TextContent message = text.getContent(); - if (!(component instanceof TextComponent)) return; + if (!(message instanceof PlainTextContent)) return; - final String id = ((TextComponent) component).content(); + final String id = ((PlainTextContent) message).string(); if (!id.equals(this.id)) return; - final List children = component.children(); + final List children = text.getSiblings(); if (children.size() != 2) return; - if (!(children.get(0) instanceof TextComponent)) return; + if (!(children.getFirst().getContent() instanceof PlainTextContent)) return; - final String hash = ((TextComponent) children.get(0)).content(); + final String hash = ((PlainTextContent) children.getFirst().getContent()).string(); final long time = System.currentTimeMillis() / 10_000; @@ -55,9 +56,9 @@ public class ChomeNSAuth extends Listener { if (!hash.equals(actual)) return; - if (!(children.get(1) instanceof TextComponent)) return; + if (!(children.get(1).getContent() instanceof PlainTextContent)) return; - final String selector = ((TextComponent) children.get(1)).content(); + final String selector = ((PlainTextContent) children.get(1).getContent()).string(); final String toSendHash = Hashing.sha256() // very pro hash input diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java b/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java index 91bd70c..ab20a34 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/ChomeNSBotCommandSuggestions.java @@ -6,10 +6,10 @@ import land.chipmunk.chipmunkmod.listeners.Listener; import land.chipmunk.chipmunkmod.listeners.ListenerManager; import land.chipmunk.chipmunkmod.util.UUIDUtilities; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.text.PlainTextContent; import net.minecraft.text.Text; import java.util.ArrayList; @@ -54,31 +54,29 @@ public class ChomeNSBotCommandSuggestions extends Listener { @Override public void chatMessageReceived(Text message) { try { - final Component component = message.asComponent(); - - final List children = component.children(); + final List children = message.getSiblings(); if (children.isEmpty()) return; - final TextComponent textComponent = (TextComponent) children.get(0); + final Text textComponent = children.getFirst(); - if (!textComponent.content().equals(ID)) return; + if (!textComponent.getString().equals(ID)) return; commands = children.subList(1, children.size()) .stream() .map( (eachComponent) -> { final ChomeNSBotCommand command = new ChomeNSBotCommand( - ChipmunkMod.CONFIG.bots.chomens.prefix + ((TextComponent) eachComponent).content(), - ChomeNSBotCommand.TrustLevel.valueOf(((TextComponent) eachComponent.children().get(0)).content()) + ChipmunkMod.CONFIG.bots.chomens.prefix + ((PlainTextContent) eachComponent.getContent()).string(), + ChomeNSBotCommand.TrustLevel.valueOf(eachComponent.getSiblings().getFirst().getString()) ); - if (!Boolean.parseBoolean(((TextComponent) eachComponent.children().get(1)).content())) return command; + if (!Boolean.parseBoolean(eachComponent.getSiblings().get(1).getString())) return command; - final List subList = eachComponent.children().subList(2, eachComponent.children().size()); + final List subList = eachComponent.getSiblings().subList(2, eachComponent.getSiblings().size()); - for (Component aliasComponent : subList) { - final String alias = ((TextComponent) aliasComponent).content(); + for (Text aliasComponent : subList) { + final String alias = aliasComponent.getString(); command.aliases.add(alias); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java index b3a8fd5..1451a9a 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java @@ -5,6 +5,7 @@ import com.google.gson.JsonElement; import land.chipmunk.chipmunkmod.ChipmunkMod; +import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; @@ -146,7 +147,7 @@ public class CustomChat { CommandCore.INSTANCE.run((KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw @a " : "tellraw @a ") + sanitizedFormat); } catch (Exception e) { if (client.player == null) return; - client.player.sendMessage(Component.text(e.toString()).color(NamedTextColor.RED)); + ((Audience) client.player).sendMessage(Component.text(e.toString()).color(NamedTextColor.RED)); } } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java index 877bcfe..d62d3af 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java @@ -66,7 +66,7 @@ public class KaboomCheck extends Listener { } } - return packet; + return true; }); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java index 1e21707..39591aa 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java @@ -107,7 +107,7 @@ public class Players extends Listener { } private MutablePlayerListEntry getEntry (PlayerListS2CPacket.Entry other) { - return getEntry(other.profile().getId()); + return getEntry(other.profileId()); } private void addPlayer (PlayerListS2CPacket.Entry newEntry) { @@ -137,7 +137,7 @@ public class Players extends Listener { if (accessor == null) return; - final PlayerListEntryAccessor entryAccessor = (PlayerListEntryAccessor) accessor.playerListEntries().get(newEntry.profile().getId()); + final PlayerListEntryAccessor entryAccessor = (PlayerListEntryAccessor) accessor.playerListEntries().get(newEntry.profileId()); entryAccessor.setGameMode(newEntry.gameMode()); } catch (Exception e) { @@ -155,7 +155,7 @@ public class Players extends Listener { if (accessor == null) return; - final PlayerListEntryAccessor entryAccessor = (PlayerListEntryAccessor) accessor.playerListEntries().get(newEntry.profile().getId()); + final PlayerListEntryAccessor entryAccessor = (PlayerListEntryAccessor) accessor.playerListEntries().get(newEntry.profileId()); entryAccessor.setLatency(newEntry.latency()); } @@ -170,7 +170,7 @@ public class Players extends Listener { if (accessor == null) return; - accessor.playerListEntries().get(newEntry.profile().getId()).setDisplayName(newEntry.displayName()); + accessor.playerListEntries().get(newEntry.profileId()).setDisplayName(newEntry.displayName()); } private void removePlayer (UUID uuid) { @@ -197,7 +197,7 @@ public class Players extends Listener { final Message tooltip = suggestion.getTooltip(); if (tooltip != null || !suggestion.getText().equals(username)) continue; - return packet; + return true; } list.remove(target); @@ -210,7 +210,7 @@ public class Players extends Listener { addToPlayerList(new PlayerListEntry(entry.profile, false)); } - return packet; + return true; }); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index 7605f92..72740cc 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -5,6 +5,7 @@ import land.chipmunk.chipmunkmod.song.Song; import land.chipmunk.chipmunkmod.song.SongLoaderException; import land.chipmunk.chipmunkmod.song.SongLoaderThread; import land.chipmunk.chipmunkmod.util.MathUtilities; +import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; @@ -55,34 +56,34 @@ public class SongPlayer { public void loadSong (Path location) { if (loaderThread != null) { - client.player.sendMessage(Component.translatable("Already loading a song, cannot load another", NamedTextColor.RED)); + ((Audience) client.player).sendMessage(Component.translatable("Already loading a song, cannot load another", NamedTextColor.RED)); return; } try { final SongLoaderThread _loaderThread = new SongLoaderThread(location); - client.player.sendMessage(Component.translatable("Loading %s", Component.text(location.getFileName().toString(), NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); + ((Audience) client.player).sendMessage(Component.translatable("Loading %s", Component.text(location.getFileName().toString(), NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); _loaderThread.start(); loaderThread = _loaderThread; } catch (SongLoaderException e) { - client.player.sendMessage(Component.translatable("Failed to load song: %s", e.message).color(NamedTextColor.RED)); + ((Audience) client.player).sendMessage(Component.translatable("Failed to load song: %s", e.message.getString()).color(NamedTextColor.RED)); loaderThread = null; } } public void loadSong (URL location) { if (loaderThread != null) { - client.player.sendMessage(Component.translatable("Already loading a song, cannot load another", NamedTextColor.RED)); + ((Audience) client.player).sendMessage(Component.translatable("Already loading a song, cannot load another", NamedTextColor.RED)); return; } try { final SongLoaderThread _loaderThread = new SongLoaderThread(location); - client.player.sendMessage(Component.translatable("Loading %s", Component.text(location.toString(), NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); + ((Audience) client.player).sendMessage(Component.translatable("Loading %s", Component.text(location.toString(), NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); _loaderThread.start(); loaderThread = _loaderThread; } catch (SongLoaderException e) { - client.player.sendMessage(Component.translatable("Failed to load song: %s", e.message).color(NamedTextColor.RED)); + ((Audience) client.player).sendMessage(Component.translatable("Failed to load song: %s", e.message.getString()).color(NamedTextColor.RED)); loaderThread = null; } } @@ -102,19 +103,19 @@ public class SongPlayer { if (loaderThread != null && !loaderThread.isAlive()) { if (loaderThread.exception != null) { - client.player.sendMessage(Component.translatable("Failed to load song: %s", loaderThread.exception.message).color(NamedTextColor.RED)); + ((Audience) client.player).sendMessage(Component.translatable("Failed to load song: %s", loaderThread.exception.message.getString()).color(NamedTextColor.RED)); } else { songQueue.add(loaderThread.song); - client.player.sendMessage(Component.translatable("Added %s to the song queue", Component.empty().append(loaderThread.song.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); + ((Audience) client.player).sendMessage(Component.translatable("Added %s to the song queue", Component.empty().append(loaderThread.song.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); } loaderThread = null; } if (currentSong == null) { - if (songQueue.size() == 0) return; + if (songQueue.isEmpty()) return; currentSong = songQueue.poll(); - client.player.sendMessage(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); + ((Audience) client.player).sendMessage(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); currentSong.play(); } @@ -122,7 +123,7 @@ public class SongPlayer { else ticksUntilPausedActionbar = 20; try { - if (!useCore && actionbar) client.player.sendActionBar(generateActionbar()); + if (!useCore && actionbar && client.player != null) ((Audience) client.player).sendActionBar(generateActionbar()); else if (actionbar) CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar())); } catch (Exception e) { e.printStackTrace(); @@ -133,7 +134,7 @@ public class SongPlayer { handlePlaying(); if (currentSong.finished()) { - client.player.sendMessage(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); + ((Audience) client.player).sendMessage(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)); currentSong = null; } } @@ -148,11 +149,11 @@ public class SongPlayer { final ClientPlayerEntity player = client.player; Component component = Component.empty() - .append(Component.translatable("%s", player.getName()).color(NamedTextColor.GREEN)) + .append(Component.translatable("%s", player.getName().getString()).color(NamedTextColor.GREEN)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) - .append(Component.translatable("%s / %s", formatTime(currentSong.time).asComponent().color(NamedTextColor.GREEN), formatTime(currentSong.length).asComponent().color(NamedTextColor.GREEN)).color(NamedTextColor.GRAY)) + .append(Component.translatable("%s / %s", formatTime(currentSong.time).color(NamedTextColor.GREEN), formatTime(currentSong.length).color(NamedTextColor.GREEN)).color(NamedTextColor.GRAY)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable("%s / %s", Component.text(currentSong.position, NamedTextColor.GREEN), Component.text(currentSong.size(), NamedTextColor.GREEN)).color(NamedTextColor.GRAY)); @@ -177,16 +178,16 @@ public class SongPlayer { return component; } - public Text formatTime (long millis) { + public Component formatTime (long millis) { final int seconds = (int) millis / 1000; final String minutePart = String.valueOf(seconds / 60); final String unpaddedSecondPart = String.valueOf(seconds % 60); - return Text.translatable( + return Component.translatable( "%s:%s", - Text.literal(minutePart), - Text.literal(unpaddedSecondPart.length() < 2 ? "0" + unpaddedSecondPart : unpaddedSecondPart) + Component.text(minutePart), + Component.text(unpaddedSecondPart.length() < 2 ? "0" + unpaddedSecondPart : unpaddedSecondPart) ); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/TabComplete.java b/src/main/java/land/chipmunk/chipmunkmod/modules/TabComplete.java index c493e8d..2f95e4e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/TabComplete.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/TabComplete.java @@ -50,7 +50,7 @@ public class TabComplete extends Listener { } public void packetReceived (CommandSuggestionsS2CPacket packet) { - final CompletableFuture future = transactions.get(packet.getCompletionId()); + final CompletableFuture future = transactions.get(packet.id()); if (future == null) return; future.complete(packet); diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/TextUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/TextUtilities.java new file mode 100644 index 0000000..a5ef87a --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/util/TextUtilities.java @@ -0,0 +1,16 @@ +package land.chipmunk.chipmunkmod.util; + +import com.google.common.base.Suppliers; +import net.minecraft.registry.DynamicRegistryManager; +import net.minecraft.registry.Registries; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; + +public class TextUtilities { + public static MutableText fromJson (String json) { + return Text.Serialization.fromJson( + json, + Suppliers.ofInstance(DynamicRegistryManager.of(Registries.REGISTRIES)).get() + ); + } +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index e677ea7..89df942 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "land.chipmunk.chipmunkmod.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "client": [ "ChatInputSuggestorMixin", "ChatScreenMixin", @@ -14,12 +14,10 @@ "StringHelperMixin", "ElderGuardianAppearanceParticleMixin", "IdentifierMixin", - "DecoratedPotBlockEntitySherdsMixin", "TextMixin", "ClientConnectionInvoker", "ClientConnectionAccessor", "PlayerListEntryAccessor", - "SharedConstantsMixin", "TextSerializerMixin", "CommandDispatcherMixin", "SoundSystemMixin", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ee790cf..324bdaf 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -30,10 +30,10 @@ ], "depends": { - "fabricloader": ">=0.14.11", + "fabricloader": ">=0.16.5", "fabric-api": "*", - "minecraft": ">1.20", - "java": ">=17" + "minecraft": ">=1.21", + "java": ">=21" }, "suggests": { "another-mod": "*"