mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-19 06:40:12 +00:00
Implement BiomeZone
This commit is contained in:
51
src/main/java/com/dfsek/terra/biome/BiomeZone.java
Normal file
51
src/main/java/com/dfsek/terra/biome/BiomeZone.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.WorldConfig;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.math.FastNoise;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BiomeZone {
|
||||
private BiomeGrid[] grids;
|
||||
private final World w;
|
||||
private final FastNoise noise;
|
||||
private static final Map<World, BiomeZone> zones = new HashMap<>();
|
||||
|
||||
public BiomeZone(World w, float freq) {
|
||||
this.w = w;
|
||||
this.noise = new FastNoise((int) w.getSeed()+2);
|
||||
noise.setNoiseType(FastNoise.NoiseType.Value);
|
||||
noise.setFrequency(freq);
|
||||
setZones(WorldConfig.fromWorld(w).definedGrids);
|
||||
zones.put(w, this);
|
||||
}
|
||||
|
||||
public void setZones(BiomeGrid[] grids) {
|
||||
if(grids.length != 16) throw new IllegalArgumentException("Illegal number of grids!");
|
||||
this.grids = grids;
|
||||
}
|
||||
|
||||
public BiomeGrid getGrid(int x, int z) {
|
||||
return grids[normalize(noise.getValue(x, z))];
|
||||
}
|
||||
|
||||
public static BiomeZone fromWorld(World w) {
|
||||
if(zones.containsKey(w)) return zones.get(w);
|
||||
else return new BiomeZone(w, WorldConfig.fromWorld(w).zoneFreq);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a noise input and normalizes it to a value between 0 and 15 inclusive.
|
||||
*
|
||||
* @param i - The noise value to normalize.
|
||||
* @return int - The normalized value.
|
||||
*/
|
||||
private static int normalize(double i) {
|
||||
if(i > 0) i = Math.pow(i, 0.8125); // Redistribute
|
||||
else i = -Math.pow(-i, 0.8125); // Redistribute
|
||||
return Math.min((int) Math.floor((i+1)*8), 15);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.WorldConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -11,29 +13,27 @@ import java.util.Map;
|
||||
public class TerraBiomeGrid extends BiomeGrid {
|
||||
|
||||
private static final Map<World, TerraBiomeGrid> grids = new HashMap<>();
|
||||
private final UserDefinedBiome[][] grid;
|
||||
private final World w;
|
||||
|
||||
public TerraBiomeGrid(World w) {
|
||||
super(w, 1f/256, 1f/512);
|
||||
this.w = w;
|
||||
grid = new UserDefinedBiome[16][16];
|
||||
load();
|
||||
grids.put(w, this);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
super.setGrid(WorldConfig.fromWorld(w).biomeGrid.getBiomeGrid());
|
||||
}
|
||||
|
||||
public static TerraBiomeGrid fromWorld(World w) {
|
||||
if(grids.containsKey(w)) return grids.get(w);
|
||||
else return new TerraBiomeGrid(w);
|
||||
}
|
||||
public static void reloadAll() {
|
||||
for(Map.Entry<World, TerraBiomeGrid> e : grids.entrySet()) {
|
||||
e.getValue().load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
return BiomeZone.fromWorld(w).getGrid(x, z).getBiome(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(Location l) {
|
||||
return getBiome(l.getBlockX(), l.getBlockZ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class UserDefinedGenerator extends BiomeTerrain {
|
||||
* @return BlocPalette - The biome's palette.
|
||||
*/
|
||||
@Override
|
||||
public BlockPalette getPalette() {
|
||||
public BlockPalette getPalette(int y) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
12
src/main/java/com/dfsek/terra/biome/UserDefinedGrid.java
Normal file
12
src/main/java/com/dfsek/terra/biome/UserDefinedGrid.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.BiomeGridConfig;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
|
||||
public class UserDefinedGrid extends BiomeGrid {
|
||||
public UserDefinedGrid(World w, float freq1, float freq2, BiomeGridConfig config) {
|
||||
super(w, freq1, freq2);
|
||||
super.setGrid(config.getBiomeGrid());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user