Jump to content

[1.12.2] java.lang.NullPointerException: Exception in server tick loop


LK1905

Recommended Posts

I've been having a problem testing my mod, where it freezes when it attempts to load terrain.

 

Crash report:

Spoiler

---- Minecraft Crash Report ----
// Shall we play a game?

Time: 3/18/18 2:25 PM
Description: Exception in server tick loop

java.lang.NullPointerException: Exception in server tick loop
    at com.lk1905.basicmod.worldgen.OreGen.generate(OreGen.java:27)
    at net.minecraftforge.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:167)
    at net.minecraft.world.chunk.Chunk.populate(Chunk.java:1091)
    at net.minecraft.world.chunk.Chunk.populate(Chunk.java:1071)
    at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:169)
    at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:383)
    at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:143)
    at net.minecraft.server.integrated.IntegratedServer.init(IntegratedServer.java:160)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:550)
    at java.lang.Thread.run(Unknown Source)


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

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_161, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 196245672 bytes (187 MB) / 445120512 bytes (424 MB) up to 820510720 bytes (782 MB)
    JVM Flags: 0 total; 
    IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
    FML: MCP 9.42 Powered by Forge 14.23.1.2555 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 |
    |:------- |:--------- |:------------ |:-------------------------------- |:--------- |
    | UCHIJAA | minecraft | 1.12.2       | minecraft.jar                    | None      |
    | UCHIJAA | mcp       | 9.42         | minecraft.jar                    | None      |
    | UCHIJAA | FML       | 8.0.99.99    | forgeSrc-1.12.2-14.23.1.2555.jar | None      |
    | UCHIJAA | forge     | 14.23.1.2555 | forgeSrc-1.12.2-14.23.1.2555.jar | None      |
    | UCHIJAA | basicmod  | 1.0.0        | bin                              | None      |

    Loaded coremods (and transformers): 
    GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
    Profiler Position: N/A (disabled)
    Player Count: 0 / 8; []
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'fml,forge'

 

The report suggests there is a problem at line 27 in my OreGen.java class, which is this class (Line 27 is under Case 0):

Spoiler

package com.lk1905.basicmod.worldgen;

import java.util.Random;

import com.google.common.base.Predicate;
import com.lk1905.basicmod.blocks.ModBlocks;

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

public class OreGen implements IWorldGenerator{
	
	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
		
		switch(world.provider.getDimension()) {
			case -1:	//--The Nether--//
				break;
			case 0:		//--Overworld--//
				runGenerator(ModBlocks.copperOre.getDefaultState(), 8, 10, 0, 255, BlockMatcher.forBlock(Blocks.STONE),
							world, random, chunkX, chunkZ);
				break;
			case 1:		//--The End--//
				break;
			default:
				break;
		}
	}
	
	private void runGenerator(IBlockState blockToGen, int blockAmount, int chancesToSpawn, int minHeight, int maxHeight,
							Predicate<IBlockState> blockToReplace, World world, Random random, int chunkX, int chunkZ) {
		
		if (minHeight < 0 || maxHeight > 256 || minHeight > maxHeight)
			throw new IllegalArgumentException("Illegal Height Arguments for WorldGenerator");
		
		WorldGenMinable generator = new WorldGenMinable(blockToGen, blockAmount, blockToReplace);
		
		int heightdiff = maxHeight - minHeight + 1;
		
		for (int i = 0; i < chancesToSpawn; i++) {
			int x = chunkX * 16 + random.nextInt(16);
			int y = minHeight + random.nextInt(heightdiff);
			int z = chunkZ * 16 + random.nextInt(16);
			
			generator.generate(world, random, new BlockPos(x, y, z));
		}
	}
}

 

 

I can't actually see any problems with any of the code in this class, so the only thing I can think of is I've initialized/registered something wrong, although I can't see anything wrong in any of those classes either, but I'll post the classes I think are relevant under here anyway.

 

My Main class:

Spoiler

package com.lk1905.basicmod;

import com.lk1905.basicmod.custommaterials.CustomToolMaterials;
import com.lk1905.basicmod.worldgen.OreGen;

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 = Main.MODID, name = Main.MODNAME, version = Main.VERSION)



public class Main {

	public static final String MODID = "basicmod";
	public static final String MODNAME = "Basic Mod";
	public static final String VERSION = "1.0.0";
	public static final String ACCEPTED_MINECRAFT_VERSIONS = "[1.12.2]";
	
	@Instance
	public static Main instance = new Main();
	
	@SidedProxy(clientSide = "com.lk1905.basicmod.ClientProxy")
	public static CommonProxy proxy;
	
