Jump to content

Using ChunkDataEvent


Emasher

Recommended Posts

I've been working on modifying some of the world generation in one of my mods so that certain resources are added to worlds that were created before installing the mod. I'm using ChunkDataEvent to save NBT tags containing the version of the mod, as well as to check to see if that tag is there or not when the chunk is loaded. If the tag is there, I don't spawn the resources, if it isn't, I do. The problem is that the tag seems to disappear after the world has been loaded, and so only the first time each chunk is loaded after the world is loaded does it prevent spawning more resources. My code is shown below.

 

public class WorldGenerationUpdater
{

private static boolean[][] hasHadSpawn = new boolean[1024][1024]; //For testing only

@ForgeSubscribe
public void Load(ChunkDataEvent event)
{
	NBTTagCompound data = event.getData();
	Chunk chunk = event.getChunk();

	if(! data.hasKey("emasher_gas_info"))
	{

		EmasherGas.gasVentGenerator.generate(new Random(System.nanoTime()), chunk.xPosition, chunk.zPosition, chunk.worldObj, null, null);

		if(hasHadSpawn[chunk.xPosition + 512][chunk.zPosition + 512]) //For testing only
		{
			System.err.println("[GasCraft]Error: Chunk @" + chunk.xPosition + ", " + chunk.zPosition +  "has already had shale gas spawn");
		}
		else
		{
			System.out.println("Adding Shale Gas @" + chunk.xPosition + ", " + chunk.zPosition);
		}

		hasHadSpawn[chunk.xPosition + 512][chunk.zPosition + 512] = true; //For testing only

	}
	else
	{
		System.out.println("Chunk @" + chunk.xPosition + ", " + chunk.zPosition +  "already has shale gas, Not spawning more");
	}
}

@ForgeSubscribe
public void Save(ChunkDataEvent event)
{
	NBTTagCompound data = event.getData();
	Chunk chunk = event.getChunk();

	NBTTagCompound tag = new NBTTagCompound();

	tag.setString("GasCraft_Version", EmasherGas.version);

	data.setCompoundTag("emasher_gas_info", tag);

	//System.out.println("Saving chunk@" + chunk.xPosition + ", " + chunk.zPosition);
}

}

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

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