Skip to content

Commit

Permalink
Minor updates for 1.19.
Browse files Browse the repository at this point in the history
* Update TerraBlender version
- Fix oak shrub placement in Desert Shrubland biome
* Simplify surface rules
* Clean up unused features
  • Loading branch information
gniftygnome committed Sep 21, 2022
1 parent bcc7161 commit 69723a5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.terraformersmc.traverse.feature;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.terraformersmc.traverse.Traverse;
import net.minecraft.block.Blocks;
import net.minecraft.util.Identifier;
Expand All @@ -11,15 +10,9 @@
import net.minecraft.world.gen.feature.ConfiguredFeatures;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.OreConfiguredFeatures;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.feature.RandomFeatureConfig;
import net.minecraft.world.gen.feature.RandomFeatureEntry;
import net.minecraft.world.gen.feature.RandomPatchFeatureConfig;
import net.minecraft.world.gen.feature.SimpleBlockFeatureConfig;
import net.minecraft.world.gen.feature.SingleStateFeatureConfig;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import net.minecraft.world.gen.feature.TreePlacedFeatures;
import net.minecraft.world.gen.stateprovider.BlockStateProvider;

import java.util.List;
Expand All @@ -34,13 +27,6 @@ public class TraverseConfiguredFeatures {
public static final RegistryEntry<ConfiguredFeature<TreeFeatureConfig, ?>> YELLOW_AUTUMNAL_TREE = register("yellow_autumnal_tree", Feature.TREE, TraverseFeatureConfigs.YELLOW_AUTUMNAL_TREE_CONFIG);
public static final RegistryEntry<ConfiguredFeature<TreeFeatureConfig, ?>> BROWN_AUTUMNAL_TREE = register("brown_autumnal_tree", Feature.TREE, TraverseFeatureConfigs.BROWN_AUTUMNAL_TREE_CONFIG);

/* Low Ores */
public static final RegistryEntry<ConfiguredFeature<OreFeatureConfig, ?>> LOW_DIRT = register("low_dirt", Feature.ORE, new OreFeatureConfig(OreConfiguredFeatures.BASE_STONE_OVERWORLD, Blocks.DIRT.getDefaultState(), 33));
public static final RegistryEntry<ConfiguredFeature<OreFeatureConfig, ?>> LOW_GRAVEL = register("low_gravel", Feature.ORE, new OreFeatureConfig(OreConfiguredFeatures.BASE_STONE_OVERWORLD, Blocks.GRAVEL.getDefaultState(), 33));
public static final RegistryEntry<ConfiguredFeature<OreFeatureConfig, ?>> LOW_GRANITE = register("low_granite", Feature.ORE, new OreFeatureConfig(OreConfiguredFeatures.BASE_STONE_OVERWORLD, Blocks.GRANITE.getDefaultState(), 33));
public static final RegistryEntry<ConfiguredFeature<OreFeatureConfig, ?>> LOW_DIORITE = register("low_diorite", Feature.ORE, new OreFeatureConfig(OreConfiguredFeatures.BASE_STONE_OVERWORLD, Blocks.DIORITE.getDefaultState(), 33));
public static final RegistryEntry<ConfiguredFeature<OreFeatureConfig, ?>> LOW_ANDESITE = register("low_andesite", Feature.ORE, new OreFeatureConfig(OreConfiguredFeatures.BASE_STONE_OVERWORLD, Blocks.ANDESITE.getDefaultState(), 33));

/* Fir Trees */
public static final RegistryEntry<ConfiguredFeature<TreeFeatureConfig, ?>> FIR_TREE = register("fir_tree", Feature.TREE, TraverseFeatureConfigs.FIR_TREE_CONFIG);

Expand All @@ -50,17 +36,6 @@ public class TraverseConfiguredFeatures {
/* Lush Vegetation */
public static final RegistryEntry<ConfiguredFeature<RandomPatchFeatureConfig, ?>> LUSH_FLOWERS = register("lush_flowers", Feature.FLOWER, TraverseFeatureConfigs.LUSH_FLOWER_CONFIG);
public static final RegistryEntry<ConfiguredFeature<RandomPatchFeatureConfig, ?>> FLATLANDS_GRASS = register("flatlands_grass", Feature.RANDOM_PATCH, ConfiguredFeatures.createRandomPatchFeatureConfig(Feature.SIMPLE_BLOCK, new SimpleBlockFeatureConfig(BlockStateProvider.of(Blocks.GRASS)), List.of(), 32));
public static final RegistryEntry<ConfiguredFeature<RandomPatchFeatureConfig, ?>> ROLLING_HILLS_GRASS = register("rolling_hills_grass", Feature.RANDOM_PATCH, ConfiguredFeatures.createRandomPatchFeatureConfig(Feature.SIMPLE_BLOCK, new SimpleBlockFeatureConfig(BlockStateProvider.of(Blocks.GRASS)), List.of(), 32));

/* Mini Jungle */
public static final RegistryEntry<ConfiguredFeature<RandomFeatureConfig, ?>> MINI_JUNGLE_TREES = register("mini_jungle_trees", Feature.RANDOM_SELECTOR,
new RandomFeatureConfig(
ImmutableList.of(new RandomFeatureEntry(TreePlacedFeatures.FANCY_OAK_CHECKED,0.1F)),
TreePlacedFeatures.JUNGLE_TREE
));

/* Rocky Edge */
public static final RegistryEntry<ConfiguredFeature<SingleStateFeatureConfig, ?>> ROCKY_EDGE_BOULDER = register("rocky_edge_boulder", Feature.FOREST_ROCK, new SingleStateFeatureConfig(Blocks.COBBLESTONE.getDefaultState()));

static <FC extends FeatureConfig, F extends Feature<FC>> RegistryEntry<ConfiguredFeature<FC, ?>> register(String id, F feature, FC config) {
return register(id, new ConfiguredFeature<>(feature, config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.gen.YOffset;
import net.minecraft.world.gen.blockpredicate.BlockPredicate;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.placementmodifier.*;
Expand All @@ -19,9 +18,8 @@

public class TraversePlacedFeatures {
/* Shrubs */
public static final RegistryEntry<PlacedFeature> ARID_SHRUBS = createPlacedFeature("arid_shrubs", TraverseConfiguredFeatures.OAK_SHRUB, PlacedFeatures.createCountExtraModifier(0, 0.5f, 1), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));
public static final RegistryEntry<PlacedFeature> DESERT_EXTRA_CACTUS = createPlacedFeature("desert_extra_cactus", VegetationConfiguredFeatures.PATCH_CACTUS, RarityFilterPlacementModifier.of(13), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BiomePlacementModifier.of());
public static final RegistryEntry<PlacedFeature> DESERT_SHRUBS = createPlacedFeature("desert_shrubs", TraverseConfiguredFeatures.OAK_SHRUB, PlacedFeatures.createCountExtraModifier(1, 0.1f, 1), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.SAND)));
public static final RegistryEntry<PlacedFeature> DESERT_SHRUBS = createPlacedFeature("desert_shrubs", TraverseConfiguredFeatures.OAK_SHRUB, PlacedFeatures.createCountExtraModifier(1, 0.1f, 1), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));

/* Autumnal Trees */
private static final RegistryEntry<PlacedFeature> RED_AUTUMNAL_TREE = createPlacedFeatureWithoutBiomeFilter("red_autumnal_tree", TraverseConfiguredFeatures.RED_AUTUMNAL_TREE);
Expand All @@ -41,33 +39,16 @@ public class TraversePlacedFeatures {
);
public static final RegistryEntry<PlacedFeature> AUTUMNAL_TREES = createPlacedFeature("autumnal_trees", AUTUMNAL_TREES_CONFIGURED, PlacedFeatures.createCountExtraModifier(10, 0.1f, 1), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));

/* Low Ores */
public static final RegistryEntry<PlacedFeature> LOW_DIRT = createPlacedFeature("low_dirt", TraverseConfiguredFeatures.LOW_DIRT, CountPlacementModifier.of(10), SquarePlacementModifier.of(), HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.aboveBottom(70)));
public static final RegistryEntry<PlacedFeature> LOW_GRAVEL = createPlacedFeature("low_gravel", TraverseConfiguredFeatures.LOW_GRAVEL, CountPlacementModifier.of(8), SquarePlacementModifier.of(), HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.aboveBottom(70)));
public static final RegistryEntry<PlacedFeature> LOW_GRANITE = createPlacedFeature("low_granite", TraverseConfiguredFeatures.LOW_GRANITE, CountPlacementModifier.of(10), SquarePlacementModifier.of(), HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.aboveBottom(70)));
public static final RegistryEntry<PlacedFeature> LOW_DIORITE = createPlacedFeature("low_diorite", TraverseConfiguredFeatures.LOW_DIORITE, CountPlacementModifier.of(10), SquarePlacementModifier.of(), HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.aboveBottom(70)));
public static final RegistryEntry<PlacedFeature> LOW_ANDESITE = createPlacedFeature("low_andesite", TraverseConfiguredFeatures.LOW_ANDESITE, CountPlacementModifier.of(10), SquarePlacementModifier.of(), HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.aboveBottom(70)));

