harlekintiger
harlekintiger

Reputation: 417

How to fix "loading model for blockstate variant '#normal' exception" in minecraft forge?

After succesfully making an item have a texture, for the last hours I am struggling to make the texture loading work for blocks (Interpreting my error message, it's the model loading I struggle with)

I followed cubicoders tutorial ( https://cubicoder.wordpress.com/2018/06/20/basic-block/ ) for the progress so far. Because his solution for creating blocks threw an error, I checked back with other tutorials. While my error log insists the problem lies within the model loading (spezifically the variant loading of the variant #normal), this part is the exact same as in every tutorial I could find.
What else could be the trigger for such an exception?

My complete project code can be found here: https://github.com/harlekintiger/modding
It's really just the basic setup, one item and this broken block.


The most important parts are the following:

"basic_block.json" located in "resources/assets/MODID/blockstate":

{
   "forge_marker": 1,
   "defaults": {
      "model": "firstforgemod:basic_block"
   },
      "variants": {
         "normal": [{}],
         "inventory": [{}]
   }
}

"basic_block.json" located in "resources/assets/MODID/models/block":

{
   "parent": "block/cube_all",
   "textures": {
      "all": "firstforgemod:blocks/basic_block"
   }
}

Class of the actual block:

public class BlockBasic extends Block{

    public BlockBasic(Material material, String unlocalizedName, String registryName){
        this(material, SoundType.STONE, unlocalizedName, registryName);
    }

    public BlockBasic(Material material, SoundType sound, String unlocalizedName, String registryName){
        super(material);
        setUnlocalizedName(FirstForgeMod.MODID + "." + unlocalizedName);
        setRegistryName(registryName);
        setCreativeTab(FirstForgeMod.TUTORIAL_TAB);
        setSoundType(sound);
    }
}

Class to collect the blocks:

@ObjectHolder(FirstForgeMod.MODID)
public class TutorialBlocks {

    public static final Block BASIC_BLOCK = null;
}

ModelRegistryHandler class: (my guess is there is something missing in here)

@EventBusSubscriber(Side.CLIENT)
public class ModelRegistryHandler {

    @SubscribeEvent
    public static void registerModels(ModelRegistryEvent event){
        registerModel(TutorialItems.BASIC_ITEM);
        registerModel(Item.getItemFromBlock(TutorialBlocks.BASIC_BLOCK));
    }

    private static void registerModel(Item item) {
        ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
    }
}

RegistryHandler class:

@EventBusSubscriber
public class RegistryHandler {

    @SubscribeEvent
    public static void registerBlocks(Register<Block> event){
        final Block[] blocks ={
            new BlockBasic(Material.ROCK, "blockBasic", "basic_block")
        };

        event.getRegistry().registerAll(blocks);
    }

    @SubscribeEvent
    public  static  void registerItems(Register<Item> event){
        final Item[] items = {
                new ItemBasic("itemBasic", "basic_item")
        };

        final Item[] itemBlocks = {
                new ItemBlock(TutorialBlocks.BASIC_BLOCK).setRegistryName(TutorialBlocks.BASIC_BLOCK.getRegistryName())
        };

        event.getRegistry().registerAll(items);
        event.getRegistry().registerAll(itemBlocks);
    }
}

Log file of minecraft starting (with the error message) and closing:
https://pastebin.com/Ff7NuFSk


What I am getting: The game starts and in-game the block can be placed, but is completely untextured (missing textures texutre) in both the world and the inventory.

Upvotes: 0

Views: 3123

Answers (1)

Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 14 column 2 path $

There's your underlying error.

https://github.com/harlekintiger/modding/blob/master/src/main/resources/assets/firstforgemod/blockstates/basic_block.json#L14

JSON is a data format, it doesn't allow comments (of any type) anywhere in the file.

Upvotes: 1

Related Questions