Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Crash on constructor. Null Pointer on validateBlockstate


naturaGodhead
 Share

Recommended Posts

So I'm trying to have a boolean property that just does a simple "Glow at night" effect on this block. I've done something similar on a block in another mod, and as far as I can tell there's nothing different about them. Stopping at the super(material) in the debugger tells me the blockstate and default states are null, but why? Here's the relevant files. 

 

Lunarworks.java:

Spoiler

package com.rose.lunarworks;

import com.rose.lunarworks.blocks.ModBlocks;
import com.rose.lunarworks.blocks.TileEntityLunarCondenser;
import com.rose.lunarworks.fluids.ModFluids;
import com.rose.lunarworks.items.ModItems;
import com.rose.lunarworks.proxy.CommonProxy;

import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
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.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;

@Mod(modid = Lunarworks.MODID, name = Lunarworks.MODNAME, version = Lunarworks.VERSION, useMetadata = true)
public class Lunarworks {

	public static final String MODID = "lunarworks";
    public static final String MODNAME = "Lunarworks";
    public static final String VERSION = "0.0.1";
    
    @SidedProxy(clientSide = "com.rose.lunarworks.proxy.ClientProxy", serverSide = "com.rose.lunarworks.proxy.CommonProxy")
    public static CommonProxy proxy;

    @Mod.Instance(MODID)
    public static Lunarworks instance;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        proxy.preInit(event); 
    	MinecraftForge.EVENT_BUS.register(ModBlocks.class);
    	MinecraftForge.EVENT_BUS.register(ModItems.class);
    	GameRegistry.registerWorldGenerator(new WorldGenOres(), 3);
		GameRegistry.registerTileEntity(TileEntityLunarCondenser.class, Lunarworks.MODID + "_lunar_condenser");
		ModFluids.registerFluids();
    }

    @EventHandler
    public void init(FMLInitializationEvent e) {
        proxy.init(e);
    	SmeltingRecipes.init();
    	OreDictionary.registerOre("oreSilver", ModBlocks.silverOre);
    	OreDictionary.registerOre("ingotSilver", ModItems.silverIngot);
    	OreDictionary.registerOre("nuggetSilver", ModItems.silverNugget);
    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent e) {
        proxy.postInit(e);
    }
	
}

 

 

ModBlocks: 
 

Spoiler

package com.rose.lunarworks.blocks;

import com.rose.lunarworks.Lunarworks;
import com.rose.lunarworks.items.ModItems;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry;

public class ModBlocks {

	public static Block silverOre = new BlockSilverOre().setCreativeTab(ModItems.tabLunarworks);
	public static Block silverBlock = new Block(Material.IRON).setHardness(4.0F).setResistance(6.0F).setUnlocalizedName("silverBlock").setRegistryName("silver_block").setCreativeTab(ModItems.tabLunarworks);
	public static Block lunarCondenser = new BlockLunarCondenser().setCreativeTab(ModItems.tabLunarworks);
	public static Block lunarTank = new BlockLunarTank().setHardness(2.0F).setResistance(2.0F);
	
	//Register Blocks
	@SubscribeEvent
	public static void registerBlocks(RegistryEvent.Register<Block> event)
	{
		IForgeRegistry<Block> registry = event.getRegistry();
		
		registry.register(silverOre);
		registry.register(silverBlock);
		registry.register(lunarCondenser);
		registry.register(lunarTank);
	}
	
}

 

 

BlockSilverOre:
 

Spoiler