/* Fir Trees */
public static final RegistryEntry<PlacedFeature> CONIFEROUS_TREES = createPlacedFeature("coniferous_trees", TraverseConfiguredFeatures.FIR_TREE, PlacedFeatures.createCountExtraModifier(7, 0.1f, 1), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));

/* Swamp Trees */
public static final RegistryEntry<PlacedFeature> TALL_SWAMP_TREE = createPlacedFeature("tall_swamp_tree", TraverseConfiguredFeatures.TALL_SWAMP_TREE, SurfaceWaterDepthFilterPlacementModifier.of(1));
public static final RegistryEntry<PlacedFeature> LUSH_SWAMP_TREES = createPlacedFeature("lush_swamp_trees", TraverseConfiguredFeatures.TALL_SWAMP_TREE, PlacedFeatures.createCountExtraModifier(2, 0.1f, 1), SquarePlacementModifier.of(), PlacedFeatures.OCEAN_FLOOR_HEIGHTMAP, SurfaceWaterDepthFilterPlacementModifier.of(3), BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));

/* Lush Vegetation */
public static final RegistryEntry<PlacedFeature> LUSH_FLOWERS = createPlacedFeature("lush_flowers", TraverseConfiguredFeatures.LUSH_FLOWERS, RarityFilterPlacementModifier.of(32), CountPlacementModifier.of(10), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));
public static final RegistryEntry<PlacedFeature> FLATLANDS_GRASS = createPlacedFeature("flatlands_grass", TraverseConfiguredFeatures.FLATLANDS_GRASS, VegetationPlacedFeatures.modifiers(15));
public static final RegistryEntry<PlacedFeature> FLATLANDS_TREES = createPlacedFeature("flatlands_trees", TreeConfiguredFeatures.OAK_BEES_005, PlacedFeatures.createCountExtraModifier(0, 0.2F, 1), BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));
public static final RegistryEntry<PlacedFeature> ROLLING_HILLS_GRASS = createPlacedFeature("rolling_hills_grass", TraverseConfiguredFeatures.ROLLING_HILLS_GRASS, VegetationPlacedFeatures.modifiers(3));
public static final RegistryEntry<PlacedFeature> ROLLING_HILLS_TREES = createPlacedFeature("rolling_hills_trees", TreeConfiguredFeatures.OAK_BEES_005, PlacedFeatures.createCountExtraModifier(2, 0.2f, 1), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));

