Posted October 21, 20214 yr Hey guys, i try to make recipes based of config options, but i can`t find the problem here, all recipes linked to an config options are always disabled and theres no error in the console, maybe a problem in the factories? ConditionsFactory public class ConditionFactory implements IConditionBuilder { //@Override public BooleanSupplier parse(JsonSerializationContext context, JsonObject json) { boolean value = JSONUtils.getBoolean(json , "value", true); String key = JSONUtils.getString(json, "type"); if (key.equals(Uncrafted.MODID + ":spawneggs_enabled")) { return () -> Config.ACTIVATE_SPAWNEGG_RECIPES.get().booleanValue() == value; } else if (key.equals(Uncrafted.MODID + ":spawner_enabled")) { return () -> Config.ACTIVATE_SPAWNER_RECIPES.get().booleanValue() == value; } else if (key.equals(Uncrafted.MODID + ":skulls_enabled")) { return () -> Config.ACTIVATE_SKULL_RECIPES.get().booleanValue() == value; } return null; } } _factories.json { "conditions": { "spawneggs_enabled": "xxrexraptorxx.util.ConditionFactory", "spawner_enabled": "xxrexraptorxx.util.ConditionFactory", "skulls_enabled": "xxrexraptorxx.util.ConditionFactory" } } example recipe: spawner.json { "conditions" : [ { "type" : "uncrafted:spawner_enabled", "value" : true } ], "type": "minecraft:crafting_shaped", "pattern": [ "XXX", "X#X", "XXX" ], "key": { "X": { "item": "minecraft:iron_bars" }, "#": { "item": "minecraft:nether_star" } }, "result": { "item": "minecraft:spawner" } } i hope anyone can help me
October 21, 20214 yr scrap all that (factory and _factories.json), it's for an older version. do have a condition in a recipe json file. the one you have up there will do fine. make a class that implements ICondition. getID() should return "uncrafted:spawner_enabled". test() should check options and enable/disable the recipe. inside the condition class make a serializer class (yes inside, inner class, static) that implements IConditionSerializer<YourCondition>. getID should return same as above; read should return an instance of your condition class. use json.getAsJsonPrimitive("value_or_flag_name_or_whatever") to get the setting name (if you use a single condition for several recipes); write should do the opposite of read - json.addProperty. finally, register your condition in FMLCommonSetupEvent. call CraftingHelper.register and pass the serializer instance. enjoy!
October 21, 20214 yr Author Thanks for your hint, but i don't quite understand this Serializer inner class Edited October 21, 20214 yr by Razor
October 21, 20214 yr one class inside another, just like you have fields and methods inside of a class. ok, i admit it's not very intuitive now that type definitions are no longer a thing... it doesn't have to be inner class, it can be a separate class. it's just more maintainable if you don't have two separate non-inner classes whose life cycles are connected. just make both classes. serializer will make condition class instances when the game needs them.
December 16, 20213 yr On 10/21/2021 at 9:41 PM, MFMods said: one class inside another, just like you have fields and methods inside of a class. ok, i admit it's not very intuitive now that type definitions are no longer a thing... it doesn't have to be inner class, it can be a separate class. it's just more maintainable if you don't have two separate non-inner classes whose life cycles are connected. just make both classes. serializer will make condition class instances when the game needs them. Could You Please Provide a simple example, I do understand java but this has me all in a twist
December 17, 20213 yr 10 hours ago, diesieben07 said: There are examples in Forge's source code, look at the built in conditions. Thanks, Will Look Now
December 17, 20213 yr { "conditions":[ { "type":"mbs:mod_check", "modid":"mbs" } ], "type": "minecraft:crafting_shaped", "pattern": [ "###", "# #" ], "key": { "#": { "item": "mbs:blue_diamond" } }, "result": { "item": "mbs:armor/blue_diamond_helmet", "count": 1 } } package com.SkyWarsFun2019.moreblock.util.Integration; import com.google.gson.JsonObject; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; import net.minecraftforge.common.crafting.conditions.ICondition; import net.minecraftforge.common.crafting.conditions.IConditionSerializer; import net.minecraftforge.fml.ModList; public class ModIntegrationRecipeCondition implements ICondition { private static final ResourceLocation NAME = new ResourceLocation("mbs", "mod_check"); private final String Modid; public ModIntegrationRecipeCondition(String Mod) { Modid = Mod; } @Override public ResourceLocation getID() { return NAME; } @Override public boolean test() { System.out.println("Testing"); return ModList.get().isLoaded(Modid); } @Override public String toString() { return "mod_loaded(\"" + Modid + "\")"; } public static class Serializer implements IConditionSerializer<ModIntegrationRecipeCondition> { public static final Serializer INSTANCE = new Serializer(); @Override public void write(JsonObject json, ModIntegrationRecipeCondition value) { json.addProperty("modid", value.Modid); } @Override public ModIntegrationRecipeCondition read(JsonObject json) { return new ModIntegrationRecipeCondition(GsonHelper.getAsString(json, "modid")); } @Override public ResourceLocation getID() { return ModIntegrationRecipeCondition.NAME; } } } this is my json and class, any reason why it doesnt work. Edited December 17, 20213 yr by DX12 Updated Information, Provided More Details
December 17, 20213 yr Just now, diesieben07 said: "mbs" is a bad ModID. Do not use abbreviations. You do not own SkyWarsFun2019.com. Forge already provides the "forge:mod_loaded" condition, there is no need to implement it yourself. You have not shown where you register your condition. for the first and second part I Am co-owner, the original owner set that. private void Setup(FMLCommonSetupEvent event) { event.enqueueWork(OreGen::RegisterOre); List<String> Mods = Searcher.GetModIDs(event); Searcher.PrintMods(Mods); System.out.println("Condition Register Starting"); CraftingHelper.register(new ModIntegrationRecipeCondition.Serializer()); System.out.println("Condition Register Complete"); } this is where and how it is registered. as with the third point i plan to change this to run a check on the mod config file
December 21, 20213 yr yes. yes, there would be. put a log command (output a line into log or a console) in serializer.read, serializer.write and condition.test. write the value they return into console (along with the method name). run the game and look into the console.
December 22, 20213 yr Quote [14:39:47] [Render thread/INFO]: Reloading ResourceManager: Default, , main Serializer Read mod_check("mbs") Condition Test true [14:40:11] [Render thread/INFO]: Loaded 7 recipes Here is the specific info you requested. I only included these lines Edited December 22, 20213 yr by DX12 Updated Information, Provided More Details
December 22, 20213 yr Quote Here is the specific info you requested. that output was for you, not us. i wanted you to assert two things: 1) serializer creates a condition with value true when config file says true 2) serializer creates a condition with value false when config file says false (after you exit the game, change config, start the game) can you confirm that you have that?
January 11, 20223 yr On 12/22/2021 at 10:57 PM, MFMods said: that output was for you, not us. i wanted you to assert two things: 1) serializer creates a condition with value true when config file says true 2) serializer creates a condition with value false when config file says false (after you exit the game, change config, start the game) can you confirm that you have that? Apologies for the late response, My computer had malfunctioned. To answer your question yes I do get the false and true when test is ran. however the issue im having is regardless of the value the recipe doesnt register. Also I have created A new topic to discuss this further. Here is the topic Topic Edited January 11, 20223 yr by DX12 Added Topic Link
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.