mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Optimize ores
This commit is contained in:
parent
eb1c3896bb
commit
1b0cbe486f
@ -31,8 +31,6 @@ public class OreConfig extends TerraConfig {
|
||||
private final double deformFrequency;
|
||||
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 {
|
||||
@ -47,11 +45,6 @@ public class OreConfig extends TerraConfig {
|
||||
deform = getDouble("deform", 0.75);
|
||||
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());
|
||||
|
||||
@ -121,12 +114,4 @@ public class OreConfig extends TerraConfig {
|
||||
public String toString() {
|
||||
return "Ore with ID " + getID();
|
||||
}
|
||||
|
||||
public boolean crossChunks() {
|
||||
return crossChunks;
|
||||
}
|
||||
|
||||
public int getChunkEdgeOffset() {
|
||||
return chunkEdgeOffset;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
super(ChunkInterpolator.InterpolationType.TRILINEAR);
|
||||
this.configPack = c;
|
||||
popMan.attach(new FloraPopulator());
|
||||
popMan.attach(new OrePopulator());
|
||||
popMan.attach(new SnowPopulator());
|
||||
}
|
||||
|
||||
@ -226,7 +225,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
|
||||
@Override
|
||||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||
return Arrays.asList(new CavePopulator(), new StructurePopulator(), popMan);
|
||||
return Arrays.asList(new CavePopulator(), new StructurePopulator(), new OrePopulator(), popMan);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,49 +3,52 @@ package com.dfsek.terra.population;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.genconfig.OreConfig;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeOreConfig;
|
||||
import com.dfsek.terra.event.OreVeinGenerateEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.math.MathUtil;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.population.GaeaBlockPopulator;
|
||||
import org.polydev.gaea.profiler.ProfileFuture;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class OrePopulator extends GaeaBlockPopulator {
|
||||
public class OrePopulator extends BlockPopulator {
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
if(!tw.isSafe()) return;
|
||||
ConfigPack config = tw.getConfig();
|
||||
Biome b = TerraWorld.getWorld(world).getGrid().getBiome((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8, GenerationPhase.POPULATE);
|
||||
BiomeOreConfig ores = config.getBiome((UserDefinedBiome) b).getOres();
|
||||
for(Map.Entry<OreConfig, Range> e : ores.getOres().entrySet()) {
|
||||
int num = e.getValue().get(random);
|
||||
OreConfig ore = e.getKey();
|
||||
int edgeOffset = ore.getChunkEdgeOffset();
|
||||
for(int i = 0; i < num; i++) {
|
||||
int x = random.nextInt(16 - (edgeOffset << 1)) + edgeOffset;
|
||||
int z = random.nextInt(16 - (edgeOffset << 1)) + edgeOffset;
|
||||
int y = ores.getOreHeights().get(ore).get(random);
|
||||
for(int cx = -1; cx <= 1; cx++) {
|
||||
for(int cz = -1; cz <= 1; cz++) {
|
||||
FastRandom r = new FastRandom(MathUtil.getCarverChunkSeed(chunk.getX() + cx, chunk.getZ() + cz, world.getSeed()));
|
||||
Biome b = TerraWorld.getWorld(world).getGrid().getBiome(((chunk.getX() + cx) << 4) + 8, ((chunk.getZ() + cz) << 4) + 8, GenerationPhase.POPULATE);
|
||||
BiomeOreConfig ores = ((UserDefinedBiome) b).getConfig().getOres();
|
||||
for(Map.Entry<OreConfig, Range> e : ores.getOres().entrySet()) {
|
||||
int num = e.getValue().get(r);
|
||||
OreConfig ore = e.getKey();
|
||||
for(int i = 0; i < num; i++) {
|
||||
int x = r.nextInt(16) + cx * 16;
|
||||
int z = r.nextInt(16) + cz * 16;
|
||||
int y = ores.getOreHeights().get(ore).get(r);
|
||||
|
||||
Vector v = new Vector(x, y, z);
|
||||
OreVeinGenerateEvent event = new OreVeinGenerateEvent(tw, v.toLocation(world), ore);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()) {
|
||||
if(ore.crossChunks()) ore.doVein(v, chunk, random);
|
||||
else ore.doVeinSingle(new Vector(x, y, z), chunk, random);
|
||||
Vector v = new Vector(x, y, z);
|
||||
OreVeinGenerateEvent event = new OreVeinGenerateEvent(tw, v.toLocation(world), ore);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()) {
|
||||
ore.doVeinSingle(new Vector(x, y, z), chunk, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user