Implement image to map

This commit is contained in:
dfsek
2020-09-21 14:28:52 -07:00
parent 44f302b564
commit 653e7f65f1
15 changed files with 241 additions and 31 deletions

View File

@@ -1,36 +1,48 @@
package com.dfsek.terra.biome;
import com.dfsek.terra.config.WorldConfig;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.polydev.gaea.biome.BiomeGrid;
import org.polydev.gaea.biome.NormalizationUtil;
import org.polydev.gaea.math.FastNoise;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class BiomeZone {
private BiomeGrid[] grids;
private final World w;
private final FastNoise noise;
private static final Map<World, BiomeZone> zones = new HashMap<>();
@Nullable
private final ImageLoader imageLoader;
private final boolean useImage;
private final ImageLoader.Channel channel;
private BiomeZone(World w, float freq) {
this.w = w;
this.noise = new FastNoise((int) w.getSeed()+2);
this.noise.setNoiseType(FastNoise.NoiseType.SimplexFractal);
this.noise.setFractalOctaves(4);
this.noise.setFrequency(WorldConfig.fromWorld(w).zoneFreq);
setZones(WorldConfig.fromWorld(w).definedGrids);
WorldConfig c = WorldConfig.fromWorld(w);
setZones(c.definedGrids);
imageLoader = c.imageLoader;
useImage = c.fromImage;
channel = c.zoneChannel;
zones.put(w, this);
}
public void setZones(BiomeGrid[] grids) {
public void setZones(@NotNull BiomeGrid[] grids) {
if(grids.length != 32) throw new IllegalArgumentException("Illegal number of grids!");
this.grids = grids;
}
protected BiomeGrid getGrid(int x, int z) {
return grids[NormalizationUtil.normalize(noise.getNoise(x, z), 32)];
return grids[NormalizationUtil.normalize(useImage ? Objects.requireNonNull(imageLoader).getNoiseVal(x, z, channel) : noise.getNoise(x, z), 32)];
}
protected static BiomeZone fromWorld(World w) {