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.

Featured Replies

Posted

Hi guys,

 

So I've come up trumps with this. I have a world gen class that can generate ores for me within stone blocks. But when I try to get it to generate in the sand blocks. Nothing happens.

 

This is the offending class right now:

 

WorldGenSand.java:

 

 

public class ComTech_WorldGenSand implements IWorldGenerator {

public ComTech_WorldGenSand() {
}

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator,
		IChunkProvider chunkProvider) {

	switch(world.provider.dimensionId) {
	case -1:
		generateInNether(random, chunkX * 16, chunkZ * 16, world);
		break;

	case 0:
		generateInOverworld(random, chunkX * 16, chunkZ * 16, world);
		break;

	case 1:
		generateInEndWorld(random, chunkX * 16, chunkZ * 16, world);
		break;

	default:
		break;
	}

}

private void generateInNether(Random random, int chunkX, int chunkZ, World world) {}

private void generateInOverworld(Random random, int chunkX, int chunkZ, World world) { 
	oreSpawnPoint(Ores.instances.sedimentSand, world, random, chunkX, chunkZ, 4, 8, 10, 20, 100);
}

private void generateInEndWorld(Random random, int chunkX, int chunkZ, World world) {}

/** Used to generate the given ore at a random point within certain parameters in the given world.
 * 
 * @param block The block in question.
 * @param world The world in which the block will be spawned.
 * @param random The random generator.
 * @param x The X axis.
 * @param z The Y axis.
 * @param minVeinSize The minimum amount of ores that can appear in the vein.
 * @param maxVeinSize The maximum amount of ores that can appear in the vein.
 * @param chanceToSpawn The amount of chance the ore has to spawn in a given location.
 * @param minY The minimum depth the ore can spawn.
 * @param maxY The maximum depth the ore can spawn.
 */
private void oreSpawnPoint(Block block, World world, Random random, int x, int z, int minVeinSize, int maxVeinSize, int chanceToSpawn,
		int minY, int maxY) {

	for (int i = 0; i < chanceToSpawn; i++) {
		int coordX = x + random.nextInt(16);
		int coordY = random.nextInt(16);
		int coordZ = z + random.nextInt(16);

		new WorldGenMinable(block, (minVeinSize + random.nextInt(maxVeinSize - minVeinSize)), Blocks.sand).generate(world,
				random, coordX, coordY, coordZ);
	}
}

}

 

And that doesn't work. At all. So my question is as follows:

 

How could I adapt that class to generate my sand (ideally next to and under water)?

 

Thanks guys!

Sea level in Minecraft is 63, so should probably go to something like 65 or 70.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

So after changing

 coordY = random.nextInt(16); 

to

 coordY = random.nextInt(70); 

It works. All I have to do is sort out the rarity of it.

 

Now, in other posts I've seen people try to do the following (which is psuedo-code):

 

if block adjacent to oreBlock is not Block.water then

    return false;

else

    return true;

 

to get their sand block to spawn next to water?

Yes, if you only want to have your ore generated next to water, you have to check the four (maybe six, if you check bottom and top) sides, and if there's a water block, generate the ore. Else, don't generate the ore continue with the generation.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

So I need to bump 

 coordY = random.nextInt(16); 

to

 coordY = random.nextInt(50); 

for example?

 

You might not want a range starting at zero, so you can do something like:

 coordY = 30 + random.nextInt (33); 

 

Also, if you just want to be related to water rather than enforcing actual contact, then you might test for biome (ocean, deep ocean, river) rather than the blocks on the many sides.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.