From 11aa30ed78e4aafaa5840e1448a02817e0ab12c4 Mon Sep 17 00:00:00 2001 From: ReclipseTheOne Date: Mon, 9 Sep 2024 17:25:13 +0300 Subject: [PATCH] First ruins --- .../modjam/content/structures/Ruins1.java | 123 ++++++++++++++++++ .../modjam/registries/MJStructures.java | 4 + .../data/modjam/structure/ruins_1.nbt | Bin 0 -> 693 bytes .../replace_with_suspicious_gravel.json | 25 ++++ .../modjam/worldgen/structure/ruins_1.json | 25 ++++ .../worldgen/structure_set/ruins_1.json | 18 +++ .../worldgen/template_pool/ruins_1.json | 15 +++ 7 files changed, 210 insertions(+) create mode 100644 src/main/java/com/portingdeadmods/modjam/content/structures/Ruins1.java create mode 100644 src/main/resources/data/modjam/structure/ruins_1.nbt create mode 100644 src/main/resources/data/modjam/worldgen/processor_list/replace_with_suspicious_gravel.json create mode 100644 src/main/resources/data/modjam/worldgen/structure/ruins_1.json create mode 100644 src/main/resources/data/modjam/worldgen/structure_set/ruins_1.json create mode 100644 src/main/resources/data/modjam/worldgen/template_pool/ruins_1.json diff --git a/src/main/java/com/portingdeadmods/modjam/content/structures/Ruins1.java b/src/main/java/com/portingdeadmods/modjam/content/structures/Ruins1.java new file mode 100644 index 00000000..a7264652 --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/content/structures/Ruins1.java @@ -0,0 +1,123 @@ +package com.portingdeadmods.modjam.content.structures; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.portingdeadmods.modjam.registries.MJStructures; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.levelgen.WorldGenerationContext; +import net.minecraft.world.level.levelgen.heightproviders.HeightProvider; +import net.minecraft.world.level.levelgen.structure.Structure; +import net.minecraft.world.level.levelgen.structure.StructureType; +import net.minecraft.world.level.levelgen.structure.pools.DimensionPadding; +import net.minecraft.world.level.levelgen.structure.pools.JigsawPlacement; +import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; +import net.minecraft.world.level.levelgen.structure.pools.alias.PoolAliasLookup; +import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure; +import net.minecraft.world.level.levelgen.structure.templatesystem.LiquidSettings; + +import java.util.Optional; + +public class Ruins1 extends Structure { + + // A custom codec that changes the size limit for our code_structure_sky_fan.json's config to not be capped at 7. + // With this, we can have a structure with a size limit up to 30 if we want to have extremely long branches of pieces in the structure. + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> + instance.group(Ruins1.settingsCodec(instance), + StructureTemplatePool.CODEC.fieldOf("start_pool").forGetter(structure -> structure.startPool), + ResourceLocation.CODEC.optionalFieldOf("start_jigsaw_name").forGetter(structure -> structure.startJigsawName), + Codec.intRange(0, 30).fieldOf("size").forGetter(structure -> structure.size), + HeightProvider.CODEC.fieldOf("start_height").forGetter(structure -> structure.startHeight), + Heightmap.Types.CODEC.optionalFieldOf("project_start_to_heightmap").forGetter(structure -> structure.projectStartToHeightmap), + Codec.intRange(1, 128).fieldOf("max_distance_from_center").forGetter(structure -> structure.maxDistanceFromCenter), + DimensionPadding.CODEC.optionalFieldOf("dimension_padding", JigsawStructure.DEFAULT_DIMENSION_PADDING).forGetter(structure -> structure.dimensionPadding), + LiquidSettings.CODEC.optionalFieldOf("liquid_settings", JigsawStructure.DEFAULT_LIQUID_SETTINGS).forGetter(structure -> structure.liquidSettings) + ).apply(instance, Ruins1::new)); + + private final Holder startPool; + private final Optional startJigsawName; + private final int size; + private final HeightProvider startHeight; + private final Optional projectStartToHeightmap; + private final int maxDistanceFromCenter; + private final DimensionPadding dimensionPadding; + private final LiquidSettings liquidSettings; + + public Ruins1(Structure.StructureSettings config, + Holder startPool, + Optional startJigsawName, + int size, + HeightProvider startHeight, + Optional projectStartToHeightmap, + int maxDistanceFromCenter, + DimensionPadding dimensionPadding, + LiquidSettings liquidSettings) + { + super(config); + this.startPool = startPool; + this.startJigsawName = startJigsawName; + this.size = size; + this.startHeight = startHeight; + this.projectStartToHeightmap = projectStartToHeightmap; + this.maxDistanceFromCenter = maxDistanceFromCenter; + this.dimensionPadding = dimensionPadding; + this.liquidSettings = liquidSettings; + } + + private static boolean extraSpawningChecks(Structure.GenerationContext context) { + // Grabs the chunk position we are at + ChunkPos chunkpos = context.chunkPos(); + + // Checks to make sure our structure does not spawn above land that's higher than y = 150 + // to demonstrate how this method is good for checking extra conditions for spawning + return context.chunkGenerator().getFirstOccupiedHeight( + chunkpos.getMinBlockX(), + chunkpos.getMinBlockZ(), + Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, + context.heightAccessor(), + context.randomState()) < context.chunkGenerator().getSeaLevel(); + } + + @Override + public Optional findGenerationPoint(Structure.GenerationContext context) { + + if (!Ruins1.extraSpawningChecks(context)) { + return Optional.empty(); + } + + int startY = this.startHeight.sample(context.random(), new WorldGenerationContext(context.chunkGenerator(), context.heightAccessor())); + + + ChunkPos chunkPos = context.chunkPos(); + BlockPos blockPos = new BlockPos(chunkPos.getMinBlockX(), startY, chunkPos.getMinBlockZ()); + + Optional structurePiecesGenerator = + JigsawPlacement.addPieces( + context, // Used for JigsawPlacement to get all the proper behaviors done. + this.startPool, // The starting pool to use to create the structure layout from + this.startJigsawName, // Can be used to only spawn from one Jigsaw block. But we don't need to worry about this. + this.size, // How deep a branch of pieces can go away from center piece. (5 means branches cannot be longer than 5 pieces from center piece) + blockPos, // Where to spawn the structure. + false, // "useExpansionHack" This is for legacy villages to generate properly. You should keep this false always. + this.projectStartToHeightmap, // Adds the terrain height's y value to the passed in blockpos's y value. (This uses WORLD_SURFACE_WG heightmap which stops at top water too) + // Here, blockpos's y value is 60 which means the structure spawn 60 blocks above terrain height. + // Set this to false for structure to be place only at the passed in blockpos's Y value instead. + // Definitely keep this false when placing structures in the nether as otherwise, heightmap placing will put the structure on the Bedrock roof. + this.maxDistanceFromCenter, // Maximum limit for how far pieces can spawn from center. You cannot set this bigger than 128 or else pieces gets cutoff. + PoolAliasLookup.EMPTY, // Optional thing that allows swapping a template pool with another per structure json instance. We don't need this but see vanilla JigsawStructure class for how to wire it up if you want it. + this.dimensionPadding, // Optional thing to prevent generating too close to the bottom or top of the dimension. + this.liquidSettings); // Optional thing to control whether the structure will be waterlogged when replacing pre-existing water in the world. + + return structurePiecesGenerator; + } + + @Override + public StructureType type() { + return MJStructures.RUINS_1.get(); + } +} + diff --git a/src/main/java/com/portingdeadmods/modjam/registries/MJStructures.java b/src/main/java/com/portingdeadmods/modjam/registries/MJStructures.java index 30458653..e377cf14 100644 --- a/src/main/java/com/portingdeadmods/modjam/registries/MJStructures.java +++ b/src/main/java/com/portingdeadmods/modjam/registries/MJStructures.java @@ -2,14 +2,18 @@ import com.mojang.serialization.MapCodec; import com.portingdeadmods.modjam.ModJam; +import com.portingdeadmods.modjam.content.structures.Ruins1; import net.minecraft.core.registries.Registries; import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.StructureType; +import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; public class MJStructures { public static final DeferredRegister> STRUCTURES = DeferredRegister.create(Registries.STRUCTURE_TYPE, ModJam.MODID); + public static DeferredHolder, StructureType> RUINS_1 = STRUCTURES.register("ruins_1", () -> explicitStructureTypeTyping(Ruins1.CODEC)); + private static StructureType explicitStructureTypeTyping(MapCodec structureCodec) { return () -> structureCodec; } diff --git a/src/main/resources/data/modjam/structure/ruins_1.nbt b/src/main/resources/data/modjam/structure/ruins_1.nbt new file mode 100644 index 0000000000000000000000000000000000000000..7359cea11a8a461623c463bf1978c8c1be6a31f6 GIT binary patch literal 693 zcmV;m0!sZKiwFP!00000|HYR}kJB&|Mz0;a)3iv#4zb|z6Ijoh4I9LY1)IoC-PTNA z*zQ32^|&*2CX?~wN+1!bQrnz+?{U6ZZB_s!Fr$9U0s#DL;a@$DvBJtrMTj8?h9Z~(!LS5F5YC=SIeRAM?3t7gMfi9o<>Q%@ zk7rWX&@(A#xU6m3hXmG6X3jLir25c6pCZtQ&X|x7oy`jQ6o@`W#@Sz=X{Ic~5Ck*L zlt&nr=tBZN^FAanE7pf4`cT9yikRh@0?{Y6cJTK!g2`n;GtQowIxiwjF0Y(3LHH2F zEQ*-r8Is8&=i`|I!Q?V65Sh;Ra*WAkI^XXxCYNc>nIL=!VirZr@=WUbP=t?Xa+&6w z;r_dPrVNoOLuASjnKDGCIcLvIov$Ly)MpuCa=GVxXuv1NCu1XfY`V6UW3C3#NNeT!5oo;x z_F1$NUbd=}PG@It_FCM@2KCm4 zfSkq#Z!QgHb=9DnM(7cH{b-Pxz#DlMBp=4w>&M!kZlQW!vA+Md>GylN1!nb8x=MQ* zqf)7z*;Wg4-0w%CJccD_k?4mStk1}%-%LhTPO!^KY2s@nsT!iDB1zfVlI zLTU3)XLHjZ?csk7?|S_=!?`{hdm4juCpzFe(HJ@Qe7eJC^-n#VecfwWiQ1|=Id2r* bYz3@8y7ynDHmdIct_}PFLj!rsi4Xt)742O% literal 0 HcmV?d00001 diff --git a/src/main/resources/data/modjam/worldgen/processor_list/replace_with_suspicious_gravel.json b/src/main/resources/data/modjam/worldgen/processor_list/replace_with_suspicious_gravel.json new file mode 100644 index 00000000..6614bb49 --- /dev/null +++ b/src/main/resources/data/modjam/worldgen/processor_list/replace_with_suspicious_gravel.json @@ -0,0 +1,25 @@ +{ + "processors": [ + { + "processor_type": "minecraft:rule", + + "rules": [ + { + "input_predicate": { + "block": "minecraft:gravel", + "probability": 0.5, + "predicate_type": "minecraft:random_block_match" + }, + + "location_predicate": { + "predicate_type": "minecraft:always_true" + }, + + "output_state": { + "Name": "minecraft:suspicious_gravel" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/modjam/worldgen/structure/ruins_1.json b/src/main/resources/data/modjam/worldgen/structure/ruins_1.json new file mode 100644 index 00000000..e07c6681 --- /dev/null +++ b/src/main/resources/data/modjam/worldgen/structure/ruins_1.json @@ -0,0 +1,25 @@ +{ + "type": "modjam:ruins_1", + + "start_pool": "modjam:ruins_1", + + "size": 1, + + "max_distance_from_center": 80, + + "biomes": "minecraft:ocean", + + "step": "surface_structures", + + "start_height": { + "absolute": 1 + }, + + "project_start_to_heightmap": "OCEAN_FLOOR_WG", + + "liquid_settings": "apply_waterlogging", + + "spawn_overrides": { + + } +} \ No newline at end of file diff --git a/src/main/resources/data/modjam/worldgen/structure_set/ruins_1.json b/src/main/resources/data/modjam/worldgen/structure_set/ruins_1.json new file mode 100644 index 00000000..a21ad4c5 --- /dev/null +++ b/src/main/resources/data/modjam/worldgen/structure_set/ruins_1.json @@ -0,0 +1,18 @@ +{ + "structures": [ + { + "structure": "modjam:ruins_1", + "weight": 1 + } + ], + "placement": { + "type": "minecraft:random_spread", + "salt": 1224466880, + "spacing": 16, + "separation": 8, + "exclusion_zone": { + "chunk_count": 10, + "other_set": "minecraft:ocean_monuments" + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/modjam/worldgen/template_pool/ruins_1.json b/src/main/resources/data/modjam/worldgen/template_pool/ruins_1.json new file mode 100644 index 00000000..45583409 --- /dev/null +++ b/src/main/resources/data/modjam/worldgen/template_pool/ruins_1.json @@ -0,0 +1,15 @@ +{ + "fallback": "minecraft:empty", + + "elements": [ + { + "weight": 1, + "element": { + "location": "modjam:ruins_1", + "processors": "modjam:replace_with_suspicious_gravel", + "projection": "rigid", + "element_type": "minecraft:single_pool_element" + } + } + ] +}