Skip to content

Commit

Permalink
Attempt to rein in permafrost perf (doesnt work well)
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Dec 20, 2023
1 parent cee04ed commit 23f9d68
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.ChunkGenerator;

import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.config.type.DimensionConfig;
import org.violetmoon.quark.base.world.generator.Generator;

Expand Down Expand Up @@ -47,17 +49,11 @@ public final void generateChunk(WorldGenRegion world, ChunkGenerator generator,
Random chunkRandom = new Random(chunkSeed);
BlockPos chunkCorner = new BlockPos(x << 4, 0, z << 4);

BlockPos[] sources = getSourcesInChunk(world, chunkRandom, generator, chunkCorner);
for(BlockPos source : sources)
if(source != null && isSourceValid(world, generator, source))
generateChunkPart(source, generator, ourRandom, pos, world);
for(BlockPos source : getSourcesInChunk(world, chunkRandom, generator, chunkCorner))
generateChunkPart(source, generator, ourRandom, pos, world);
}
}

public boolean isSourceValid(WorldGenRegion world, ChunkGenerator generator, BlockPos pos) {
return true;
}

public abstract int getFeatureRadius();

public abstract void generateChunkPart(BlockPos src, ChunkGenerator generator, Random random, BlockPos chunkCorner, WorldGenRegion world);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,19 @@ public BigStoneClusterGenerator(BigStoneClusterConfig config, BlockState placeSt
}

@Override
public boolean isSourceValid(WorldGenRegion world, ChunkGenerator generator, BlockPos pos) {
return config.biomes.canSpawn(getBiome(world, pos, true));
}

@Override
public BlockPos[] getSourcesInChunk(WorldGenRegion world, Random random, ChunkGenerator generator, BlockPos chunkLeft) {
public BlockPos[] getSourcesInChunk(WorldGenRegion world, Random random, ChunkGenerator generator, BlockPos chunkCorner) {
int chance = config.rarity;

BlockPos[] sources;
if(chance > 0 && random.nextInt(chance) == 0) {
sources = new BlockPos[1];
int lower = config.minYLevel;
int range = Math.abs(config.maxYLevel - config.minYLevel);

BlockPos pos = chunkLeft.offset(random.nextInt(16), random.nextInt(range) + lower, random.nextInt(16));
sources[0] = pos;
} else
sources = new BlockPos[0];
BlockPos pos = chunkCorner.offset(random.nextInt(16), random.nextInt(range) + lower, random.nextInt(16));
if(config.biomes.canSpawn(getBiome(world, pos, true)))
return new BlockPos[] { pos };
}

return sources;
return new BlockPos[0];
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;

import net.minecraft.world.level.levelgen.Heightmap;
import org.violetmoon.quark.base.world.generator.multichunk.ClusterBasedGenerator;

import java.util.Random;
Expand All @@ -27,9 +28,14 @@ public int getFeatureRadius() {
@Override
public BlockPos[] getSourcesInChunk(WorldGenRegion world, Random random, ChunkGenerator generator, BlockPos chunkCorner) {
if(info.rarity > 0 && random.nextInt(info.rarity) == 0) {
return new BlockPos[] {
chunkCorner.offset(random.nextInt(16), info.minYLevel + random.nextInt(info.maxYLevel - info.minYLevel), random.nextInt(16))
};
int x = chunkCorner.getX() + random.nextInt(16);
int y = random.nextInt(info.maxYLevel - info.minYLevel);
int z = chunkCorner.getZ() + random.nextInt(16);
BlockPos pos = new BlockPos(x, y, z);

//check the biome at world height, and don't start blobs unless theyre actually underground
if(info.biomes.canSpawn(getBiome(world, pos, true)) && world.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z) >= y)
return new BlockPos[]{ pos };
}

return new BlockPos[0];
Expand All @@ -40,13 +46,6 @@ public IGenerationContext createContext(BlockPos src, ChunkGenerator generator,
return new Context(world, src, generator, random, info);
}

@Override
public boolean isSourceValid(WorldGenRegion world, ChunkGenerator generator, BlockPos pos) {
BlockPos check = new BlockPos(pos.getX(), info.minYLevel, pos.getZ());
Holder<Biome> biome = getBiome(world, check, true);
return info.biomes.canSpawn(biome);
}

@Override
public String toString() {
return "UndergroundBiomeGenerator[" + info.biomeObj + "]";
Expand Down

0 comments on commit 23f9d68

Please sign in to comment.