Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-264149

Armour trims can be inlined on item stacks

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Works As Intended
    • None
    • 1.20.1
    • None
    • Plausible
    • Items

      Armour trim materials and patterns can be inlined in the NBT for item stacks.

       

      Steps to reproduce:

      1. Open any world (ideally one without any data packs to showcase the bug better)
      2. Apply the resource pack present in this bug report: Armour Trims Bug Resource Pack.zip
      3. Give yourself the following item stack and wear it (I expanded it to make it easier to read)
        minecraft:leather_chestplate{
        	Trim: {
        		material: {
        			asset_name: "test",
        			description: {
        				text: "Test Material",
        				color: "#66B24C"
        			},
        			ingredient: "minecraft:air",
        			item_model_index: 0.15f
        		},
        		pattern: {
        			asset_id: "bug:test",
        			description: {
        				text: "Test Armour Trim"
        			},
        			template_item: "minecraft:air"
        		}
        	}
        }
      1. Notice how the armour trim is applied

      Code analysis

      In the TrimMaterial and TrimPattern records the CODEC field calls RegistryFileCodec::create(ResourceKey<? extends Registry<E>>, Codec<E>), which creates a new instance of RegistryFileCodec with allowInline set to true. See the copied bit for TrimMaterial.

      public record TrimMaterial(String assetName, Holder<Item> ingredient, float itemModelIndex, Map<ArmorMaterials, String> overrideArmorMaterials, Component description) {
          // ...
          public static final Codec<Holder<TrimMaterial>> CODEC = RegistryFileCodec.create(Registries.TRIM_MATERIAL, DIRECT_CODEC);
          // ...
      }
      

      This can be fixed by calling the method overload RegistryFileCodec::create(ResourceKey<? extends Registry<E>>, Codec<E>, boolean) instead, with the boolean set to false and thereby disallowing inline entries.

        1. Armour Trims Bug Resource Pack.zip
          6 kB
        2. command_result.png
          command_result.png
          97 kB
        3. inventory.png
          inventory.png
          11 kB
        4. smithing_table.png
          smithing_table.png
          4 kB
        5. world.png
          world.png
          165 kB

            Unassigned Unassigned
            ErrorCraft ErrorCraft
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: