Jump to content

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

Posted
	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

Posted
2 hours ago, TheRPGAdventurer said:

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.

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.