Modular Machinery: Community Edition

Modular Machinery: Community Edition

252k Downloads

[Bug] Single upgrade modifier blocks allow substitution of all blocks of the original type in the machine pattern

jchung01 opened this issue ยท 2 comments

commented

If a modifier block is specified in the machine's JSON, as of 2.0.3, the base block that you can substitute the modifier block is not restricted to the specified position. In the example below, the brick block offset at (0, 0, 2) should be the only block that can be replaced by a gold block to apply the modifier. However, upon testing and as implied in JEI preview, the machine structure is still valid if ANY brick block is replaced by a gold block. If you were to test a recipe though, the modifier (duration decrease) only applies if the gold block is in the correct position.

In other words, all positions of the base block can be substituted for the modifier block for a valid structure, instead of just the specified position (unexpected), but the modifier only actually applies if the modifier block is in the specified position (expected).

Broken in 2.0.3, works as expected in 2.0.0-pre7. I suspect it was due to BlockArray changes in da00495.

Original machine, bricks in + pattern:
Image

Machine with modifier block, but the modifier block can replace any block in the + pattern, not just the center of the +.
(Note I have the modifier block highlighted, and only the specified position is highlighted, as expected)
Image

Test Machine JSON:

{
  "registryname": "test_machine",
  "localizedname": "Test Machine",
    "modifiers": [
        {
            "elements": "minecraft:gold_block",
            "x": 0,
            "y": 0,
            "z": 2,
            "modifier": {
                "io": "input",
                "target": "modularmachinery:duration",
                "operation": 1,
                "multiplier": 0.2
            }
        }
    ],
    "parts": [
        {
            "x": 1,
            "y": 0,
            "z": 0,
     
            "elements": [
                "modularmachinery:blockinputbus@0"
            ]
        },
        {
            "x": -1,
            "y": 0,
            "z": 1,
            "elements": [
                "minecraft:stonebrick@0"
            ]
        },
        {
            "x": 0,
            "y": 0,
            "z": 1,
            "elements": [
                "minecraft:brick_block@0"
            ]
        },
        {
            "x": 1,
            "y": 0,
            "z": 1,
            "elements": [
                "minecraft:stonebrick@0"
            ]
        },
        {
            "x": -1,
            "y": 0,
            "z": 3,
            "elements": [
                "minecraft:stonebrick@0"
            ]
        },
        {
            "x": 0,
            "y": 0,
            "z": 3,
            "elements": [
                "minecraft:brick_block@0"
            ]
        },
        {
            "x": 1,
            "y": 0,
            "z": 3,
            "elements": [
                "minecraft:stonebrick@0"
            ]
        },
        {
            "x": -1,
            "y": 0,
            "z": 2,
            "elements": [
                "minecraft:brick_block@0"
            ]
        },
        {
            "x": 0,
            "y": 0,
            "z": 2,
            "elements": [
                "minecraft:brick_block@0"
            ]
        },
        {
            "x": 1,
            "y": 0,
            "z": 2,
            "elements": [
                "minecraft:brick_block@0"
            ]
        },
        {
            "x": -1,
            "y": 0,
            "z": 0,
            "elements": [
                "modularmachinery:blockoutputbus@0"
            ]
        }
    ]}
commented

This issue is present in 2.1.4 as well, if it helps at all

commented

I found the issue and it has to do with BlockInformation#canonicalize() introduced since 2.0.3.
Because block info is now deduplicated, BlockArray's pattern shares references to the same BlockInformation for different block positions. This means when the JEI preview is rendered, in WorldSceneRendererWidget#addUpgradeIngredientToPattern() here, the modifier block will be added as a valid blockstate to the shared BlockInformation. This means all positions with the replaceable block will allow the modifier.
A similar issue will occur if you try using the blueprint's place preview due to the code here.