Jump to content

[1.8] Attempted Ore Generation Throwing Error


SPECIALPANCAKE6

Recommended Posts

Hi, I'm trying to get an ore to generate in the world. When I run Minecraft with my mod, it throws a "java.lang.NullPointerException" error when initializing. The error is in my world gen code at this line:

 		this.genCopperOre = new WorldGenMinable(ModBlocks.copperOre.getDefaultState(), 3 + random.nextInt(4));

 

This is the important part that the console kicks out:

 

 [17:24:08] [Client thread/ERROR] [FML]: Caught exception from compuchests
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_60]
at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_60]
at net.minecraftforge.fml.common.FMLModContainer.constructMod(FMLModContainer.java:445) ~[forgeSrc-1.8-11.14.3.1450.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) ~[forgeSrc-1.8-11.14.3.1450.jar:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190) ~[forgeSrc-1.8-11.14.3.1450.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:507) [Loader.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:213) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:446) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:356) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
Caused by: java.lang.NullPointerException
at com.github.specialpancake6.compuChests.generation.CompuChestsWorldGen.<init>(CompuChestsWorldGen.java:29) ~[CompuChestsWorldGen.class:?]
at com.github.specialpancake6.compuChests.CompuChests.<init>(CompuChests.java:31) ~[CompuChests.class:?]
at com.github.specialpancake6.compuChests.CompuChests.<clinit>(CompuChests.java:34) ~[CompuChests.class:?]
... 37 more

 

 

This is my world gen code:

 

package com.github.specialpancake6.compuChests.generation;

import java.util.Random;

import com.github.specialpancake6.compuChests.CompuChests;
import com.github.specialpancake6.compuChests.init.ModBlocks;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockHelper;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;

public class CompuChestsWorldGen implements IWorldGenerator
{
private WorldGenerator genCopperOre;
private WorldGenerator genCopperOreN;
private WorldGenerator genCopperOreE;


public CompuChestsWorldGen()
{
	Random random = new Random();
		this.genCopperOre = new WorldGenMinable(ModBlocks.copperOre.getDefaultState(), 3 + random.nextInt(4));
	this.genCopperOreN = new WorldGenMinable(ModBlocks.copperOre.getDefaultState(), 3 + random.nextInt(, BlockHelper.forBlock(Blocks.netherrack));
	this.genCopperOreE = new WorldGenMinable(ModBlocks.copperOre.getDefaultState(), 3 + random.nextInt(, BlockHelper.forBlock(Blocks.end_stone)); 

}
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
	switch (world.provider.getDimensionId())
	{
    		case 0: //Overworld
    			generateSurface(world, random, chunkX * 16, chunkZ * 16);
    			break;
    		case -1: //Nether
    			generateNether(world, random, chunkX * 16, chunkZ * 16);
    			break;
    		case 1: //End
    			generateEnd(world, random, chunkX * 16, chunkZ * 16);
    			break;
	}
}

private void generateSurface(World world, Random random, int x, int z)
{
	addOreSpawn(this.genCopperOre, world, random, x, z, 16, 16, 3 + random.nextInt(4), 9, 16, 54);
}

private void generateNether(World world, Random random, int x, int z)
{
	addOreSpawn(this.genCopperOreN, world, random, x, z, 16, 16, 3 + random.nextInt(, 9, 0, 256);
}

private void generateEnd(World world, Random random, int x, int z)
{
	addOreSpawn(this.genCopperOreE, world, random, x, z, 16, 16, 3 + random.nextInt(, 9, 0, 256);
}

private void addOreSpawn(WorldGenerator generator, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY)
{
	if (minY < 0 || maxY > 256 || minY > maxY)
        throw new IllegalArgumentException("Illegal Height Arguments for WorldGenerator");

	for (int i = 0; i < chanceToSpawn; i++)
	{
		int posX = blockXPos + random.nextInt(maxX);
		int posY = minY + random.nextInt(maxY - minY);
		int posZ = blockZPos + random.nextInt(maxZ);
		generator.generate(world, random, new BlockPos(posX, posY, posZ));
	}
}

}

 

 

Here is the code for the block in ModBlocks:

 

package com.github.specialpancake6.compuChests.init;

import com.github.specialpancake6.compuChests.blocks.BasicBlock;
import com.github.specialpancake6.compuChests.help.Reference;
import com.github.specialpancake6.compuChests.help.RegisterHelper;

import net.minecraft.block.Block;
import net.minecraft.block.Block.SoundType;
import net.minecraft.block.material.Material;

public class ModBlocks
{	
public static Block copperOre;

public static void init()
    {
	RegisterHelper.registerBlock(copperOre = new BasicBlock("copperOre", Material.iron, 2.5F, 10.0F, Block.soundTypeStone, "pickaxe", 2), "copperOre");
    }
}

 

 

BasicBlock is a default constructor that I plan to use for all blocks in my mod. Here is its code:

 

package com.github.specialpancake6.compuChests.blocks;

import com.github.specialpancake6.compuChests.CompuChests;
import com.github.specialpancake6.compuChests.help.Reference;
import com.github.specialpancake6.compuChests.tabs.ModTabs;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class BasicBlock extends Block
{
public BasicBlock(String unlocalizedName, Material material, float hardness, float resistance, SoundType stepSound, String harvestTool, int harvestLevel)
    {
            super(material);
            this.setUnlocalizedName(unlocalizedName);
            int meta = 0;
            this.setCreativeTab(ModTabs.tabCompuChests);
  		  	this.setHardness(hardness);
  		  	this.setResistance(resistance);
  		  	this.setStepSound(stepSound);
  		  	this.setHarvestLevel(harvestTool, harvestLevel);
    }

public BasicBlock(String unlocalizedName, float hardness, float resistance)
{
        this(unlocalizedName, Material.rock, hardness, resistance, Block.soundTypeStone, "pickaxe", 1);
    }

    public BasicBlock(String unlocalizedName)
    {
        this(unlocalizedName, 2.0f, 10.0f);
    }
}

 

Link to comment
Share on other sites

I've changed a little code since I made thread, but still the problem occurs except with the ItemRenderer this time. Can you be a little bit more specific with the solution?

 

This is the default code I use to register stuff:

 

package com.github.specialpancake6.compuChests.help;

import com.github.specialpancake6.compuChests.generation.CompuChestsWorldGen;
import com.github.specialpancake6.compuChests.init.ModItems;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class RegisterHelper
{
public static void registerBlock(Block block, String name)
{
	GameRegistry.registerBlock(block, name);
}

public static void registerItem(Item item, String name)
{
	GameRegistry.registerItem(item, name);
}

public static void registerItemRenderer(Item item, String name)
{		
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getUnlocalizedName(), name));
}

public static void registerBlockRenderer(Block block, String name)
{
	Item item = Item.getItemFromBlock(block);	
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(block.getUnlocalizedName(), name));
}

public static void registerWorldGenerator(IWorldGenerator worldGen)
{
	GameRegistry.registerWorldGenerator(worldGen, 0);
}
}

 

 

