Elmartino4 / mechanical-factory

A Minecraft Fabric mod that adds factory style mechanisms which can run server side
MIT License
6 stars 2 forks source link

Configurable recipes #5

Closed daemonspring closed 2 years ago

daemonspring commented 3 years ago

Loading recipes from a config file would be ideal for a mod like this.

This is an excellent base for tweaking the resource economy of the game without breaking the vanilla feel.

Elmartino4 commented 3 years ago

I've looked into using an extension of Minecraft's RecipeSerializer but this seems to be fairly specific to using a GUI. If I do implement this (most likely using json in the config folder), would you recommend doing this through a single, or many files (one per recipe)?

And how would I implement the possibility to extend this with other mods?

Also, How would I refer to blocks and items in a string format?

daemonspring commented 3 years ago

would you recommend doing this through a single, or many files (one per recipe)?

I recommend having a config/mechanical-factory/recipes folder and reading every json file in that folder. That makes it easy for people to split the configuration in whatever way is convenient. You can also generate a default.json file for your normal configuration. Something like this:

{
  "anvil":[
    {
      "ingredients": ["minecraft:stone", "minecraft:sand"],
      "products": ["minecraft:diorite"],
      "reversible": true, // Saves having to list a reversed recipe.
      "order_matters": false // Maybe order doesn't matter at all for some recipes? Makes reversible redundant.
    }
  ],
  "seive":[
    {
      "input":"minecraft:dirt",
      "delay":10,
      "outputs":[
        { "id":"minecraft:wheat_seeds",    "weight":6, "min":2, "max":3 },
        { "id":"minecraft:beetroot_seeds", "weight":5, "min":2, "max":3 },
        { "id":"minecraft:melon_seeds",    "weight":4, "min":1, "max":3 },
        { "id":"minecraft:pumpkin_seeds",  "weight":4, "min":1, "max":3 },
        { "id":"minecraft:potato",         "weight":5, "min":1, "max":2 },
        { "id":"minecraft:carrot",         "weight":5, "min":1, "max":2 },
        { "id":"minecraft:bone_meal",      "weight":7, "min":2, "max":4 }
      ]
    }
  ],
  "generator":[
    {
      "primary_fluid":{ "id":"minecraft:water", "flowing":true },
      "secondary_block":"minecraft:blue_ice",
      "output":"minecraft:end_stone"
    },
    {
      "primary_fluid":{ "id":"minecraft:water", "flowing":false },
      "secondary_block":"minecraft:blue_ice",
      "output":"minecraft:end_stone"
    },
    {
      "primary_fluid":{ "id":"minecraft:water", "flowing":true },
      "secondary_fluid":{ "id":"minecraft:lava", "flowing":true },
      "underneath_block":"minecraft:purpur_block",
      "output":"minecraft:end_stone"
    },
    {
      "primary_fluid":{ "id":"minecraft:water", "flowing":false },
      "secondary_fluid":{ "id":"minecraft:lava", "flowing":true },
      "underneath_block":"minecraft:purpur_block",
      "output":"minecraft:end_stone"
    }
  ],
  "weathering":[
    {
      "input":"minecraft:cobblestone",
      "output":"minecraft:mossy_cobblestone",
      "fluid":{ "id":"minecraft:water", "flowing": false },
      "probability":0.7
    },
    {
      "input":"minecraft:cobblestone",
      "output":"minecraft:mossy_cobblestone",
      "fluid": { "id":"minecraft:water", "flowing": true },
      "probability":0.3
    }
  ]
}

Also, How would I refer to blocks and items in a string format?

Use namespaced identifiers: e.g. minecraft:dirt, just like you'd use in in-game commands. I'm not familiar with the Minecraft source, but I think net.minecraft.util.registry.Registry and net.minecraft.util.Identifier can be used to get blocks and items from their names. e.g. Registry.BLOCK.get(Identifier("minecraft:dirt")).

And how would I implement the possibility to extend this with other mods?

You get this for free by using namespaced identifiers in your recipes. It should be possible for someone to then write a config to add recipes relevant to the mods they have loaded. For example:

{
  "anvil":[
    {
      "ingredients": ["minecraft:blue_ice", "minecraft:blue_ice", "minecraft:blue_ice"],
      "products": ["coolmod:super_ice"]
    }
  ]
}
Elmartino4 commented 2 years ago

I have began implementing this through the use of datapacks in the 1.18-datadriven branch

Elmartino4 commented 2 years ago

Some interesting and useful features have been shown in your sample JSON text, I will implement these after an initial version is complete and functional

Elmartino4 commented 2 years ago

1.18-datadriven has been merged to the 1.18 branch. This includes the bare-bones of a datapack based data-driven recipe system as described in the README.md An alpha jar will be uploaded to modrinth for this update. Blocktags, anvil combination mixing, command execution and more will be coming soon