/* Mini Jungle */
public static final RegistryEntry<PlacedFeature> MINI_JUNGLE_SEAGRASS = createPlacedFeature("mini_jungle_seagrass", OceanConfiguredFeatures.SEAGRASS_SHORT, PlacedFeatures.WORLD_SURFACE_WG_HEIGHTMAP);
public static final RegistryEntry<PlacedFeature> MINI_JUNGLE_TREES = createPlacedFeature("mini_jungle_trees", TraverseConfiguredFeatures.MINI_JUNGLE_TREES, PlacedFeatures.createCountExtraModifier(50, 0.1f, 1), SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BlockFilterPlacementModifier.of(BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.DIRT)));

/* Rocky Edge */
public static final RegistryEntry<PlacedFeature> ROCKY_EDGE_BOULDER = createPlacedFeature("rocky_edge_boulder", TraverseConfiguredFeatures.ROCKY_EDGE_BOULDER, CountPlacementModifier.of(2), SquarePlacementModifier.of(), PlacedFeatures.WORLD_SURFACE_WG_HEIGHTMAP);

/* Woodlands */
private static final RegistryEntry<ConfiguredFeature<RandomFeatureConfig, ?>> WOODLANDS_TREES_CONFIGURED = register("woodlands_trees", Feature.RANDOM_SELECTOR,
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ terraform_wood_api_version=4.1.1
fabric_version=0.60.0+1.19.2

# TerraBlender for worldgen module and testing
terrablender_version=1.19.2-2.0.1.125
terrablender_version=1.19.2-2.0.1.127

# Project Metadata
project_name=Traverse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
package com.terraformersmc.traverse.surfacerules;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.terraformersmc.traverse.Traverse;
import com.terraformersmc.traverse.biome.TraverseBiomes;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.CodecHolder;
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.gen.YOffset;
import net.minecraft.world.gen.noise.NoiseParametersKeys;
import net.minecraft.world.gen.surfacebuilder.MaterialRules;
import net.minecraft.world.gen.surfacebuilder.MaterialRules.MaterialRule;
import net.minecraft.world.gen.surfacebuilder.VanillaSurfaceRules;

import static net.minecraft.world.gen.surfacebuilder.MaterialRules.*;

Expand All @@ -26,50 +17,28 @@ private static MaterialRule block(Block block) {
}

public static MaterialRule createRules() {
MaterialRule defaultGrass = VanillaSurfaceRules.createDefaultRule(true, false, true);
MaterialRule sandAndSandstone = sequence(condition(MaterialRules.STONE_DEPTH_FLOOR_WITH_SURFACE_DEPTH,
block(Blocks.SAND)), block(Blocks.SANDSTONE));

// Sandy surface rules
MaterialRule sandAndSandstone = sequence(condition(STONE_DEPTH_FLOOR_WITH_SURFACE_DEPTH,
block(Blocks.SAND)), block(Blocks.SANDSTONE));
MaterialRule redSandAndSandstone = sequence(condition(STONE_DEPTH_FLOOR_WITH_SURFACE_DEPTH,
block(Blocks.RED_SAND)), block(Blocks.RED_SANDSTONE));

// Biome-level rules
MaterialRule desertShrubland = condition(MaterialRules.biome(TraverseBiomes.DESERT_SHRUBLAND),
new SandWithPatchesSurfaceRule(0.01D, NoiseParametersKeys.BADLANDS_SURFACE, sandAndSandstone, defaultGrass));
condition(noiseThreshold(NoiseParametersKeys.BADLANDS_SURFACE, 0.01D), sandAndSandstone));
MaterialRule lushSwamp = condition(MaterialRules.biome(TraverseBiomes.LUSH_SWAMP),
condition(MaterialRules.STONE_DEPTH_FLOOR,
condition(MaterialRules.aboveY(YOffset.fixed(62), 0),
condition(MaterialRules.not(MaterialRules.aboveY(YOffset.fixed(63), 0)),
condition(MaterialRules.noiseThreshold(NoiseParametersKeys.SURFACE_SWAMP, 0.0),
block(Blocks.WATER))))));

return sequence(condition(MaterialRules.surface(), sequence(desertShrubland, lushSwamp, defaultGrass)), defaultGrass);
condition(MaterialRules.STONE_DEPTH_FLOOR,
condition(MaterialRules.aboveY(YOffset.fixed(62), 0),
condition(MaterialRules.not(MaterialRules.aboveY(YOffset.fixed(63), 0)),
condition(MaterialRules.noiseThreshold(NoiseParametersKeys.SURFACE_SWAMP, 0.0),
block(Blocks.WATER))))));

