Jump to content

MC 1.10+ Improving Worldgen


winnetrie

Recommended Posts

While my worldgen is working, i have the feeling something is not right.

I think the way i get the coordinates is wrong.

Why? Because i have a block that needs to be generated in river biomes, now when i dig down in a river i mostly do not find my block, but i do find my block generating the biome next to the river.

It isn't a big deal, people will still find it after all,but when i do something wrong i like to know what and how to improve it.

 

Here is my worldgen code:

 

public class ModWorldGenerator implements IWorldGenerator {

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
	// TODO Auto-generated method stub
	switch(world.provider.getDimensionType())
	{
	case NETHER:
		generateNether(world, random, chunkX, chunkZ);
		break;
	case OVERWORLD:
		generateOverworld(world, random, chunkX, chunkZ);
		break;
	case THE_END:
		generateEnd(world, random, chunkX, chunkZ);
		break;
	}
}
public void generateNether(World world, Random rand, int x, int z){
	if (ModConfig.enabledemonite==true){
		generateOre(ModBlocks.demonite.getDefaultState(), world, rand, 0, x, z, 33, 66, 75, 1, 256, BlockMatcher.forBlock(Blocks.NETHERRACK));
		if (ModConfig.enablefeliron==true){
			generateSingleOre(ModBlocks.feliron.getDefaultState(), world, rand, 0, x, z, 100, 1, 256, BlockMatcher.forBlock(ModBlocks.demonite));

		}
	}
}
public void generateOverworld(World world, Random rand, int x, int z){

	int XX = x *16;
	int ZZ = z *16;
	BlockPos pos = new BlockPos(XX, 70, ZZ);
	String biome = world.getBiomeGenForCoords(pos).getBiomeName();//getWorldChunkManager().getBiomeGenAt(XX, ZZ);

	if (ModConfig.enablechalkstone==true){
		if(biome.contains("River")){
			generateOre(ModBlocks.chalkstone.getDefaultState(), world, rand, 0, x, z, 25, 33, 100, 45, 65, BlockMatcher.forBlock(Blocks.STONE));
		}
		if(biome.contains("Ocean")){
			generateOre(ModBlocks.chalkstone.getDefaultState(), world, rand, 0, x, z, 15, 33, 50, 20, 50, BlockMatcher.forBlock(Blocks.STONE));
			generateOre(ModBlocks.chalkstone.getDefaultState(), world, rand, 0, x, z, 15, 33, 50, 10, 50, BlockMatcher.forBlock(Blocks.STONE));
			generateOre(ModBlocks.chalkstone.getDefaultState(), world, rand, 0, x, z, 10, 15, 50, 30, 50, BlockMatcher.forBlock(Blocks.GRAVEL));
		}
	}
	if (ModConfig.enablemarblestone==true){
		if(biome.contains("Hills") || biome.contains("Mountain")){
			generateOre(ModBlocks.marblestone.getDefaultState(), world, rand, 0, x, z, 25, 33, 50, 65, 256, BlockMatcher.forBlock(Blocks.STONE));
		}
	}		
}
public void generateEnd(World world, Random rand, int x, int z){

}
public void generateOre(IBlockState state, World world, Random random, int meta, int chunkX, int chunkZ, int minVienSize, 
		int maxVienSize, int chance, int minY, int maxY, Predicate<IBlockState> generatedIn){
	int vienSize = minVienSize + random.nextInt(maxVienSize - minVienSize);
	int heightRange = maxY - minY + 1;
	WorldGenMinable gen = new WorldGenMinable(state,vienSize, generatedIn);
	for(int i =0; i < chance; i++){
		int xRand = chunkX * 16 + random.nextInt(16);
		int yRand = random.nextInt(heightRange) + minY;
		int zRand = chunkZ * 16 + random.nextInt(16);
		//Block testblock = world.getBlock(xRand, yRand, zRand);
		BlockPos pos = new BlockPos(xRand, yRand, zRand);	
		gen.generate(world,  random ,pos);		
	}	
}

