Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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

  • Author
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?

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.