mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-18 22:30:00 +00:00
build ore addon
This commit is contained in:
@@ -2,16 +2,12 @@ package com.dfsek.terra.addons.ore;
|
||||
|
||||
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;
|
||||
@@ -33,10 +29,11 @@ public class OrePopulator implements TerraBlockPopulator {
|
||||
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()));
|
||||
Random random = new Random(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;
|
||||
@@ -49,6 +46,8 @@ public class OrePopulator implements TerraBlockPopulator {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ 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.MaterialSet;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.dfsek.terra.addons.ore.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.util.MaterialSet;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.addons.ore.ores;
|
||||
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.function.BiConsumer;
|
||||
* Holds ordered list of ores mapped to their configs.
|
||||
*/
|
||||
public class OreHolder {
|
||||
private final List<Entry> entries = new GlueList<>();
|
||||
private final List<Entry> entries = new ArrayList<>();
|
||||
|
||||
public void forEach(BiConsumer<String, ImmutablePair<Ore, OreConfig>> consumer) {
|
||||
entries.forEach(entry -> consumer.accept(entry.getId(), ImmutablePair.of(entry.getOre(), entry.getConfig())));
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.dfsek.terra.addons.ore.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.MaterialSet;
|
||||
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;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface MaterialSet extends Set<BlockType> {
|
||||
}
|
||||
@@ -5,12 +5,12 @@ import com.dfsek.terra.api.world.Chunk;
|
||||
import java.util.Random;
|
||||
|
||||
public final class PopulationUtil {
|
||||
public static FastRandom getRandom(Chunk c) {
|
||||
public static Random getRandom(Chunk c) {
|
||||
return getRandom(c, 0);
|
||||
}
|
||||
|
||||
public static FastRandom getRandom(Chunk c, long salt) {
|
||||
return new FastRandom(getCarverChunkSeed(c.getX(), c.getZ(), c.getWorld().getSeed() + salt));
|
||||
public static Random getRandom(Chunk c, long salt) {
|
||||
return new Random(getCarverChunkSeed(c.getX(), c.getZ(), c.getWorld().getSeed() + salt));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,7 +22,7 @@ public final class PopulationUtil {
|
||||
* @return long - The carver seed.
|
||||
*/
|
||||
public static long getCarverChunkSeed(int chunkX, int chunkZ, long seed) {
|
||||
Random r = new FastRandom(seed);
|
||||
Random r = new Random(seed);
|
||||
return chunkX * r.nextLong() ^ chunkZ * r.nextLong() ^ seed;
|
||||
}
|
||||
}
|
||||
@@ -2,33 +2,34 @@ package com.dfsek.terra.api.util.collections;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.util.MaterialSet;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class MaterialSet extends HashSet<BlockType> {
|
||||
public class MaterialSetImpl extends HashSet<BlockType> implements MaterialSet {
|
||||
private static final long serialVersionUID = 3056512763631017301L;
|
||||
|
||||
public static MaterialSet singleton(BlockType material) {
|
||||
MaterialSet set = new MaterialSet();
|
||||
public static MaterialSetImpl singleton(BlockType material) {
|
||||
MaterialSetImpl set = new MaterialSetImpl();
|
||||
set.add(material);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static MaterialSet get(BlockType... materials) {
|
||||
MaterialSet set = new MaterialSet();
|
||||
public static MaterialSetImpl get(BlockType... materials) {
|
||||
MaterialSetImpl set = new MaterialSetImpl();
|
||||
set.addAll(Arrays.asList(materials));
|
||||
return set;
|
||||
}
|
||||
|
||||
public static MaterialSet get(BlockState... materials) {
|
||||
MaterialSet set = new MaterialSet();
|
||||
public static MaterialSetImpl get(BlockState... materials) {
|
||||
MaterialSetImpl set = new MaterialSetImpl();
|
||||
Arrays.stream(materials).forEach(set::add);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static MaterialSet empty() {
|
||||
return new MaterialSet();
|
||||
public static MaterialSetImpl empty() {
|
||||
return new MaterialSetImpl();
|
||||
}
|
||||
|
||||
private void add(BlockState data) {
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
import com.dfsek.terra.api.util.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSetImpl;
|
||||
import com.dfsek.terra.api.world.biome.generation.pipeline.BiomeSource;
|
||||
import com.dfsek.terra.config.loaders.LinkedHashMapLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||
@@ -27,7 +27,7 @@ public class GenericLoaders implements LoaderRegistrar {
|
||||
public void register(TypeRegistry registry) {
|
||||
registry.registerLoader(ProbabilityCollection.class, new ProbabilityCollectionLoader())
|
||||
.registerLoader(Range.class, new RangeLoader())
|
||||
.registerLoader(MaterialSet.class, new MaterialSetLoader())
|
||||
.registerLoader(MaterialSetImpl.class, new MaterialSetLoader())
|
||||
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader())
|
||||
.registerLoader(BiomeSource.Type.class, (t, object, cf) -> BiomeSource.Type.valueOf((String) object));
|
||||
|
||||
|
||||
@@ -4,17 +4,17 @@ import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSetImpl;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MaterialSetLoader implements TypeLoader<MaterialSet> {
|
||||
public class MaterialSetLoader implements TypeLoader<MaterialSetImpl> {
|
||||
@Override
|
||||
public MaterialSet load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
public MaterialSetImpl load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
List<String> stringData = (List<String>) o;
|
||||
MaterialSet set = new MaterialSet();
|
||||
MaterialSetImpl set = new MaterialSetImpl();
|
||||
|
||||
for(String string : stringData) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user