From 46a324a213c2bfcdcda3fe7e45fd9049711ed179 Mon Sep 17 00:00:00 2001 From: Tristan Kechlo <66692834+tristankechlo@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:22:15 +0200 Subject: [PATCH] remove custom argument type --- Changelog.md | 4 ++ .../commands/LivingThingsCommand.java | 10 ++-- .../commands/ProjectLinksArgumentType.java | 51 ------------------- .../mixin/ArgumentTypesMixin.java | 32 ------------ .../main/resources/livingthings.mixins.json | 1 - gradle.properties | 2 +- 6 files changed, 12 insertions(+), 88 deletions(-) delete mode 100644 common/src/main/java/com/tristankechlo/livingthings/commands/ProjectLinksArgumentType.java delete mode 100644 common/src/main/java/com/tristankechlo/livingthings/mixin/ArgumentTypesMixin.java diff --git a/Changelog.md b/Changelog.md index 115dbd60..fd7e2fbf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # Changelog +### Version 1.21.1 - 2.1.3 + +- remove custom argument type, which caused some incompatibilities with other mods + ### Version 1.21.1 - 2.1.2 - fix advancements unlocking all recipes at world start diff --git a/common/src/main/java/com/tristankechlo/livingthings/commands/LivingThingsCommand.java b/common/src/main/java/com/tristankechlo/livingthings/commands/LivingThingsCommand.java index 37cfa908..b891841f 100644 --- a/common/src/main/java/com/tristankechlo/livingthings/commands/LivingThingsCommand.java +++ b/common/src/main/java/com/tristankechlo/livingthings/commands/LivingThingsCommand.java @@ -18,13 +18,17 @@ public final class LivingThingsCommand { public static void register(CommandDispatcher dispatcher) { LiteralArgumentBuilder command = literal(LivingThings.MOD_ID) - .then(argument("type", ProjectLinksArgumentType.get()).executes(LivingThingsCommand::execute)); + .then(literal("github").executes((context) -> display(context, ProjectLinks.GITHUB))) + .then(literal("issue").executes((context) -> display(context, ProjectLinks.GITHUB_ISSUES))) + .then(literal("wiki").executes((context) -> display(context, ProjectLinks.GITHUB_WIKI))) + .then(literal("discord").executes((context) -> display(context, ProjectLinks.DISCORD))) + .then(literal("curseforge").executes((context) -> display(context, ProjectLinks.CURSEFORGE))) + .then(literal("modrinth").executes((context) -> display(context, ProjectLinks.MODRINTH))); dispatcher.register(command); LivingThings.LOGGER.info("Command '/{}' registered", LivingThings.MOD_ID); } - private static int execute(CommandContext context) { - ProjectLinks type = context.getArgument("type", ProjectLinks.class); + private static int display(CommandContext context, ProjectLinks type) { CommandSourceStack source = context.getSource(); Component link = clickableLink(type.getUrl()); Component message = Component.literal(type.getMessage()).withStyle(ChatFormatting.WHITE).append(link); diff --git a/common/src/main/java/com/tristankechlo/livingthings/commands/ProjectLinksArgumentType.java b/common/src/main/java/com/tristankechlo/livingthings/commands/ProjectLinksArgumentType.java deleted file mode 100644 index 3374f5c4..00000000 --- a/common/src/main/java/com/tristankechlo/livingthings/commands/ProjectLinksArgumentType.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.tristankechlo.livingthings.commands; - -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import com.tristankechlo.livingthings.util.ProjectLinks; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.network.chat.Component; - -import java.util.Collection; -import java.util.concurrent.CompletableFuture; - -public final class ProjectLinksArgumentType implements ArgumentType { - - private static final DynamicCommandExceptionType ERROR_INVALID = new DynamicCommandExceptionType((o) -> Component.literal("Invalid type: " + o)); - private static final ProjectLinksArgumentType INSTANCE = new ProjectLinksArgumentType(); - private static final Collection EXAMPLES = ProjectLinks.getNames().toList(); - - @Override - public ProjectLinks parse(StringReader reader) throws CommandSyntaxException { - String s = reader.readUnquotedString(); - ProjectLinks type = ProjectLinks.byName(s, null); - if (type == null) { - throw ERROR_INVALID.createWithContext(reader, s); - } else { - return type; - } - } - - @Override - public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { - if (context.getSource() instanceof SharedSuggestionProvider) { - return SharedSuggestionProvider.suggest(ProjectLinks.getNames(), builder); - } - return Suggestions.empty(); - } - - @Override - public Collection getExamples() { - return EXAMPLES; - } - - public static ProjectLinksArgumentType get() { - return INSTANCE; - } - -} diff --git a/common/src/main/java/com/tristankechlo/livingthings/mixin/ArgumentTypesMixin.java b/common/src/main/java/com/tristankechlo/livingthings/mixin/ArgumentTypesMixin.java deleted file mode 100644 index 64835c25..00000000 --- a/common/src/main/java/com/tristankechlo/livingthings/mixin/ArgumentTypesMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.tristankechlo.livingthings.mixin; - -import com.mojang.brigadier.arguments.ArgumentType; -import com.tristankechlo.livingthings.LivingThings; -import com.tristankechlo.livingthings.commands.ProjectLinksArgumentType; -import net.minecraft.commands.synchronization.ArgumentTypeInfo; -import net.minecraft.commands.synchronization.ArgumentTypeInfos; -import net.minecraft.commands.synchronization.SingletonArgumentInfo; -import net.minecraft.core.Registry; -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.callback.CallbackInfoReturnable; - -@Mixin(ArgumentTypeInfos.class) -public abstract class ArgumentTypesMixin { - - @Inject(at = @At("HEAD"), method = "bootstrap") - private static void LivingThings$bootstrap(Registry> registry, CallbackInfoReturnable> cir) { - // register custom argument type - register(registry, LivingThings.MOD_ID + ":sampler_types", ProjectLinksArgumentType.class, SingletonArgumentInfo.contextFree(ProjectLinksArgumentType::get)); - } - - @Shadow - private static , T extends ArgumentTypeInfo.Template> ArgumentTypeInfo register( - Registry> registry, String id, Class clazz, ArgumentTypeInfo info - ) { - throw new AssertionError(); - } - -} diff --git a/common/src/main/resources/livingthings.mixins.json b/common/src/main/resources/livingthings.mixins.json index 0967dc67..0d1b4a2b 100644 --- a/common/src/main/resources/livingthings.mixins.json +++ b/common/src/main/resources/livingthings.mixins.json @@ -4,7 +4,6 @@ "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "mixins": [ - "ArgumentTypesMixin", "PlayerMixin", "SpawnPlacementsInvoker", "entity.MobAccessor", diff --git a/gradle.properties b/gradle.properties index d71929ae..a3a94b51 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ neoforge_range=[21,) mod_name=LivingThings mod_author=Buecher_wurm mod_id=livingthings -mod_version=2.1.2 +mod_version=2.1.3 # Other Mods modmenu_version=11.0.2 patchouli_version=1.21-87