Posted April 29, 20214 yr As title asks. It's not as simple as I'd hoped but if you have an immediate answer, there is no need to read the following. If you'd like to know why it's not as easy as simply getting the SRG name and access transformering, please read on. Story time. So I went into the main GameRules class and looked at how that's implemented. It was as follows: public static final GameRules.RuleKey<GameRules.BooleanValue> DO_FIRE_TICK = register("doFireTick", GameRules.Category.UPDATES, GameRules.BooleanValue.create(true)); Nothing too hard, I pulled this over to my own class and tried it but unfortunately GameRules.BooleanValue.create has private access in that class. "No biggie", I thought, "I'll just AT it." I rebuild my gradle so it can run the AT, it finishes after redownloading everything and I go into the newly downloaded GameRules.java and it still has private access. This confused me a bit so I tried some reflection but kept getting NoSuchMethodExceptions, even using ASMAPI.mapMethod("func_223568_b") as my method name input. I decided to run the following script on it to check what was going on. for (Method m : GameRules.BooleanValue.class.getMethods()) { AppleOfMyEye.LOGGER.info(m.getName()); for (Class<?> c : m.getParameterTypes()) { AppleOfMyEye.LOGGER.debug(c.getName()); } } which didn't show any 'create' methods. I then ran the same again with getDeclaredMethods() and that showed the create method and it's overload. [22:26:25] [Worker-Main-14/INFO] [co.le.ao.AppleOfMyEye/]: create [22:26:25] [Worker-Main-14/DEBUG] [co.le.ao.AppleOfMyEye/]: boolean [22:26:25] [Worker-Main-14/DEBUG] [co.le.ao.AppleOfMyEye/]: java.util.function.BiConsumer [22:26:25] [Worker-Main-14/INFO] [co.le.ao.AppleOfMyEye/]: create [22:26:25] [Worker-Main-14/DEBUG] [co.le.ao.AppleOfMyEye/]: boolean So I've had to use reflection but it's kind of nasty-looking and means I have to crash the game if an exception occurs or risk having the mod run in a not-fully-functional state. This not really preferable to what I could usually achieve with ATs where the code just wouldn't compile if there was a problem with it rather than compiling but with some missing values. Essentially, how do I add GameRules.BooleanValue.create(boolean) to my access transformer? The following doesn't work: public net.minecraft.world.GameRules.BooleanValue func_223568_b(Z)Lnet/minecraft/world/GameRules$RuleType; #create Thank you for your time
April 29, 20214 yr So if I got it right you want to create your own gamerule? Some time ago I wrote a mod in which I created my own Gamerules those would be the most important classes that I created: the GameRule class the class with the GameRule fields (includes all my created GameRules) and the registration if you should ever create gamerules like me then didn't use DeferredWorkQueue#runLater as registration use FMLCommonSetupEvent#enqueueWork instead
April 29, 20214 yr Author No, as I said, I can add the gamerule just fine I just want to figure out how to put the normal GameRules.BooleanValue methods in my AT rather than have to use reflection. Looks like your mod uses reflection though. Edit: this could be an XY Problem, I just want them in the access transformer so I can invoke them directly rather than with reflection invocations. Any alternative to reflection is good with me. Edited April 29, 20214 yr by Lemon Lord
April 29, 20214 yr 10 minutes ago, Lemon Lord said: No, as I said, I can add the gamerule just fine I just want to figure out how to put the normal GameRules.BooleanValue methods in my AT rather than have to use reflection. Looks like your mod uses reflection though. Edit: this could be an XY Problem, I just want them in the access transformer so I can invoke them directly rather than with reflection invocations. Any alternative to reflection is good with me. Damn, I probably misunderstood the question unfortunately I can't help you with the access transformer because I prefer java reflection. therefore i use it to add the gamerules Edited April 29, 20214 yr by Luis_ST
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.