Add more ore performance options.

This commit is contained in:
dfsek
2020-10-12 00:54:26 -07:00
parent 6480fb0bb6
commit 42b012b36d
2 changed files with 12 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ public class OreConfig extends TerraConfig {
private final String id;
private final boolean update;
private final boolean crossChunks;
private final int chunkEdgeOffset;
Set<Material> replaceable;
public OreConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
super(file, config);
@@ -46,6 +47,9 @@ public class OreConfig extends TerraConfig {
deformFrequency = getDouble("deform-frequency", 0.1);
update = getBoolean("update", false);
crossChunks = getBoolean("cross-chunks", true);
chunkEdgeOffset = getInt("edge-offset", 1);
if(chunkEdgeOffset > 7 || chunkEdgeOffset < 0) throw new ConfigException("Edge offset is too high/low!", getID());
replaceable = ConfigUtil.toBlockData(getStringList("replace"), "replaceable", getID());
@@ -76,7 +80,7 @@ public class OreConfig extends TerraConfig {
if(source.distance(l) < (rad + 0.5) * ((ore.getSimplexFractal(x, y, z)+1)*deform)) {
ChunkCoordinate coord = new ChunkCoordinate(Math.floorDiv(oreLoc.getBlockX(), 16), Math.floorDiv(oreLoc.getBlockZ(), 16), chunk.getWorld().getUID());
Block b = chunks.computeIfAbsent(coord, k -> chunk.getWorld().getChunkAt(oreLoc.toLocation(chunk.getWorld())))
.getBlock(Math.floorMod(source.getBlockX(), 16), source.getBlockY(), Math.floorMod(source.getBlockZ(), 16));
.getBlock(Math.floorMod(source.getBlockX(), 16), source.getBlockY(), Math.floorMod(source.getBlockZ(), 16)); // Chunk caching conditional computation
if(replaceable.contains(b.getType()) && b.getLocation().getY() >= 0) b.setBlockData(oreData, update);
}
}
@@ -114,4 +118,8 @@ public class OreConfig extends TerraConfig {
public boolean crossChunks() {
return crossChunks;
}
public int getChunkEdgeOffset() {
return chunkEdgeOffset;
}
}

View File

@@ -30,9 +30,10 @@ public class OrePopulator extends GaeaBlockPopulator {
BiomeOreConfig ores = config.getBiome((UserDefinedBiome) b).getOres();
for(Map.Entry<OreConfig, Range> e : ores.getOres().entrySet()) {
int num = e.getValue().get(random);
int edgeOffset = e.getKey().getChunkEdgeOffset();
for(int i = 0; i < num; i++) {
int x = random.nextInt(16);
int z = random.nextInt(16);
int x = random.nextInt(16 - edgeOffset*2) + edgeOffset;
int z = random.nextInt(16 - edgeOffset*2) + edgeOffset;
int y = ores.getOreHeights().get(e.getKey()).get(random);
if(e.getKey().crossChunks()) e.getKey().doVein(new Vector(x, y, z), chunk, random);
else e.getKey().doVeinSingle(new Vector(x, y, z), chunk, random);