-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
11 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
src/generated/resources/data/railcraft/worldgen/structure/geode.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,6 @@ | ||
{ | ||
"type": "railcraft:geode", | ||
"biomes": "#minecraft:is_deep_ocean", | ||
"spawn_overrides": {}, | ||
"step": "surface_structures" | ||
} |
15 changes: 15 additions & 0 deletions
15
src/generated/resources/data/railcraft/worldgen/structure_set/geode.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 @@ | ||
{ | ||
"placement": { | ||
"type": "minecraft:random_spread", | ||
"salt": 73927265, | ||
"separation": 4, | ||
"spacing": 16, | ||
"spread_type": "triangular" | ||
}, | ||
"structures": [ | ||
{ | ||
"structure": "railcraft:geode", | ||
"weight": 1 | ||
} | ||
] | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/mods/railcraft/data/worldgen/RailcraftStructureSets.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,22 @@ | ||
package mods.railcraft.data.worldgen; | ||
|
||
import mods.railcraft.Railcraft; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.data.worldgen.BootstapContext; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.structure.StructureSet; | ||
import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStructurePlacement; | ||
import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadType; | ||
|
||
public class RailcraftStructureSets { | ||
|
||
private static final ResourceKey<StructureSet> GEODE = ResourceKey | ||
.create(Registries.STRUCTURE_SET, new ResourceLocation(Railcraft.ID, "geode")); | ||
|
||
public static void bootstrap(BootstapContext<StructureSet> context) { | ||
var holdergetter = context.lookup(Registries.STRUCTURE); | ||
context.register(GEODE, new StructureSet(holdergetter.getOrThrow(RailcraftStructures.GEODE), | ||
new RandomSpreadStructurePlacement(16, 4, RandomSpreadType.TRIANGULAR, 73927265))); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/mods/railcraft/data/worldgen/RailcraftStructures.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,27 @@ | ||
package mods.railcraft.data.worldgen; | ||
|
||
import mods.railcraft.Railcraft; | ||
import mods.railcraft.world.level.levelgen.structure.GeodeStructure; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.data.worldgen.BootstapContext; | ||
import net.minecraft.data.worldgen.Structures; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.BiomeTags; | ||
import net.minecraft.world.level.levelgen.GenerationStep; | ||
import net.minecraft.world.level.levelgen.structure.Structure; | ||
import net.minecraft.world.level.levelgen.structure.TerrainAdjustment; | ||
|
||
public class RailcraftStructures { | ||
|
||
public static final ResourceKey<Structure> GEODE = ResourceKey | ||
.create(Registries.STRUCTURE, new ResourceLocation(Railcraft.ID, "geode")); | ||
|
||
public static void bootstrap(BootstapContext<Structure> context) { | ||
var holdergetter = context.lookup(Registries.BIOME); | ||
|
||
context.register(GEODE, new GeodeStructure(Structures | ||
.structure(holdergetter.getOrThrow(BiomeTags.IS_DEEP_OCEAN), | ||
GenerationStep.Decoration.SURFACE_STRUCTURES, TerrainAdjustment.NONE))); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/mods/railcraft/world/level/levelgen/structure/GeodeStructure.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,49 @@ | ||
package mods.railcraft.world.level.levelgen.structure; | ||
|
||
import java.util.Optional; | ||
import net.minecraft.tags.BiomeTags; | ||
import net.minecraft.world.level.levelgen.Heightmap; | ||
import net.minecraft.world.level.levelgen.structure.Structure; | ||
import net.minecraft.world.level.levelgen.structure.StructureType; | ||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder; | ||
|
||
public class GeodeStructure extends Structure { | ||
|
||
public GeodeStructure(StructureSettings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
protected Optional<GenerationStub> findGenerationPoint(GenerationContext context) { | ||
int x = context.chunkPos().getBlockX(9); | ||
int z = context.chunkPos().getBlockZ(9); | ||
|
||
for(var holder : context.biomeSource().getBiomesWithin(x, | ||
context.chunkGenerator().getSeaLevel(),z, 29, context.randomState().sampler())) { | ||
if (!holder.is(BiomeTags.IS_DEEP_OCEAN)) { | ||
return Optional.empty(); | ||
} | ||
} | ||
return onTopOfChunkCenter(context, Heightmap.Types.OCEAN_FLOOR_WG, (structurePiecesBuilder) -> { | ||
generatePieces(structurePiecesBuilder, context); | ||
}); | ||
} | ||
|
||
private void generatePieces(StructurePiecesBuilder builder, GenerationContext context) { | ||
var chunkPos = context.chunkPos(); | ||
var generator = context.chunkGenerator(); | ||
var heightAccessor = context.heightAccessor(); | ||
var random = context.random(); | ||
var state = context.randomState(); | ||
|
||
int x = chunkPos.getBlockX(random.nextInt(16)); | ||
int z = chunkPos.getBlockZ(random.nextInt(16)); | ||
int y = generator.getBaseHeight(x, z, Heightmap.Types.OCEAN_FLOOR, heightAccessor, state); | ||
builder.addPiece(new GeodeStructurePiece(x, y - 6, z)); | ||
} | ||
|
||
@Override | ||
public StructureType<?> type() { | ||
return RailcraftStructureTypes.GEODE.get(); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/mods/railcraft/world/level/levelgen/structure/GeodeStructurePiece.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,99 @@ | ||
package mods.railcraft.world.level.levelgen.structure; | ||
|
||
import mods.railcraft.world.level.block.RailcraftBlocks; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.ChunkPos; | ||
import net.minecraft.world.level.StructureManager; | ||
import net.minecraft.world.level.WorldGenLevel; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.chunk.ChunkGenerator; | ||
import net.minecraft.world.level.levelgen.structure.BoundingBox; | ||
import net.minecraft.world.level.levelgen.structure.StructurePiece; | ||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext; | ||
|
||
public class GeodeStructurePiece extends StructurePiece { | ||
|
||
private static final int DISTANCE_OUTER_SQ = 8 * 8; | ||
private static final int DISTANCE_ORE_SQ = 5 * 5; | ||
private static final int DISTANCE_INNER_SQ = 4 * 4; | ||
|
||
public GeodeStructurePiece(int minX, int y, int minZ) { | ||
super(RailcraftStructurePieces.GEODE.get(), 0, createBoundingBox(minX, y, minZ)); | ||
this.setOrientation(null); | ||
} | ||
|
||
private static BoundingBox createBoundingBox(int minX, int y, int minZ) { | ||
return new BoundingBox(minX, y, minZ, minX + 16, y + 16, minZ + 16); | ||
} | ||
|
||
public GeodeStructurePiece(CompoundTag tag) { | ||
super(RailcraftStructurePieces.GEODE.get(), tag); | ||
} | ||
|
||
@Override | ||
protected void addAdditionalSaveData(StructurePieceSerializationContext context, | ||
CompoundTag tag) { | ||
} | ||
|
||
@Override | ||
public void postProcess(WorldGenLevel level, StructureManager structureManager, | ||
ChunkGenerator generator, RandomSource random, BoundingBox box, ChunkPos chunkPos, | ||
BlockPos pos) { | ||
for (int x = -8; x < 8; x++) { | ||
for (int y = -8; y < 8; y++) { | ||
for (int z = -8; z < 8; z++) { | ||
int distSq = x * x + y * y + z * z; | ||
var targetPos = pos.offset(x, 9 + y, z); | ||
if (distSq <= DISTANCE_INNER_SQ) { | ||
placeAir(level, targetPos); | ||
} else if (distSq <= DISTANCE_OUTER_SQ) { | ||
placeStone(level, targetPos, random); | ||
} | ||
var existingState = level.getBlockState(targetPos); | ||
if (distSq > DISTANCE_INNER_SQ && distSq <= DISTANCE_ORE_SQ) { | ||
placeOre(level, existingState, random, targetPos); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void placeAir(WorldGenLevel level, BlockPos pos) { | ||
if (this.canBeReplaced(level, pos.getX(), pos.getY(), pos.getZ(), new BoundingBox(pos))) { | ||
this.placeBlock(level, Blocks.AIR.defaultBlockState(), pos.getX(), pos.getY(), pos.getZ(), | ||
new BoundingBox(pos)); | ||
} | ||
} | ||
|
||
private void placeStone(WorldGenLevel level, BlockPos pos, RandomSource random) { | ||
if (this.canBeReplaced(level, pos.getX(), pos.getY(), pos.getZ(), new BoundingBox(pos))) { | ||
var state = random.nextDouble() < 0.2 | ||
? random.nextDouble() < 0.5 | ||
? Blocks.DEEPSLATE.defaultBlockState() | ||
: Blocks.SMOOTH_BASALT.defaultBlockState() | ||
: RailcraftBlocks.ABYSSAL_STONE.get().defaultBlockState(); | ||
this.placeBlock(level, state, pos.getX(), pos.getY(), pos.getZ(), new BoundingBox(pos)); | ||
} | ||
} | ||
|
||
private void placeOre(WorldGenLevel level, BlockState existingState, RandomSource random, | ||
BlockPos pos) { | ||
if (existingState.is(RailcraftBlocks.ABYSSAL_STONE.get())) { | ||
double chance = random.nextDouble(); | ||
BlockState oreState = null; | ||
if (chance <= 0.004) { | ||
oreState = Blocks.DEEPSLATE_DIAMOND_ORE.defaultBlockState(); | ||
} else if (chance <= 0.008) { | ||
oreState = Blocks.DEEPSLATE_EMERALD_ORE.defaultBlockState(); | ||
} else if (chance <= 0.02) { | ||
oreState = Blocks.DEEPSLATE_LAPIS_ORE.defaultBlockState(); | ||
} | ||
if (oreState != null) { | ||
this.placeBlock(level, oreState, pos.getX(), pos.getY(), pos.getZ(), new BoundingBox(pos)); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/mods/railcraft/world/level/levelgen/structure/RailcraftStructurePieces.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,21 @@ | ||
package mods.railcraft.world.level.levelgen.structure; | ||
|
||
import mods.railcraft.Railcraft; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.minecraftforge.registries.DeferredRegister; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
public class RailcraftStructurePieces { | ||
|
||
private static final DeferredRegister<StructurePieceType> deferredRegister = | ||
DeferredRegister.create(Registries.STRUCTURE_PIECE, Railcraft.ID); | ||
|
||
public static final RegistryObject<StructurePieceType.ContextlessType> GEODE = | ||
deferredRegister.register("geode", () -> GeodeStructurePiece::new); | ||
|
||
public static void register(IEventBus modEventBus) { | ||
deferredRegister.register(modEventBus); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/mods/railcraft/world/level/levelgen/structure/RailcraftStructureTypes.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,23 @@ | ||
package mods.railcraft.world.level.levelgen.structure; | ||
|
||
import mods.railcraft.Railcraft; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.world.level.levelgen.structure.Structure; | ||
import net.minecraft.world.level.levelgen.structure.StructureType; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.minecraftforge.registries.DeferredRegister; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
public class RailcraftStructureTypes { | ||
|
||
private static final DeferredRegister<StructureType<?>> deferredRegister = | ||
DeferredRegister.create(Registries.STRUCTURE_TYPE, Railcraft.ID); | ||
|
||
public static final RegistryObject<StructureType<GeodeStructure>> GEODE = | ||
deferredRegister.register("geode", | ||
() -> () -> Structure.simpleCodec(GeodeStructure::new)); | ||
|
||
public static void register(IEventBus modEventBus) { | ||
deferredRegister.register(modEventBus); | ||
} | ||
} |
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