1919import clientapi .ClientAPI ;
2020import clientapi .config .ClientConfiguration ;
2121import clientapi .config .JsonConfiguration ;
22- import clientapi .load .argument . Argument ;
23- import clientapi . load . argument . Arguments ;
24- import net . minecraft . launchwrapper . ITweaker ;
22+ import clientapi .load .transform . impl . ValueAccessorTransformer ;
23+ import io . github . impactdevelopment . simpletweaker . SimpleTweaker ;
24+ import io . github . impactdevelopment . simpletweaker . transform . SimpleTransformer ;
2525import net .minecraft .launchwrapper .Launch ;
2626import net .minecraft .launchwrapper .LaunchClassLoader ;
2727import org .apache .logging .log4j .Level ;
3030import org .spongepowered .asm .mixin .Mixins ;
3131import org .spongepowered .tools .obfuscation .mcp .ObfuscationServiceMCP ;
3232
33- import java .io .File ;
3433import java .io .InputStream ;
35- import java .util .ArrayList ;
3634import java .util .List ;
3735
3836/**
4139 * @author Brady
4240 * @since 1/20/2017
4341 */
44- public final class ClientTweaker implements ITweaker {
45-
46- /**
47- * The raw game launch arguments that are provided in {@link ClientTweaker#acceptOptions(List, File, File, String)}
48- */
49- private List <String > args ;
50-
51- @ Override
52- public void acceptOptions (List <String > args , File gameDir , File assetsDir , String profile ) {
53- (this .args = new ArrayList <>()).addAll (args );
54- addArg ("gameDir" , gameDir );
55- addArg ("assetsDir" , assetsDir );
56- addArg ("version" , profile );
57- }
42+ public final class ClientTweaker extends SimpleTweaker {
5843
5944 @ Override
6045 public void injectIntoClassLoader (LaunchClassLoader classLoader ) {
46+ super .injectIntoClassLoader (classLoader );
47+
6148 ClientAPI .LOGGER .log (Level .INFO , "Injecting into ClassLoader" );
6249
6350 this .setupMixin ();
6451
6552 ClientConfiguration config = findClientConfig ();
6653
67- // Load bytecode transformers
68- classLoader .registerTransformer (ClientTransformer .class .getName ());
69- ClientTransformer .getInstance ().registerAll (config .getTransformers ());
70-
71- ClientAPI .LOGGER .log (Level .INFO , "Registered Bytecode Transformes" );
54+ this .setupTransformers (config );
7255
7356 // Load mixin configs
7457 loadMixinConfig ("mixins.capi.json" );
@@ -85,38 +68,39 @@ public final String getLaunchTarget() {
8568 return "net.minecraft.client.main.Main" ;
8669 }
8770
88- @ Override
8971 @ SuppressWarnings ("unchecked" )
90- public final String [] getLaunchArguments () {
91- // Parse the arguments that we are able to pass to the game
92- List <Argument > parsed = Arguments .parse (this .args );
93-
94- // Parse the arguments that are already being passed to the game
95- List <Argument > existing = Arguments .parse ((List <String >) Launch .blackboard .get ("ArgumentList" ));
96-
97- // Remove any arguments that conflict with existing ones
98- parsed .removeIf (argument -> existing .stream ().anyMatch (a -> a .conflicts (argument )));
99-
100- // Join back the filtered arguments and pass those to the game
101- return Arguments .join (parsed ).toArray (new String [0 ]);
102- }
103-
10472 private void setupMixin () {
10573 MixinBootstrap .init ();
10674 ClientAPI .LOGGER .log (Level .INFO , "Initialized Mixin bootstrap" );
10775
76+ // Find all of the other tweakers that are being loaded
77+ List <String > tweakClasses = (List <String >) Launch .blackboard .get ("TweakClasses" );
78+
79+ // Default to NOTCH obfuscation context
10880 String obfuscation = ObfuscationServiceMCP .NOTCH ;
10981
110- // If there are any transformers that have "fml" in their class name , then use the searge obfuscation context
111- if (Launch . classLoader . getTransformers (). stream ().anyMatch (t -> t . getClass (). getName (). contains ("fml " ))) {
82+ // If there are any tweak classes that contain "FMLTweaker" , then set the obfuscation context to SEARGE
83+ if (tweakClasses . stream ().anyMatch (s -> s . contains ("FMLTweaker " ))) {
11284 obfuscation = ObfuscationServiceMCP .SEARGE ;
85+ ClientAPI .LOGGER .log (Level .INFO , "Discovered FML! Switching to SEARGE mappings." );
11386 }
11487
11588 MixinEnvironment .getDefaultEnvironment ().setSide (MixinEnvironment .Side .CLIENT );
11689 MixinEnvironment .getDefaultEnvironment ().setObfuscationContext (obfuscation );
11790 ClientAPI .LOGGER .log (Level .INFO , "Setup Mixin Environment" );
11891 }
11992
93+ private void setupTransformers (ClientConfiguration config ) {
94+ SimpleTransformer transformer = SimpleTransformer .getInstance ();
95+
96+ if (!Boolean .valueOf (System .getProperty ("clientapi.load.devMode" , "false" )))
97+ transformer .registerAll (new ValueAccessorTransformer ());
98+
99+ transformer .registerAll (config .getTransformers ());
100+
101+ ClientAPI .LOGGER .log (Level .INFO , "Registered Bytecode Transformes" );
102+ }
103+
120104 private ClientConfiguration findClientConfig () {
121105 InputStream stream ;
122106 if ((stream = this .getClass ().getResourceAsStream ("/client.json" )) == null )
@@ -132,16 +116,4 @@ private void loadMixinConfig(String config) {
132116
133117 Mixins .addConfiguration (config );
134118 }
135-
136- private void addArg (String label , File file ) {
137- if (file != null )
138- addArg (label , file .getAbsolutePath ());
139- }
140-
141- private void addArg (String label , String value ) {
142- if (!args .contains ("--" + label ) && value != null ) {
143- this .args .add ("--" + label );
144- this .args .add (value );
145- }
146- }
147119}
0 commit comments