I made this to resemble how I register Blocks and items:

 

package com.github.specialpancake6.compuChests.init;

import com.github.specialpancake6.compuChests.help.RegisterHelper;
import com.github.specialpancake6.compuChests.generation.CompuChestsWorldGen;

import net.minecraft.item.Item;
import net.minecraftforge.fml.common.IWorldGenerator;

public class ModWorldGen
{
public static IWorldGenerator CompuChestsWorldGen;

public static void init()
    {
	RegisterHelper.registerWorldGenerator(CompuChestsWorldGen = new CompuChestsWorldGen());
    }
}

 

 

The ModItems code:

 

package com.github.specialpancake6.compuChests.init;

import com.github.specialpancake6.compuChests.help.Reference;
import com.github.specialpancake6.compuChests.help.RegisterHelper;
import com.github.specialpancake6.compuChests.items.BasicItem;

import net.minecraft.item.Item;

public final class ModItems
{
public static Item copperIngot;

public static void init()
    {
	RegisterHelper.registerItem(copperIngot = new BasicItem("copperIngot"), "copperIngot");
	RegisterHelper.registerItemRenderer(ModItems.copperIngot, "copperOre");
    }
}

 

 

This is my main code:

 

package com.github.specialpancake6.compuChests;

import com.github.specialpancake6.compuChests.blocks.BasicBlock;
import com.github.specialpancake6.compuChests.crafting.ModRecipes;
import com.github.specialpancake6.compuChests.generation.CompuChestsWorldGen;
import com.github.specialpancake6.compuChests.help.Reference;
import com.github.specialpancake6.compuChests.help.RegisterHelper;
import com.github.specialpancake6.compuChests.init.ModBlocks;
import com.github.specialpancake6.compuChests.init.ModItems;
import com.github.specialpancake6.compuChests.items.BasicItem;
import com.github.specialpancake6.compuChests.proxies.CommonProxy;
import com.github.specialpancake6.compuChests.init.ModWorldGen;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
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;

@Mod(modid = Reference.MODID, version = Reference.VERSION)
public class CompuChests 
{	
    @Instance
    public static CompuChests instance = new CompuChests();

@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.SERVER_PROXY)
public static CommonProxy proxy;
    
    @Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
        this.proxy.preInit(event);
        ModItems.init();
	ModBlocks.init();
	ModWorldGen.init();
}

