mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 05:50:08 +00:00
fix spawn checks at biome edge
This commit is contained in:
1 parent
d16c28aebd
commit
c283f37390
5 files changed
+36
-14
No files matched your search
@@ -5,8 +5,8 @@ import com.dfsek.terra.api.platform.TerraPlugin;
|
|||||||
import com.dfsek.terra.api.platform.world.World;
|
import com.dfsek.terra.api.platform.world.World;
|
||||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
|
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
|
||||||
|
|
||||||
public class AirCheck extends SpawnCheck {
|
public class AirCheck extends SpawnCheck {
|
||||||
public AirCheck(World world, TerraPlugin main) {
|
public AirCheck(World world, TerraPlugin main) {
|
||||||
@@ -16,10 +16,10 @@ public class AirCheck extends SpawnCheck {
|
|||||||
@Override
|
@Override
|
||||||
public boolean check(int x, int y, int z) {
|
public boolean check(int x, int y, int z) {
|
||||||
TerraWorld tw = main.getWorld(world);
|
TerraWorld tw = main.getWorld(world);
|
||||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
TerraBiomeGrid g = tw.getGrid();
|
||||||
|
UserDefinedBiome b = (UserDefinedBiome) g.getBiome(x, z, GenerationPhase.POPULATE);
|
||||||
BiomeTemplate c = b.getConfig();
|
BiomeTemplate c = b.getConfig();
|
||||||
if(y <= c.getSeaLevel()) return false;
|
if(y <= c.getSeaLevel()) return false;
|
||||||
double elevation = ((WorldGenerator) b.getGenerator(world)).getElevation(x, z);
|
return sample(x, y, z, g) <= 0;
|
||||||
return b.getGenerator(world).getNoise(x, y, z) + elevation <= 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,6 @@ package com.dfsek.terra.api.structures.world;
|
|||||||
import com.dfsek.terra.TerraWorld;
|
import com.dfsek.terra.TerraWorld;
|
||||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||||
import com.dfsek.terra.api.platform.world.World;
|
import com.dfsek.terra.api.platform.world.World;
|
||||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
|
||||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
|
||||||
|
|
||||||
public class LandCheck extends SpawnCheck {
|
public class LandCheck extends SpawnCheck {
|
||||||
public LandCheck(World world, TerraPlugin main) {
|
public LandCheck(World world, TerraPlugin main) {
|
||||||
@@ -15,8 +12,6 @@ public class LandCheck extends SpawnCheck {
|
|||||||
@Override
|
@Override
|
||||||
public boolean check(int x, int y, int z) {
|
public boolean check(int x, int y, int z) {
|
||||||
TerraWorld tw = main.getWorld(world);
|
TerraWorld tw = main.getWorld(world);
|
||||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
return sample(x, y, z, tw.getGrid()) > 0;
|
||||||
double elevation = ((WorldGenerator) b.getGenerator(world)).getElevation(x, z);
|
|
||||||
return b.getGenerator(world).getNoise(x, y, z) + elevation > 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,8 +5,8 @@ import com.dfsek.terra.api.platform.TerraPlugin;
|
|||||||
import com.dfsek.terra.api.platform.world.World;
|
import com.dfsek.terra.api.platform.world.World;
|
||||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
|
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
|
||||||
|
|
||||||
public class OceanCheck extends SpawnCheck {
|
public class OceanCheck extends SpawnCheck {
|
||||||
public OceanCheck(World world, TerraPlugin main) {
|
public OceanCheck(World world, TerraPlugin main) {
|
||||||
@@ -16,10 +16,10 @@ public class OceanCheck extends SpawnCheck {
|
|||||||
@Override
|
@Override
|
||||||
public boolean check(int x, int y, int z) {
|
public boolean check(int x, int y, int z) {
|
||||||
TerraWorld tw = main.getWorld(world);
|
TerraWorld tw = main.getWorld(world);
|
||||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
TerraBiomeGrid grid = tw.getGrid();
|
||||||
|
UserDefinedBiome b = (UserDefinedBiome) grid.getBiome(x, z, GenerationPhase.POPULATE);
|
||||||
BiomeTemplate c = b.getConfig();
|
BiomeTemplate c = b.getConfig();
|
||||||
if(y > c.getSeaLevel()) return false;
|
if(y > c.getSeaLevel()) return false;
|
||||||
double elevation = ((WorldGenerator) b.getGenerator(world)).getElevation(x, z);
|
return sample(x, y, z, grid) <= 0;
|
||||||
return b.getGenerator(world).getNoise(x, y, z) + elevation <= 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,16 +2,35 @@ package com.dfsek.terra.api.structures.world;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||||
import com.dfsek.terra.api.platform.world.World;
|
import com.dfsek.terra.api.platform.world.World;
|
||||||
|
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||||
|
import com.dfsek.terra.generation.math.Sampler;
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class SpawnCheck {
|
public abstract class SpawnCheck {
|
||||||
protected final World world;
|
protected final World world;
|
||||||
protected final TerraPlugin main;
|
protected final TerraPlugin main;
|
||||||
|
private final Map<Long, Sampler> cache;
|
||||||
|
|
||||||
protected SpawnCheck(World world, TerraPlugin main) {
|
protected SpawnCheck(World world, TerraPlugin main) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.main = main;
|
this.main = main;
|
||||||
|
cache = new LinkedHashMap<Long, Sampler>() {
|
||||||
|
@Override
|
||||||
|
protected boolean removeEldestEntry(Map.Entry<Long, Sampler> eldest) {
|
||||||
|
return size() > main.getTerraConfig().getCheckCache();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean check(int x, int y, int z);
|
public abstract boolean check(int x, int y, int z);
|
||||||
|
|
||||||
|
protected double sample(int x, int y, int z, TerraBiomeGrid grid) {
|
||||||
|
int cx = FastMath.floorDiv(x, 16);
|
||||||
|
int cz = FastMath.floorDiv(z, 16);
|
||||||
|
long key = (((long) cx) << 32) | (cz & 0xffffffffL);
|
||||||
|
return cache.computeIfAbsent(key, k -> new Sampler(cx, cz, grid, world, 4, 8)).sample(x - (cx << 4), y, z - (cz << 4));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,10 @@ public class PluginConfig implements ConfigTemplate {
|
|||||||
@Default
|
@Default
|
||||||
private int structureCache = 128;
|
private int structureCache = 128;
|
||||||
|
|
||||||
|
@Value("cache.checks")
|
||||||
|
@Default
|
||||||
|
private int checkCache = 128;
|
||||||
|
|
||||||
@Value("dump-default")
|
@Value("dump-default")
|
||||||
@Default
|
@Default
|
||||||
private boolean dumpDefaultConfig = true;
|
private boolean dumpDefaultConfig = true;
|
||||||
@@ -90,4 +94,8 @@ public class PluginConfig implements ConfigTemplate {
|
|||||||
public int getStructureCache() {
|
public int getStructureCache() {
|
||||||
return structureCache;
|
return structureCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCheckCache() {
|
||||||
|
return checkCache;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user