Jump to content

Recommended Posts

Posted

Hello, I'm making a structure only generate 3 times within a world using a custom WorldSavedData class. Whenever I try accessing it, it gives me this crash:

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

Time: 10/11/14 1:05 AM
Description: Exception in server tick loop

java.lang.NullPointerException: Exception in server tick loop
at terrarium.data.WorldSavedDataT.getInt(WorldSavedDataT.java:50)
at terrarium.world.WorldGeneratorT.generateOverworld(WorldGeneratorT.java:26)
at terrarium.world.WorldGeneratorT.generate(WorldGeneratorT.java:17)
at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106)
at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:314)
at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1157)
at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:208)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:149)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:119)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:305)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:79)
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:445)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)


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

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_67, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 787348752 bytes (750 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 9, tallocated: 72
FML: MCP v9.05 FML v7.10.85.1224 Minecraft Forge 10.13.1.1224 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available
FML{7.10.85.1224} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.1.1224.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available
Forge{10.13.1.1224} [Minecraft Forge] (forgeSrc-1.7.10-10.13.1.1224.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available
terrarium{Indev} [Terrarium] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 0 / 8; []
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

WorldData:

package terrarium.data;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
import net.minecraft.world.storage.MapStorage;

public class WorldSavedDataT extends WorldSavedData {
private static final String KEY = "TerrariumWorldSavedData";

private NBTTagCompound data;

public WorldSavedDataT(String name) {
	super(name);
}

public static WorldSavedDataT getWorldDataFor(World world) {
	MapStorage storage = world.perWorldStorage;
	WorldSavedDataT worldData = (WorldSavedDataT) storage.loadData(WorldSavedDataT.class, KEY);

	if(worldData == null) {
		worldData = new WorldSavedDataT(KEY);
		storage.setData(KEY, worldData);
	}

	return (WorldSavedDataT) storage.loadData(WorldSavedDataT.class, KEY);
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	if(!nbt.hasKey("Terrarium")) {
		nbt.setTag("Terrarium", new NBTTagCompound());
	}

	data = nbt.getCompoundTag("Terrarium");
}

@Override
public void writeToNBT(NBTTagCompound nbt) {
	nbt.setTag("Terrarium", data);
}

public void setInt(String name, int value) {
	data.setInteger(name, value);

	this.markDirty();
}

public int getInt(String name) {
	if(!data.hasKey(name)) {
		setInt(name, 0);
	}

	return data.getInteger(name);
}

public void setBoolean(String name, boolean value) {
	data.setBoolean(name, value);

	this.markDirty();
}

public boolean getBoolean(String name) {
	if(!data.hasKey(name)) {
		setBoolean(name, false);
	}

	return data.getBoolean(name);
}

public void setFloat(String name, float value) {
	data.setFloat(name, value);

	this.markDirty();
}

public float getFloat(String name) {
	if(!data.hasKey(name)) {
		setFloat(name, 0F);
	}

	return data.getFloat(name);
}

public void setDouble(String name, double value) {
	data.setDouble(name, value);

	this.markDirty();
}

public double getDouble(String name) {
	if(!data.hasKey(name)) {
		setDouble(name, 0D);
	}

	return data.getDouble(name);
}
}

 

WorldGenerator:

package terrarium.world;

import java.util.Random;

import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import terrarium.data.WorldSavedDataT;
import terrarium.util.MathUtil;
import terrarium.world.gen.WorldGenFloatingIsland;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGeneratorT implements IWorldGenerator {
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
	switch(world.provider.dimensionId) {
	case (0): {
		generateOverworld(random, chunkX * 16, chunkZ * 16, world);
		break;
	}
	}
}

public void generateOverworld(Random random, int x, int z, World world) {
	if(MathUtil.getChance(random, 1, 500)) {
		WorldSavedDataT worldData = WorldSavedDataT.getWorldDataFor(world);
		int amt = worldData.getInt("AmountOfStructures");

		if(amt < 4) {
			worldData.setInt("Structure", amt++);

			int x2 = x + random.nextInt(16);
			int z2 = z + random.nextInt(16);

			//Generate something
		}
	}

	if(MathUtil.getChance(random, 1, 150)) {
		WorldGenFloatingIsland.generate(world, random, x + random.nextInt(16), 200 + random.nextInt(32), z + random.nextInt(16));
	}
}
}

 

The crash occurs when I try generating a world.

Kain

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.