diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/UWorldGen.java b/src/main/java/com/minelittlepony/unicopia/server/world/UWorldGen.java index c7c781a6..5100d075 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/UWorldGen.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/UWorldGen.java @@ -6,7 +6,9 @@ import java.util.function.Consumer; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.block.ShellsBlock; import com.minelittlepony.unicopia.block.UBlocks; +import com.minelittlepony.unicopia.server.world.gen.CaveCarvingStructureProcessor; import com.minelittlepony.unicopia.server.world.gen.OverworldBiomeSelectionCallback; +import com.minelittlepony.unicopia.server.world.gen.SurfaceGrowthStructureProcessor; import com.minelittlepony.unicopia.util.registry.DynamicRegistry; import net.fabricmc.fabric.api.biome.v1.BiomeModifications; @@ -23,6 +25,7 @@ import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.BiomeTags; import net.minecraft.sound.BiomeMoodSound; import net.minecraft.sound.SoundEvents; +import net.minecraft.structure.processor.StructureProcessorType; import net.minecraft.util.collection.DataPool; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3i; @@ -120,6 +123,9 @@ public interface UWorldGen { .build(); }); + StructureProcessorType SURFACE_GROWTH_STRUCTURE_PROCESSOR = Registry.register(Registries.STRUCTURE_PROCESSOR, Unicopia.id("surface_growth"), () -> SurfaceGrowthStructureProcessor.CODEC); + StructureProcessorType CAVE_CARVING_STRUCTURE_PROCESSOR = Registry.register(Registries.STRUCTURE_PROCESSOR, Unicopia.id("cave_carving"), () -> CaveCarvingStructureProcessor.CODEC); + @SafeVarargs static T applyAll(T t, Consumer ...consumers) { for (Consumer consumer : consumers) { diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/gen/CaveCarvingStructureProcessor.java b/src/main/java/com/minelittlepony/unicopia/server/world/gen/CaveCarvingStructureProcessor.java new file mode 100644 index 00000000..cfb2db26 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/server/world/gen/CaveCarvingStructureProcessor.java @@ -0,0 +1,36 @@ +package com.minelittlepony.unicopia.server.world.gen; + +import org.jetbrains.annotations.Nullable; + +import com.minelittlepony.unicopia.server.world.UWorldGen; +import com.mojang.serialization.Codec; +import net.minecraft.structure.StructurePlacementData; +import net.minecraft.structure.StructureTemplate; +import net.minecraft.structure.processor.StructureProcessor; +import net.minecraft.structure.processor.StructureProcessorType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.Heightmap; +import net.minecraft.world.WorldView; + +public class CaveCarvingStructureProcessor extends StructureProcessor { + public static final Codec CODEC = Codec.unit(new CaveCarvingStructureProcessor()); + + @Override + protected StructureProcessorType getType() { + return UWorldGen.SURFACE_GROWTH_STRUCTURE_PROCESSOR; + } + + @Nullable + @Override + public StructureTemplate.StructureBlockInfo process( + WorldView world, + BlockPos pos, + BlockPos pivot, + StructureTemplate.StructureBlockInfo originalBlockInfo, + StructureTemplate.StructureBlockInfo currentBlockInfo, + StructurePlacementData data + ) { + int topY = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, currentBlockInfo.pos().getX(), currentBlockInfo.pos().getZ()); + return currentBlockInfo.pos().getY() > topY && world.isAir(currentBlockInfo.pos()) ? null : currentBlockInfo; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/gen/SurfaceGrowthStructureProcessor.java b/src/main/java/com/minelittlepony/unicopia/server/world/gen/SurfaceGrowthStructureProcessor.java new file mode 100644 index 00000000..33ef60c7 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/server/world/gen/SurfaceGrowthStructureProcessor.java @@ -0,0 +1,67 @@ +package com.minelittlepony.unicopia.server.world.gen; + +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import com.minelittlepony.unicopia.server.world.UWorldGen; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.block.BlockState; +import net.minecraft.structure.StructurePlacementData; +import net.minecraft.structure.StructureTemplate; +import net.minecraft.structure.processor.StructureProcessor; +import net.minecraft.structure.processor.StructureProcessorType; +import net.minecraft.structure.rule.RuleTest; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.random.Random; +import net.minecraft.world.ServerWorldAccess; + +public class SurfaceGrowthStructureProcessor extends StructureProcessor { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + RuleTest.TYPE_CODEC.fieldOf("input_predicate").forGetter(rule -> rule.inputPredicate), + BlockState.CODEC.fieldOf("output_state").forGetter(rule -> rule.outputState) + ).apply(instance, SurfaceGrowthStructureProcessor::new)); + + private final RuleTest inputPredicate; + private final BlockState outputState; + + public SurfaceGrowthStructureProcessor(RuleTest inputPredicate, BlockState outputState) { + this.inputPredicate = inputPredicate; + this.outputState = outputState; + } + + @Override + protected StructureProcessorType getType() { + return UWorldGen.SURFACE_GROWTH_STRUCTURE_PROCESSOR; + } + + @SuppressWarnings("deprecation") + @Override + public List reprocess( + ServerWorldAccess world, + BlockPos pos, + BlockPos pivot, + List originalBlockInfos, + List currentBlockInfos, + StructurePlacementData data + ) { + Map positionalInfos = currentBlockInfos.stream().collect(Collectors.toMap( + StructureTemplate.StructureBlockInfo::pos, + Function.identity() + )); + + return currentBlockInfos.stream().map(currentBlockInfo -> { + StructureTemplate.StructureBlockInfo aboveBlockInfo = positionalInfos.get(currentBlockInfo.pos().up()); + BlockState currentState = aboveBlockInfo == null ? world.getBlockState(currentBlockInfo.pos().up()) : aboveBlockInfo.state(); + if ((currentState.isAir() || currentState.isReplaceable()) + && inputPredicate.test(currentBlockInfo.state(), Random.create(MathHelper.hashCode(currentBlockInfo.pos())))) { + return new StructureTemplate.StructureBlockInfo(currentBlockInfo.pos(), outputState, currentBlockInfo.nbt()); + } + return currentBlockInfo; + }).collect(Collectors.toList()); + } +} diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/entrance_large_lower.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/entrance_large_lower.nbt new file mode 100644 index 00000000..2a6cd5e5 Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/entrance_large_lower.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/entrance_large_upper.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/entrance_large_upper.nbt new file mode 100644 index 00000000..c2eb01d0 Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/entrance_large_upper.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/empty.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/empty.nbt new file mode 100644 index 00000000..106da760 Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/empty.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_1.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_1.nbt new file mode 100644 index 00000000..86e553a7 Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_1.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_2.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_2.nbt new file mode 100644 index 00000000..185d053b Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_2.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_3.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_3.nbt new file mode 100644 index 00000000..53574e14 Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/slime_3.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/spikes.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/spikes.nbt new file mode 100644 index 00000000..c3932214 Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/floor_decoration/spikes.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/empty.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/empty.nbt new file mode 100644 index 00000000..bd44b266 Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/empty.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/slime.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/slime.nbt new file mode 100644 index 00000000..521802b8 Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/slime.nbt differ diff --git a/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/spikes.nbt b/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/spikes.nbt new file mode 100644 index 00000000..7a388fab Binary files /dev/null and b/src/main/resources/data/unicopia/structures/changeling_hive/roof_decoration/spikes.nbt differ diff --git a/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_decay.json b/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_decay.json index 63441ea5..4e9c23c6 100644 --- a/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_decay.json +++ b/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_decay.json @@ -13,10 +13,23 @@ }, "output_state": { "name": "unicopia:hive", - "Name": "unicopia:hive", - "properties": [] + "Name": "unicopia:hive" } } ] + }, + { + "processor_type": "unicopia:cave_carving" + }, + { + "processor_type": "unicopia:surface_growth", + "input_predicate": { + "predicate_type": "block_match", + "block": "unicopia:chitin" + }, + "output_state": { + "name": "unicopia:surface_chitin", + "Name": "unicopia:surface_chitin" + } } ] \ No newline at end of file diff --git a/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_entrance_decay.json b/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_entrance_decay.json new file mode 100644 index 00000000..0ab08c0b --- /dev/null +++ b/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_entrance_decay.json @@ -0,0 +1,32 @@ +[ + { + "processor_type": "minecraft:rule", + "rules": [ + { + "location_predicate": { + "predicate_type": "always_true" + }, + "input_predicate": { + "predicate_type": "random_block_match", + "block": "unicopia:chitin", + "probability": 0.2 + }, + "output_state": { + "name": "unicopia:hive", + "Name": "unicopia:hive" + } + } + ] + }, + { + "processor_type": "unicopia:surface_growth", + "input_predicate": { + "predicate_type": "block_match", + "block": "unicopia:chitin" + }, + "output_state": { + "name": "unicopia:surface_chitin", + "Name": "unicopia:surface_chitin" + } + } +] \ No newline at end of file diff --git a/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_surfacing.json b/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_surfacing.json new file mode 100644 index 00000000..91d90a09 --- /dev/null +++ b/src/main/resources/data/unicopia/worldgen/processor_list/changeling_hive_surfacing.json @@ -0,0 +1,13 @@ +[ + { + "processor_type": "unicopia:surface_growth", + "input_predicate": { + "predicate_type": "block_match", + "block": "unicopia:chitin" + }, + "output_state": { + "name": "unicopia:surface_chitin", + "Name": "unicopia:surface_chitin" + } + } +] \ No newline at end of file diff --git a/src/main/resources/data/unicopia/worldgen/structure/abandoned_changeling_hive.json b/src/main/resources/data/unicopia/worldgen/structure/abandoned_changeling_hive.json index 452e16aa..978a4940 100644 --- a/src/main/resources/data/unicopia/worldgen/structure/abandoned_changeling_hive.json +++ b/src/main/resources/data/unicopia/worldgen/structure/abandoned_changeling_hive.json @@ -18,7 +18,7 @@ } }, "start_height": { - "absolute": -7 + "absolute": -6 }, "start_pool": "unicopia:changeling_hive/start", "step": "underground_structures", diff --git a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/chamber_decors.json b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/chamber_decors.json index beb46991..68d93295 100644 --- a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/chamber_decors.json +++ b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/chamber_decors.json @@ -4,9 +4,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/chamber_decoration/nothing", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 7 @@ -24,9 +22,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/chamber_decoration/spiders", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 4 @@ -35,9 +31,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/chamber_decoration/spiked", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 2 @@ -46,9 +40,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/chamber_decoration/slime", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 2 diff --git a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/floor_additions.json b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/floor_additions.json new file mode 100644 index 00000000..b4619725 --- /dev/null +++ b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/floor_additions.json @@ -0,0 +1,50 @@ +{ + "elements": [ + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/floor_decoration/empty", + "processors": [], + "projection": "rigid" + }, + "weight": 6 + }, + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/floor_decoration/slime_1", + "processors": [], + "projection": "rigid" + }, + "weight": 1 + }, + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/floor_decoration/slime_2", + "processors": [], + "projection": "rigid" + }, + "weight": 1 + }, + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/floor_decoration/slime_3", + "processors": [], + "projection": "rigid" + }, + "weight": 1 + }, + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/floor_decoration/spikes", + "processors": [], + "projection": "rigid" + }, + "weight": 3 + } + ], + "fallback": "unicopia:changeling_hive/floor_additions_termination" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/floor_additions_termination.json b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/floor_additions_termination.json new file mode 100644 index 00000000..a75d7346 --- /dev/null +++ b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/floor_additions_termination.json @@ -0,0 +1,14 @@ +{ + "elements": [ + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/floor_decoration/empty", + "processors": [], + "projection": "rigid" + }, + "weight": 1 + } + ], + "fallback": "minecraft:empty" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/main_entrance_shafts.json b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/main_entrance_shafts.json new file mode 100644 index 00000000..872201a0 --- /dev/null +++ b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/main_entrance_shafts.json @@ -0,0 +1,14 @@ +{ + "elements": [ + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/entrance_large_lower", + "processors": [], + "projection": "rigid" + }, + "weight": 6 + } + ], + "fallback": "minecraft:empty" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/pit_decors.json b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/pit_decors.json index f5380f91..660a7749 100644 --- a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/pit_decors.json +++ b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/pit_decors.json @@ -4,9 +4,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/pit_decoration/eggs", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 1 @@ -15,9 +13,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/pit_decoration/lava", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 1 @@ -35,9 +31,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/pit_decoration/spiders", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 1 @@ -46,9 +40,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/pit_decoration/spikes", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 1 @@ -57,9 +49,7 @@ "element": { "element_type": "minecraft:single_pool_element", "location": "unicopia:changeling_hive/pit_decoration/bulb", - "processors": { - "processors": [] - }, + "processors": "unicopia:changeling_hive_surfacing", "projection": "rigid" }, "weight": 1 diff --git a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/roof_additions.json b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/roof_additions.json new file mode 100644 index 00000000..0dff505a --- /dev/null +++ b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/roof_additions.json @@ -0,0 +1,32 @@ +{ + "elements": [ + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/roof_decoration/empty", + "processors": [], + "projection": "rigid" + }, + "weight": 6 + }, + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/roof_decoration/slime", + "processors": [], + "projection": "rigid" + }, + "weight": 1 + }, + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/roof_decoration/spikes", + "processors": [], + "projection": "rigid" + }, + "weight": 3 + } + ], + "fallback": "unicopia:changeling_hive/roof_additions_termination" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/roof_additions_termination.json b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/roof_additions_termination.json new file mode 100644 index 00000000..307bb99b --- /dev/null +++ b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/roof_additions_termination.json @@ -0,0 +1,14 @@ +{ + "elements": [ + { + "element": { + "element_type": "minecraft:single_pool_element", + "location": "unicopia:changeling_hive/roof_decoration/empty", + "processors": [], + "projection": "rigid" + }, + "weight": 1 + } + ], + "fallback": "minecraft:empty" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/start.json b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/start.json index 2b17e07a..5bfb0c50 100644 --- a/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/start.json +++ b/src/main/resources/data/unicopia/worldgen/template_pool/changeling_hive/start.json @@ -3,26 +3,8 @@ { "element": { "element_type": "minecraft:single_pool_element", - "location": "unicopia:changeling_hive/entrance", - "processors": "unicopia:changeling_hive_decay", - "projection": "rigid" - }, - "weight": 3 - }, - { - "element": { - "element_type": "minecraft:single_pool_element", - "location": "unicopia:changeling_hive/spiked/entrance", - "processors": "unicopia:changeling_hive_decay", - "projection": "rigid" - }, - "weight": 3 - }, - { - "element": { - "element_type": "minecraft:single_pool_element", - "location": "unicopia:changeling_hive/slimey/entrance", - "processors": "unicopia:changeling_hive_decay", + "location": "unicopia:changeling_hive/entrance_large_upper", + "processors": "unicopia:changeling_hive_entrance_decay", "projection": "rigid" }, "weight": 1