-
Notifications
You must be signed in to change notification settings - Fork 1
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
8 changed files
with
300 additions
and
30 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
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
148 changes: 148 additions & 0 deletions
148
src/main/java/net/cr24/primeval/world/gen/structure/OreFieldGenerator.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,148 @@ | ||
package net.cr24.primeval.world.gen.structure; | ||
|
||
import net.cr24.primeval.block.PrimevalBlocks; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtHelper; | ||
import net.minecraft.structure.*; | ||
import net.minecraft.tag.BlockTags; | ||
import net.minecraft.util.math.BlockBox; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.ChunkPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.world.StructureWorldAccess; | ||
import net.minecraft.world.gen.StructureAccessor; | ||
import net.minecraft.world.gen.chunk.ChunkGenerator; | ||
|
||
import java.awt.geom.Point2D; | ||
|
||
public class OreFieldGenerator { | ||
|
||
public static class Blob extends ShiftableStructurePiece { | ||
|
||
public final int height; | ||
public final int size; | ||
public final int[] ballParams; | ||
public final float richness; | ||
public final BlockState largeState; | ||
public final BlockState mediumState; | ||
public final BlockState smallState; | ||
public final BlockState extraState; | ||
|
||
public Blob(Random random, int x, int z, int height, int size, int ballCount, int ballSizeMin, int ballSizeMax, float richness, BlockState[] states) { | ||
super(PrimevalStructures.ORE_FIELD_PIECE, x, height, z, size, 20, size, Direction.NORTH); | ||
this.height = height; | ||
this.size = size; | ||
int[] params = new int[ballCount*4]; | ||
for (int i = 0; i < ballCount*4; i += 4) { | ||
int ballSize = random.nextBetween(ballSizeMin, ballSizeMax); | ||
params[i] = ballSize-2; | ||
params[i+1] = random.nextBetween(ballSize, size-ballSize); | ||
params[i+2] = random.nextBetween(0, 6); | ||
params[i+3] = random.nextBetween(ballSize, size-ballSize); | ||
} | ||
this.ballParams = params; | ||
this.richness = richness; | ||
this.largeState = states[0]; | ||
this.mediumState = states[1]; | ||
this.smallState = states[2]; | ||
this.extraState = states[3]; | ||
} | ||
|
||
public Blob(NbtCompound nbt) { | ||
super(PrimevalStructures.ORE_FIELD_PIECE, nbt); | ||
this.height = nbt.getInt("Height"); | ||
this.size = nbt.getInt("Size"); | ||
this.ballParams = nbt.getIntArray("BallParams"); | ||
this.richness = nbt.getFloat("Richness"); | ||
this.largeState = NbtHelper.toBlockState(nbt.getCompound("LargeState")); | ||
this.mediumState = NbtHelper.toBlockState(nbt.getCompound("MediumState")); | ||
this.smallState = NbtHelper.toBlockState(nbt.getCompound("SmallState")); | ||
this.extraState = NbtHelper.toBlockState(nbt.getCompound("ExtraState")); | ||
} | ||
|
||
|
||
public Blob(StructureContext structureContext, NbtCompound nbtCompound) { | ||
this(nbtCompound); | ||
} | ||
|
||
protected void writeNbt(StructureContext context, NbtCompound nbt) { | ||
super.writeNbt(context, nbt); | ||
nbt.putInt("Height", this.height); | ||
nbt.putInt("Size", this.size); | ||
nbt.putIntArray("BallParams", this.ballParams); | ||
nbt.putFloat("Richness", this.richness); | ||
nbt.put("LargeState", NbtHelper.fromBlockState(this.largeState)); | ||
nbt.put("MediumState", NbtHelper.fromBlockState(this.mediumState)); | ||
nbt.put("SmallState", NbtHelper.fromBlockState(this.smallState)); | ||
nbt.put("ExtraState", NbtHelper.fromBlockState(this.extraState)); | ||
} | ||
|
||
public void generate(StructureWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockBox chunkBox, ChunkPos chunkPos, BlockPos pivot) { | ||
if (this.adjustToAverageHeight(world, chunkBox, -24)) { | ||
for (int i = 0; i < ballParams.length; i += 4) { | ||
Ball b = new Ball(ballParams[i], ballParams[i + 1], ballParams[i + 2], ballParams[i + 3], richness, largeState, mediumState, smallState, extraState); | ||
b.generate(this, world, chunkBox, random); | ||
} | ||
} | ||
} | ||
|
||
public void pAddBlock(StructureWorldAccess world, BlockState block, int x, int y, int z, BlockBox box) { | ||
this.addBlock(world, block, x, y, z, box); | ||
} | ||
|
||
public boolean validBlock(StructureWorldAccess world, int x, int y, int z, BlockBox box) { | ||
return this.getBlockAt(world, x, y, z, box).isIn(BlockTags.BASE_STONE_OVERWORLD); | ||
} | ||
|
||
} | ||
|
||
private static class Ball { | ||
|
||
public final int size; | ||
public final int xOffset; | ||
public final int yOffset; | ||
public final int zOffset; | ||
public final float richness; | ||
private final Point2D center = new Point2D.Float(0, 0); | ||
public final BlockState largeState; | ||
public final BlockState mediumState; | ||
public final BlockState smallState; | ||
public final BlockState extraState; | ||
|
||
public Ball(int size, int xOffset, int yOffset, int zOffset, float richness, BlockState largeState, BlockState mediumState, BlockState smallState, BlockState extraState) { | ||
this.size = size; | ||
this.xOffset = xOffset; | ||
this.yOffset = yOffset; | ||
this.zOffset = zOffset; | ||
this.richness = richness; | ||
this.largeState = largeState; | ||
this.mediumState = mediumState; | ||
this.smallState = smallState; | ||
this.extraState = extraState; | ||
} | ||
|
||
public void generate(Blob blob, StructureWorldAccess world, BlockBox chunkBox, Random random) { | ||
for (int i = -size; i < size; i++) { | ||
for (int j = -size; j < size; j++) { | ||
for (int k = -size/2; k <= size/2; k++) { | ||
if (center.distance(i, j) < size-Math.abs(k/2) && blob.validBlock(world, xOffset+i, yOffset+k, zOffset+j, chunkBox)) { | ||
float threshold = random.nextFloat(); | ||
if (threshold > richness) { | ||
blob.pAddBlock(world, largeState, xOffset+i, yOffset+k, zOffset+j, chunkBox); | ||
} else if (threshold > richness/2) { | ||
blob.pAddBlock(world, mediumState, xOffset+i, yOffset+k, zOffset+j, chunkBox); | ||
} else if (threshold > richness/4) { | ||
blob.pAddBlock(world, smallState, xOffset+i, yOffset+k, zOffset+j, chunkBox); | ||
} else if (threshold > richness/8) { | ||
blob.pAddBlock(world, extraState, xOffset+i, yOffset+k, zOffset+j, chunkBox); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/net/cr24/primeval/world/gen/structure/OreFieldStructure.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,60 @@ | ||
package net.cr24.primeval.world.gen.structure; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.cr24.primeval.block.PrimevalBlocks; | ||
import net.cr24.primeval.world.PrimevalWorld; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.structure.StructurePiecesCollector; | ||
import net.minecraft.world.Heightmap; | ||
import net.minecraft.world.gen.structure.Structure; | ||
import net.minecraft.world.gen.structure.StructureType; | ||
|
||
import java.util.Optional; | ||
|
||
public class OreFieldStructure extends Structure { | ||
|
||
public static final Codec<OreFieldStructure> CODEC = createCodec(OreFieldStructure::new); | ||
|
||
public OreFieldStructure(Config config) { | ||
super(config); | ||
} | ||
|
||
public Optional<Structure.StructurePosition> getStructurePosition(Structure.Context context) { | ||
return getStructurePosition(context, Heightmap.Type.WORLD_SURFACE_WG, (collector) -> { | ||
addPieces(collector, context); | ||
}); | ||
} | ||
|
||
private static void addPieces(StructurePiecesCollector collector, Structure.Context context) { | ||
int height = 110; | ||
BlockState[] ores = new BlockState[] { | ||
PrimevalBlocks.COPPER_NATIVE_ORE.large().getDefaultState(), | ||
PrimevalBlocks.COPPER_NATIVE_ORE.medium().getDefaultState(), | ||
PrimevalBlocks.COPPER_NATIVE_ORE.small().getDefaultState(), | ||
PrimevalBlocks.STONE.getDefaultState() | ||
}; | ||
// Motherlode | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX(), context.chunkPos().getStartZ(), height, 60, 8, 7, 9, 0.5f, ores)); | ||
// Inner ring | ||
int innerRingRadius = 32; | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX()+innerRingRadius, context.chunkPos().getStartZ(), height, 50, 6, 3, 6, 0.6f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX()-innerRingRadius, context.chunkPos().getStartZ(), height, 50, 6, 3, 6, 0.7f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX(), context.chunkPos().getStartZ()+innerRingRadius, height, 50, 6, 3, 6, 0.6f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX(), context.chunkPos().getStartZ()-innerRingRadius, height, 50, 6, 3, 6, 0.7f, ores)); | ||
// Outer Ring | ||
int outerRingRadius1 = 60; | ||
int outerRingRadius2 = 48; | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX()+outerRingRadius1, context.chunkPos().getStartZ(), height, 42, 4, 3, 4, 0.9f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX()-outerRingRadius1, context.chunkPos().getStartZ(), height, 42, 4, 3, 4, 0.9f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX(), context.chunkPos().getStartZ()+outerRingRadius1, height, 42, 4, 3, 4, 0.9f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX(), context.chunkPos().getStartZ()-outerRingRadius1, height, 42, 4, 3, 4, 0.9f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX()+outerRingRadius2, context.chunkPos().getStartZ()+outerRingRadius2, height, 35, 5, 3, 4, 1.2f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX()-outerRingRadius2, context.chunkPos().getStartZ()+outerRingRadius2, height, 35, 5, 3, 4, 1.2f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX()+outerRingRadius2, context.chunkPos().getStartZ()-outerRingRadius2, height, 35, 5, 3, 4, 1.2f, ores)); | ||
collector.addPiece(new OreFieldGenerator.Blob(context.random(), context.chunkPos().getStartX()-outerRingRadius2, context.chunkPos().getStartZ()-outerRingRadius2, height, 35, 5, 3, 4, 1.2f, ores)); | ||
} | ||
|
||
public StructureType<?> getType() { | ||
return PrimevalStructures.ORE_FIELD; | ||
} | ||
} |
Oops, something went wrong.