mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 15:37:24 +00:00
Fix an elusive crash.
This commit is contained in:
parent
224dfbe638
commit
17fe3530a4
@ -1,11 +1,14 @@
|
||||
package com.dfsek.terra.config;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public abstract class TerraConfig extends YamlConfiguration {
|
||||
private final ConfigPack config;
|
||||
@ -15,6 +18,11 @@ public abstract class TerraConfig extends YamlConfiguration {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public TerraConfig(InputStream stream, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
load(new InputStreamReader(stream));
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public ConfigPack getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ import com.dfsek.terra.config.genconfig.biome.AbstractBiomeConfig;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.util.StructureTypeEnum;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -33,6 +35,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Represents a Terra configuration pack.
|
||||
@ -77,6 +80,10 @@ public class ConfigPack extends YamlConfiguration {
|
||||
public final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
|
||||
|
||||
public ConfigPack(File file) throws IOException, InvalidConfigurationException {
|
||||
if(file.isDirectory());
|
||||
else if(FilenameUtils.getExtension(file.getAbsolutePath()).equals("zip")) {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
}
|
||||
long l = System.nanoTime();
|
||||
load(new File(file, "pack.yml"));
|
||||
dataFolder = file;
|
||||
|
@ -47,8 +47,8 @@ import java.util.logging.Level;
|
||||
public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
private final PopulationManager popMan = new PopulationManager(Terra.getInstance());
|
||||
private boolean needsLoad = true;
|
||||
private int octaves;
|
||||
private float frequency;
|
||||
private final int octaves;
|
||||
private final float frequency;
|
||||
|
||||
|
||||
private static final Map<World, PopulationManager> popMap = new HashMap<>();
|
||||
@ -65,7 +65,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
@Override
|
||||
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, FastNoiseLite fastNoise) {
|
||||
if(needsLoad) load(world); // Load population data for world.
|
||||
StructureSpawnRequirement.putNoise(world, fastNoise); // Assign noise to world to be used for structures.
|
||||
ChunkData chunk = createChunkData(world);
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
if(! tw.isSafe()) return chunk;
|
||||
|
@ -2,6 +2,8 @@ package com.dfsek.terra.structure;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||
import org.bukkit.World;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
@ -15,14 +17,18 @@ public enum StructureSpawnRequirement implements Serializable {
|
||||
AIR {
|
||||
@Override
|
||||
public boolean matches(World w, int x, int y, int z) {
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeConfig c = TerraWorld.getWorld(w).getConfig().getBiome(b);
|
||||
setNoise(w, x, y, z);
|
||||
TerraWorld tw = TerraWorld.getWorld(w);
|
||||
ConfigPack wc = tw.getConfig();
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeConfig c = wc.getBiome(b);
|
||||
if(y <= c.getOcean().getSeaLevel()) return false;
|
||||
return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0;
|
||||
}
|
||||
}, OCEAN {
|
||||
@Override
|
||||
public boolean matches(World w, int x, int y, int z) {
|
||||
setNoise(w, x, y, z);
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeConfig c = TerraWorld.getWorld(w).getConfig().getBiome(b);
|
||||
if(y > c.getOcean().getSeaLevel()) return false;
|
||||
@ -31,6 +37,7 @@ public enum StructureSpawnRequirement implements Serializable {
|
||||
}, LAND {
|
||||
@Override
|
||||
public boolean matches(World w, int x, int y, int z) {
|
||||
setNoise(w, x, y, z);
|
||||
UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
return b.getGenerator().getNoise(getNoise(w), w, x, y, z) > 0;
|
||||
}
|
||||
@ -52,4 +59,17 @@ public enum StructureSpawnRequirement implements Serializable {
|
||||
private static FastNoiseLite getNoise(World w) {
|
||||
return noiseMap.get(w);
|
||||
}
|
||||
|
||||
private static void setNoise(World w, int x, int y, int z) {
|
||||
TerraWorld tw = TerraWorld.getWorld(w);
|
||||
ConfigPack wc = tw.getConfig();
|
||||
if(getNoise(w) == null) {
|
||||
FastNoiseLite gen = new FastNoiseLite((int) w.getSeed());
|
||||
gen.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
gen.setFractalType(FastNoiseLite.FractalType.FBm);
|
||||
gen.setFractalOctaves(wc.octaves);
|
||||
gen.setFrequency(wc.frequency);
|
||||
putNoise(w, gen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: Terra
|
||||
depend: [ "Gaea" ]
|
||||
main: com.dfsek.terra.Terra
|
||||
version: 1.0.2-BETA
|
||||
version: 1.0.3-BETA
|
||||
load: STARTUP
|
||||
api-version: "1.16"
|
||||
softdepend: [ "WorldEdit" ]
|
||||
|
Loading…
x
Reference in New Issue
Block a user