Skip to content

Commit

Permalink
feat: Use has_structure/*_waystone tags to allow for better control o…
Browse files Browse the repository at this point in the history
…ver where waystones spawn #903
  • Loading branch information
BlayTheNinth committed Oct 24, 2024
1 parent fc063aa commit 329af2d
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
{
"id": "#minecraft:is_nether",
"required": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
{
"id": "#minecraft:is_end",
"required": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"values": [
"minecraft:swamp",
"minecraft:mangrove_swamp",
"minecraft:mushroom_fields",
{
"id": "#minecraft:is_jungle",
"required": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"values": [
"minecraft:plains",
"minecraft:sunflower_plains",
"minecraft:snowy_plains",
"minecraft:ice_spikes",
"minecraft:forest",
"minecraft:flower_forest",
"minecraft:birch_forest",
"minecraft:dark_forest",
"minecraft:old_growth_birch_forest",
"minecraft:old_growth_pine_taiga",
"minecraft:old_growth_spruce_taiga",
"minecraft:taiga",
"minecraft:snowy_taiga",
"minecraft:savanna",
"minecraft:savanna_plateau",
"minecraft:windswept_hills",
"minecraft:windswept_gravelly_hills",
"minecraft:windswept_forest",
"minecraft:windswept_savanna",
"minecraft:jungle",
"minecraft:sparse_jungle",
"minecraft:bamboo_jungle",
"minecraft:badlands",
"minecraft:eroded_badlands",
"minecraft:wooded_badlands",
"minecraft:meadow",
"minecraft:cherry_grove",
"minecraft:grove",
"minecraft:snowy_slopes",
"minecraft:frozen_peaks",
"minecraft:jagged_peaks",
"minecraft:stony_peaks",
"minecraft:river",
"minecraft:frozen_river",
"minecraft:beach",
"minecraft:snowy_beach",
"minecraft:stony_shore",
"minecraft:warm_ocean",
"minecraft:lukewarm_ocean",
"minecraft:deep_lukewarm_ocean",
"minecraft:ocean",
"minecraft:deep_ocean",
"minecraft:cold_ocean",
"minecraft:deep_cold_ocean",
"minecraft:frozen_ocean",
"minecraft:deep_frozen_ocean",
"minecraft:dripstone_caves",
"minecraft:lush_caves",
"minecraft:deep_dark"
]
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import net.minecraft.world.level.biome.Biome;

public class ModBiomeTags {
public static final TagKey<Biome> IS_DESERT = TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, "is_desert"));
public static final TagKey<Biome> IS_SWAMP = TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, "is_swamp"));
public static final TagKey<Biome> IS_MUSHROOM = TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, "is_mushroom"));
public static final TagKey<Biome> HAS_STRUCTURE_WAYSTONE = TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, "has_structure/waystone"));
public static final TagKey<Biome> HAS_STRUCTURE_MOSSY_WAYSTONE = TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, "has_structure/mossy_waystone"));
public static final TagKey<Biome> HAS_STRUCTURE_SANDY_WAYSTONE = TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, "has_structure/sandy_waystone"));
public static final TagKey<Biome> HAS_STRUCTURE_BLACKSTONE_WAYSTONE = TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, "has_structure/blackstone_waystone"));
public static final TagKey<Biome> HAS_STRUCTURE_END_STONE_WAYSTONE = TagKey.create(Registries.BIOME, ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, "has_structure/end_stone_waystone"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.GenerationStep;
Expand Down Expand Up @@ -59,22 +58,19 @@ public static void initialize(BalmWorldGen worldGen) {

waystonePlacement = worldGen.registerPlacementModifier(id("waystone"), () -> () -> WaystonePlacement.CODEC);

worldGen.addFeatureToBiomes(matchesTag(ModBiomeTags.IS_DESERT), GenerationStep.Decoration.VEGETAL_DECORATION, getWaystoneFeature(WorldGenStyle.SANDY));
worldGen.addFeatureToBiomes(matchesTag(BiomeTags.IS_JUNGLE), GenerationStep.Decoration.VEGETAL_DECORATION, getWaystoneFeature(WorldGenStyle.MOSSY));
worldGen.addFeatureToBiomes(matchesTag(ModBiomeTags.IS_SWAMP), GenerationStep.Decoration.VEGETAL_DECORATION, getWaystoneFeature(WorldGenStyle.MOSSY));
worldGen.addFeatureToBiomes(matchesTag(ModBiomeTags.IS_MUSHROOM),
worldGen.addFeatureToBiomes(matchesTag(ModBiomeTags.HAS_STRUCTURE_SANDY_WAYSTONE),
GenerationStep.Decoration.VEGETAL_DECORATION,
getWaystoneFeature(WorldGenStyle.SANDY));
worldGen.addFeatureToBiomes(matchesTag(ModBiomeTags.HAS_STRUCTURE_MOSSY_WAYSTONE),
GenerationStep.Decoration.VEGETAL_DECORATION,
getWaystoneFeature(WorldGenStyle.MOSSY));
worldGen.addFeatureToBiomes(matchesTag(BiomeTags.IS_NETHER),
worldGen.addFeatureToBiomes(matchesTag(ModBiomeTags.HAS_STRUCTURE_BLACKSTONE_WAYSTONE),
GenerationStep.Decoration.VEGETAL_DECORATION,
getWaystoneFeature(WorldGenStyle.BLACKSTONE));
worldGen.addFeatureToBiomes(matchesTag(BiomeTags.IS_END), GenerationStep.Decoration.VEGETAL_DECORATION, getWaystoneFeature(WorldGenStyle.END_STONE));
worldGen.addFeatureToBiomes(matchesNeitherTag(List.of(ModBiomeTags.IS_SWAMP,
ModBiomeTags.IS_DESERT,
BiomeTags.IS_JUNGLE,
ModBiomeTags.IS_MUSHROOM,
BiomeTags.IS_NETHER,
BiomeTags.IS_END)),
worldGen.addFeatureToBiomes(matchesTag(ModBiomeTags.HAS_STRUCTURE_END_STONE_WAYSTONE),
GenerationStep.Decoration.VEGETAL_DECORATION,
getWaystoneFeature(WorldGenStyle.END_STONE));
worldGen.addFeatureToBiomes(matchesTag(ModBiomeTags.HAS_STRUCTURE_WAYSTONE),
GenerationStep.Decoration.VEGETAL_DECORATION,
getWaystoneFeature(WorldGenStyle.DEFAULT));

Expand All @@ -86,18 +82,6 @@ private static BiomePredicate matchesTag(TagKey<Biome> tag) {
return (resourceLocation, biome) -> biome.is(tag);
}

private static BiomePredicate matchesNeitherTag(List<TagKey<Biome>> tags) {
return (resourceLocation, biome) -> {
for (TagKey<Biome> tag : tags) {
if (biome.is(tag)) {
return false;
}
}

return true;
};
}

private static ResourceLocation id(String name) {
return ResourceLocation.fromNamespaceAndPath(Waystones.MOD_ID, name);
}
Expand Down Expand Up @@ -134,15 +118,16 @@ public static void setupDynamicRegistries(RegistryAccess registryAccess) {
}

private static void addWaystoneStructureToVillageConfig(RegistryAccess registryAccess, String villagePiece, ResourceLocation waystoneStructure, int weight) {

Holder<StructureProcessorList> emptyProcessorList = registryAccess.lookupOrThrow(Registries.PROCESSOR_LIST)
.getOrThrow(EMPTY_PROCESSOR_LIST_KEY);
LegacySinglePoolElement piece = StructurePoolElement.legacy(waystoneStructure.toString(), emptyProcessorList)
.apply(StructureTemplatePool.Projection.RIGID);
if (piece instanceof WaystoneStructurePoolElement element) {
element.waystones$setIsWaystone(true);
}
StructureTemplatePool pool = registryAccess.lookupOrThrow(Registries.TEMPLATE_POOL).getOptional(ResourceLocation.withDefaultNamespace(villagePiece)).orElse(null);
StructureTemplatePool pool = registryAccess.lookupOrThrow(Registries.TEMPLATE_POOL)
.getOptional(ResourceLocation.withDefaultNamespace(villagePiece))
.orElse(null);
if (pool != null) {
var poolAccessor = (StructureTemplatePoolAccessor) pool;
// pretty sure this can be an immutable list (when datapacked) so gotta make a copy to be safe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;

Expand All @@ -17,9 +18,65 @@ public ModBiomeTagProvider(FabricDataOutput output, CompletableFuture<HolderLook

@Override
protected void addTags(HolderLookup.Provider arg) {
getOrCreateTagBuilder(ModBiomeTags.IS_SWAMP).add(Biomes.SWAMP, Biomes.MANGROVE_SWAMP);
getOrCreateTagBuilder(ModBiomeTags.IS_DESERT).add(Biomes.DESERT);
getOrCreateTagBuilder(ModBiomeTags.IS_MUSHROOM).add(Biomes.MUSHROOM_FIELDS);
final var hasMossyWaystones = getOrCreateTagBuilder(ModBiomeTags.HAS_STRUCTURE_MOSSY_WAYSTONE);
hasMossyWaystones.add(Biomes.SWAMP, Biomes.MANGROVE_SWAMP, Biomes.MUSHROOM_FIELDS);
hasMossyWaystones.addOptionalTag(BiomeTags.IS_JUNGLE);
getOrCreateTagBuilder(ModBiomeTags.HAS_STRUCTURE_SANDY_WAYSTONE).add(Biomes.DESERT);
getOrCreateTagBuilder(ModBiomeTags.HAS_STRUCTURE_BLACKSTONE_WAYSTONE).addOptionalTag(BiomeTags.IS_NETHER);
getOrCreateTagBuilder(ModBiomeTags.HAS_STRUCTURE_END_STONE_WAYSTONE).addOptionalTag(BiomeTags.IS_END);

final var hasWaystones = getOrCreateTagBuilder(ModBiomeTags.HAS_STRUCTURE_WAYSTONE);
hasWaystones.add(
Biomes.PLAINS,
Biomes.SUNFLOWER_PLAINS,
Biomes.SNOWY_PLAINS,
Biomes.ICE_SPIKES,
Biomes.FOREST,
Biomes.FLOWER_FOREST,
Biomes.BIRCH_FOREST,
Biomes.DARK_FOREST,
Biomes.OLD_GROWTH_BIRCH_FOREST,
Biomes.OLD_GROWTH_PINE_TAIGA,
Biomes.OLD_GROWTH_SPRUCE_TAIGA,
Biomes.TAIGA,
Biomes.SNOWY_TAIGA,
Biomes.SAVANNA,
Biomes.SAVANNA_PLATEAU,
Biomes.WINDSWEPT_HILLS,
Biomes.WINDSWEPT_GRAVELLY_HILLS,
Biomes.WINDSWEPT_FOREST,
Biomes.WINDSWEPT_SAVANNA,
Biomes.JUNGLE,
Biomes.SPARSE_JUNGLE,
Biomes.BAMBOO_JUNGLE,
Biomes.BADLANDS,
Biomes.ERODED_BADLANDS,
Biomes.WOODED_BADLANDS,
Biomes.MEADOW,
Biomes.CHERRY_GROVE,
Biomes.GROVE,
Biomes.SNOWY_SLOPES,
Biomes.FROZEN_PEAKS,
Biomes.JAGGED_PEAKS,
Biomes.STONY_PEAKS,
Biomes.RIVER,
Biomes.FROZEN_RIVER,
Biomes.BEACH,
Biomes.SNOWY_BEACH,
Biomes.STONY_SHORE,
Biomes.WARM_OCEAN,
Biomes.LUKEWARM_OCEAN,
Biomes.DEEP_LUKEWARM_OCEAN,
Biomes.OCEAN,
Biomes.DEEP_OCEAN,
Biomes.COLD_OCEAN,
Biomes.DEEP_COLD_OCEAN,
Biomes.FROZEN_OCEAN,
Biomes.DEEP_FROZEN_OCEAN,
Biomes.DRIPSTONE_CAVES,
Biomes.LUSH_CAVES,
Biomes.DEEP_DARK
);
}

}

0 comments on commit 329af2d

Please sign in to comment.