package com.rose.lunarworks.blocks;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockSilverOre extends Block {
		
		public static IProperty<Boolean> isGlowing = PropertyBool.create("isGlowing");

		public BlockSilverOre() {
			super(Material.ROCK);
			this.setDefaultState(this.getDefaultState().withProperty(isGlowing, false));
			this.setUnlocalizedName("silverOre");
			this.setRegistryName("silver_ore");
			setHardness(3f);
			setResistance(5f);
			this.setTickRandomly(true);
			this.setHarvestLevel("pickaxe", 2);
		}
		
		@Override
	    protected BlockStateContainer createBlockState()
	    {
	        return new BlockStateContainer(this, new IProperty[] {isGlowing});
	    }
		
		@Override
		public BlockStateContainer getBlockState() {
		// TODO Auto-generated method stub
			return new BlockStateContainer(this, new IProperty[] {isGlowing});
		}
		
		@Override
		public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random) {
		// TODO Auto-generated method stub
			if(worldIn.isDaytime()) {
				worldIn.setBlockState(pos, state.withProperty(isGlowing, false));
			}
			
			else if(!worldIn.isDaytime()) {
				worldIn.setBlockState(pos, state.withProperty(isGlowing, true));
			}
		}
		
		
		@SideOnly(Side.CLIENT)
		@Override
		public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
		// TODO Auto-generated method stub
			if(stateIn.getValue(isGlowing)) {
				this.setLightLevel(8.0F);
			}
			
			else if(!stateIn.getValue(isGlowing)) {
				this.setLightLevel(0F);
			}
		}
		
		@Override
		public IBlockState getStateFromMeta(int meta)
	    {
			if(meta < 0) {
				meta = 0;
			}
			
			if(meta > 1) {
				meta = 1;
			}
			if(meta == 0) {
				return this.blockState.getBaseState().withProperty(isGlowing, false);
			}
			else {
				return this.blockState.getBaseState().withProperty(isGlowing, true);
			}
	    }
		
		@Override
	    public int getMetaFromState(IBlockState state)
	    {
			if(!state.getValue(isGlowing))
				return 0;
			
			else return 1;
	    }
}

 

Crash Report:

Spoiler

---- Minecraft Crash Report ----
// You're mean.

Time: 1/18/18 3:31 PM
Description: Initializing game

java.lang.ExceptionInInitializerError
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_11_ModBlocks_registerBlocks_Register.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:143)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
    at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:736)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:603)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:270)
    at net.minecraft.client.Minecraft.init(Minecraft.java:513)
    at net.minecraft.client.Minecraft.run(Minecraft.java:421)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:26)
Caused by: java.lang.NullPointerException
    at net.minecraft.block.state.BlockStateContainer.validateProperty(BlockStateContainer.java:103)
    at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:77)
    at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:62)
    at com.rose.lunarworks.blocks.BlockSilverOre.createBlockState(BlockSilverOre.java:34)
    at net.minecraft.block.Block.<init>(Block.java:290)
    at net.minecraft.block.Block.<init>(Block.java:299)
    at com.rose.lunarworks.blocks.BlockSilverOre.<init>(BlockSilverOre.java:21)
    at com.rose.lunarworks.blocks.ModBlocks.<clinit>(ModBlocks.java:15)
    ... 22 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_11_ModBlocks_registerBlocks_Register.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:143)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
    at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:736)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:603)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:270)
    at net.minecraft.client.Minecraft.init(Minecraft.java:513)

-- Initialization --
Details:
Stacktrace:
    at net.minecraft.client.Minecraft.run(Minecraft.java:421)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:26)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_121, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 665606408 bytes (634 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
    FML: MCP 9.42 Powered by Forge 14.23.1.2589 5 mods loaded, 5 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State | ID         | Version      | Source                           | Signature |
    |:----- |:---------- |:------------ |:-------------------------------- |:--------- |
    | UCH   | minecraft  | 1.12.2       | minecraft.jar                    | None      |
    | UCH   | mcp        | 9.42         | minecraft.jar                    | None      |
    | UCH   | FML        | 8.0.99.99    | forgeSrc-1.12.2-14.23.1.2589.jar | None      |
    | UCH   | forge      | 14.23.1.2589 | forgeSrc-1.12.2-14.23.1.2589.jar | None      |
    | UCH   | lunarworks | 0.0.1        | bin                              | None      |

    Loaded coremods (and transformers): 
    GL info: ' Vendor: 'Intel' Version: '4.0.0 - Build 10.18.10.4358' Renderer: 'Intel(R) HD Graphics 4000'
    Launched Version: 1.12.2
    LWJGL: 2.9.4
    OpenGL: Intel(R) HD Graphics 4000 GL version 4.0.0 - Build 10.18.10.4358, Intel
    GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

    Using VBOs: Yes
    Is Modded: Definitely; Client brand changed to 'fml,forge'
    Type: Client (map_client.txt)
    Resource Packs: 
    Current Language: English (US)
    Profiler Position: N/A (disabled)
    CPU: 4x Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz

 

 

Just a little insight would be helpful because I'm missing something obvious.

Link to comment
Share on other sites

You can't set the default state to the default state: there is no default state yet. You want getBaseState()

Edited by Draco18s

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.