Jump to content

[1.12.1] How would I prevent 'cascading worldgen lag' during worldgen


JJ42001

Recommended Posts

So what I am having issues with is generating Limestone into the world in big veins. Unfortunately every time I go into the hundreds for 'blockCount' when I go to load new chunks in a pre-existing world I get no visible chunk loading / generation at all, and the game just stops all world interaction. (Can still do commands, but not exit the world) When creating a new world it just stays on the generating world loading screen. Both loading new chunks after updating 'blockCount', and creating a new world throw this too many times to count (but with a different x / y coords):

 

[00:15:56] [Server thread/WARN]: PDS loaded a new chunk (1475, 1  Dimension: 0) during chunk population, causing cascading worldgen lag. Please report this to the mod's issue tracker. This log can be disabled in the Forge config.

Here is the worldGen code:

Spoiler

package jtb.isdev.pds.util;

import jtb.isdev.pds.init.PDSBlocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;

import java.util.Random;

public class WorldGen implements IWorldGenerator {

private WorldGenerator limestone_overworld;

public WorldGen() {
  limestone_overworld = new WorldGenMinable(PDSBlocks.BLOCKS[1].getDefaultState(), 800);
}

private void runGenerator(WorldGenerator generator, World world, Random rand, int chunk_X,
                          int chunk_Z, int chancesToSpawn, int minHeight, int maxHeight) {
  if (minHeight < 0 || maxHeight > 256 || minHeight > maxHeight)
    throw new IllegalArgumentException("Illegal Height Arguments for WorldGenerator");

  int heightDiff = maxHeight - minHeight + 1;
  for (int i = 0; i < chancesToSpawn; i++) {
    int x = chunk_X * 16 + rand.nextInt(16);
    int y = minHeight + rand.nextInt(heightDiff);
    int z = chunk_Z * 16 + rand.nextInt(16);
    generator.generate(world, rand, new BlockPos(x, y, z));
  }
}

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
                     IChunkProvider chunkProvider) {
  switch (world.provider.getDimension()) {
    case 0:
      runGenerator(limestone_overworld, world, random, chunkX, chunkZ, 1, 42, 46);
      break;
    case -1:

      break;
    case 1:

      break;
  }
}
}

This is the only way I know how to generate blocks into the world, so any help on this would be helpful. Thanks in advance, Sincerely JJ42001

Link to comment
Share on other sites

See:

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Alright well that shows me whats causing the issue, but I'm still not quite sure what to do to fix it.

 

Quote

Correct world generation offsets everything by +8, +8 so that all generation happens in the middle of loaded chunks, and has a low chance of spilling out.

Because I am trying to generate such a large number of blocks in a single instance, that one instance takes up about 4-9 chunks every time that a limestone patch is generated, wouldn't centering the generation still cause overlapped generation to load the other chunks?

 

Quote

If you use vanilla classes like WorldGenMinable then the offset is already built in, but if you have a custom one make sure it is generating properly.

I am using

worldGenMinable

Am I using it correctly?

 

Edit:

Quote

Yeah, one thing I didn't mention in the original post is that if your worldgen structure is bigger than a chunk it's going to always overflow, so you need more advanced strategies.

I'll keep looking deeper into it.

Edited by JJ42001
Link to comment
Share on other sites

In other words, look at how large structures (fortress, mine, stronghold) are generated. Devise a way to generate only the portion within the called chunk and the neighboring edges of the chunks to the South & East. Even when generating within the called chunk, take care to avoid changing any blocks along the north or west edges.

 

Alternatively, it might be possible to cheat by setting a flag while generating a vein and clearing the flag after the vein and all of its chunks are complete. Don't allow a new vein to generate if the flag is already set. You'd have to experiment to see if this would contain the spread. Even then, it would mean that your world would be non-deterministic in that the positions of these veins would depend partly on the order in which players explore the world.

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.

Link to comment
Share on other sites

So, I still cant figure out how to see minecraft's worldGen codes, but I've been changing and adding things in my code here and there and still can't quite get it to function.

 

This is what I currently have, which what I thought would only spawn the portion of the vein if 'isLoaded' returns true, but when I load up a world, there are none to be found....anywhere.

Quote

package jtb.isdev.pds.util;

import jtb.isdev.pds.init.PDSBlocks;
import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;

import java.util.Random;

import static jtb.isdev.pds.DataMain.MLOG;

public class WorldGen implements IWorldGenerator {

private WorldGenerator limestone_overworld;

public WorldGen() {
  limestone_overworld = new WorldGenMinable(PDSBlocks.BLOCKS[1].getDefaultState(), 256);
}

private void limestoneGenerator(WorldGenerator generator, World world, Random rand, int chunkXPos, int chunkZPos, int chanceToSpawn, int height) {
  if (height < 0 || height > 256)
    throw new IllegalArgumentException("Illegal Height Arguments for WorldGenerator");

  int doGen = rand.nextInt(chanceToSpawn);
  if (doGen == chanceToSpawn) {
    int y = height;
    int cx = chunkXPos * 16 + rand.nextInt(16);
    int cz = chunkZPos * 16 + rand.nextInt(16);

    BlockPos veinPos = new BlockPos(cx, y, cz);
    boolean isLoaded = new ChunkProviderClient(world).isChunkGeneratedAt(cx, cz);

    if (isLoaded) {
      generator.generate(world, rand, veinPos);
      Utils.getLogger().info(MLOG + ": Limestone vein at: x= " + cx + " y= " + y + " z= " + cz);
    }
  }
}

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
                     IChunkProvider chunkProvider) {
  switch (world.provider.getDimension()) {
    case 0:
      limestoneGenerator(limestone_overworld, world, random, chunkX, chunkZ, 5, 48);
      break;
    case -1:

      break;
    case 1:

      break;
  }
}
}

Even when I remove the if statement I still get no veins to generate.

 

Edited by JJ42001
Link to comment
Share on other sites

Look at the net.minecraft.world.gen package for Minecraft's world generation classes. Structures like the Stronghold, Mineshaft and Nether Fortress are in the net.minecraft.world.gen.structure package.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

23 hours ago, JJ42001 said:

int doGen = rand.nextInt(chanceToSpawn)

; if (doGen == chanceToSpawn) {...

 

nextInt will always return 0-(n-1), so its result will never equal n.

Edited by jeffryfisher

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.

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



×
×
  • Create New...

Important Information

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