Skip to content

Commit

Permalink
new ore stuffs #34
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Aug 26, 2023
1 parent 281ddc4 commit 626661b
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/cr24/primeval/PrimevalMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.cr24.primeval.recipe.rei.PrimevalREIIntegration;
import net.cr24.primeval.util.PrimevalSoundEvents;
import net.cr24.primeval.world.PrimevalWorld;
import net.cr24.primeval.world.gen.structure.PrimevalStructures;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -27,6 +28,7 @@ public void onInitialize() {
PrimevalFluids.init();
PrimevalRecipes.init();
PrimevalWorld.init();
PrimevalStructures.init();
PrimevalVillagerTrades.init();
PrimevalSoundEvents.init();
}
Expand Down
42 changes: 12 additions & 30 deletions src/main/java/net/cr24/primeval/world/PrimevalWorld.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package net.cr24.primeval.world;

import net.cr24.primeval.PrimevalMain;
import net.cr24.primeval.world.gen.feature.PrimevalFeatures;
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
import net.minecraft.client.realms.dto.RealmsServer;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.passive.PigEntity;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
Expand All @@ -22,29 +18,16 @@
public class PrimevalWorld {

/* BIOMES */
public static final BiomeEffects UNIVERSAL_EFFECTS = new BiomeEffects.Builder() .skyColor(7907327).fogColor(12638463).grassColor(9551193).waterColor(5404090).waterFogColor(329011).build();
public static final BiomeEffects UNIVERSAL_EFFECTS = new BiomeEffects.Builder().skyColor(7907327).fogColor(12638463).grassColor(9551193).waterColor(5404090).waterFogColor(329011).build();

public static final List<RegistryEntry<PlacedFeature>> UNDERGROUND_FEATURES_NO_ZINC = List.of(
NATIVE_COPPER_ORE_CLUSTER, MALACHITE_COPPER_ORE_CLUSTER, CASSITERITE_TIN_ORE_CLUSTER, LAZURITE_ORE_CLUSTER,
DIRT_ORE_BLOBS, GRAVEL_ORE_BLOBS, FOSSIL_ORE_BLOBS
);
public static final List<RegistryEntry<PlacedFeature>> UNDERGROUND_FEATURES_NO_TIN = List.of(
NATIVE_COPPER_ORE_CLUSTER, MALACHITE_COPPER_ORE_CLUSTER, SPHALERITE_ZINC_ORE_CLUSTER, LAZURITE_ORE_CLUSTER,
DIRT_ORE_BLOBS, GRAVEL_ORE_BLOBS, FOSSIL_ORE_BLOBS
);
public static final List<RegistryEntry<PlacedFeature>> UNDERGROUND_FEATURES_NO_COPPER = List.of(
CASSITERITE_TIN_ORE_CLUSTER, SPHALERITE_ZINC_ORE_CLUSTER, LAZURITE_ORE_CLUSTER,
DIRT_ORE_BLOBS, GRAVEL_ORE_BLOBS, FOSSIL_ORE_BLOBS
);
public static final List<RegistryEntry<PlacedFeature>> UNDERGROUND_FEATURES_ALL = List.of(
NATIVE_COPPER_ORE_CLUSTER, MALACHITE_COPPER_ORE_CLUSTER, CASSITERITE_TIN_ORE_CLUSTER, SPHALERITE_ZINC_ORE_CLUSTER, LAZURITE_ORE_CLUSTER,
public static final List<RegistryEntry<PlacedFeature>> UNDERGROUND_FEATURES = List.of(
DIRT_ORE_BLOBS, GRAVEL_ORE_BLOBS, FOSSIL_ORE_BLOBS
);

// INLAND
public static final RegistryEntry<Biome> PLAINS = registerBiome(getBiomeKey("inland/plains"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_NO_TIN,
UNDERGROUND_FEATURES,
List.of(PLAINS_OAK_TRUNKED_TREE,
MOSS_RARE, RIVER_GRASS,
STICK_ITEM_PATCH, FLINT_ITEM_PATCH, ROCK_ITEM_PATCH,
Expand All @@ -56,7 +39,7 @@ public class PrimevalWorld {
));
public static final RegistryEntry<Biome> OAK_FOREST = registerBiome(getBiomeKey("inland/oak_forest"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_NO_ZINC,
UNDERGROUND_FEATURES,
List.of(FOREST_OAK_TRUNKED_TREE,
MOSS_RARE, RIVER_GRASS,
STICK_ITEM_PATCH, FLINT_ITEM_PATCH, ROCK_ITEM_PATCH,
Expand All @@ -68,7 +51,7 @@ public class PrimevalWorld {
));
public static final RegistryEntry<Biome> DENSE_OAK_FOREST = registerBiome(getBiomeKey("inland/dense_oak_forest"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_NO_ZINC,
UNDERGROUND_FEATURES,
List.of(FOREST_DENSE_OAK_TRUNKED_TREE,
MOSS_RARE, RIVER_GRASS,
STICK_ITEM_PATCH, FLINT_ITEM_PATCH, ROCK_ITEM_PATCH,
Expand All @@ -80,7 +63,7 @@ public class PrimevalWorld {
));
public static final RegistryEntry<Biome> BIRCH_FOREST = registerBiome(getBiomeKey("inland/birch_forest"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_NO_ZINC,
UNDERGROUND_FEATURES,
List.of(FOREST_BIRCH_TRUNKED_TREE,
MOSS_RARE, RIVER_GRASS,
STICK_ITEM_PATCH, FLINT_ITEM_PATCH, ROCK_ITEM_PATCH,
Expand All @@ -92,7 +75,7 @@ public class PrimevalWorld {
));
public static final RegistryEntry<Biome> TAIGA = registerBiome(getBiomeKey("inland/taiga"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_ALL,
UNDERGROUND_FEATURES,
List.of(FOREST_SPRUCE_TRUNKED_TREE,
MOSS_RARE, RIVER_GRASS,
STICK_ITEM_PATCH, FLINT_ITEM_PATCH, ROCK_ITEM_PATCH,
Expand All @@ -104,7 +87,7 @@ public class PrimevalWorld {
));
public static final RegistryEntry<Biome> ROCKY_OUTCROP = registerBiome(getBiomeKey("inland/rocky_outcrop"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_ALL,
UNDERGROUND_FEATURES,
List.of(MOSS_RARE,
FLINT_ITEM_PATCH, ROCK_ITEM_PATCH,
NATIVE_COPPER_ITEM_PATCH, MALACHITE_COPPER_ITEM_PATCH, MIXED_COPPER_ITEM_PATCH, CASSITERITE_TIN_ITEM_PATCH, SPHALERITE_ZINC_ITEM_PATCH,
Expand All @@ -115,7 +98,7 @@ public class PrimevalWorld {
));
public static final RegistryEntry<Biome> CRUMBLING_CLIFFS = registerBiome(getBiomeKey("inland/crumbling_cliffs"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_ALL,
UNDERGROUND_FEATURES,
List.of(FLINT_ITEM_PATCH, ROCK_ITEM_PATCH,
NATIVE_COPPER_ITEM_PATCH, MALACHITE_COPPER_ITEM_PATCH, MIXED_COPPER_ITEM_PATCH, CASSITERITE_TIN_ITEM_PATCH, SPHALERITE_ZINC_ITEM_PATCH
)
Expand All @@ -125,15 +108,15 @@ public class PrimevalWorld {
// COASTAL
public static final RegistryEntry<Biome> SANDY_SHORE = registerBiome(getBiomeKey("coastal/sandy_shore"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_NO_TIN,
UNDERGROUND_FEATURES,
List.of(STICK_ITEM_PATCH, ROCK_ITEM_PATCH,
SPARSE_GRASS_PATCH, CORNFLOWER_PATCH
)
)
));
public static final RegistryEntry<Biome> ROCKY_SHORE = registerBiome(getBiomeKey("coastal/rocky_shore"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_NO_TIN,
UNDERGROUND_FEATURES,
List.of(STICK_ITEM_PATCH, FLINT_ITEM_PATCH, ROCK_ITEM_PATCH,
WILD_CARROTS_PATCH
)
Expand All @@ -143,12 +126,11 @@ public class PrimevalWorld {
// ETC
public static final RegistryEntry<Biome> OCEAN = registerBiome(getBiomeKey("ocean"), createBiome(
buildGeneratorSettings(
UNDERGROUND_FEATURES_ALL,
UNDERGROUND_FEATURES,
List.of()
)
));


public static void init() {}

private static Biome createBiome(GenerationSettings g) {
Expand Down
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);
}
}
}
}
}
}
}

}
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;
}
}
Loading

0 comments on commit 626661b

Please sign in to comment.