[JAVA] How to reduce JsonModel of Item by using Forge expression BlockState

Overview

For example, to add an Item with metadata, you needed as many json files as the number of metadata (4 this time), but how to do it with 2 (reuse the same Model)

environment

Minecraft-1.10.2 Minecraft-1.11.2 Minecraft-1.12.2

(* I haven't tried it, maybe other versions are possible)

JSON file to add

(Hereafter, modid is the ID of the mod that adds the item)

First, create the following JSON file in assets / modid / models / ** block ** / ** At this time, make sure to add it to the Model position of the block instead of the item **

item_generated.json


{
  "parent": "item/generated"
}
This is an item that is displayed like a normal plate, and if you want to have tools etc. properly, change ** generated ** to ** handheld **.
For other models (including self-made ones), you can use them by placing them under assets / modid / models / ** block ** and specifying the Model.

Next, create the following JSON file in assets / modid / blockstates / (Add as many metas to add to variants)

sample_item.json


{
  "forge_marker": 1,
  "defaults": {
    "model": "modid:item_generated",
    "transform": "forge:default-item",
    "uvlock": true
  },
  "variants": {
    "meta0": [{
      "textures": {
        "layer0": "modid:items/sample_item_0"
      }
    }],
    "meta1": [{
      "textures": {
        "layer0": "modid:items/sample_item_1"
      }
    }],
    "meta2": [{
      "textures": {
        "layer0": "modid:items/sample_item_2"
      }
    }],
    "meta3": [{
      "textures": {
        "layer0": "modid:items/sample_item_3"
      }
    }]
  }
}
Texture specifications are displayed on top of each other as the number goes up, such as layer0 and layer1 (it is unknown how many sheets can be used).

Model registration (kotlin)

Next is the registration of the Model added earlier.

ClientProxy.kt


for (i in 0 until 4) {
    ModelLoader.setCustomModelResourceLocation(sampleItem, i,
            ModelResourceLocation(ResourceLocation(modid, "sample_item"), "meta$i"))
}

The same is true for java

ClientProxy.java


for (int i = 0; i < 4; i++) {
    ModelLoader.setCustomModelResourceLocation(sampleItem, i,
            new ModelResourceLocation(new ResourceLocation(modid, "sample_item"), "meta" + i));
}

Finally

Perhaps if you play with the second argument of ModelResourceLocation, just like Block,

sample_item.json


{
  "forge_marker": 1,
  "defaults": {
    "model": "modid:item_generated",
    "transform": "forge:default-item",
    "uvlock": true
  },
  "variants": {
    "meta": {
      "0":{   },
      "1":{   },
      "2":{   },
      "3":{   }
  }
}

I think it can be shaped like this ~~ But I stopped it because it's annoying ~~.

Recommended Posts