I am updating my mod to 1.12(registry), until i hit a wall when my game crashed with:
java.lang.NullPointerException: Can't use a null-name for the registry, object net.minecraft.item.ItemBlock@73ae7ce4.
While debugging i also found that the ArrayList was filled but with null blocks.
I did the same thing for items and that's working fine.
Thanks in advance.
(full crash log)
My code:
@Mod.EventBusSubscriber(modid = Ref.MODID)
public class BlockHandler {
public static List<Block> BLOCKS = new ArrayList<Block>();
public static Block test_block = new BlockTestBlock(Material.ROCK, "test_block", CreativeTabHandler.tabMW, 5f, 15f, 3, "pickaxe");
public static Block shard_ore_orange = new BlockShardOre(Material.ROCK, "shard_ore_orange", CreativeTabHandler.tabMW, 4f, 10f, 2,"pickaxe", ItemHandler.orangeShard, "orange");
public static Block shard_ore_green = new BlockShardOre(Material.WOOD, "shard_ore_green", CreativeTabHandler.tabMW, 4f, 10f, 2, "axe", ItemHandler.greenShard, "green");
public static Block shard_ore_white = new BlockShardOre(Material.ROCK, "shard_ore_white", CreativeTabHandler.tabMW, 4f, 10f, 2, "pickaxe" ,ItemHandler.whiteShard, "white");
public static Block shard_ore_purple = new BlockShardOre(Material.ROCK, "shard_ore_purple", CreativeTabHandler.tabMW, 4f, 10f, 2, "pickaxe" , ItemHandler.purpleShard, "purple");
public static Block trinket_maker = new BlockTrinketMaker(Material.WOOD, "trinket_maker", CreativeTabHandler.tabMW, 4f, 10f, 3,"axe", true);
//TODO Fix this, error: nullpointer exeption. added blocks are null.
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event){
BLOCKS.add(test_block);
BLOCKS.add(shard_ore_green);
BLOCKS.add(shard_ore_orange);
BLOCKS.add(shard_ore_purple);
BLOCKS.add(shard_ore_white);
BLOCKS.add(trinket_maker);
for(Block block : BLOCKS){
event.getRegistry().register(block);
}
}
@SubscribeEvent
public static void registerItemBlocks(RegistryEvent.Register<Item> event){
for(Block block : BLOCKS){
ItemBlock itemBlock = new ItemBlock(block);
event.getRegistry().register(itemBlock);
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void registerModels(ModelRegistryEvent event){
for(Block block: BLOCKS){
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));
}
}
}
(edit) Solution:
Registry name wasn't set, code:
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event){
BLOCKS.add(test_block);
BLOCKS.add(shard_ore_green);
BLOCKS.add(shard_ore_orange);
BLOCKS.add(shard_ore_purple);
BLOCKS.add(shard_ore_white);
BLOCKS.add(trinket_maker);
for(Block block : BLOCKS){
event.getRegistry().register(block);
}
}
@SubscribeEvent
public static void registerItemBlocks(RegistryEvent.Register<Item> event){
for(Block block: BLOCKS){
event.getRegistry().register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
}
}