// Return a surface-only sequence of our surface rules
return condition(surface(),
sequence(desertShrubland, lushSwamp));
}

public static void register() {
Registry.register(Registry.MATERIAL_RULE, new Identifier(Traverse.MOD_ID, "sand_with_patches"), SandWithPatchesSurfaceRule.CODEC.codec());
}

record SandWithPatchesSurfaceRule(double threshold, RegistryKey<DoublePerlinNoiseSampler.NoiseParameters> noise, MaterialRule thenRun, MaterialRule elseRun) implements MaterialRule {
static final CodecHolder<SandWithPatchesSurfaceRule> CODEC = CodecHolder.of(RecordCodecBuilder.mapCodec(instance -> instance.group(Codec.DOUBLE.fieldOf("threshold").forGetter(SandWithPatchesSurfaceRule::threshold),
RegistryKey.createCodec(Registry.NOISE_KEY).fieldOf("noise").forGetter(SandWithPatchesSurfaceRule::noise),
MaterialRule.CODEC.fieldOf("then_run").forGetter(SandWithPatchesSurfaceRule::thenRun),
MaterialRule.CODEC.fieldOf("else_run").forGetter(SandWithPatchesSurfaceRule::elseRun)).apply(instance, SandWithPatchesSurfaceRule::new)));

@Override
public CodecHolder<? extends MaterialRule> codec() {
return CODEC;
}

@Override
public MaterialRules.BlockStateRule apply(final MaterialRules.MaterialRuleContext context) {
MaterialRules.BlockStateRule followup1 = thenRun.apply(context);
MaterialRules.BlockStateRule followup2 = elseRun.apply(context);
final DoublePerlinNoiseSampler doublePerlinNoiseSampler = context.noiseConfig.getOrCreateSampler(this.noise);
return (x, y, z) -> {
double noise = doublePerlinNoiseSampler.sample(x, 0.0, z);
if (noise > threshold){
return followup1.tryApply(x, y, z);
} else {
return followup2.tryApply(x, y, z);
}
};
}
}
}

0 comments on commit 69723a5

Please sign in to comment.