Posted February 3, 201312 yr 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); } }
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.