Skip to content

Commit

Permalink
Backport some improvements from Cinderscapes.
Browse files Browse the repository at this point in the history
* Move more registration to TerrestriaRegistry
* More AbstractBlock.Settings.copy I missed before
  • Loading branch information
gniftygnome committed Feb 29, 2024
1 parent c519f63 commit 5d8b0a1
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 122 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package com.terraformersmc.terrestria.init;

import com.mojang.serialization.Codec;
import com.terraformersmc.terrestria.Terrestria;
import com.terraformersmc.terrestria.feature.CattailFeature;
import com.terraformersmc.terrestria.feature.misc.DumDumHeadFeature;
import com.terraformersmc.terrestria.feature.tree.treeconfigs.QuarteredMegaTreeConfig;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import com.terraformersmc.terrestria.init.helpers.TerrestriaRegistry;
import net.minecraft.world.gen.ProbabilityConfig;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.TreeFeature;

// This class exports public feature constants, these fields have to be public
@SuppressWarnings("WeakerAccess")
public class TerrestriaFeatures {

public static CattailFeature CATTAIL;
Expand All @@ -24,14 +18,10 @@ public class TerrestriaFeatures {

@SuppressWarnings({"rawtypes, unchecked"})
public static void init() {
CATTAIL = register("cattail", new CattailFeature(ProbabilityConfig.CODEC, TerrestriaBlocks.CATTAIL, TerrestriaBlocks.TALL_CATTAIL));
DUM_DUM_HEAD = register("dum_dum_head", new DumDumHeadFeature(DefaultFeatureConfig.CODEC));
CATTAIL = TerrestriaRegistry.register("cattail", new CattailFeature(ProbabilityConfig.CODEC, TerrestriaBlocks.CATTAIL, TerrestriaBlocks.TALL_CATTAIL));
DUM_DUM_HEAD = TerrestriaRegistry.register("dum_dum_head", new DumDumHeadFeature(DefaultFeatureConfig.CODEC));

// Super hacky casts, but it works
QUARTERED_MEGA_TREE = register("quartered_mega_tree", new TreeFeature((Codec) QuarteredMegaTreeConfig.CODEC));
}

public static <T extends Feature<FC>, FC extends FeatureConfig> T register(String name, T feature) {
return Registry.register(Registries.FEATURE, new Identifier(Terrestria.MOD_ID, name), feature);
QUARTERED_MEGA_TREE = TerrestriaRegistry.register("quartered_mega_tree", new TreeFeature((Codec) QuarteredMegaTreeConfig.CODEC));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.terraformersmc.terrestria.Terrestria;
import com.terraformersmc.terrestria.init.helpers.SurfaceLevelFilterPlacementModifier;
import com.terraformersmc.terrestria.init.helpers.TerrestriaRegistry;
import net.minecraft.registry.Registerable;
import net.minecraft.registry.RegistryEntryLookup;
import net.minecraft.registry.RegistryKey;
Expand Down Expand Up @@ -81,56 +82,56 @@ public static void bootstrap(Registerable<PlacedFeature> registerable) {
final BlockPredicate ON_SAND = BlockPredicate.matchingBlockTag(Direction.DOWN.getVector(), BlockTags.SAND);
final BlockPredicate ON_DIRT_OR_SAND = BlockPredicate.eitherOf(ON_DIRT, ON_SAND);

register(registerable, CATTAILS_WARM, TerrestriaConfiguredFeatures.CATTAIL,
TerrestriaRegistry.register(registerable, CATTAILS_WARM, TerrestriaConfiguredFeatures.CATTAIL,
CountPlacementModifier.of(80),
SquarePlacementModifier.of(),
PlacedFeatures.OCEAN_FLOOR_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT_OR_SAND),
BiomePlacementModifier.of());

register(registerable, SPARSE_OAK_SHRUBS, TerrestriaConfiguredFeatures.OAK_SHRUB,
TerrestriaRegistry.register(registerable, SPARSE_OAK_SHRUBS, TerrestriaConfiguredFeatures.OAK_SHRUB,
PlacedFeatures.createCountExtraModifier(1, 0.1f, 1),
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT),
BiomePlacementModifier.of());

register(registerable, PATCH_LUSH_FERNS, VegetationConfiguredFeatures.PATCH_TAIGA_GRASS,
TerrestriaRegistry.register(registerable, PATCH_LUSH_FERNS, VegetationConfiguredFeatures.PATCH_TAIGA_GRASS,
CountPlacementModifier.of(16),
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT),
BiomePlacementModifier.of());

register(registerable, PATCH_VOLCANIC_ISLAND_GRASS, TerrestriaConfiguredFeatures.PATCH_VOLCANIC_ISLAND_GRASS,
TerrestriaRegistry.register(registerable, PATCH_VOLCANIC_ISLAND_GRASS, TerrestriaConfiguredFeatures.PATCH_VOLCANIC_ISLAND_GRASS,
CountPlacementModifier.of(12),
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT),
BiomePlacementModifier.of());

register(registerable, PATCH_DEAD_GRASS, TerrestriaConfiguredFeatures.PATCH_DEAD_GRASS,
TerrestriaRegistry.register(registerable, PATCH_DEAD_GRASS, TerrestriaConfiguredFeatures.PATCH_DEAD_GRASS,
CountPlacementModifier.of(12),
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT_OR_SAND),
BiomePlacementModifier.of());

register(registerable, PATCH_OUTBACK_BUSHLAND_GRASS, TerrestriaConfiguredFeatures.PATCH_OUTBACK_BUSHLAND_GRASS,
TerrestriaRegistry.register(registerable, PATCH_OUTBACK_BUSHLAND_GRASS, TerrestriaConfiguredFeatures.PATCH_OUTBACK_BUSHLAND_GRASS,
CountPlacementModifier.of(12),
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT_OR_SAND),
BiomePlacementModifier.of());

register(registerable, PATCH_OASIS_VEGETATION, TerrestriaConfiguredFeatures.PATCH_OASIS_VEGETATION,
TerrestriaRegistry.register(registerable, PATCH_OASIS_VEGETATION, TerrestriaConfiguredFeatures.PATCH_OASIS_VEGETATION,
CountPlacementModifier.of(6),
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT_OR_SAND),
BiomePlacementModifier.of());

register(registerable, PATCH_LUSH_DESERT_VEGETATION, TerrestriaConfiguredFeatures.PATCH_LUSH_DESERT_VEGETATION,
TerrestriaRegistry.register(registerable, PATCH_LUSH_DESERT_VEGETATION, TerrestriaConfiguredFeatures.PATCH_LUSH_DESERT_VEGETATION,
CountPlacementModifier.of(4),
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
Expand All @@ -153,15 +154,15 @@ public static void bootstrap(Registerable<PlacedFeature> registerable) {

registerTreeFeature(registerable, SPARSE_SMALL_REDWOOD_TREES, 1, ON_DIRT, TerrestriaConfiguredFeatures.SMALL_REDWOOD_TREE);

register(registerable, CALDERA_SMALL_HEMLOCK_TREES, TerrestriaConfiguredFeatures.SMALL_HEMLOCK_TREE,
TerrestriaRegistry.register(registerable, CALDERA_SMALL_HEMLOCK_TREES, TerrestriaConfiguredFeatures.SMALL_HEMLOCK_TREE,
PlacedFeatures.createCountExtraModifier(1, 0.1f, 1),
SquarePlacementModifier.of(),
SurfaceLevelFilterPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG, 80, 320),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT),
BiomePlacementModifier.of());

register(registerable, CALDERA_SMALL_REDWOOD_TREES, TerrestriaConfiguredFeatures.SMALL_REDWOOD_TREE,
TerrestriaRegistry.register(registerable, CALDERA_SMALL_REDWOOD_TREES, TerrestriaConfiguredFeatures.SMALL_REDWOOD_TREE,
PlacedFeatures.createCountExtraModifier(1, 0.1f, 1),
SquarePlacementModifier.of(),
SurfaceLevelFilterPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG, 80, 320),
Expand All @@ -177,15 +178,15 @@ public static void bootstrap(Registerable<PlacedFeature> registerable) {

registerTreeFeature(registerable, SPARSE_REDWOOD_TREES, 1, ON_DIRT, TerrestriaConfiguredFeatures.REDWOOD_TREE);

register(registerable, CALDERA_HEMLOCK_TREES, TerrestriaConfiguredFeatures.HEMLOCK_TREE,
TerrestriaRegistry.register(registerable, CALDERA_HEMLOCK_TREES, TerrestriaConfiguredFeatures.HEMLOCK_TREE,
PlacedFeatures.createCountExtraModifier(1, 0.1f, 1),
SquarePlacementModifier.of(),
SurfaceLevelFilterPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG, 64, 100),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT),
BiomePlacementModifier.of());

register(registerable, CALDERA_REDWOOD_TREES, TerrestriaConfiguredFeatures.REDWOOD_TREE,
TerrestriaRegistry.register(registerable, CALDERA_REDWOOD_TREES, TerrestriaConfiguredFeatures.REDWOOD_TREE,
PlacedFeatures.createCountExtraModifier(1, 0.1f, 1),
SquarePlacementModifier.of(),
SurfaceLevelFilterPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG, 64, 100),
Expand Down Expand Up @@ -223,23 +224,23 @@ public static void bootstrap(Registerable<PlacedFeature> registerable) {

registerTreeFeature(registerable, DENSEST_FANCY_OAK_TREES, 7, ON_DIRT, TreeConfiguredFeatures.FANCY_OAK);

register(registerable, JUNGLE_PALM_TREES, TerrestriaConfiguredFeatures.JUNGLE_PALM_TREE,
TerrestriaRegistry.register(registerable, JUNGLE_PALM_TREES, TerrestriaConfiguredFeatures.JUNGLE_PALM_TREE,
PlacedFeatures.createCountExtraModifier(2, 0.1f, 1),
SquarePlacementModifier.of(),
SurfaceLevelFilterPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG, 62, 71),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT_OR_SAND),
BiomePlacementModifier.of());

register(registerable, DENSER_JUNGLE_PALM_TREES, TerrestriaConfiguredFeatures.JUNGLE_PALM_TREE,
TerrestriaRegistry.register(registerable, DENSER_JUNGLE_PALM_TREES, TerrestriaConfiguredFeatures.JUNGLE_PALM_TREE,
PlacedFeatures.createCountExtraModifier(5, 0.1f, 1),
SquarePlacementModifier.of(),
SurfaceLevelFilterPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG, 72, 320),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(ON_DIRT_OR_SAND),
BiomePlacementModifier.of());

register(registerable, RARE_DUM_DUM_HEADS, TerrestriaConfiguredFeatures.DUM_DUM_HEAD,
TerrestriaRegistry.register(registerable, RARE_DUM_DUM_HEADS, TerrestriaConfiguredFeatures.DUM_DUM_HEAD,
PlacedFeatures.createCountExtraModifier(0, 0.1f, 1),
SquarePlacementModifier.of(),
SurfaceLevelFilterPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG, 62, 64),
Expand All @@ -265,7 +266,7 @@ public static void bootstrap(Registerable<PlacedFeature> registerable) {

registerTreeFeature(registerable, SPARSE_WILLOW_TREES, 1, ON_DIRT_OR_SAND, TerrestriaConfiguredFeatures.WILLOW_TREE);

register(registerable, OUTBACK_YUCCA_PALM, TerrestriaConfiguredFeatures.YUCCA_PALM_TREE, PlacedFeatures.wouldSurvive(TerrestriaBlocks.YUCCA_PALM_SAPLING));
TerrestriaRegistry.register(registerable, OUTBACK_YUCCA_PALM, TerrestriaConfiguredFeatures.YUCCA_PALM_TREE, PlacedFeatures.wouldSurvive(TerrestriaBlocks.YUCCA_PALM_SAPLING));

registerTreeFeature(registerable, OUTBACK_BUSHLAND_TREES, 2, ON_DIRT_OR_SAND, TerrestriaConfiguredFeatures.OUTBACK_BUSHLAND_TREES);

Expand All @@ -277,7 +278,7 @@ public static void bootstrap(Registerable<PlacedFeature> registerable) {

registerTreeFeature(registerable, SAGUARO_CACTUSES, 2, ON_SAND, TerrestriaConfiguredFeatures.SAGUARO_CACTUS);

register(registerable, RARE_BRYCE_TREES, TerrestriaConfiguredFeatures.BRYCE_TREE,
TerrestriaRegistry.register(registerable, RARE_BRYCE_TREES, TerrestriaConfiguredFeatures.BRYCE_TREE,
RarityFilterPlacementModifier.of(2),
SquarePlacementModifier.of(),
SurfaceLevelFilterPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG, 80, 320),
Expand All @@ -286,32 +287,26 @@ public static void bootstrap(Registerable<PlacedFeature> registerable) {
BiomePlacementModifier.of());
}

public static RegistryKey<PlacedFeature> createRegistryKey(String name) {
private static RegistryKey<PlacedFeature> createRegistryKey(String name) {
return RegistryKey.of(RegistryKeys.PLACED_FEATURE, Identifier.of(Terrestria.MOD_ID, name));
}

public static void registerTreeFeature(Registerable<PlacedFeature> registerable, RegistryKey<PlacedFeature> key, int count, BlockPredicate predicate, RegistryKey<ConfiguredFeature<?, ?>> feature) {
register(registerable, key, feature,
private static void registerTreeFeature(Registerable<PlacedFeature> registerable, RegistryKey<PlacedFeature> key, int count, BlockPredicate predicate, RegistryKey<ConfiguredFeature<?, ?>> feature) {
TerrestriaRegistry.register(registerable, key, feature,
PlacedFeatures.createCountExtraModifier(count, 0.1f, 1),
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BlockFilterPlacementModifier.of(predicate),
BiomePlacementModifier.of());
}

public static void registerTreeFeature(Registerable<PlacedFeature> registerable, RegistryKey<PlacedFeature> key, int count, int maxWaterDepth, BlockPredicate predicate, RegistryKey<ConfiguredFeature<?, ?>> feature) {
register(registerable, key, feature,
private static void registerTreeFeature(Registerable<PlacedFeature> registerable, RegistryKey<PlacedFeature> key, int count, int maxWaterDepth, BlockPredicate predicate, RegistryKey<ConfiguredFeature<?, ?>> feature) {
TerrestriaRegistry.register(registerable, key, feature,
PlacedFeatures.createCountExtraModifier(count, 0.1f, 1),
SquarePlacementModifier.of(),
PlacedFeatures.OCEAN_FLOOR_HEIGHTMAP,
SurfaceWaterDepthFilterPlacementModifier.of(maxWaterDepth),
BlockFilterPlacementModifier.of(predicate),
BiomePlacementModifier.of());
}

private static void register(Registerable<PlacedFeature> registerable, RegistryKey<PlacedFeature> key, RegistryKey<ConfiguredFeature<?, ?>> feature, PlacementModifier... placementModifiers) {
PlacedFeatures.register(registerable, key,
registerable.getRegistryLookup(RegistryKeys.CONFIGURED_FEATURE).getOrThrow(feature),
placementModifiers);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.terraformersmc.terrestria.init.helpers;

import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;

public class StoneBlocks {
Expand Down Expand Up @@ -28,10 +27,10 @@ public static StoneBlocks register(String name, MapColor color) {
blocks.bricks = StoneVariantBlocks.register(name + "_bricks", name + "_brick", color, Blocks.STONE_BRICKS);
blocks.mossyBricks = StoneVariantBlocks.register("mossy_" + name + "_bricks", "mossy_" + name + "_brick", color, Blocks.MOSSY_STONE_BRICKS);

blocks.button = TerrestriaRegistry.register(name + "_button", new ButtonBlock(BlockSetType.STONE, 20, FabricBlockSettings.copyOf(Blocks.STONE_BUTTON).mapColor(color)));
blocks.pressurePlate = TerrestriaRegistry.register(name + "_pressure_plate", new PressurePlateBlock(BlockSetType.STONE, FabricBlockSettings.copyOf(Blocks.STONE_PRESSURE_PLATE).mapColor(color)));
blocks.chiseledBricks = TerrestriaRegistry.register("chiseled_" + name + "_bricks", new Block(FabricBlockSettings.copyOf(Blocks.CRACKED_STONE_BRICKS).mapColor(color)));
blocks.crackedBricks = TerrestriaRegistry.register("cracked_" + name + "_bricks", new Block(FabricBlockSettings.copyOf(Blocks.CHISELED_STONE_BRICKS).mapColor(color)));
blocks.button = TerrestriaRegistry.register(name + "_button", new ButtonBlock(BlockSetType.STONE, 20, AbstractBlock.Settings.copy(Blocks.STONE_BUTTON).mapColor(color)));
blocks.pressurePlate = TerrestriaRegistry.register(name + "_pressure_plate", new PressurePlateBlock(BlockSetType.STONE, AbstractBlock.Settings.copy(Blocks.STONE_PRESSURE_PLATE).mapColor(color)));
blocks.chiseledBricks = TerrestriaRegistry.register("chiseled_" + name + "_bricks", new Block(AbstractBlock.Settings.copy(Blocks.CRACKED_STONE_BRICKS).mapColor(color)));
blocks.crackedBricks = TerrestriaRegistry.register("cracked_" + name + "_bricks", new Block(AbstractBlock.Settings.copy(Blocks.CHISELED_STONE_BRICKS).mapColor(color)));

return blocks;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.terraformersmc.terrestria.init.helpers;

import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;

public class StoneVariantBlocks {
Expand All @@ -18,10 +17,10 @@ public static StoneVariantBlocks register(String name, MapColor color, Block fam
public static StoneVariantBlocks register(String name, String shapedName, MapColor color, Block family) {
StoneVariantBlocks blocks = new StoneVariantBlocks();

blocks.full = TerrestriaRegistry.register(name, new Block(FabricBlockSettings.copyOf(family).mapColor(color)));
blocks.slab = TerrestriaRegistry.register(shapedName + "_slab", new SlabBlock(FabricBlockSettings.copyOf(family).mapColor(color)));
blocks.stairs = TerrestriaRegistry.register(shapedName + "_stairs", new StairsBlock(blocks.full.getDefaultState(), FabricBlockSettings.copyOf(family).mapColor(color)));
blocks.wall = TerrestriaRegistry.register(shapedName + "_wall", new WallBlock(FabricBlockSettings.copyOf(family).mapColor(color)));
blocks.full = TerrestriaRegistry.register(name, new Block(AbstractBlock.Settings.copy(family).mapColor(color)));
blocks.slab = TerrestriaRegistry.register(shapedName + "_slab", new SlabBlock(AbstractBlock.Settings.copy(family).mapColor(color)));
blocks.stairs = TerrestriaRegistry.register(shapedName + "_stairs", new StairsBlock(blocks.full.getDefaultState(), AbstractBlock.Settings.copy(family).mapColor(color)));
blocks.wall = TerrestriaRegistry.register(shapedName + "_wall", new WallBlock(AbstractBlock.Settings.copy(family).mapColor(color)));

return blocks;
}
Expand Down
Loading

0 comments on commit 5d8b0a1

Please sign in to comment.