mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8876dc3b21
@ -1,6 +1,7 @@
|
|||||||
package com.dfsek.terra.async;
|
package com.dfsek.terra.async;
|
||||||
|
|
||||||
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
||||||
|
import com.dfsek.terra.config.base.ConfigUtil;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -27,11 +28,11 @@ public class AsyncBiomeFinder extends AsyncFeatureFinder<Biome> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(int x, int z, Biome target) {
|
public boolean isValid(int x, int z, Biome target) {
|
||||||
return getGrid().getBiome(x, z, GenerationPhase.POST_GEN).equals(target);
|
return getGrid().getBiome(x * ConfigUtil.biomeSearchRes, z * ConfigUtil.biomeSearchRes, GenerationPhase.POST_GEN).equals(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector finalizeVector(Vector orig) {
|
public Vector finalizeVector(Vector orig) {
|
||||||
return orig;
|
return orig.multiply(ConfigUtil.biomeSearchRes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.dfsek.terra.async;
|
package com.dfsek.terra.async;
|
||||||
|
|
||||||
import com.dfsek.terra.TerraWorld;
|
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
||||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||||
@ -34,7 +33,7 @@ public class AsyncStructureFinder extends AsyncFeatureFinder<StructureConfig> {
|
|||||||
public boolean isValid(int x, int z, StructureConfig target) {
|
public boolean isValid(int x, int z, StructureConfig target) {
|
||||||
World world = getWorld();
|
World world = getWorld();
|
||||||
Location spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed()).toLocation(world);
|
Location spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed()).toLocation(world);
|
||||||
if(!TerraWorld.getWorld(world).getConfig().getBiome((UserDefinedBiome) getGrid().getBiome(spawn)).getStructures().contains(target))
|
if(!((UserDefinedBiome) getGrid().getBiome(spawn)).getConfig().getStructures().contains(target))
|
||||||
return false;
|
return false;
|
||||||
Random r2 = new FastRandom(spawn.hashCode());
|
Random r2 = new FastRandom(spawn.hashCode());
|
||||||
Structure struc = target.getStructure(r2);
|
Structure struc = target.getStructure(r2);
|
||||||
|
@ -60,7 +60,7 @@ public class UserDefinedCarver extends Carver {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
||||||
ConfigPack c = TerraWorld.getWorld(w).getConfig();
|
ConfigPack c = TerraWorld.getWorld(w).getConfig();
|
||||||
return new FastRandom(random.nextLong() + hash).nextInt(100) < c.getBiome((UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getCarverChance(this);
|
return new FastRandom(random.nextLong() + hash).nextInt(100) < ((UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getConfig().getCarverChance(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UserDefinedWorm extends Worm {
|
private class UserDefinedWorm extends Worm {
|
||||||
|
@ -25,7 +25,7 @@ public class BiomeCommand extends WorldCommand {
|
|||||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
|
||||||
TerraBiomeGrid grid = TerraWorld.getWorld(sender.getWorld()).getGrid();
|
TerraBiomeGrid grid = TerraWorld.getWorld(sender.getWorld()).getGrid();
|
||||||
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(sender.getLocation(), GenerationPhase.POPULATE);
|
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(sender.getLocation(), GenerationPhase.POPULATE);
|
||||||
LangUtil.send("command.biome.in", sender, TerraWorld.getWorld(w).getConfig().getBiome(biome).getID());
|
LangUtil.send("command.biome.in", sender, biome.getID());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class BiomeInfoCommand extends WorldCommand {
|
|||||||
sender.sendMessage("Erodible: " + b.isErodible());
|
sender.sendMessage("Erodible: " + b.isErodible());
|
||||||
|
|
||||||
|
|
||||||
BiomeConfig bio = cfg.getBiome(b);
|
BiomeConfig bio = b.getConfig();
|
||||||
List<StructureConfig> structureConfigs = bio.getStructures();
|
List<StructureConfig> structureConfigs = bio.getStructures();
|
||||||
|
|
||||||
if(structureConfigs.size() == 0) sender.sendMessage("No Structures");
|
if(structureConfigs.size() == 0) sender.sendMessage("No Structures");
|
||||||
|
@ -2,7 +2,6 @@ package com.dfsek.terra.config.base;
|
|||||||
|
|
||||||
import com.dfsek.terra.Debug;
|
import com.dfsek.terra.Debug;
|
||||||
import com.dfsek.terra.Terra;
|
import com.dfsek.terra.Terra;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
|
||||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||||
import com.dfsek.terra.config.ConfigLoader;
|
import com.dfsek.terra.config.ConfigLoader;
|
||||||
import com.dfsek.terra.config.exception.ConfigException;
|
import com.dfsek.terra.config.exception.ConfigException;
|
||||||
@ -274,13 +273,6 @@ public class ConfigPack extends YamlConfiguration {
|
|||||||
return dataFolder;
|
return dataFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BiomeConfig getBiome(UserDefinedBiome b) {
|
|
||||||
for(BiomeConfig biome : biomes.values()) {
|
|
||||||
if(biome.getBiome().equals(b)) return biome;
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("No BiomeConfig for provided biome.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public BiomeConfig getBiome(String id) {
|
public BiomeConfig getBiome(String id) {
|
||||||
return biomes.get(id);
|
return biomes.get(id);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import java.io.IOException;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -29,7 +28,7 @@ public final class ConfigUtil {
|
|||||||
public static boolean debug;
|
public static boolean debug;
|
||||||
public static long dataSave; // Period of population data saving, in ticks.
|
public static long dataSave; // Period of population data saving, in ticks.
|
||||||
public static boolean masterDisableCaves;
|
public static boolean masterDisableCaves;
|
||||||
public static int cacheSize;
|
public static int biomeSearchRes;
|
||||||
|
|
||||||
public static void loadConfig(JavaPlugin main) {
|
public static void loadConfig(JavaPlugin main) {
|
||||||
main.saveDefaultConfig();
|
main.saveDefaultConfig();
|
||||||
@ -38,9 +37,9 @@ public final class ConfigUtil {
|
|||||||
LangUtil.load(config.getString("language", "en_us"), main);
|
LangUtil.load(config.getString("language", "en_us"), main);
|
||||||
|
|
||||||
debug = config.getBoolean("debug", false);
|
debug = config.getBoolean("debug", false);
|
||||||
cacheSize = config.getInt("cache-size", 3);
|
|
||||||
dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis() / 20L;
|
dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis() / 20L;
|
||||||
masterDisableCaves = config.getBoolean("master-disable.caves", false);
|
masterDisableCaves = config.getBoolean("master-disable.caves", false);
|
||||||
|
biomeSearchRes = config.getInt("biome-search-resolution", 4);
|
||||||
|
|
||||||
if(config.getBoolean("dump-default", true)) {
|
if(config.getBoolean("dump-default", true)) {
|
||||||
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||||
|
@ -31,8 +31,6 @@ public class OreConfig extends TerraConfig {
|
|||||||
private final double deformFrequency;
|
private final double deformFrequency;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final boolean update;
|
private final boolean update;
|
||||||
private final boolean crossChunks;
|
|
||||||
private final int chunkEdgeOffset;
|
|
||||||
Set<Material> replaceable;
|
Set<Material> replaceable;
|
||||||
|
|
||||||
public OreConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
public OreConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||||
@ -47,11 +45,6 @@ public class OreConfig extends TerraConfig {
|
|||||||
deform = getDouble("deform", 0.75);
|
deform = getDouble("deform", 0.75);
|
||||||
deformFrequency = getDouble("deform-frequency", 0.1);
|
deformFrequency = getDouble("deform-frequency", 0.1);
|
||||||
update = getBoolean("update", false);
|
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());
|
replaceable = ConfigUtil.toBlockData(getStringList("replace"), "replaceable", getID());
|
||||||
|
|
||||||
@ -121,12 +114,4 @@ public class OreConfig extends TerraConfig {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "Ore with ID " + getID();
|
return "Ore with ID " + getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean crossChunks() {
|
|
||||||
return crossChunks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getChunkEdgeOffset() {
|
|
||||||
return chunkEdgeOffset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,13 @@ import java.util.Map;
|
|||||||
public class BiomeSnowConfig extends TerraConfigSection {
|
public class BiomeSnowConfig extends TerraConfigSection {
|
||||||
private final int[] snowHeights;
|
private final int[] snowHeights;
|
||||||
private boolean doSnow = false;
|
private boolean doSnow = false;
|
||||||
|
private final boolean physics;
|
||||||
|
|
||||||
public BiomeSnowConfig(TerraConfig parent) throws InvalidConfigurationException {
|
public BiomeSnowConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||||
super(parent);
|
super(parent);
|
||||||
snowHeights = new int[256];
|
snowHeights = new int[256];
|
||||||
List<Map<?, ?>> maps = parent.getMapList("snow");
|
List<Map<?, ?>> maps = parent.getMapList("snow");
|
||||||
|
this.physics = getParent().getBoolean("snow-physics", false);
|
||||||
if(maps.size() == 0) return;
|
if(maps.size() == 0) return;
|
||||||
try {
|
try {
|
||||||
for(Map<?, ?> e : maps) {
|
for(Map<?, ?> e : maps) {
|
||||||
@ -41,4 +43,8 @@ public class BiomeSnowConfig extends TerraConfigSection {
|
|||||||
public boolean doSnow() {
|
public boolean doSnow() {
|
||||||
return doSnow;
|
return doSnow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean doPhysics() {
|
||||||
|
return physics;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class DebugFrame extends JFrame implements ActionListener {
|
|||||||
xp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
xp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockX(), x) / x) * getWidth());
|
||||||
zp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
|
zp = (int) (((double) FastMath.floorMod(p.getLocation().getBlockZ(), z) / z) * getHeight());
|
||||||
}
|
}
|
||||||
String str = TerraWorld.getWorld(p.getWorld()).getConfig().getBiome((UserDefinedBiome) TerraWorld.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
|
String str = ((UserDefinedBiome) TerraWorld.getWorld(p.getWorld()).getGrid().getBiome(p.getLocation(), GenerationPhase.POPULATE)).getID();
|
||||||
g.setColor(new Color(255, 255, 255, 128));
|
g.setColor(new Color(255, 255, 255, 128));
|
||||||
g.fillRect(xp + 13, zp - 13, (int) (8 + 8.25 * str.length()), 33);
|
g.fillRect(xp + 13, zp - 13, (int) (8 + 8.25 * str.length()), 33);
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
@ -57,7 +57,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
|||||||
super(ChunkInterpolator.InterpolationType.TRILINEAR);
|
super(ChunkInterpolator.InterpolationType.TRILINEAR);
|
||||||
this.configPack = c;
|
this.configPack = c;
|
||||||
popMan.attach(new FloraPopulator());
|
popMan.attach(new FloraPopulator());
|
||||||
popMan.attach(new OrePopulator());
|
|
||||||
popMan.attach(new SnowPopulator());
|
popMan.attach(new SnowPopulator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +225,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
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
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.dfsek.terra.math;
|
package com.dfsek.terra.math;
|
||||||
|
|
||||||
import com.dfsek.terra.config.base.ConfigUtil;
|
|
||||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||||
import org.polydev.gaea.math.FastNoiseLite;
|
import org.polydev.gaea.math.FastNoiseLite;
|
||||||
import parsii.eval.Expression;
|
import parsii.eval.Expression;
|
||||||
@ -8,7 +7,6 @@ import parsii.eval.Expression;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NoiseFunction2 implements NoiseFunction {
|
public class NoiseFunction2 implements NoiseFunction {
|
||||||
private final Cache cache = new Cache();
|
|
||||||
private final FastNoiseLite gen;
|
private final FastNoiseLite gen;
|
||||||
|
|
||||||
public NoiseFunction2(long seed, NoiseBuilder builder) {
|
public NoiseFunction2(long seed, NoiseBuilder builder) {
|
||||||
@ -22,32 +20,11 @@ public class NoiseFunction2 implements NoiseFunction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double eval(List<Expression> list) {
|
public double eval(List<Expression> list) {
|
||||||
return cache.get(list.get(0).evaluate(), list.get(1).evaluate());
|
return gen.getNoise(list.get(0).evaluate(), list.get(1).evaluate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNaturalFunction() {
|
public boolean isNaturalFunction() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class Cache {
|
|
||||||
private final double[] cacheX = new double[ConfigUtil.cacheSize];
|
|
||||||
private final double[] cacheZ = new double[ConfigUtil.cacheSize];
|
|
||||||
private final double[] cacheValues = new double[ConfigUtil.cacheSize];
|
|
||||||
|
|
||||||
public double get(double x, double z) {
|
|
||||||
for(int i = 0; i < cacheX.length; i++) {
|
|
||||||
if(cacheX[i] == x && cacheZ[i] == z) return cacheValues[i];
|
|
||||||
}
|
|
||||||
cacheX[0] = x;
|
|
||||||
cacheZ[0] = z;
|
|
||||||
cacheValues[0] = gen.getNoise(x, z);
|
|
||||||
for(int i = 0; i < cacheX.length - 1; i++) {
|
|
||||||
cacheX[i + 1] = cacheX[i];
|
|
||||||
cacheZ[i + 1] = cacheZ[i];
|
|
||||||
cacheValues[i + 1] = cacheValues[i];
|
|
||||||
}
|
|
||||||
return cacheValues[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import com.dfsek.terra.TerraProfiler;
|
|||||||
import com.dfsek.terra.TerraWorld;
|
import com.dfsek.terra.TerraWorld;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
|
||||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||||
import com.dfsek.terra.config.genconfig.biome.BiomeFloraConfig;
|
import com.dfsek.terra.config.genconfig.biome.BiomeFloraConfig;
|
||||||
import com.dfsek.terra.event.TreeGenerateEvent;
|
import com.dfsek.terra.event.TreeGenerateEvent;
|
||||||
@ -34,7 +33,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
|||||||
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
|
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
|
||||||
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
|
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
|
||||||
Tree tree = biome.getDecorator().getTrees().get(random);
|
Tree tree = biome.getDecorator().getTrees().get(random);
|
||||||
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
|
Range range = biome.getConfig().getTreeRange(tree);
|
||||||
if(!range.isInRange(block.getY())) continue;
|
if(!range.isInRange(block.getY())) continue;
|
||||||
try {
|
try {
|
||||||
Location l = block.getLocation();
|
Location l = block.getLocation();
|
||||||
@ -70,7 +69,6 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
|||||||
int originX = chunk.getX() << 4;
|
int originX = chunk.getX() << 4;
|
||||||
int originZ = chunk.getZ() << 4;
|
int originZ = chunk.getZ() << 4;
|
||||||
TerraBiomeGrid grid = tw.getGrid();
|
TerraBiomeGrid grid = tw.getGrid();
|
||||||
ConfigPack config = tw.getConfig();
|
|
||||||
for(int x = 0; x < 16; x++) {
|
for(int x = 0; x < 16; x++) {
|
||||||
for(int z = 0; z < 16; z++) {
|
for(int z = 0; z < 16; z++) {
|
||||||
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE);
|
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE);
|
||||||
@ -84,7 +82,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
|||||||
}
|
}
|
||||||
if(biome.getDecorator().getFloraChance() <= 0) continue;
|
if(biome.getDecorator().getFloraChance() <= 0) continue;
|
||||||
try {
|
try {
|
||||||
BiomeConfig c = config.getBiome(biome);
|
BiomeConfig c = biome.getConfig();
|
||||||
BiomeFloraConfig f = c.getFlora();
|
BiomeFloraConfig f = c.getFlora();
|
||||||
for(int i = 0; i < f.getFloraAttempts(); i++) {
|
for(int i = 0; i < f.getFloraAttempts(); i++) {
|
||||||
Flora item;
|
Flora item;
|
||||||
|
@ -3,49 +3,52 @@ package com.dfsek.terra.population;
|
|||||||
import com.dfsek.terra.TerraProfiler;
|
import com.dfsek.terra.TerraProfiler;
|
||||||
import com.dfsek.terra.TerraWorld;
|
import com.dfsek.terra.TerraWorld;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
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.OreConfig;
|
||||||
import com.dfsek.terra.config.genconfig.biome.BiomeOreConfig;
|
import com.dfsek.terra.config.genconfig.biome.BiomeOreConfig;
|
||||||
import com.dfsek.terra.event.OreVeinGenerateEvent;
|
import com.dfsek.terra.event.OreVeinGenerateEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.polydev.gaea.biome.Biome;
|
import org.polydev.gaea.biome.Biome;
|
||||||
import org.polydev.gaea.generation.GenerationPhase;
|
import org.polydev.gaea.generation.GenerationPhase;
|
||||||
|
import org.polydev.gaea.math.MathUtil;
|
||||||
import org.polydev.gaea.math.Range;
|
import org.polydev.gaea.math.Range;
|
||||||
import org.polydev.gaea.population.GaeaBlockPopulator;
|
|
||||||
import org.polydev.gaea.profiler.ProfileFuture;
|
import org.polydev.gaea.profiler.ProfileFuture;
|
||||||
|
import org.polydev.gaea.util.FastRandom;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class OrePopulator extends GaeaBlockPopulator {
|
public class OrePopulator extends BlockPopulator {
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
@Override
|
@Override
|
||||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
|
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) {
|
||||||
TerraWorld tw = TerraWorld.getWorld(world);
|
TerraWorld tw = TerraWorld.getWorld(world);
|
||||||
if(!tw.isSafe()) return;
|
if(!tw.isSafe()) return;
|
||||||
ConfigPack config = tw.getConfig();
|
for(int cx = -1; cx <= 1; cx++) {
|
||||||
Biome b = TerraWorld.getWorld(world).getGrid().getBiome((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8, GenerationPhase.POPULATE);
|
for(int cz = -1; cz <= 1; cz++) {
|
||||||
BiomeOreConfig ores = config.getBiome((UserDefinedBiome) b).getOres();
|
FastRandom r = new FastRandom(MathUtil.getCarverChunkSeed(chunk.getX() + cx, chunk.getZ() + cz, world.getSeed()));
|
||||||
for(Map.Entry<OreConfig, Range> e : ores.getOres().entrySet()) {
|
Biome b = TerraWorld.getWorld(world).getGrid().getBiome(((chunk.getX() + cx) << 4) + 8, ((chunk.getZ() + cz) << 4) + 8, GenerationPhase.POPULATE);
|
||||||
int num = e.getValue().get(random);
|
BiomeOreConfig ores = ((UserDefinedBiome) b).getConfig().getOres();
|
||||||
OreConfig ore = e.getKey();
|
for(Map.Entry<OreConfig, Range> e : ores.getOres().entrySet()) {
|
||||||
int edgeOffset = ore.getChunkEdgeOffset();
|
int num = e.getValue().get(r);
|
||||||
for(int i = 0; i < num; i++) {
|
OreConfig ore = e.getKey();
|
||||||
int x = random.nextInt(16 - (edgeOffset << 1)) + edgeOffset;
|
for(int i = 0; i < num; i++) {
|
||||||
int z = random.nextInt(16 - (edgeOffset << 1)) + edgeOffset;
|
int x = r.nextInt(16) + cx * 16;
|
||||||
int y = ores.getOreHeights().get(ore).get(random);
|
int z = r.nextInt(16) + cz * 16;
|
||||||
|
int y = ores.getOreHeights().get(ore).get(r);
|
||||||
|
|
||||||
Vector v = new Vector(x, y, z);
|
Vector v = new Vector(x, y, z);
|
||||||
OreVeinGenerateEvent event = new OreVeinGenerateEvent(tw, v.toLocation(world), ore);
|
OreVeinGenerateEvent event = new OreVeinGenerateEvent(tw, v.toLocation(world), ore);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if(!event.isCancelled()) {
|
if(!event.isCancelled()) {
|
||||||
if(ore.crossChunks()) ore.doVein(v, chunk, random);
|
ore.doVeinSingle(new Vector(x, y, z), chunk, r);
|
||||||
else ore.doVeinSingle(new Vector(x, y, z), chunk, random);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class SnowPopulator extends GaeaBlockPopulator {
|
|||||||
TerraBiomeGrid g = w.getGrid();
|
TerraBiomeGrid g = w.getGrid();
|
||||||
for(int x = 0; x < 16; x++) {
|
for(int x = 0; x < 16; x++) {
|
||||||
for(int z = 0; z < 16; z++) {
|
for(int z = 0; z < 16; z++) {
|
||||||
BiomeConfig biome = w.getConfig().getBiome((UserDefinedBiome) g.getBiome(origX + x, origZ + z, GenerationPhase.PALETTE_APPLY));
|
BiomeConfig biome = ((UserDefinedBiome) g.getBiome(origX + x, origZ + z, GenerationPhase.PALETTE_APPLY)).getConfig();
|
||||||
if(!biome.getSnow().doSnow()) continue;
|
if(!biome.getSnow().doSnow()) continue;
|
||||||
int y;
|
int y;
|
||||||
Block b = null;
|
Block b = null;
|
||||||
@ -66,7 +66,7 @@ public class SnowPopulator extends GaeaBlockPopulator {
|
|||||||
if(random.nextInt(100) >= biome.getSnow().getSnowChance(y))
|
if(random.nextInt(100) >= biome.getSnow().getSnowChance(y))
|
||||||
continue;
|
continue;
|
||||||
if(blacklistSpawn.contains(b.getType()) || b.isPassable()) continue;
|
if(blacklistSpawn.contains(b.getType()) || b.isPassable()) continue;
|
||||||
chunk.getBlock(x, ++y, z).setBlockData(DataUtil.SNOW);
|
chunk.getBlock(x, ++y, z).setBlockData(DataUtil.SNOW, biome.getSnow().doPhysics());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class StructurePopulator extends BlockPopulator {
|
|||||||
structure:
|
structure:
|
||||||
for(StructureConfig conf : config.getAllStructures()) {
|
for(StructureConfig conf : config.getAllStructures()) {
|
||||||
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
||||||
if(!config.getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(conf)) continue;
|
if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(conf)) continue;
|
||||||
Random r2 = new FastRandom(spawn.hashCode());
|
Random r2 = new FastRandom(spawn.hashCode());
|
||||||
Structure struc = conf.getStructure(r2);
|
Structure struc = conf.getStructure(r2);
|
||||||
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||||
|
@ -2,7 +2,6 @@ package com.dfsek.terra.structure.spawn;
|
|||||||
|
|
||||||
import com.dfsek.terra.TerraWorld;
|
import com.dfsek.terra.TerraWorld;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
|
||||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -16,9 +15,8 @@ public class AirSpawn extends Requirement {
|
|||||||
@Override
|
@Override
|
||||||
public boolean matches(int x, int y, int z) {
|
public boolean matches(int x, int y, int z) {
|
||||||
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
||||||
ConfigPack wc = tw.getConfig();
|
|
||||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||||
BiomeConfig c = wc.getBiome(b);
|
BiomeConfig c = b.getConfig();
|
||||||
if(y <= c.getOcean().getSeaLevel()) return false;
|
if(y <= c.getOcean().getSeaLevel()) return false;
|
||||||
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
||||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
||||||
|
@ -16,7 +16,7 @@ public class OceanSpawn extends Requirement {
|
|||||||
public boolean matches(int x, int y, int z) {
|
public boolean matches(int x, int y, int z) {
|
||||||
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
||||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||||
BiomeConfig c = tw.getConfig().getBiome(b);
|
BiomeConfig c = b.getConfig();
|
||||||
if(y > c.getOcean().getSeaLevel()) return false;
|
if(y > c.getOcean().getSeaLevel()) return false;
|
||||||
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
||||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
||||||
|
@ -3,6 +3,6 @@ data-save: PT6M
|
|||||||
language: "en_us"
|
language: "en_us"
|
||||||
fail-type: SHUTDOWN
|
fail-type: SHUTDOWN
|
||||||
dump-default: true
|
dump-default: true
|
||||||
cache-size: 8
|
biome-search-resolution: 4
|
||||||
master-disable:
|
master-disable:
|
||||||
caves: false
|
caves: false
|
28
src/test/java/NoiseTest.java
Normal file
28
src/test/java/NoiseTest.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||||
|
import com.dfsek.terra.math.NoiseFunction2;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import parsii.eval.Expression;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class NoiseTest {
|
||||||
|
@Test
|
||||||
|
public void noise() {
|
||||||
|
NoiseFunction2 noiseFunction = new NoiseFunction2(12345, new NoiseBuilder());
|
||||||
|
|
||||||
|
for(int i = 0; i < 10; i++) {
|
||||||
|
long l = System.nanoTime();
|
||||||
|
for(int j = 0; j < 1000000; j++) {
|
||||||
|
noiseFunction.eval(Arrays.asList(get(j), get(i)));
|
||||||
|
noiseFunction.eval(Arrays.asList(get(j), get(i)));
|
||||||
|
noiseFunction.eval(Arrays.asList(get(j), get(i)));
|
||||||
|
}
|
||||||
|
double n = System.nanoTime() - l;
|
||||||
|
System.out.println(n / 1000000 + "ms");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Expression get(double val) {
|
||||||
|
return () -> val;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user