Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Crafting recipes enable/disable with config file [1.16]


Razor
 Share

Recommended Posts

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 :D

 

 

Link to comment
Share on other sites

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!

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.