Jump to content

Structure only generating once


shucke

Recommended Posts

How can i make a structure generate only once?

i want to make a structure which generates only once and not everytime a new chunk is beeing generated.

i got the code to work but the problem is i used a variable to check if the structure is already generated.

but when i exit the game it resets the variable and the structure is beeing generated again.

so can i write the variable to NBT or something?

or is there another way to save variables in for example in my baseclass or CommonProxy?

Link to comment
Share on other sites

i did that but it wont save.

i set my variable to true and when i restart the game it is false again.

if(world.loadItemData(WorldSaveData.class, "LegendzWorldSaveData") == null){
		WorldSavedData data = new WorldSaveData("LegendzWorldSaveData");
		world.setItemData("LegendzWorldSaveData", data);
	}

	WorldSaveData worldSaveData = (WorldSaveData) world.loadItemData(WorldSaveData.class, "LegendzWorldSaveData");


	System.out.println(worldSaveData.alreadyGenerated[0]);

i put this in the generate method in my WorldGenerator.

and here is my WorldSaveData Class

package legendz.common;

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

public class WorldSaveData extends WorldSavedData {

public static boolean[] alreadyGenerated = new boolean[8];

public WorldSaveData(String par1Str) {
	super(par1Str);
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	for(int i = 0; i < alreadyGenerated.length; i++){
		alreadyGenerated[i] = nbt.getBoolean("generated"+i);
	}
}

@Override
public void writeToNBT(NBTTagCompound nbt) {
	for(int i = 0; i < alreadyGenerated.length; i++){
		nbt.setBoolean("generated"+i, alreadyGenerated[i]);
	}
}

}

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.