generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cb1c1e
commit 11aa30e
Showing
7 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
src/main/java/com/portingdeadmods/modjam/content/structures/Ruins1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Ruins1> 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<StructureTemplatePool> startPool; | ||
private final Optional<ResourceLocation> startJigsawName; | ||
private final int size; | ||
private final HeightProvider startHeight; | ||
private final Optional<Heightmap.Types> projectStartToHeightmap; | ||
private final int maxDistanceFromCenter; | ||
private final DimensionPadding dimensionPadding; | ||
private final LiquidSettings liquidSettings; | ||
|
||
public Ruins1(Structure.StructureSettings config, | ||
Holder<StructureTemplatePool> startPool, | ||
Optional<ResourceLocation> startJigsawName, | ||
int size, | ||
HeightProvider startHeight, | ||
Optional<Heightmap.Types> 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<Structure.GenerationStub> 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<Structure.GenerationStub> 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(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
25 changes: 25 additions & 0 deletions
25
src/main/resources/data/modjam/worldgen/processor_list/replace_with_suspicious_gravel.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/resources/data/modjam/worldgen/structure/ruins_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": { | ||
|
||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/resources/data/modjam/worldgen/structure_set/ruins_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/resources/data/modjam/worldgen/template_pool/ruins_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
] | ||
} |