public void generateSingleOre(IBlockState iBlockState, World world, Random random, int meta, int chunkX, int chunkZ, 
		int chance, int minY, int maxY, BlockMatcher blockMatcher){
	//int vienSize = minVienSize + random.nextInt(maxVienSize - minVienSize);
	int heightRange = maxY - minY + 1;
	WorldGenSingleMinable gen = new WorldGenSingleMinable(iBlockState, meta,  blockMatcher);
	for(int i =0; i < chance; i++){
		int xRand = chunkX * 16 + random.nextInt(16);
		int yRand = random.nextInt(heightRange) + minY;
		int zRand = chunkZ * 16 + random.nextInt(16);
		BlockPos pos = new BlockPos(xRand, yRand, zRand);
		gen.generate(world,  random, pos );	
	}	
}
}

 

Link to comment
Share on other sites

generateOre(ModBlocks.chalkstone.getDefaultState(), world, rand, 0, x, z, 25, 33, 100, 45, 65, BlockMatcher.forBlock(Blocks.STONE));

You should be using

xx

and

zz

instead of

x

and

z

.

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/

Link to comment
Share on other sites

@larsgerrits

No, he was using it "correctly". Quotation marks as the method wants the chunk coords, but a chunk can of course contain 1-256 different biomes

 

@winnetrie

The biome next to the river... It doesn't happen to be in the same chunk? Because all you do, is say "[this chunk] has a river. Spawn [block] in this chunk. Where? Randomly."

I recommend that you change your

generateOre

to make use of a blockpos directly, or at least a regular x & z coordinate instead of chunk coords.

This way, you can more easily oversee where they spawn.

I also recommend that you instead for-loop through

BlockPos#getAllInBox(from, to)

and check if the biome is what you want, instead of randomly generating nearby, where the biome can have changed drastically, just 1 block away.

 

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

 

@winnetrie

The biome next to the river... It doesn't happen to be in the same chunk? Because all you do, is say "[this chunk] has a river. Spawn [block] in this chunk. Where? Randomly."

Yeah i was already aware that this could be the reason, but i didn't know an alternative or an improvement!

 

I don't know how to use the thing you say, but i will look into that later.

As i said before it isn't yet important, because it works. Improvements are for later when everything is finished.

 

