3. Custom Machines: Variables - HellFirePvP/ModularMachinery GitHub Wiki

As shown at the end of the previous page of the wiki, machine definitions can be extremly long and especially when a lot of blockstates are potentially allowed for a specific position, it can get messy and contain a lot of cuplicates since most parts then only differ at their position, not at the blockstates that are allowed.

Variables help adress this at least a little bit. So instead of having to write all blockstates and copy and paste that over and over again in the final machine definition, you can define a variable that's equivalent to that specific set of blockstates and use the variable instead.

Variables need to be defined in their own file(s). You can have multiple variable json files, defining 2 variables with the same names (even when in different files) will then cause one to overwrite the other - the order is not defined and may vary, so define your variables with a unique name. Variable files have to end with .var.json instead of just .json. They have to be in the same folder as the machine jsons and are loaded before any of the machines are.

Example of a variable: The centrifuge 'casings' on the bottom layer of the example of the previous page:

{
    "x": 1,
    "y": -1,
    "z": 2,
    "elements": [
        "modularmachinery:blockcasing",
        "modularmachinery:blockinputitem",
        "modularmachinery:blockinputenergy",
        "modularmachinery:blockoutputitem",
        "modularmachinery:blockoutputfluid"
    ]
}

A variable file (let's call it "variables.var.json") would look like this:

{
    "iron_centrifuge_casing": [
        "modularmachinery:blockcasing",
        "modularmachinery:blockinputitem",
        "modularmachinery:blockinputenergy",
        "modularmachinery:blockoutputitem",
        "modularmachinery:blockoutputfluid"
    ]
}

You can of course define multiple variables in the same variable-json file just by separating them with a comma. Variables cannot contain other variables in their list of applicable blockstates.

You can after defining this variable use it to make your machine jsons smaller:

{
    "x": 1,
    "y": -1,
    "z": 2,
    "elements": "iron_centrifuge_casing"
}