# how do I make a limit on how many times my structure spawn in a world just like how strongholds only spawn 3 of them in the worl

## Recommended Posts

```	public void generateNestAtNether(World world, Random random, int chunkX, int chunkZ) {
if (RealmOfTheDragonsConfig.canSpawnNetherNest) {
int x = (chunkX * RealmOfTheDragonsConfig.netherNestRarerityInX) + random.nextInt(RealmOfTheDragonsConfig.netherNestRarerityInX);
int z = (chunkZ * RealmOfTheDragonsConfig.netherNestRarerityInZ) + random.nextInt(RealmOfTheDragonsConfig.netherNestRarerityInZ);
for (int y = 85; y >= 5; y--) {
if ((world.getBlockState(new BlockPos(x,y,z)).isBlockNormalCube()) && (world.isAirBlock(new BlockPos(x,y,z)))) {
if((random.nextInt() * RealmOfTheDragonsConfig.netherNestRarity) <= 1) {
boolean place = true;

if(place) {
dragonNestNether.generate(world, new BlockPos(x,y,z), random);
Utils.getLogger().info("Nether Nest here at: " + new BlockPos(x,y,z));
}
}
}
}
}
}```

I would like to limit them because they cause too much lag

##### Share on other sites

Count them or otherwise keep track of them and if there is already enough don't generate more.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

##### Share on other sites

Just now, jabelar said:

Count them or otherwise keep track of them and if there is already enough don't generate more.

How do I count them? How do I keep track of them?

##### Share on other sites

How do I count them? How do I keep track of them?

This is your own code, so you create an int field and each time your world generator wants to generate you check if the field shows that enough have already been built and if not you build it and increment your counter.

Note though that that wouldn't be saved so you should also make some world save data and store your int value there. There is are built in classes for saving data: WorldSavedData. How you do it depends if you want to store it per-dimension (different data for e.g. nether and overworld, these are two World instances in the code) or per save-file (same data for all dimensions).  For the former use world.perWorldStorage, otherwise use world.mapStorage Be sure to always call markDirty() on your data when you change a value, otherwise Minecraft will not save it. You can see diesieben07's simple example here: WorldSaveData example code

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

## 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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• ### Posts

• I fixed the crash but epic fight and weapons of miracles are crashing the game, i deleted WoM and trying to fix Epic Fight
• Wow this looks a lot simpler than I thought it would be. Especially compared to the setup I had to do for capabilities. I'll look at all this and update if I have any issues ty
• Me and a group of friends were trying to get a modpack to work so we can play together. It works for everyone else, except me. At first when I tried to import the modpack, it said "invalid file" but it didn't with anyone else's. The owner of the modpack resent it several times and I still kept getting the same issue, so I opened the modlist and downloaded every single mod by hand. I thought that it would resolve the issue, but instead, it started saying "Forge Modloader Installation Failed" after I created a new installation, so I tried to use a pre-existing modpack, made sure it was the same version "1.20.1, forge version 47.3.0" and swap the mods there, but it still had the same issue, and now none of my modpacks are working at all. They all keep saying that the modloader installation failed. None of us have any idea what to do as we aren't the techiest people. Any help is appreciated. Thank you!

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...