diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenCrystalOre.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenCrystalOre.java index 628de04b..151b3776 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenCrystalOre.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenCrystalOre.java @@ -15,8 +15,6 @@ import java.util.Random; public class WorldGenCrystalOre implements IWorldGenerator { - // TODO: Probably this and the flowers are causing cascading lag! - @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider){ diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenLibraryRuins.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenLibraryRuins.java index cfe446c6..4243b0f1 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenLibraryRuins.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenLibraryRuins.java @@ -41,7 +41,8 @@ public class WorldGenLibraryRuins extends WorldGenSurfaceStructure { @Override public boolean canGenerate(Random random, World world, int chunkX, int chunkZ){ return ArrayUtils.contains(Wizardry.settings.libraryDimensions, world.provider.getDimension()) - && BiomeDictionary.getTypes(world.getBiome(new BlockPos(chunkX * 16 + 8, 0, chunkZ * 16 + 8))) + // +8 for the anti-cascading offset, and +8 for the middle of the generated area makes +16 in total + && BiomeDictionary.getTypes(world.getBiome(new BlockPos(chunkX * 16 + 16, 0, chunkZ * 16 + 16))) .stream().anyMatch(BIOME_TYPES::contains) && Wizardry.settings.libraryRarity > 0 && random.nextInt(Wizardry.settings.libraryRarity) == 0; } @@ -91,7 +92,7 @@ public class WorldGenLibraryRuins extends WorldGenSurfaceStructure { } ); - template.addBlocksToWorld(world, origin, processor, settings, 2); + template.addBlocksToWorld(world, origin, processor, settings, 2 | 16); WizardryAntiqueAtlasIntegration.markLibrary(world, origin.getX(), origin.getZ()); } diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java index 7408baee..486e8606 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenObelisk.java @@ -62,7 +62,7 @@ public class WorldGenObelisk extends WorldGenSurfaceStructure { ITemplateProcessor processor = (w, p, i) -> i.blockState.getBlock() instanceof BlockRunestone ? new Template.BlockInfo( i.pos, i.blockState.withProperty(BlockRunestone.ELEMENT, element), i.tileentityData) : i; - template.addBlocksToWorld(world, origin, processor, settings, 2); + template.addBlocksToWorld(world, origin, processor, settings, 2 | 16); WizardryAntiqueAtlasIntegration.markObelisk(world, origin.getX(), origin.getZ()); diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenShrine.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenShrine.java index 076a811d..7e9b4d5d 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenShrine.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenShrine.java @@ -54,7 +54,7 @@ public class WorldGenShrine extends WorldGenSurfaceStructure { ITemplateProcessor processor = (w, p, i) -> i.blockState.getBlock() instanceof BlockRunestone ? new Template.BlockInfo( i.pos, i.blockState.withProperty(BlockRunestone.ELEMENT, element), i.tileentityData) : i; - template.addBlocksToWorld(world, origin, processor, settings, 2); + template.addBlocksToWorld(world, origin, processor, settings, 2 | 16); WizardryAntiqueAtlasIntegration.markShrine(world, origin.getX(), origin.getZ()); diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java index bb8847f3..a83cd54d 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenSurfaceStructure.java @@ -45,12 +45,12 @@ public abstract class WorldGenSurfaceStructure extends WorldGenWizardryStructure protected BlockPos attemptPosition(Template template, PlacementSettings settings, Random random, World world, int chunkX, int chunkZ, String structureFile){ - // Offset by (8, 8) to minimise cascading worldgen lag + BlockPos size = template.transformedSize(settings.getRotation()); + + // Offset by (8, 8) to minimise cascading worldgen lag, MINUS half the width of the structure (important!) // See https://www.reddit.com/r/feedthebeast/cowmments/5x0twz/investigating_extreme_worldgen_lag/?ref=share&ref_source=embed&utm_content=title&utm_medium=post_embed&utm_name=c07cbb545f74487793783012794733d8&utm_source=embedly&utm_term=5x0twz // Multiplying and left-shifting are identical but it's good practice to bitshift here I guess - BlockPos origin = new BlockPos(8 + (chunkX << 4) + random.nextInt(16), 0, 8 + (chunkZ << 4) + random.nextInt(16)); - - BlockPos size = template.transformedSize(settings.getRotation()); + BlockPos origin = new BlockPos((chunkX << 4) + random.nextInt(16) + 8 - size.getX()/2, 0, (chunkZ << 4) + random.nextInt(16) + 8 - size.getZ()/2); // Estimate a starting height for searching for the floor BlockPos centre = world.getTopSolidOrLiquidBlock(new BlockPos(origin.add(size.getX()/2, 0, size.getZ()/2))); @@ -150,6 +150,9 @@ public abstract class WorldGenSurfaceStructure extends WorldGenWizardryStructure for(int y1 = boundingBox.minY - border; y1 <= y + border; y1++){ for(int z = boundingBox.minZ - border; z <= boundingBox.maxZ + border; z++){ BlockPos pos = new BlockPos(x, y1, z); + // Skip blocks that haven't been generated yet + // If you think about it, there can't possibly be floating trees in unloaded chunks anyway + if(!world.isBlockLoaded(pos)) continue; if(world.getBlockState(pos).getBlock() instanceof BlockLeaves) leaves.add(pos); } } diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenUndergroundLibraryRuins.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenUndergroundLibraryRuins.java index 331ee9e1..1338af36 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenUndergroundLibraryRuins.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenUndergroundLibraryRuins.java @@ -96,7 +96,7 @@ public class WorldGenUndergroundLibraryRuins extends WorldGenUndergroundStructur } ); - template.addBlocksToWorld(world, origin, processor, settings, 2); + template.addBlocksToWorld(world, origin, processor, settings, 2 | 16); WizardryAntiqueAtlasIntegration.markLibrary(world, origin.getX(), origin.getZ()); } diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenUndergroundStructure.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenUndergroundStructure.java index 1dc80174..7e223f58 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenUndergroundStructure.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenUndergroundStructure.java @@ -25,9 +25,13 @@ public abstract class WorldGenUndergroundStructure extends WorldGenWizardryStruc @Override protected BlockPos attemptPosition(Template template, PlacementSettings settings, Random random, World world, int chunkX, int chunkZ, String structureFile){ - BlockPos origin = new BlockPos(8 + (chunkX << 4) + random.nextInt(16), 20 + random.nextInt(40), 8 + (chunkZ << 4) + random.nextInt(16)); - BlockPos size = template.transformedSize(settings.getRotation()); + + // Offset by (8, 8) to minimise cascading worldgen lag, MINUS half the width of the structure (important!) + // See https://www.reddit.com/r/feedthebeast/cowmments/5x0twz/investigating_extreme_worldgen_lag/?ref=share&ref_source=embed&utm_content=title&utm_medium=post_embed&utm_name=c07cbb545f74487793783012794733d8&utm_source=embedly&utm_term=5x0twz + // Multiplying and left-shifting are identical but it's good practice to bitshift here I guess + BlockPos origin = new BlockPos((chunkX << 4) + random.nextInt(16) + 8 - size.getX()/2, 20 + random.nextInt(40), (chunkZ << 4) + random.nextInt(16) + 8 - size.getZ()/2); + BlockPos corner = origin.add(size.getX(), 1, size.getZ()); // Need not iterate through everything // Criteria for a valid position: diff --git a/src/main/java/electroblob/wizardry/worldgen/WorldGenWizardTower.java b/src/main/java/electroblob/wizardry/worldgen/WorldGenWizardTower.java index 28b12681..dc4bf11f 100644 --- a/src/main/java/electroblob/wizardry/worldgen/WorldGenWizardTower.java +++ b/src/main/java/electroblob/wizardry/worldgen/WorldGenWizardTower.java @@ -101,7 +101,7 @@ public class WorldGenWizardTower extends WorldGenSurfaceStructure { (w, p, i) -> {if(i.blockState.getBlock() != Blocks.AIR) blocksPlaced.add(p); return i;} ); - template.addBlocksToWorld(world, origin, processor, settings, 2); + template.addBlocksToWorld(world, origin, processor, settings, 2 | 16); WizardryAntiqueAtlasIntegration.markTower(world, origin.getX(), origin.getZ());