2424package com .fox2code .foxloader .patching .game ;
2525
2626import com .fox2code .foxloader .patching .TransformerUtils ;
27+ import org .objectweb .asm .Opcodes ;
2728import org .objectweb .asm .tree .*;
2829
2930final class CommandGamePatch extends GamePatch {
@@ -32,28 +33,42 @@ final class CommandGamePatch extends GamePatch {
3233 private static final String ServerPlayerCommandHandler = "net/minecraft/server/command/ServerPlayerCommandHandler" ;
3334 private static final String CommandRegistry$Internal = "com/fox2code/foxloader/registry/CommandRegistry$Internal" ;
3435 private static final String GameRegistry = "com/fox2code/foxloader/registry/GameRegistry" ;
36+ private static final String EntityRegistry = "com/fox2code/foxloader/registry/EntityRegistry" ;
3537 private static final String CommandCompletionRegistry$Item =
3638 "net/minecraft/common/command/completion/CommandCompletionRegistry$Type$1" ;
39+ private static final String CommandCompletionRegistry$Entity =
40+ "net/minecraft/common/command/completion/CommandCompletionRegistry$Type$2" ;
3741
3842 CommandGamePatch () {
3943 super (new String []{PlayerCommandHandler , ClientPlayerCommandHandler , ServerPlayerCommandHandler ,
40- CommandCompletionRegistry$Item });
44+ CommandCompletionRegistry$Item , CommandCompletionRegistry$Entity });
4145 }
4246
4347 @ Override
4448 public ClassNode transform (ClassNode classNode ) {
45- if (ClientPlayerCommandHandler .equals (classNode .name ) ||
46- ServerPlayerCommandHandler .equals (classNode .name )) {
47- MethodNode init = TransformerUtils .getMethod (classNode , "<init>" );
48- TransformerUtils .insertToEndOfCode (init ,
49- new MethodInsnNode (INVOKESTATIC , CommandRegistry$Internal , "register" , "()V" , false ));
50- TransformerUtils .bringSelfCallToEndOfCode (init , "reloadCommandCompletions" );
51- } else if (PlayerCommandHandler .equals (classNode .name )) {
52- MethodNode init = TransformerUtils .getMethod (classNode , "reloadCommands" );
53- TransformerUtils .insertToEndOfCode (init ,
54- new MethodInsnNode (INVOKESTATIC , CommandRegistry$Internal , "register" , "()V" , false ));
55- } else if (CommandCompletionRegistry$Item .equals (classNode .name )) {
56- patchCommandCompletionRegistry$Item (classNode );
49+ switch (classNode .name ) {
50+ case ClientPlayerCommandHandler :
51+ case ServerPlayerCommandHandler : {
52+ MethodNode init = TransformerUtils .getMethod (classNode , "<init>" );
53+ TransformerUtils .insertToEndOfCode (init ,
54+ new MethodInsnNode (INVOKESTATIC , CommandRegistry$Internal , "register" , "()V" , false ));
55+ TransformerUtils .bringSelfCallToEndOfCode (init , "reloadCommandCompletions" );
56+ break ;
57+ }
58+ case PlayerCommandHandler : {
59+ MethodNode init = TransformerUtils .getMethod (classNode , "reloadCommands" );
60+ TransformerUtils .insertToEndOfCode (init ,
61+ new MethodInsnNode (INVOKESTATIC , CommandRegistry$Internal , "register" , "()V" , false ));
62+ break ;
63+ }
64+ case CommandCompletionRegistry$Item : {
65+ patchCommandCompletionRegistry$Item (classNode );
66+ break ;
67+ }
68+ case CommandCompletionRegistry$Entity : {
69+ patchCommandCompletionRegistry$Entity (classNode );
70+ break ;
71+ }
5772 }
5873 return classNode ;
5974 }
@@ -112,4 +127,17 @@ public ClassNode transform(ClassNode classNode) {
112127 classNode .methods .remove (complete );
113128 classNode .methods .add (newComplete );
114129 }
130+
131+ private static void patchCommandCompletionRegistry$Entity (ClassNode classNode ) {
132+ MethodNode complete = TransformerUtils .getMethod (classNode , "complete" );
133+ for (AbstractInsnNode abstractInsnNode : complete .instructions ) {
134+ if (abstractInsnNode .getOpcode () == Opcodes .INVOKESTATIC ) {
135+ MethodInsnNode methodInsnNode = (MethodInsnNode ) abstractInsnNode ;
136+ if ("getEntityTypeNames" .equals (methodInsnNode .name )) {
137+ methodInsnNode .owner = EntityRegistry ;
138+ methodInsnNode .name = "getCommandCompletionEntityIDs" ;
139+ }
140+ }
141+ }
142+ }
115143}
0 commit comments