@EventHandler
    public void init(FMLInitializationEvent event)
    {
    	this.proxy.init(event);
    }

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event)
{
	this.proxy.postInit(event);
}
}

 

 

Thanks so much, and if you need anything else just let me know.

Link to comment
Share on other sites

What error log are you getting now? Is the error raised on the server? If so, that would be because everything about rendering is client-side only.

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

Sorry, I forgot to put the new error.

 

 

Time: 10/7/15 4:24 PM
Description: Initializing game

java.lang.NullPointerException: Initializing game
at com.github.specialpancake6.compuChests.help.RegisterHelper.registerItemRenderer(RegisterHelper.java:28)
at com.github.specialpancake6.compuChests.init.ModItems.init(ModItems.java:16)
at com.github.specialpancake6.compuChests.CompuChests.preInit(CompuChests.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:550)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:248)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:446)
at net.minecraft.client.Minecraft.run(Minecraft.java:356)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

 

Link to comment
Share on other sites

Thanks!

I fixed that, but now I've got another problem. I'm not sure if the two are related. When I have the block or item in my inventory, they don't have the texture I assigned. However, when I place the block it has the texture... any idea what this might be? Again, let me know if you need any additional code.

Link to comment
Share on other sites

Items, including items from blocks, must be "meshed" in your client proxy's init method. If you've done that and still see the "missing" texture, then you must carefully examine your item model json files for name mismatches. They can be tricky to spot; I lost hours over an errant underscore hiding within a json file. Case matters too, and one missing comma in a json file ruins the whole thing. Use a tool like JSON Lint to validate your json contents.

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

Not really sure what you mean by "meshed" but this is what I have with the same result.

 

Client Proxy:

 

package com.github.specialpancake6.compuChests.proxies;

import com.github.specialpancake6.compuChests.blocks.BasicBlock;
import com.github.specialpancake6.compuChests.help.RegisterHelper;
import com.github.specialpancake6.compuChests.init.ModBlocks;
import com.github.specialpancake6.compuChests.init.ModItems;
import com.github.specialpancake6.compuChests.init.ModWorldGen;
import com.github.specialpancake6.compuChests.items.BasicItem;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public class ClientProxy  extends CommonProxy
{
@Override
public void preInit(FMLPreInitializationEvent e) 
{
	RegisterHelper.registerItem(ModItems.copperIngot = new BasicItem("copperIngot"), "copperIngot");
	RegisterHelper.registerBlock(ModBlocks.copperOre = new BasicBlock("copperOre", Material.iron, 2.5F, 10.0F, Block.soundTypeStone, "pickaxe", 2), "copperOre");
    }

@Override
    public void init(FMLInitializationEvent e) 
    {
	ModItems.init();
	ModBlocks.init();
	ModWorldGen.init(); 
    }

@Override
public void postInit(FMLPostInitializationEvent e) 
    {

    }
}

 

 

I went to the JSON Lint thing and it said all of my JSON Files were valid. I'll go ahead and let you check them out, though.

 

assets.compuchests.blockstates.copperOre:

 

{
"variants": {
"normal": { "model": "compuchests:copperOre" }
}
}

 

 

asssets.compuchests.models.block.copperOre:

 

{
"parent": "block/cube_all",
"textures": {
	"all": "compuchests:blocks/copperOre"
}
}

 

 

assets.compuchests.models.item.copperIngot:

 

{
"parent": "builtin/generated",
"textures": {
	"layer0": "compuchests:items/copperIngot"
},
"display": {
	"thirdperson": {
		"rotation": [-90, 0, 0],
		"translation": [0, 1, -3],
		"scale": [0.55, 0.55, 0.55 ]
	},
	"firstperson": {
		"rotation": [0, -135, 25 ],
		"translation": [0, 4, 2 ],
		"scale": [1.7, 1.7, 1.7]
	}
}
}

 

 

assets.compuchests.models.item.copperIngot:

 

{
    "parent": "compuchests:block/copperOre",
    "textures": {
        "layer0": "compuchests:blocks/copperOre"
    },"display": {
    "thirdperson": {
        "rotation": [ 10, -45, 170 ],
        "translation": [ 0, 1.5, -2.75 ],
        "scale": [ 0.375, 0.375, 0.375 ]
        }
    }
}

 

 

And then I've got my textures in assets.compuchests.textures.blocks & .textures.items with the corresponding names copperOre.png and copperIngot.png.

 

Hopefully this info can help you help me even more than you already have.

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.

Announcements



×
×
  • Create New...

Important Information

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