	@EventHandler
	public void preInit(FMLPreInitializationEvent e) {
		System.out.println("Called method: e");
		Main.proxy.preInit(e);		
	}
	
	@EventHandler
	public void init(FMLInitializationEvent e) {
		System.out.println("Called method: e");
		Main.proxy.init(e);
		SmeltingRecipes.init();
		CustomToolMaterials.init();
		GameRegistry.registerWorldGenerator(new OreGen(), 0);
	}
	
	@EventHandler
	public void postInit(FMLPostInitializationEvent e) {
		System.out.println("Called method: e");
		Main.proxy.postInit(e);
	}
	
}

 

 

My CommonProxy class:

Spoiler

package com.lk1905.basicmod;

import java.io.File;

import com.lk1905.basicmod.blocks.*;
import com.lk1905.basicmod.items.*;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.RegistryEvent;
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;

public class CommonProxy {

	public static Configuration config;
	
	public void preInit(FMLPreInitializationEvent e) {
		File directory = e.getModConfigurationDirectory();
		config = new Configuration(new File(directory.getPath(), "basicmod.cfg"));

	}
	
	public void init(FMLInitializationEvent e) {
		
	}
	
	public void postInit(FMLPostInitializationEvent e) {
		if (config.hasChanged()) {
			config.save();
		}
	}
	
	@SubscribeEvent
	public static void registerBlocks(RegistryEvent.Register<Block> event) {
		event.getRegistry().registerAll(new OreCopper(),
										new BlockCopper());
	}
	
	@SubscribeEvent
	public static void registerItems(RegistryEvent.Register<Item> event) {
		event.getRegistry().registerAll(new ItemBlock(ModBlocks.copperOre).setRegistryName(ModBlocks.copperOre.getRegistryName()),
										new ItemBlock(ModBlocks.copperBlock).setRegistryName(ModBlocks.copperBlock.getRegistryName()),
				
										new IngotCopper(),
										
										new NuggetCopper(),
										
										new AxeCopper(null, null),
										
										new PickaxeCopper(null, null),
										
										new ShovelCopper(null, null),
										
										new HoeCopper(null, null),
										
										new DaggerCopper(0, null));
	}
}

 

 

My ClientProxy class:

Spoiler

package com.lk1905.basicmod;

import com.lk1905.basicmod.blocks.ModBlocks;
import com.lk1905.basicmod.items.ModItems;

import net.minecraftforge.client.event.ModelRegistryEvent;
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;

public class ClientProxy extends CommonProxy{

	@Override
	public void preInit(FMLPreInitializationEvent e) {
		// TODO Auto-generated method stub
		super.preInit(e);
	}

	@Override
	public void init(FMLInitializationEvent e) {
		// TODO Auto-generated method stub
		super.init(e);
	}

	@Override
	public void postInit(FMLPostInitializationEvent e) {
		// TODO Auto-generated method stub
		super.postInit(e);
	}

	@SubscribeEvent
	public static void registerModels(ModelRegistryEvent event) {
		ModBlocks.initModels();
		ModItems.initModels();
	}
}

 

 

And my ModBlocks class:

Spoiler

package com.lk1905.basicmod.blocks;


import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ModBlocks {

	@GameRegistry.ObjectHolder("basicmod:orecopper")
	public static OreCopper copperOre;
	
	@GameRegistry.ObjectHolder("basicmod:blockcopper")
	public static OreCopper copperBlock;
	

	
	@SideOnly(Side.CLIENT)
	public static void initModels() {
		copperOre.initModel();
	}
	
	
}

 

 

Does anyone know what the problem is, or what I've done wrong?

Link to comment
Share on other sites

The only thing that could be null there is

1 hour ago, LK1905 said:

ModBlocks.copperOre

I would try and trace this back, but you fill the value with an @ObjectHolder annotation, but your main mod class defines itself via public static final Strings

That said, why does your @ObjectHolder annotation not also use these strings?

You also haven't included your Block class, which is presumably where you've called setRegistryName on it, so I can't verify that it matches your annotation..

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

My OreCopper class:

Spoiler

package com.lk1905.basicmod.blocks;

import com.lk1905.basicmod.customtabs.ModTabs;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class OreCopper extends Block{

	public OreCopper() {
		super(Material.ROCK);
		setUnlocalizedName(".orecopper");
		setRegistryName("orecopper");
		setCreativeTab(ModTabs.CUSTOM_BLOCKS);
		setHarvestLevel("pickaxe", 1);
	}
	
	@SideOnly(Side.CLIENT)
	public void initModel() {
		ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(),"inventory"));
	}
}

 

 

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.