Siphalor / nbt-crafting

A 1.15+ fabric Minecraft mod to enable nbt related recipe stuff
https://modrinth.com/mod/nbt-crafting
Apache License 2.0
49 stars 26 forks source link

Damage to remainder items is sometimes applied incorrectly #93

Closed SlayeRRROAR closed 2 years ago

SlayeRRROAR commented 2 years ago

Version Minecraft 1.18.1 nbtcrafting-2.1.1+mc1.18.1

Describe the bug I was trying to create some crafting recipes for enchanted books using a custom item with durability so that it would lose 1 durability per craft. Original Recipe:

{
  "type": "minecraft:crafting_shaped",
  "pattern": [
    " A ",
    "BCB",
    " D "
  ],
  "key": {
    "A": {
      "item": "reborn12k:magical_ink",
      "remainder": {
        "item": "reborn12k:magical_ink",
        "data": {
          "Damage": "$ i0.Damage + 1"
        }
      }
    },
    "B": {
      "item": "minecraft:lapis_lazuli"
    },
    "C": {
      "item": "minecraft:wooden_sword"
    },
    "D": {
      "item": "minecraft:book"
    }
  },
  "result": {
    "item": "minecraft:enchanted_book",
      "data": {
        "Enchantments": [
          {
            "id": "minecraft:sharpness",
            "lvl": 1
          }
        ]
      },
      "count": 1
    }
}

When using this recipe the remainder item would always be set to 63 out of 64 durability, which made me wonder if I wrote something wrong. So I tested by literally copying the example on the wiki (wooden sword to sticks) and changed the wooden sword to my item, and it worked correctly. This led me to make some testing.

Recipe 1:

{
  "type": "minecraft:crafting_shaped",
  "pattern": [
    "A",
    "B"
  ],
  "key": {
    "A": {
      "item": "reborn12k:magical_ink",
      "remainder": {
        "item": "reborn12k:magical_ink",
        "data": {
          "Damage": "$ i0.Damage + 1"
        }
      }
    },
    "B": {
      "item": "minecraft:wooden_sword"
    }
  },
  "result": {
    "item": "minecraft:enchanted_book",
    "data": {
      "Enchantments": [
        {
          "id": "minecraft:sharpness",
          "lvl": 1
        }
      ]
    },
    "count": 1
  }
}

This recipe worked correctly, damaging the ink by 1 per craft.

Recipe 2:

{
  "type": "minecraft:crafting_shaped",
  "pattern": [
    "A  ",
    "B C"
  ],
  "key": {
    "A": {
      "item": "reborn12k:magical_ink",
      "remainder": {
        "item": "reborn12k:magical_ink",
        "data": {
          "Damage": "$ i0.Damage + 1"
        }
      }
    },
    "B": {
      "item": "minecraft:wooden_sword"
    },
    "C": {
      "item": "minecraft:lapis_lazuli"
    }
  },
  "result": {
    "item": "minecraft:enchanted_book",
    "data": {
      "Enchantments": [
        {
          "id": "minecraft:sharpness",
          "lvl": 1
        }
      ]
    },
    "count": 1
  }
}

This recipe also worked correcly.

Recipe 3:

{
  "type": "minecraft:crafting_shaped",
  "pattern": [
    " A ",
    "BCB"
  ],
  "key": {
    "A": {
      "item": "reborn12k:magical_ink",
      "remainder": {
        "item": "reborn12k:magical_ink",
        "data": {
          "Damage": "$ i0.Damage + 1"
        }
      }
    },
    "B": {
      "item": "minecraft:lapis_lazuli"
    },
    "C": {
      "item": "minecraft:wooden_sword"
    }
  },
  "result": {
    "item": "minecraft:enchanted_book",
    "data": {
      "Enchantments": [
        {
          "id": "minecraft:sharpness",
          "lvl": 1
        }
      ]
    },
    "count": 1
  }
}

This recipe didn't work in the same way as the original, it crafted the item and damaged the ink, but subsequent crafts didn't damage the item further. Damaging the item with commands and using it for crafting would set it to 63 out of 64 durability.

Recipe 4:

{
  "type": "minecraft:crafting_shaped",
  "pattern": [
    " A ",
    "B C",
    " D "
  ],
  "key": {
    "A": {
      "item": "reborn12k:magical_ink",
      "remainder": {
        "item": "reborn12k:magical_ink",
        "data": {
          "Damage": "$ i0.Damage + 1"
        }
      }
    },
    "B": {
      "item": "minecraft:wooden_sword"
    },
    "C": {
      "item": "minecraft:lapis_lazuli"
    },
    "D": {
      "item": "minecraft:book"
    }
  },
  "result": {
    "item": "minecraft:enchanted_book",
    "data": {
      "Enchantments": [
        {
          "id": "minecraft:sharpness",
          "lvl": 1
        }
      ]
    },
    "count": 1
  }
}

Same as the last one, the craft happens, but the remainder item is set to 63 out of 64 durability.

I have no idea why it does that, I tought it might be because in recipe 3 lapis is used twice (BCB), but that doesn't explain why recipe 4 doesn't work when recipe 2 does. I also tried different items (both custom and mincraft items) with the same results.

Expected behavior The item that gets remainded with damage should get damaged based on its current durability, not on its total durability

Siphalor commented 2 years ago

Well, this is caused by one of the more unintuitive twists of this mod ^^

In shaped crafting recipes the dollar references refer to the position in the crafting grid. This means that i0 always refers to the item/ingredient in the top left slot. This behavior is explained here in the wiki.

Adjusting your references should resolve the issue.

I still want to thank you for the detailed bug report, that really helped a lot in finding out what was going on :)