Skip to content

Commit

Permalink
Cut some unused worldgen stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Dec 20, 2023
1 parent 1be2ef6 commit cee04ed
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import org.jetbrains.annotations.NotNull;

import org.violetmoon.quark.base.world.generator.IGenerator;
import org.violetmoon.quark.base.world.generator.Generator;
import org.violetmoon.zeta.module.ZetaModule;

public record WeightedGenerator(ZetaModule module,
IGenerator generator,
Generator generator,
int weight) implements Comparable<WeightedGenerator> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.handler.GeneralConfig;
import org.violetmoon.quark.base.world.generator.IGenerator;
import org.violetmoon.quark.base.world.generator.Generator;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZRegister;
import org.violetmoon.zeta.module.ZetaModule;
Expand All @@ -41,17 +41,15 @@

public class WorldGenHandler {

private static final Map<GenerationStep.Decoration, Holder<PlacedFeature>> defers = new HashMap<>();
private static final Map<GenerationStep.Decoration, SortedSet<WeightedGenerator>> generators = new HashMap<>();
private static final Map<GenerationStep.Decoration, Holder<PlacedFeature>> defers = new EnumMap<>(GenerationStep.Decoration.class);
private static final Map<GenerationStep.Decoration, SortedSet<WeightedGenerator>> generators = new EnumMap<>(GenerationStep.Decoration.class);

@LoadEvent
public static void register(ZRegister event) {
for(GenerationStep.Decoration stage : GenerationStep.Decoration.values()) {
Feature<NoneFeatureConfiguration> deferredFeature = new DeferredFeature(stage);

// Always do .toLowerCase(Locale.ENGLISH) with that locale. If you leave it off, computers in
// countries like Turkey will use a special character instead of i and well, crash the ResourceLocation.
String name = "deferred_feature_" + stage.name().toLowerCase(Locale.ENGLISH);
String name = "deferred_feature_" + stage.name().toLowerCase(Locale.ROOT);
Quark.ZETA.registry.register(deferredFeature, name, Registries.FEATURE);

ConfiguredFeature<?, ?> feature = new ConfiguredFeature<>(deferredFeature, FeatureConfiguration.NONE);
Expand All @@ -75,7 +73,7 @@ public static void modifyBiome(Holder<Biome> biome, ModifiableBiomeInfo.BiomeInf
}
}

public static void addGenerator(ZetaModule module, IGenerator generator, GenerationStep.Decoration stage, int weight) {
public static void addGenerator(ZetaModule module, Generator generator, GenerationStep.Decoration stage, int weight) {
WeightedGenerator weighted = new WeightedGenerator(module, generator, weight);
if(!generators.containsKey(stage))
generators.put(stage, new TreeSet<>());
Expand All @@ -100,7 +98,7 @@ public static void generateChunk(FeaturePlaceContext<NoneFeatureConfiguration> c
SortedSet<WeightedGenerator> set = generators.get(stage);

for(WeightedGenerator wgen : set) {
IGenerator gen = wgen.generator();
Generator gen = wgen.generator();

if(wgen.module().enabled && gen.canGenerate(region)) {
if(GeneralConfig.enableWorldgenWatchdog) {
Expand All @@ -113,7 +111,7 @@ public static void generateChunk(FeaturePlaceContext<NoneFeatureConfiguration> c
}
}

private static int watchdogRun(IGenerator gen, Callable<Integer> run, int time, TimeUnit unit) {
private static int watchdogRun(Generator gen, Callable<Integer> run, int time, TimeUnit unit) {
ExecutorService exec = Executors.newSingleThreadExecutor();
Future<Integer> future = exec.submit(run);
exec.shutdown();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.util.function.BooleanSupplier;

public abstract class Generator implements IGenerator {
public abstract class Generator {

public final DimensionConfig dimConfig;
private final BooleanSupplier condition;
Expand All @@ -30,7 +30,6 @@ public Generator(DimensionConfig dimConfig, BooleanSupplier condition) {
this.condition = condition;
}

@Override
public final int generate(int seedIncrement, long seed, GenerationStep.Decoration stage, WorldGenRegion worldIn, ChunkGenerator generator, WorldgenRandom rand, BlockPos pos) {
rand.setFeatureSeed(seed, seedIncrement, stage.ordinal());
generateChunk(worldIn, generator, rand, pos);
Expand All @@ -39,7 +38,6 @@ public final int generate(int seedIncrement, long seed, GenerationStep.Decoratio

public abstract void generateChunk(WorldGenRegion worldIn, ChunkGenerator generator, RandomSource rand, BlockPos pos);

@Override
public boolean canGenerate(ServerLevelAccessor world) {
return condition.getAsBoolean() && dimConfig.canSpawnHere(world.getLevel());
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public void generateChunkPart(BlockPos src, ChunkGenerator generator, Random ran
if(noise > 0)
context.consume(pos, noise);
});

if(context instanceof IFinishableContext finishableContext)
finishableContext.finish();
}

public abstract IGenerationContext createContext(BlockPos src, ChunkGenerator generator, Random random, BlockPos chunkCorner, WorldGenRegion world);
Expand All @@ -50,8 +47,4 @@ public interface IGenerationContext {
void consume(BlockPos pos, double noise);
}

public interface IFinishableContext extends IGenerationContext {
void finish();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ public boolean isSourceValid(WorldGenRegion world, ChunkGenerator generator, Blo
public void forEachChunkBlock(LevelReader level, BlockPos chunkCorner, int minY, int maxY, Consumer<BlockPos> func) {
minY = Math.max(level.getMinBuildHeight() + 1, minY);
maxY = Math.min(level.getMaxBuildHeight() - 1, maxY);
int chunkCornerX = chunkCorner.getX(); //hoisting out of loop
int chunkCornerZ = chunkCorner.getZ();

BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos(0, 0, 0);
for(int x = 0; x < 16; x++)
for(int y = minY; y < maxY; y++)
for(int z = 0; z < 16; z++) {
mutable.set(chunkCorner.getX() + x, y, chunkCorner.getZ() + z);
mutable.set(chunkCornerX + x, y, chunkCornerZ + z);
func.accept(mutable);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package org.violetmoon.quark.content.world.undergroundstyle.base;

import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;

import net.minecraft.world.level.levelgen.Heightmap;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.handler.MiscUtil;
import org.violetmoon.quark.content.world.undergroundstyle.base.UndergroundStyleGenerator.Context;
Expand All @@ -19,19 +18,8 @@

public abstract class UndergroundStyle {

private static TagKey<Block> fillerTag = null;

public static final Predicate<BlockState> STONE_TYPES_MATCHER = (state) -> {
if(state == null)
return false;

if(fillerTag == null)
fillerTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "underground_biome_replaceable"));

return state.is(fillerTag);
};

public double dungeonChance;
private static final TagKey<Block> fillerTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "underground_biome_replaceable"));
public static final Predicate<BlockState> UNDERGROUND_BIOME_REPLACEABLE = state -> state != null && state.is(fillerTag);

public final void fill(Context context, BlockPos pos) {
LevelAccessor world = context.world;
Expand All @@ -40,55 +28,35 @@ public final void fill(Context context, BlockPos pos) {
if(state.getDestroySpeed(world, pos) == -1)
return;

boolean shrouded = false;
BlockPos testPos = new MutableBlockPos(pos.getX(), pos.getY(), pos.getZ());
while(!world.isOutsideBuildHeight(testPos)) {
testPos = testPos.above();
if(world.getBlockState(testPos).isSolidRender(world, testPos)) {
shrouded = true;
break;
}
}

if(!shrouded)
//boolean shrouded = false;
//BlockPos testPos = new MutableBlockPos(pos.getX(), pos.getY(), pos.getZ());
//while(!world.isOutsideBuildHeight(testPos)) {
// testPos = testPos.above();
// if(world.getBlockState(testPos).isSolidRender(world, testPos)) {
// shrouded = true;
// break;
// }
//}
//if(!shrouded)
// return;
if(world.getHeight(Heightmap.Types.WORLD_SURFACE_WG, pos.getX(), pos.getZ()) >= pos.getY())
return;

if(isFloor(world, pos, state)) {
context.floorList.add(pos);
if(isFloor(world, pos, state))
fillFloor(context, pos, state);
} else if(isCeiling(world, pos, state)) {
context.ceilingList.add(pos);
else if(isCeiling(world, pos, state))
fillCeiling(context, pos, state);
} else if(isWall(world, pos, state)) {
context.wallMap.put(pos, getBorderSide(world, pos));
else if(isWall(world, pos, state))
fillWall(context, pos, state);
} else if(isInside(state)) {
context.insideList.add(pos);
else if(isInside(state))
fillInside(context, pos, state);
}
}

public abstract void fillFloor(Context context, BlockPos pos, BlockState state);
public abstract void fillCeiling(Context context, BlockPos pos, BlockState state);
public abstract void fillWall(Context context, BlockPos pos, BlockState state);
public abstract void fillInside(Context context, BlockPos pos, BlockState state);

public void finalFloorPass(Context context, BlockPos pos) {
// NO-OP
}

public void finalCeilingPass(Context context, BlockPos pos) {
// NO-OP
}

public void finalWallPass(Context context, BlockPos pos) {
// NO-OP
}

public void finalInsidePass(Context context, BlockPos pos) {
// NO-OP
}

public boolean isFloor(LevelAccessor world, BlockPos pos, BlockState state) {
if(!state.isSolidRender(world, pos))
return false;
Expand All @@ -106,7 +74,7 @@ public boolean isCeiling(LevelAccessor world, BlockPos pos, BlockState state) {
}

public boolean isWall(LevelAccessor world, BlockPos pos, BlockState state) {
if(!state.isSolidRender(world, pos) || !STONE_TYPES_MATCHER.test(state))
if(!state.isSolidRender(world, pos) || !UNDERGROUND_BIOME_REPLACEABLE.test(state))
return false;

return isBorder(world, pos);
Expand All @@ -130,16 +98,7 @@ public boolean isBorder(LevelAccessor world, BlockPos pos) {
}

public boolean isInside(BlockState state) {
return STONE_TYPES_MATCHER.test(state);
}

public static Rotation rotationFromFacing(Direction facing) {
return switch(facing) {
case SOUTH -> Rotation.CLOCKWISE_180;
case WEST -> Rotation.COUNTERCLOCKWISE_90;
case EAST -> Rotation.CLOCKWISE_90;
default -> Rotation.NONE;
};
return UNDERGROUND_BIOME_REPLACEABLE.test(state);
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package org.violetmoon.quark.content.world.undergroundstyle.base;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;

import org.violetmoon.quark.base.world.generator.multichunk.ClusterBasedGenerator;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class UndergroundStyleGenerator<T extends UndergroundStyle> extends ClusterBasedGenerator {
Expand Down Expand Up @@ -57,20 +52,14 @@ public String toString() {
return "UndergroundBiomeGenerator[" + info.biomeObj + "]";
}

public static class Context implements IFinishableContext {
public static class Context implements IGenerationContext {

public final WorldGenRegion world;
public final BlockPos source;
public final ChunkGenerator generator;
public final Random random;
public final UndergroundStyleConfig<?> info;

public final List<BlockPos> floorList = new LinkedList<>();
public final List<BlockPos> ceilingList = new LinkedList<>();
public final List<BlockPos> insideList = new LinkedList<>();

public final Map<BlockPos, Direction> wallMap = new HashMap<>();

public Context(WorldGenRegion world, BlockPos source, ChunkGenerator generator, Random random, UndergroundStyleConfig<?> info) {
this.world = world;
this.source = source;
Expand All @@ -84,13 +73,5 @@ public void consume(BlockPos pos, double noise) {
info.biomeObj.fill(this, pos);
}

@Override
public void finish() {
floorList.forEach(pos -> info.biomeObj.finalFloorPass(this, pos));
ceilingList.forEach(pos -> info.biomeObj.finalCeilingPass(this, pos));
wallMap.keySet().forEach(pos -> info.biomeObj.finalWallPass(this, pos));
insideList.forEach(pos -> info.biomeObj.finalInsidePass(this, pos));
}

}
}

0 comments on commit cee04ed

Please sign in to comment.