Thank you very much for the info!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I created my own modpack just for mainly entities right now and im having issues with only a handful of the mobs. is there a way someone could help go over my work and check whats wrong? its a file 
    • Hi, I have a problem with my minecraft: I'm in forge 1.20.1 and I have several mods installed, (link to photo below) and after a while, at random, the game freezes, I can't play or move but I can still hear the game in the background, there's just the image that remains, (problematic when I fight a fire dragon :() ) can you help me? my mods:   zmedievalmusic-1.20.1-2.1 treeharvester-1.20.1-8.7 tctcore-1.0-1.20.1 specialmobs-1.20.1-3.1.3 simpleOres2-1.20.1-6.0.0.2 OldCombatMod_1.20x.jar oculus-mc1.20.1-1.7.0 medieval_buildings-forge-1.0.2 matmos-5.2-forge-1.20.1 journeymap-1.20.1-5.9.18-forge jei-1.20.1-forge-15.8.0.11 iceandfire-2.1.13-1.20.1-beta-4 healthindicatortxf-1.20.1-1.2.2-forge geckolib-forge-1.20.1-4.4.7 embeddium-0.3.25+mc1.20.1 dynamiclights-1.20.1-1.2 cupboard-1.20.1-2.7 crust-1.20.1-2.3.3 collective-1.20.1-7.71 citadel-2.4.9-1.20.1 bucketlib-1.20.1-2.3.0.5 born_in_chaos_(Forge)1.20.1_1.3.1 betterfpsdist-4.4   forge 1.20.1 (47.3.5) i fink it's because of ice and fire mod, but i want it thank to help me! i hope you are well Translated with DeepL.com (free version)
    • Long story short, my girlfriend found a mod for Minecraft she wanted but it was for Pocket Edition. So I took it on myself to try and port it over and it has gone fairly well until the point I had to work with particles. Basically, I had it working using animateTick but I was checking if the block name contained a certain value to specify the lantern's color and as such choose which particle to spawn. I was initially trying to do this via the constructor, but this value hasn't been initialized that early and I can't seem to find some event or method to override which ideally happens when the block is loaded/placed. Performing upwards to 16 string comparisons per tick isn't exactly efficient so I want to try and optimize this. By the time animateTick starts executing, the name is properly initialized and I can use that to set my property accordingly. But this is where I'm starting to run into a weird issue. This is my current code; public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource randomSource) { // It's not fully initialized yet... I guess? if (this.getName().toString().contains("air")) return; if (!state.getValue(COLOR_SET)) { // This method doesn't work at all, neither states are updated var blockState = level.getBlockState(pos); blockState.setValue(LANTERNCOLOR, this.getBlockColor()); blockState.setValue(COLOR_SET, true); level.setBlockAndUpdate(pos, blockState); } double d0 = (double)pos.getX() + randomSource.nextDouble(); double d1 = (double)pos.getY() + randomSource.nextDouble(); double d2 = (double)pos.getZ() + randomSource.nextDouble(); // No idea how to better do this without adding 5 000 new files if (level.getBlockState(pos).getValue(LANTERNCOLOR) == DyeColor.WHITE.getId()) level.addParticle(PaperLanterns.LANTERN_GLOW_WHITE.get(), d0, d1, d2, 0.0D, ThreadLocalRandom.current().nextDouble(-0.10D, 0.0D), 0.0D); if (level.getBlockState(pos).getValue(LANTERNCOLOR) == DyeColor.BLUE.getId()) level.addParticle(PaperLanterns.LANTERN_GLOW_BLUE.get(), d0, d1, d2, 0.0D, ThreadLocalRandom.current().nextDouble(-0.10D, 0.0D), 0.0D); } COLOR_SET is a BooleanProperty meant to ensure this is only executed once, for performance reasons. LANTERNCOLOR is currently an IntegerProperty (it used to be an EnumProperty, but been changing stuff around trying to fix the issue) which specified the color. My issue is that I can only set one of these states, for example like this; if (!state.getValue(COLOR_SET)) { // LANTERNCOLOR is set successfully, but not COLORSET level.setBlockAndUpdate(pos, state.setValue(LANTERNCOLOR, this.getBlockColor())); level.setBlockAndUpdate(pos, state.setValue(COLOR_SET, true)); } // OR if (!state.getValue(COLOR_SET)) { // COLOR_SET is set successfully, but not LANTERNCOLOR level.setBlockAndUpdate(pos, state.setValue(COLOR_SET, true)); level.setBlockAndUpdate(pos, state.setValue(LANTERNCOLOR, this.getBlockColor())); } So I can only seemingly set one state at a time, I now know that my issue wasn't in my usage of EnumProperty so once I solve this I will be going back to that and using a switch-case. But I would love some pointers as to why I can only set one of these states. Is it because once you set it and update it, that instance of the block is now considered dirty and as such accepts no more state changes or something? I know the code's a bit all over the place with how I retrieve the states. I'm still learning and have been testing a bunch trying to get this to work, but have now found the issue but no idea how to solve it 😅 If there's a better way of setting this LANTERNCOLOR property and ensuring it's only executed once, that would be even better. The sole purpose of this is to choose which particle to spawn, since the particle colors are hardcoded.
    • Hi, I have a problem with my minecraft: I'm in forge 1.20.1 and I have several mods installed, (link to photo below) and after a while, at random, the game freezes, I can't play or move but I can still hear the game in the background, there's just the image that remains, (problematic when I fight a fire dragon :() ) can you help me? my mods: file:///C:/Users/meria/Pictures/Capture.PNG forge 1.20.1 (47.3.5) i fink it's because of ice and fire mod, but i want it thank to help me! i hope you are well Translated with DeepL.com (free version)
  • Topics

×
×
  • Create New...

Important Information

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