Jump to content

New at modding, need help with nullPointerException


Buudeluu

Recommended Posts

Trying to start off with modding. Can't figure out how to solve this error.

 

Full crash log attached.

My code:

 

Spoiler

 

package Blocks;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.registries.IForgeRegistry;

public class ModBlocks {

    public static BlockOre oreCopper = new BlockOre("ore_copper").setCreativeTab(CreativeTabs.MATERIALS);

    public static void register(IForgeRegistry<Block> registry)
    {
        registry.registerAll
        (
                oreCopper
        );
    }
    
    public static void registerItemBlocks(IForgeRegistry<Item> registry)
    {
        registry.registerAll
        (
                oreCopper.createItemBlock()
        );
    }
    
    public static void registerItemModels()
    {
        oreCopper.registerItemModel(Item.getItemFromBlock(oreCopper));
    }

}

 

 

Thanks in advance!

 

crash-2017-08-03_16.21.21-client.txt

Edited by Buudeluu
Link to comment
Share on other sites

Am I not doing this here?

 

Spoiler

 

package Blocks;

import buudeluu.quantumfarming.QuantumFarming;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;

public class BlockBase extends Block
{
  // ...
    public Item createItemBlock()
    {
        return new ItemBlock(this);
    }

//...
}

 


 

 

Link to comment
Share on other sites

Right, I think this is where I'm setting it. Java gives me some headaches. :D


 

Spoiler

 

package buudeluu.quantumfarming;

import Blocks.ModBlocks;
import Items.ModItems;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import proxy.CommonProxy;

@Mod(modid = QuantumFarming.modId, name = QuantumFarming.name, version = QuantumFarming.version)

public class QuantumFarming
{
//...
    @Mod.EventBusSubscriber
    public static class RegistrationHandler
    {
        @SubscribeEvent
        public static void registerBlocks(RegistryEvent.Register<Block> event)
        {
            ModBlocks.register(event.getRegistry());
        }
        
        @SubscribeEvent
        public static void registerItems(RegistryEvent.Register<Item> event)
        {
            ModItems.register(event.getRegistry());
            ModBlocks.registerItemBlocks(event.getRegistry());
        }
        
        @SubscribeEvent
        public static void registerModels(ModelRegistryEvent event)
        {
            ModItems.registerItemModels();
            ModBlocks.registerItemModels();
        }
    }
}

 

 

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

6 hours ago, Buudeluu said:

I'm new at java

Admitting that here is just begging to get your thread locked (see Draco's signature). Go find yourself some Java resources and lean on them until nobody here can detect a lack of Java awareness in your work or questions. Do the same for Eclipse if that's new too.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

If you are still lost, maybe this method will be a bit more helpfull. Take all your blocks, put them in a list. When registering itemblocks, take that list and by using for put "setRegistryName()" on the end.

This is how it should look like. I hope really this helps ;-)

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");
    
    @SubscribeEvent
    public static void registerBlocks(RegistryEvent.Register<Block> event){
        BLOCKS.add(test_block);

        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()));
        }
    }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.