2424package net .kyori .adventure .platform .fabric .impl .mixin .minecraft .commands ;
2525
2626import com .google .common .collect .Iterators ;
27+ import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
28+ import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
29+ import com .llamalad7 .mixinextras .sugar .Local ;
2730import com .mojang .brigadier .arguments .ArgumentType ;
2831import com .mojang .brigadier .builder .ArgumentBuilder ;
2932import com .mojang .brigadier .builder .RequiredArgumentBuilder ;
30- import com .mojang .brigadier .suggestion .SuggestionProvider ;
3133import com .mojang .brigadier .tree .CommandNode ;
3234import java .util .Iterator ;
33- import java .util .Map ;
3435import java .util .Set ;
3536import net .kyori .adventure .platform .fabric .impl .ServerArgumentType ;
3637import net .kyori .adventure .platform .fabric .impl .ServerArgumentTypes ;
4243import net .minecraft .resources .ResourceLocation ;
4344import org .spongepowered .asm .mixin .Mixin ;
4445import org .spongepowered .asm .mixin .injection .At ;
45- import org .spongepowered .asm .mixin .injection .Inject ;
4646import org .spongepowered .asm .mixin .injection .ModifyVariable ;
47- import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
48- import org .spongepowered .asm .mixin .injection .callback .LocalCapture ;
4947
5048@ Mixin (Commands .class )
5149public abstract class CommandsMixin {
5250
5351 @ SuppressWarnings ({"rawtypes" , "unchecked" }) // argument type generics
54- @ Inject (
52+ @ WrapOperation (
5553 method = "fillUsableCommands" ,
56- locals = LocalCapture .CAPTURE_FAILEXCEPTION ,
5754 at = @ At (
5855 value = "INVOKE" ,
5956 target = "Lcom/mojang/brigadier/builder/ArgumentBuilder;build()Lcom/mojang/brigadier/tree/CommandNode;" ,
6057 remap = false
6158 )
6259 )
63- private static <T > void adventure$replaceArgumentType (
64- final CommandNode <T > commandNode ,
65- final CommandNode <T > commandNode2 ,
66- final T object ,
67- final Map <CommandNode <T >, CommandNode <T >> map ,
68- final CallbackInfo ci ,
69- final CommandNode <T > commandNode3 ,
70- final ArgumentBuilder <T , ?> argBuilder
60+ private static <T > CommandNode <T > adventure$replaceArgumentType (
61+ final ArgumentBuilder <T , ?> instance ,
62+ final Operation <CommandNode <T >> original ,
63+ final @ Local (argsOnly = true ) T sourceRaw
7164 ) {
72- if (!(argBuilder instanceof RequiredArgumentBuilder builder )) {
73- return ; // only replace argument types for required arguments
65+ if (!(instance instanceof RequiredArgumentBuilder builder )) {
66+ return original . call ( instance ) ; // only replace argument types for required arguments
7467 }
75- final CommandSourceStack source = (CommandSourceStack ) object ;
68+ final CommandSourceStack source = (CommandSourceStack ) sourceRaw ;
7669 ServerArgumentType <ArgumentType <T >> type = ServerArgumentTypes .byClass ((Class ) builder .getType ().getClass ());
7770 final Set <ResourceLocation > knownExtraCommands = ServerArgumentTypes .knownArgumentTypes (source .getPlayer ()); // throws an exception, we can ignore bc this is always a player
7871 // If we have a replacement and the arg type isn't known to the client, change the argument type
@@ -82,10 +75,11 @@ public abstract class CommandsMixin {
8275 final CommandBuildContext ctx = CommandBuildContext .simple (source .registryAccess (), source .enabledFeatures ());
8376 ((RequiredArgumentBuilderAccess ) builder ).accessor$type (type .fallbackProvider ().apply (builder .getType (), ctx ));
8477 if (type .fallbackSuggestions () != null ) {
85- builder .suggests (( SuggestionProvider ) type .fallbackSuggestions ());
78+ builder .suggests (type .fallbackSuggestions ());
8679 }
8780 type = ServerArgumentTypes .byClass ((Class ) builder .getType ().getClass ());
8881 }
82+ return original .call (instance );
8983 }
9084
9185 /**
0 commit comments