From 42b012b36dc37cf055ce095d8d3df832f9a545a1 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 12 Oct 2020 00:54:26 -0700 Subject: [PATCH] Add more ore performance options. --- .../com/dfsek/terra/config/genconfig/OreConfig.java | 10 +++++++++- .../java/com/dfsek/terra/population/OrePopulator.java | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dfsek/terra/config/genconfig/OreConfig.java b/src/main/java/com/dfsek/terra/config/genconfig/OreConfig.java index 0bade68e3..a89234d88 100644 --- a/src/main/java/com/dfsek/terra/config/genconfig/OreConfig.java +++ b/src/main/java/com/dfsek/terra/config/genconfig/OreConfig.java @@ -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 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; + } } diff --git a/src/main/java/com/dfsek/terra/population/OrePopulator.java b/src/main/java/com/dfsek/terra/population/OrePopulator.java index 7c845c302..1bbc6feeb 100644 --- a/src/main/java/com/dfsek/terra/population/OrePopulator.java +++ b/src/main/java/com/dfsek/terra/population/OrePopulator.java @@ -30,9 +30,10 @@ public class OrePopulator extends GaeaBlockPopulator { BiomeOreConfig ores = config.getBiome((UserDefinedBiome) b).getOres(); for(Map.Entry 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);