Posted August 2, 20196 yr I need to access my configuration inside my IConditionSerializer. My current solution is very ugly, as it relies on reflection. How would I do this correctly? Current code: @Mod.EventBusSubscriber( modid = "hadron", bus = Mod.EventBusSubscriber.Bus.MOD ) public class HadronConfigConditionFactory implements IConditionSerializer { @Override public BooleanSupplier parse(JsonObject json) { String setting = JSONUtils.getString(json, "config", null); if (setting != null) { return new BooleanSupplier() { @Override public boolean getAsBoolean() { try { Field f = ForgeConfigSpec.class.getDeclaredField("childConfig"); f.setAccessible(true); Config config = (Config) f.get(HadronConfigHolder.config); return config.getOrElse(setting, true); } catch(Exception e) { return true; } } }; } else { return () -> true; } } @SubscribeEvent public static void setup(FMLCommonSetupEvent e) { CraftingHelper.register(new ResourceLocation("hadron", "config"), new HadronConfigConditionFactory()); } }
August 2, 20196 yr 1 hour ago, F43nd1r said: How would I do this correctly? Store your configuration when you create it in your setup method in a static field. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20196 yr Author I have my configuration, it is HadronConfigHolder.config The problem is I need to access a value by name, which usually is done by ConfigValue. But I don't have those in a IConditionSerializer, because it reads from json.
August 2, 20196 yr ForgeConfigSpec implements UnmodifiableConfig, have you tried calling UnmodifiableConfig#getOrElse on your ForgeConfigSpec instance? Note that if you've followed Forge's example and made your ForgeConfigSpec fields private, you'll need to create a public method in your config class that calls UnmodifiableConfig#get(String) on the appropriate ForgeConfigSpec instance. Edited August 2, 20196 yr by Choonster Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
August 2, 20196 yr Author 16 minutes ago, Choonster said: ForgeConfigSpec implements UnmodifiableConfig, have you tried calling UnmodifiableConfig#getOrElse on your ForgeConfigSpec instance? I've tried that. Problem is, that calls to ForgeConfigSpec.config , while the real values are in ForgeConficSpec.childConfig . Hence the dirty workaround to access childConfig. Edited August 2, 20196 yr by F43nd1r
August 2, 20196 yr why have this a config condition? If they are changing the config then they can change the loot table I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
August 2, 20196 yr Author 3 minutes ago, LexManos said: why have this a config condition? If they are changing the config then they can change the loot table Here is an example using this condition: magma_bricks.json { "result":{"item":"hadron:magma_bricks","count":4}, "conditions":[{"config":"Building.MagmaBricks","type":"hadron:config"}], "ingredients":[ {"item":"minecraft:stone_bricks"}, {"item":"minecraft:stone_bricks"}, {"item":"minecraft:magma_block"}, {"item":"minecraft:magma_block"}], "type":"minecraft:crafting_shapeless" } I'm not aware of any solutions outside of conditions to disable multiple recipes based on settings. Aren't loot tables for item drops?
August 3, 20196 yr Then they can change the recipes. The issue is dependant recipes is advancements and other things. You're just moving the config from one file to another. I can see your usecasse, but it has downsides of just missing recipes. I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
August 3, 20196 yr Author 6 hours ago, LexManos said: Then they can change the recipes. The issue is dependant recipes is advancements and other things. You're just moving the config from one file to another. I can see your usecasse, but it has downsides of just missing recipes. Lets assume a mod like quark, which is registering lots of blocks. IMO such a mod should provide a userfriendly way to enable/disable groups of these blocks. Overwriting all recipes of blocks in this group is not user friendly, because a group can have like 50 recipes (Do you disagree?). This also doesn't consider creative tabs. My current solution registers all blocks (according to you "always register everything"), and then disables recipes of disabled blocks and removes them from creative tabs based on a configuration file. Would you say this approach is valid? Is there a better approach?
August 18, 20196 yr Author @LexManos if you can see the usecase, but my solution has downsides, maybe we could build a new solution in forge without these downsides?
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.