mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 23:06:05 +00:00
refactor ores
This commit is contained in:
@@ -46,8 +46,8 @@ import com.dfsek.terra.addons.palette.palette.PaletteLayerLoader;
|
||||
import com.dfsek.terra.addons.palette.palette.slant.SlantHolderLoader;
|
||||
import com.dfsek.terra.addons.flora.flora.FloraLayer;
|
||||
import com.dfsek.terra.addons.flora.flora.TerraFlora;
|
||||
import com.dfsek.terra.world.population.items.ores.OreConfig;
|
||||
import com.dfsek.terra.world.population.items.ores.OreHolder;
|
||||
import com.dfsek.terra.addons.ore.ores.OreConfig;
|
||||
import com.dfsek.terra.addons.ore.ores.OreHolder;
|
||||
import com.dfsek.terra.world.population.items.tree.TreeLayer;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.config.templates.OreTemplate;
|
||||
import com.dfsek.terra.world.population.items.ores.Ore;
|
||||
import com.dfsek.terra.world.population.items.ores.VanillaOre;
|
||||
|
||||
public class OreFactory implements ConfigFactory<OreTemplate, Ore> {
|
||||
@Override
|
||||
public Ore build(OreTemplate config, TerraPlugin main) {
|
||||
BlockState m = config.getMaterial();
|
||||
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main, config.getMaterialOverrides());
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.math.range.ConstantRange;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.world.population.items.ores.OreConfig;
|
||||
import com.dfsek.terra.addons.ore.ores.OreConfig;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.dfsek.terra.config.loaders.config;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.world.population.items.ores.Ore;
|
||||
import com.dfsek.terra.world.population.items.ores.OreConfig;
|
||||
import com.dfsek.terra.world.population.items.ores.OreHolder;
|
||||
import com.dfsek.terra.addons.ore.ores.Ore;
|
||||
import com.dfsek.terra.addons.ore.ores.OreConfig;
|
||||
import com.dfsek.terra.addons.ore.ores.OreHolder;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.dfsek.terra.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class OreTemplate implements AbstractableTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("material")
|
||||
@Abstractable
|
||||
private BlockState material;
|
||||
|
||||
@Value("material-overrides")
|
||||
@Default
|
||||
@Abstractable
|
||||
private Map<BlockType, BlockState> materials = new HashMap<>();
|
||||
|
||||
@Value("replace")
|
||||
@Abstractable
|
||||
private MaterialSet replaceable;
|
||||
|
||||
@Value("physics")
|
||||
@Abstractable
|
||||
@Default
|
||||
private boolean physics = false;
|
||||
|
||||
@Value("size")
|
||||
@Abstractable
|
||||
private Range size;
|
||||
|
||||
@Value("deform")
|
||||
@Abstractable
|
||||
@Default
|
||||
private double deform = 0.75D;
|
||||
|
||||
@Value("deform-frequency")
|
||||
@Abstractable
|
||||
@Default
|
||||
private double deformFrequency = 0.1D;
|
||||
|
||||
public double getDeform() {
|
||||
return deform;
|
||||
}
|
||||
|
||||
public double getDeformFrequency() {
|
||||
return deformFrequency;
|
||||
}
|
||||
|
||||
public Range getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public BlockState getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public boolean doPhysics() {
|
||||
return physics;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Map<BlockType, BlockState> getMaterialOverrides() {
|
||||
return materials;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
import com.dfsek.terra.world.population.items.ores.Ore;
|
||||
import com.dfsek.terra.addons.ore.ores.Ore;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.dfsek.terra.world.population;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.util.PopulationUtil;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.TerraWorld;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.generator.TerraBlockPopulator;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class OrePopulator implements TerraBlockPopulator {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public OrePopulator(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Chunk chunk) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("ore")) {
|
||||
if(tw.getConfig().disableOres()) return;
|
||||
|
||||
if(!tw.isSafe()) return;
|
||||
for(int cx = -1; cx <= 1; cx++) {
|
||||
for(int cz = -1; cz <= 1; cz++) {
|
||||
Random random = new FastRandom(PopulationUtil.getCarverChunkSeed(chunk.getX() + cx, chunk.getZ() + cz, world.getSeed()));
|
||||
int originX = ((chunk.getX() + cx) << 4);
|
||||
int originZ = ((chunk.getZ() + cz) << 4);
|
||||
TerraBiome b = tw.getBiomeProvider().getBiome(originX + 8, originZ + 8);
|
||||
BiomeTemplate config = ((UserDefinedBiome) b).getConfig();
|
||||
int finalCx = cx;
|
||||
int finalCz = cz;
|
||||
config.getOreHolder().forEach((id, orePair) -> {
|
||||
try(ProfileFrame ignored = main.getProfiler().profile("ore:" + id)) {
|
||||
int amount = orePair.getRight().getAmount().get(random);
|
||||
for(int i = 0; i < amount; i++) {
|
||||
Vector3 location = new Vector3(random.nextInt(16) + 16 * finalCx, orePair.getRight().getHeight().get(random), random.nextInt(16) + 16 * finalCz);
|
||||
orePair.getLeft().generate(location, chunk, random);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.dfsek.terra.world.population.items.ores;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Ore {
|
||||
|
||||
private final BlockState material;
|
||||
private final MaterialSet replaceable;
|
||||
private final boolean applyGravity;
|
||||
protected TerraPlugin main;
|
||||
private final Map<BlockType, BlockState> materials;
|
||||
|
||||
public Ore(BlockState material, MaterialSet replaceable, boolean applyGravity, TerraPlugin main, Map<BlockType, BlockState> materials) {
|
||||
this.material = material;
|
||||
this.replaceable = replaceable;
|
||||
this.applyGravity = applyGravity;
|
||||
this.main = main;
|
||||
this.materials = materials;
|
||||
}
|
||||
|
||||
public abstract void generate(Vector3 origin, Chunk c, Random r);
|
||||
|
||||
public BlockState getMaterial(BlockType replace) {
|
||||
return materials.getOrDefault(replace, material);
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public boolean isApplyGravity() {
|
||||
return applyGravity;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.world.population.items.ores;
|
||||
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
public class OreConfig {
|
||||
private final Range amount;
|
||||
private final Range height;
|
||||
|
||||
public OreConfig(Range amount, Range height) {
|
||||
this.amount = amount;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Range getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Range getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.dfsek.terra.world.population.items.ores;
|
||||
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Holds ordered list of ores mapped to their configs.
|
||||
*/
|
||||
public class OreHolder {
|
||||
private final List<Entry> entries = new GlueList<>();
|
||||
|
||||
public void forEach(BiConsumer<String, ImmutablePair<Ore, OreConfig>> consumer) {
|
||||
entries.forEach(entry -> consumer.accept(entry.getId(), ImmutablePair.of(entry.getOre(), entry.getConfig())));
|
||||
}
|
||||
|
||||
public OreHolder add(Ore ore, OreConfig config, String id) {
|
||||
entries.add(new Entry(ore, config, id));
|
||||
return this;
|
||||
}
|
||||
|
||||
private static final class Entry {
|
||||
private final Ore ore;
|
||||
private final OreConfig config;
|
||||
private final String id;
|
||||
|
||||
private Entry(Ore ore, OreConfig config, String id) {
|
||||
this.ore = ore;
|
||||
this.config = config;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public OreConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Ore getOre() {
|
||||
return ore;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.dfsek.terra.world.population.items.ores;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class VanillaOre extends Ore {
|
||||
private final Range sizeRange;
|
||||
|
||||
public VanillaOre(BlockState material, MaterialSet replaceable, boolean applyGravity, Range size, TerraPlugin main, Map<BlockType, BlockState> materials) {
|
||||
super(material, replaceable, applyGravity, main, materials);
|
||||
this.sizeRange = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Vector3 location, Chunk chunk, Random random) {
|
||||
double size = sizeRange.get(random);
|
||||
|
||||
int centerX = location.getBlockX();
|
||||
int centerZ = location.getBlockZ();
|
||||
int centerY = location.getBlockY();
|
||||
|
||||
|
||||
double f = random.nextFloat() * Math.PI;
|
||||
|
||||
double fS = FastMath.sin(f) * size / 8.0F;
|
||||
double fC = FastMath.cos(f) * size / 8.0F;
|
||||
|
||||
double d1 = centerX + 8 + fS;
|
||||
double d2 = centerX + 8 - fS;
|
||||
double d3 = centerZ + 8 + fC;
|
||||
double d4 = centerZ + 8 - fC;
|
||||
|
||||
double d5 = centerY + random.nextInt(3) - 2D;
|
||||
double d6 = centerY + random.nextInt(3) - 2D;
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
double iFactor = i / size;
|
||||
|
||||
double d10 = random.nextDouble() * size / 16.0D;
|
||||
double d11 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0;
|
||||
|
||||
int xStart = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor - d11 / 2.0D));
|
||||
int yStart = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor - d11 / 2.0D));
|
||||
int zStart = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor - d11 / 2.0D));
|
||||
|
||||
int xEnd = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor + d11 / 2.0D));
|
||||
int yEnd = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor + d11 / 2.0D));
|
||||
int zEnd = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor + d11 / 2.0D));
|
||||
|
||||
for(int x = xStart; x <= xEnd; x++) {
|
||||
double d13 = (x + 0.5D - (d1 + (d2 - d1) * iFactor)) / (d11 / 2.0D);
|
||||
|
||||
if(d13 * d13 < 1.0D) {
|
||||
for(int y = yStart; y <= yEnd; y++) {
|
||||
double d14 = (y + 0.5D - (d5 + (d6 - d5) * iFactor)) / (d11 / 2.0D);
|
||||
if(d13 * d13 + d14 * d14 < 1.0D) {
|
||||
for(int z = zStart; z <= zEnd; z++) {
|
||||
double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D);
|
||||
if(x > 15 || z > 15 || y > 255 || x < 0 || z < 0 || y < 0) continue;
|
||||
|
||||
BlockType type = chunk.getBlock(x, y, z).getBlockType();
|
||||
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(type)) {
|
||||
chunk.setBlock(x, y, z, getMaterial(type), isApplyGravity());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user