feat: bukkit metapacks and clean up

This commit is contained in:
Zoe Gidiere committed 2026-11-09 19:42:48 -07:00
1 parent dcf38956c4
commit 02c2176222
36 files changed
+1026 -230

No files matched your search

@@ -17,51 +17,18 @@
package com.dfsek.terra.mod.config;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.terra.api.properties.Properties;
import com.dfsek.terra.minecraft.config.MinecraftCompatibilityOptions;
@SuppressWarnings("FieldMayBeFinal")
public class PreLoadCompatibilityOptions implements ConfigTemplate, Properties {
@Value("minecraft.use-vanilla-biomes")
@Default
private boolean vanillaBiomes = false;
@Value("minecraft.beard.enable")
@Default
private boolean beard = true;
@Value("minecraft.beard.threshold")
@Default
private double beardThreshold = 0.5;
@Value("minecraft.beard.air-threshold")
@Default
private double airThreshold = -0.5;
public class PreLoadCompatibilityOptions extends MinecraftCompatibilityOptions {
@Value("minecraft.inject-flora")
@Default
private boolean injectFlora = false;
public boolean useVanillaBiomes() {
return vanillaBiomes;
}
public boolean isBeard() {
return beard;
}
public double getBeardThreshold() {
return beardThreshold;
}
public double getAirThreshold() {
return airThreshold;
}
public boolean isInjectFlora() {
return injectFlora;
}
@@ -51,7 +51,7 @@ public final class Codecs {
TERRA_CONSTANT_RANGE.fieldOf("height").stable().forGetter(GenerationSettings::height),
Codec.INT.fieldOf("sea_level").forGetter(GenerationSettings::sealevel),
Codec.BOOL.fieldOf("mob_generation").forGetter(GenerationSettings::mobGeneration),
Codec.INT.fieldOf("spawn_height").forGetter(GenerationSettings::sealevel))
Codec.INT.fieldOf("spawn_height").forGetter(GenerationSettings::spawnHeight))
.apply(instance, instance.stable(GenerationSettings::new)));
@@ -18,7 +18,6 @@
package com.dfsek.terra.mod.generation;
import com.mojang.serialization.MapCodec;
import net.minecraft.commands.arguments.blocks.BlockInput;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.server.level.WorldGenRegion;
@@ -31,10 +30,8 @@ import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.Beardifier;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.RandomState;
@@ -57,7 +54,7 @@ import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
import com.dfsek.terra.api.world.chunk.generation.stage.Chunkified;
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.api.world.info.WorldProperties;
import com.dfsek.terra.minecraft.generation.TerraTerrain;
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.mod.data.Codecs;
import com.dfsek.terra.mod.mixin.access.StructureManagerAccessor;
@@ -109,51 +106,12 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.ch
BiomeProvider biomeProvider = pack.getBiomeProvider();
delegate.generateChunkData((ProtoChunk) chunk, world, biomeProvider, chunk.getPos().x(), chunk.getPos().z());
PreLoadCompatibilityOptions compatibilityOptions = pack.getContext().get(PreLoadCompatibilityOptions.class);
if(compatibilityOptions.isBeard()) {
beard(structureAccessor, chunk, world, biomeProvider, compatibilityOptions);
}
TerraTerrain.beard(chunk, structureAccessor, delegate, biomeProvider, world,
pack.getContext().get(PreLoadCompatibilityOptions.class), MinecraftChunkGeneratorWrapper::vanilla);
return chunk;
}, Util.backgroundExecutor());
}
private void beard(StructureManager structureAccessor, ChunkAccess chunk, WorldProperties world, BiomeProvider biomeProvider,
PreLoadCompatibilityOptions compatibilityOptions) {
Beardifier structureWeightSampler = Beardifier.forStructuresInChunk(structureAccessor,
chunk.getPos());
double threshold = compatibilityOptions.getBeardThreshold();
double airThreshold = compatibilityOptions.getAirThreshold();
int xi = chunk.getPos().x() << 4;
int zi = chunk.getPos().z() << 4;
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
int depth = 0;
for(int y = world.getMaxHeight(); y >= world.getMinHeight(); y--) {
double noise = structureWeightSampler.sampleValue(SamplerContext.EMPTY_UNCACHED, x + xi, y, z + zi);
if(noise > threshold) {
com.dfsek.terra.api.block.state.BlockState data = delegate.getPalette(x + xi, y, z + zi, world, biomeProvider).get(
depth, x + xi, y, z + zi, world.getSeed());
BlockPos blockPos = new BlockPos(x, y, z);
boolean isExtended = data.isExtended() && data.getClass().equals(BlockInput.class);
if(isExtended) {
BlockStateExtended blockStateExtended = (BlockStateExtended) data;
net.minecraft.world.level.block.state.BlockState blockState = (net.minecraft.world.level.block.state.BlockState) blockStateExtended.getState();
chunk.setBlockState(blockPos, blockState, 0);
} else {
chunk.setBlockState(blockPos, (net.minecraft.world.level.block.state.BlockState) data, 0);
}
depth++;
} else if(noise < airThreshold) {
chunk.setBlockState(new BlockPos(x, y, z), Blocks.AIR.defaultBlockState(), 0);
} else {
depth = 0;
}
}
}
}
}
@Override
public void applyBiomeDecoration(WorldGenLevel world, ChunkAccess chunk, StructureManager structureAccessor) {
super.applyBiomeDecoration(world, chunk, structureAccessor);
@@ -186,32 +144,18 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.level.ch
@Override
public int getBaseHeight(int x, int z, Types heightmap, LevelHeightAccessor height, RandomState noiseConfig) {
WorldProperties properties = MinecraftAdapter.adapt(height, noiseConfig.seed());
BiomeProvider biomeProvider = pack.getBiomeProvider();
int min = height.getMinY();
for(int y = height.getMaxY() - 1; y >= min; y--) {
com.dfsek.terra.api.block.state.BlockState terraBlockState = delegate.getBlock(properties, x, y, z, biomeProvider);
BlockState blockState =
(BlockState) (terraBlockState.isExtended() ? ((BlockStateExtended) terraBlockState).getState() : terraBlockState);
if(heightmap
.isOpaque()
.test(blockState)) return y + 1;
}
return min;
return TerraTerrain.baseHeight(delegate, pack.getBiomeProvider(), MinecraftAdapter.adapt(height, noiseConfig.seed()), height, x, z,
heightmap.isOpaque(), MinecraftChunkGeneratorWrapper::vanilla);
}
@Override
public NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor height, RandomState noiseConfig) {
BlockState[] array = new BlockState[height.getHeight()];
WorldProperties properties = MinecraftAdapter.adapt(height, noiseConfig.seed());
BiomeProvider biomeProvider = pack.getBiomeProvider();
for(int y = height.getMaxY() - 1; y >= height.getMinY(); y--) {
com.dfsek.terra.api.block.state.BlockState terraBlockState = delegate.getBlock(properties, x, y, z, biomeProvider);
BlockState blockState =
(BlockState) (terraBlockState.isExtended() ? ((BlockStateExtended) terraBlockState).getState() : terraBlockState);
array[y - height.getMinY()] = blockState;
}
return new NoiseColumn(height.getMinY(), array);
return TerraTerrain.baseColumn(delegate, pack.getBiomeProvider(), MinecraftAdapter.adapt(height, noiseConfig.seed()), height, x, z,
MinecraftChunkGeneratorWrapper::vanilla);
}
private static BlockState vanilla(com.dfsek.terra.api.block.state.BlockState state) {
return (BlockState) (state.isExtended() ? ((BlockStateExtended) state).getState() : state);
}
@Override
@@ -1,33 +1,19 @@
package com.dfsek.terra.mod.util;
import net.minecraft.resources.Identifier;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.minecraft.attribute.BiomeTags.PlatformTagSource;
import com.dfsek.terra.minecraft.attribute.TerraBiomeIndex;
public class BiomeUtil {
public static final Map<Identifier, List<Identifier>>
TERRA_BIOME_MAP = new HashMap<>();
public final class BiomeUtil {
private static volatile TerraBiomeIndex terraBiomes = new TerraBiomeIndex();
public static final Map<Identifier, PlatformTagSource>
TERRA_BIOME_PLATFORM_TAGS = new HashMap<>();
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
return pack.getID()
.toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT);
private BiomeUtil() {
}
public static Map<Identifier, List<Identifier>> getTerraBiomeMap() {
return Map.copyOf(TERRA_BIOME_MAP);
public static TerraBiomeIndex terraBiomes() {
return terraBiomes;
}
public static Map<Identifier, PlatformTagSource> getTerraBiomePlatformTags() {
return Map.copyOf(TERRA_BIOME_PLATFORM_TAGS);
public static void setTerraBiomes(TerraBiomeIndex biomes) {
terraBiomes = biomes;
}
}
@@ -38,6 +38,7 @@ import com.dfsek.terra.api.block.entity.Sign;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.util.range.ConstantRange;
import com.dfsek.terra.minecraft.attribute.MinecraftBiomeFactory;
import com.dfsek.terra.mod.CommonPlatform;
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
@@ -133,7 +134,7 @@ public final class MinecraftUtil {
ResourceKey<net.minecraft.world.level.biome.Biome> vanillaKey = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(biomeRegistry);
biomeRegistry.getOptional(vanillaKey)
.ifPresentOrElse(vanillaBiome -> {
Identifier terraBiomeIdentifier = Identifier.fromNamespaceAndPath("terra", BiomeUtil.createBiomeID(pack, id));
Identifier terraBiomeIdentifier = MinecraftBiomeFactory.terraId(pack, id);
biomeRegistry.getOptional(terraBiomeIdentifier).ifPresentOrElse(
terraBiome -> {
List<Feature> flowerFeatures = List.copyOf(
@@ -105,8 +105,7 @@ public class PresetUtil {
Identifier demensionIdentifier = Identifier.parse(key);
MinecraftAttributeParents parents = platform.attributeParents();
VanillaContext context = parents.context();
if(context == null) throw new IllegalStateException("no registry load has begun");
VanillaContext context = parents.requireContext();
ResourceKey<DimensionType> filled = MinecraftUtil.registerDimensionTypeKey(demensionIdentifier);
if(context.dimensionTypes().get(filled).isEmpty()) filled = BuiltinDimensionTypes.OVERWORLD;
PackParents packParents = parents.prepare(pack, platform.getAttributeHandle().pack(pack), AttributeReport.logging(pack), filled);
@@ -73,8 +73,7 @@ public final class TagUtil {
logger.info("Doing biome tag garbage....");
Map<TagKey<Biome>, List<Holder<Biome>>> collect = tagsToMutableMap(registry);
BiomeTags.addTerraBiomes(collect, id -> MinecraftUtil.getEntry(registry, id), BiomeUtil.getTerraBiomeMap(),
BiomeUtil.getTerraBiomePlatformTags());
BiomeTags.addTerraBiomes(collect, id -> MinecraftUtil.getEntry(registry, id), BiomeUtil.terraBiomes());
registry.prepareTagReload(new LoadResult<>(registry.key(), collect)).apply();