mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-09 17:26:07 +00:00
Reformat & add .editorconfig
This commit is contained in:
@@ -86,6 +86,17 @@ public class TerraWorld {
|
||||
return map.computeIfAbsent(w, TerraWorld::new);
|
||||
}
|
||||
|
||||
public static synchronized void invalidate() {
|
||||
map.clear();
|
||||
for(WorldConfig config : loaded.values()) {
|
||||
config.load(); // Reload all stored WorldConfigs
|
||||
}
|
||||
}
|
||||
|
||||
public static int numWorlds() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
public TerraBiomeGrid getGrid() {
|
||||
return grid;
|
||||
}
|
||||
@@ -102,17 +113,6 @@ public class TerraWorld {
|
||||
return zone;
|
||||
}
|
||||
|
||||
public static synchronized void invalidate() {
|
||||
map.clear();
|
||||
for(WorldConfig config : loaded.values()) {
|
||||
config.load(); // Reload all stored WorldConfigs
|
||||
}
|
||||
}
|
||||
|
||||
public static int numWorlds() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
public boolean isSafe() {
|
||||
return safe;
|
||||
}
|
||||
|
||||
@@ -14,12 +14,11 @@ import java.util.logging.Level;
|
||||
|
||||
public class TerraBiomeGrid extends BiomeGrid {
|
||||
private static int failNum = 0;
|
||||
private final BiomeZone zone;
|
||||
private CoordinatePerturb perturb;
|
||||
private ErosionNoise erode;
|
||||
private UserDefinedGrid erosionGrid;
|
||||
|
||||
private final BiomeZone zone;
|
||||
|
||||
public TerraBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c, UserDefinedGrid erosion) {
|
||||
super(w, freq1, freq2, 0, 0);
|
||||
if(c.biomeBlend) {
|
||||
|
||||
@@ -39,6 +39,10 @@ public class SimplexCarver extends Carver {
|
||||
hasCaves.setFrequency(0.005f);
|
||||
}
|
||||
|
||||
private static double acot(double x) {
|
||||
return Math.PI / 2 - Math.atan(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector vector) {
|
||||
return null;
|
||||
@@ -76,8 +80,4 @@ public class SimplexCarver extends Carver {
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private static double acot(double x) {
|
||||
return Math.PI / 2 - Math.atan(x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class UserDefinedCarver extends Carver {
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector vector) {
|
||||
Random r = new Random(l + hash);
|
||||
return new UserDefinedWorm((int) (length.get(r) / 2), r, vector, radius.getMax(), topCut, bottomCut);
|
||||
return new UserDefinedWorm(length.get(r) / 2, r, vector, radius.getMax(), topCut, bottomCut);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.dfsek.terra.command.biome;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeSnowConfig;
|
||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import org.bukkit.World;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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;
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ import com.dfsek.terra.config.genconfig.CarverConfig;
|
||||
import com.dfsek.terra.config.genconfig.FloraConfig;
|
||||
import com.dfsek.terra.config.genconfig.OreConfig;
|
||||
import com.dfsek.terra.config.genconfig.PaletteConfig;
|
||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||
import com.dfsek.terra.config.genconfig.TreeConfig;
|
||||
import com.dfsek.terra.config.genconfig.biome.AbstractBiomeConfig;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.util.StructureTypeEnum;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -40,6 +40,25 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class ConfigPack extends YamlConfiguration {
|
||||
private static final Map<String, ConfigPack> configs = new HashMap<>();
|
||||
public final List<String> biomeList;
|
||||
public final double zoneFreq;
|
||||
public final double freq1;
|
||||
public final double freq2;
|
||||
public final double erosionFreq;
|
||||
public final double erosionThresh;
|
||||
public final boolean erosionEnable;
|
||||
public final int erosionOctaves;
|
||||
public final String erosionName;
|
||||
public final int blendAmp;
|
||||
public final boolean biomeBlend;
|
||||
public final double blendFreq;
|
||||
public final int octaves;
|
||||
public final double frequency;
|
||||
public final boolean vanillaCaves;
|
||||
public final boolean vanillaStructures;
|
||||
public final boolean vanillaDecoration;
|
||||
public final boolean vanillaMobs;
|
||||
public final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
|
||||
private final Map<String, OreConfig> ores;
|
||||
private final Map<String, PaletteConfig> palettes;
|
||||
private final Map<String, CarverConfig> carvers;
|
||||
@@ -50,38 +69,9 @@ public class ConfigPack extends YamlConfiguration {
|
||||
private final Map<String, BiomeGridConfig> grids;
|
||||
private final Map<String, TreeConfig> trees;
|
||||
private final Set<StructureConfig> allStructures = new HashSet<>();
|
||||
|
||||
|
||||
private final File dataFolder;
|
||||
|
||||
private final String id;
|
||||
|
||||
public final List<String> biomeList;
|
||||
|
||||
public final double zoneFreq;
|
||||
public final double freq1;
|
||||
public final double freq2;
|
||||
|
||||
public final double erosionFreq;
|
||||
public final double erosionThresh;
|
||||
public final boolean erosionEnable;
|
||||
public final int erosionOctaves;
|
||||
public final String erosionName;
|
||||
|
||||
public final int blendAmp;
|
||||
public final boolean biomeBlend;
|
||||
public final double blendFreq;
|
||||
|
||||
public final int octaves;
|
||||
public final double frequency;
|
||||
|
||||
public final boolean vanillaCaves;
|
||||
public final boolean vanillaStructures;
|
||||
public final boolean vanillaDecoration;
|
||||
public final boolean vanillaMobs;
|
||||
|
||||
public final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
|
||||
|
||||
public ConfigPack(File file) throws IOException, InvalidConfigurationException {
|
||||
long l = System.nanoTime();
|
||||
load(new File(file, "pack.yml"));
|
||||
@@ -168,26 +158,6 @@ public class ConfigPack extends YamlConfiguration {
|
||||
LangUtil.log("config-pack.loaded", Level.INFO, getID(), String.valueOf((System.nanoTime() - l) / 1000000D));
|
||||
}
|
||||
|
||||
public Map<StructureTypeEnum, StructureConfig> getLocatable() {
|
||||
return locatable;
|
||||
}
|
||||
|
||||
public Map<String, AbstractBiomeConfig> getAbstractBiomes() {
|
||||
return abstractBiomes;
|
||||
}
|
||||
|
||||
public Map<String, BiomeConfig> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
public Map<String, CarverConfig> getCarvers() {
|
||||
return carvers;
|
||||
}
|
||||
|
||||
public Set<StructureConfig> getAllStructures() {
|
||||
return allStructures;
|
||||
}
|
||||
|
||||
public static synchronized void loadAll(JavaPlugin main) {
|
||||
configs.clear();
|
||||
File file = new File(main.getDataFolder(), "packs");
|
||||
@@ -217,6 +187,30 @@ public class ConfigPack extends YamlConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized ConfigPack fromID(String id) {
|
||||
return configs.get(id);
|
||||
}
|
||||
|
||||
public Map<StructureTypeEnum, StructureConfig> getLocatable() {
|
||||
return locatable;
|
||||
}
|
||||
|
||||
public Map<String, AbstractBiomeConfig> getAbstractBiomes() {
|
||||
return abstractBiomes;
|
||||
}
|
||||
|
||||
public Map<String, BiomeConfig> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
public Map<String, CarverConfig> getCarvers() {
|
||||
return carvers;
|
||||
}
|
||||
|
||||
public Set<StructureConfig> getAllStructures() {
|
||||
return allStructures;
|
||||
}
|
||||
|
||||
public File getDataFolder() {
|
||||
return dataFolder;
|
||||
}
|
||||
@@ -225,10 +219,6 @@ public class ConfigPack extends YamlConfiguration {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static synchronized ConfigPack fromID(String id) {
|
||||
return configs.get(id);
|
||||
}
|
||||
|
||||
public BiomeConfig getBiome(UserDefinedBiome b) {
|
||||
for(BiomeConfig biome : biomes.values()) {
|
||||
if(biome.getBiome().equals(b)) return biome;
|
||||
|
||||
@@ -19,21 +19,17 @@ import java.util.logging.Level;
|
||||
public class WorldConfig {
|
||||
|
||||
|
||||
private final String worldID;
|
||||
private final String configID;
|
||||
private final GaeaPlugin main;
|
||||
public boolean fromImage;
|
||||
public ConfigPack config;
|
||||
public ImageLoader.Channel biomeXChannel;
|
||||
public ImageLoader.Channel biomeZChannel;
|
||||
public ImageLoader.Channel zoneChannel;
|
||||
|
||||
public ImageLoader imageLoader;
|
||||
|
||||
|
||||
private ConfigPack tConfig;
|
||||
|
||||
private final String worldID;
|
||||
private final String configID;
|
||||
private final GaeaPlugin main;
|
||||
|
||||
|
||||
public WorldConfig(String w, String configID, GaeaPlugin main) {
|
||||
this.worldID = w;
|
||||
|
||||
@@ -40,14 +40,6 @@ public class PaletteConfig extends TerraConfig {
|
||||
palette = getPalette(getMapList("layers"), pal);
|
||||
}
|
||||
|
||||
public Palette<BlockData> getPalette() {
|
||||
return palette;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return paletteID;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static Palette<BlockData> getPalette(List<Map<?, ?>> maps, Palette<BlockData> p) throws InvalidConfigurationException {
|
||||
for(Map<?, ?> m : maps) {
|
||||
@@ -76,6 +68,14 @@ public class PaletteConfig extends TerraConfig {
|
||||
return p;
|
||||
}
|
||||
|
||||
public Palette<BlockData> getPalette() {
|
||||
return palette;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return paletteID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Palette with ID " + getID() + " with " + getPalette().getSize() + " layers, using Simplex: " + useNoise;
|
||||
|
||||
@@ -12,8 +12,8 @@ import java.util.List;
|
||||
public class AbstractBiomeConfig extends TerraConfig {
|
||||
private final String biomeID;
|
||||
private final String equation;
|
||||
private BiomeSlabConfig slabs;
|
||||
private final int seaLevel;
|
||||
private BiomeSlabConfig slabs;
|
||||
private List<String> structureConfigs;
|
||||
private BiomePaletteConfig palette;
|
||||
private BiomeFloraConfig flora;
|
||||
|
||||
@@ -34,10 +34,9 @@ public class BiomeConfig extends TerraConfig {
|
||||
private final BiomeOceanConfig ocean;
|
||||
private final BiomeSlabConfig slab;
|
||||
private final BiomeSnowConfig snow;
|
||||
private String eq;
|
||||
|
||||
private final List<StructureConfig> structures;
|
||||
private final ConfigPack config;
|
||||
private String eq;
|
||||
|
||||
public BiomeConfig(File file, ConfigPack config) throws InvalidConfigurationException, IOException {
|
||||
super(file, config);
|
||||
|
||||
@@ -16,9 +16,9 @@ import org.polydev.gaea.world.palette.RandomPalette;
|
||||
import java.util.Random;
|
||||
|
||||
public class BiomeOceanConfig extends TerraConfigSection {
|
||||
private static final Palette<BlockData> oceanDefault = new RandomPalette<BlockData>(new Random(0)).add(Material.WATER.createBlockData(), 1);
|
||||
private final Palette<BlockData> ocean;
|
||||
private final int seaLevel;
|
||||
private static final Palette<BlockData> oceanDefault = new RandomPalette<BlockData>(new Random(0)).add(Material.WATER.createBlockData(), 1);
|
||||
|
||||
public BiomeOceanConfig(@NotNull TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Random;
|
||||
public class BiomeSlabConfig extends TerraConfigSection {
|
||||
private final Map<Material, Palette<BlockData>> slabs;
|
||||
private final Map<Material, Palette<BlockData>> stairs;
|
||||
private double slabThreshold;
|
||||
private final double slabThreshold;
|
||||
|
||||
public BiomeSlabConfig(@NotNull TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
|
||||
@@ -22,9 +22,12 @@ public class EntityFeatureConfig implements FeatureConfig {
|
||||
if(! items.containsKey("entity")) throw new ConfigException("No EntityType specified!", "EntityFeature");
|
||||
if(! items.containsKey("amount")) throw new ConfigException("No amount specified!", "EntityFeature");
|
||||
if(! items.containsKey("attempts")) throw new ConfigException("Attempts not specified!", "EntityFeature");
|
||||
if(! items.containsKey("in-height")) throw new ConfigException("Spawn Checking Height not specified!", "EntityFeature");
|
||||
if(! items.containsKey("spawnable-on")) throw new ConfigException("No Spawnable-on materials specified!", "EntityFeature");
|
||||
if(! items.containsKey("spawnable-in")) throw new ConfigException("No Spawnable-in materials specified!", "EntityFeature");
|
||||
if(! items.containsKey("in-height"))
|
||||
throw new ConfigException("Spawn Checking Height not specified!", "EntityFeature");
|
||||
if(! items.containsKey("spawnable-on"))
|
||||
throw new ConfigException("No Spawnable-on materials specified!", "EntityFeature");
|
||||
if(! items.containsKey("spawnable-in"))
|
||||
throw new ConfigException("No Spawnable-in materials specified!", "EntityFeature");
|
||||
|
||||
EntityType type;
|
||||
try {
|
||||
@@ -52,6 +55,7 @@ public class EntityFeatureConfig implements FeatureConfig {
|
||||
this.feature = new EntityFeature(type, amount, attempts, on, in, height);
|
||||
Debug.info("Loaded EntityFeature with type: " + type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature getFeature() {
|
||||
return feature;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.config.genconfig.structure;
|
||||
|
||||
import com.dfsek.terra.config.TerraConfigSection;
|
||||
import com.dfsek.terra.structure.features.Feature;
|
||||
|
||||
public interface FeatureConfig {
|
||||
|
||||
@@ -14,14 +14,14 @@ public class OreVeinGenerateEvent extends TerraWorldEvent implements Cancellable
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void setConfig(OreConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public OreConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig(OreConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
||||
@@ -16,14 +16,14 @@ public abstract class TerraWorldEvent extends Event {
|
||||
this.location = l.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@ public class TreeGenerateEvent extends TerraWorldEvent implements Cancellable {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
public void setTree(Tree tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
public Tree getTree() {
|
||||
return tree;
|
||||
}
|
||||
|
||||
public void setTree(Tree tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.dfsek.terra.population.FloraPopulator;
|
||||
import com.dfsek.terra.population.OrePopulator;
|
||||
import com.dfsek.terra.population.SnowPopulator;
|
||||
import com.dfsek.terra.population.StructurePopulator;
|
||||
import com.dfsek.terra.structure.StructureSpawnRequirement;
|
||||
import com.dfsek.terra.util.DataUtil;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
@@ -26,12 +25,10 @@ import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
import org.polydev.gaea.generation.GaeaChunkGenerator;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.generation.GenerationPopulator;
|
||||
import org.polydev.gaea.math.ChunkInterpolator;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import org.polydev.gaea.population.PopulationManager;
|
||||
import org.polydev.gaea.profiler.WorldProfiler;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
@@ -47,12 +44,10 @@ import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
private final PopulationManager popMan = new PopulationManager(Terra.getInstance());
|
||||
private boolean needsLoad = true;
|
||||
private final ConfigPack configPack;
|
||||
|
||||
|
||||
private static final Map<World, PopulationManager> popMap = new HashMap<>();
|
||||
private final PopulationManager popMan = new PopulationManager(Terra.getInstance());
|
||||
private final ConfigPack configPack;
|
||||
private boolean needsLoad = true;
|
||||
|
||||
public TerraChunkGenerator(ConfigPack c) {
|
||||
super(ChunkInterpolator.InterpolationType.TRILINEAR);
|
||||
@@ -62,6 +57,22 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
popMan.attach(new SnowPopulator());
|
||||
}
|
||||
|
||||
public static synchronized void saveAll() {
|
||||
for(Map.Entry<World, PopulationManager> e : popMap.entrySet()) {
|
||||
try {
|
||||
e.getValue().saveBlocks(e.getKey());
|
||||
Debug.info("Saved data for world " + e.getKey().getName());
|
||||
} catch(IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void fixChunk(Chunk c) {
|
||||
if(! (c.getWorld().getGenerator() instanceof TerraChunkGenerator)) throw new IllegalArgumentException();
|
||||
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) {
|
||||
if(needsLoad) load(world); // Load population data for world.
|
||||
@@ -143,28 +154,12 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
needsLoad = false;
|
||||
}
|
||||
|
||||
public static synchronized void saveAll() {
|
||||
for(Map.Entry<World, PopulationManager> e : popMap.entrySet()) {
|
||||
try {
|
||||
e.getValue().saveBlocks(e.getKey());
|
||||
Debug.info("Saved data for world " + e.getKey().getName());
|
||||
} catch(IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachProfiler(WorldProfiler p) {
|
||||
super.attachProfiler(p);
|
||||
popMan.attachProfiler(p);
|
||||
}
|
||||
|
||||
public static synchronized void fixChunk(Chunk c) {
|
||||
if(! (c.getWorld().getGenerator() instanceof TerraChunkGenerator)) throw new IllegalArgumentException();
|
||||
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNoiseOctaves(World world) {
|
||||
return configPack.octaves;
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class UserDefinedGenerator extends Generator {
|
||||
private static final Object noiseLock = new Object();
|
||||
private final Expression noiseExp;
|
||||
private final Scope s = new Scope();
|
||||
private final Variable xVar = s.getVariable("x");
|
||||
@@ -28,11 +29,8 @@ public class UserDefinedGenerator extends Generator {
|
||||
private final Palette<BlockData>[] palettes = new Palette[256];
|
||||
private final NoiseFunction2 n2 = new NoiseFunction2();
|
||||
private final NoiseFunction3 n3 = new NoiseFunction3();
|
||||
|
||||
private final boolean preventSmooth;
|
||||
|
||||
private static final Object noiseLock = new Object();
|
||||
|
||||
|
||||
public UserDefinedGenerator(String equation, List<Variable> v, TreeMap<Integer, Palette<BlockData>> pa, boolean preventSmooth) throws ParseException {
|
||||
Parser p = new Parser();
|
||||
|
||||
@@ -24,24 +24,6 @@ public class ImageLoader {
|
||||
this.align = align;
|
||||
}
|
||||
|
||||
|
||||
public int getChannel(int x, int y, Channel channel) {
|
||||
int rgb;
|
||||
rgb = align.getRGB(image, x, y);
|
||||
switch(channel) {
|
||||
case RED:
|
||||
return rgb >> 16 & 0xff;
|
||||
case GREEN:
|
||||
return rgb >> 8 & 0xff;
|
||||
case BLUE:
|
||||
return rgb & 0xff;
|
||||
case ALPHA:
|
||||
return rgb >> 32 & 0xff;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void debugWorld(boolean genStep, World w) {
|
||||
if(! ConfigUtil.debug) return;
|
||||
BufferedImage newImg = new WorldImageGenerator(w, 1024, 1024).drawWorld(0, 0).getDraw();
|
||||
@@ -69,6 +51,31 @@ public class ImageLoader {
|
||||
return newImg;
|
||||
}
|
||||
|
||||
private static BufferedImage copyImage(BufferedImage source) {
|
||||
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
|
||||
Graphics g = b.getGraphics();
|
||||
g.drawImage(source, 0, 0, null);
|
||||
g.dispose();
|
||||
return b;
|
||||
}
|
||||
|
||||
public int getChannel(int x, int y, Channel channel) {
|
||||
int rgb;
|
||||
rgb = align.getRGB(image, x, y);
|
||||
switch(channel) {
|
||||
case RED:
|
||||
return rgb >> 16 & 0xff;
|
||||
case GREEN:
|
||||
return rgb >> 8 & 0xff;
|
||||
case BLUE:
|
||||
return rgb & 0xff;
|
||||
case ALPHA:
|
||||
return rgb >> 32 & 0xff;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public void debug(boolean genStep, World w) {
|
||||
if(! ConfigUtil.debug) return;
|
||||
BufferedImage newImg = copyImage(image);
|
||||
@@ -83,14 +90,6 @@ public class ImageLoader {
|
||||
return ((double) (getChannel(x, y, channel) - 128) / 128) * inverseRoot2;
|
||||
}
|
||||
|
||||
private static BufferedImage copyImage(BufferedImage source) {
|
||||
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
|
||||
Graphics g = b.getGraphics();
|
||||
g.drawImage(source, 0, 0, null);
|
||||
g.dispose();
|
||||
return b;
|
||||
}
|
||||
|
||||
public Align getAlign() {
|
||||
return align;
|
||||
}
|
||||
@@ -113,10 +112,10 @@ public class ImageLoader {
|
||||
}
|
||||
};
|
||||
|
||||
public abstract int getRGB(BufferedImage image, int x, int y);
|
||||
|
||||
private static int getRGBNoAlign(BufferedImage image, int x, int y) {
|
||||
return image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(y, image.getHeight()));
|
||||
}
|
||||
|
||||
public abstract int getRGB(BufferedImage image, int x, int y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import parsii.eval.Function;
|
||||
import java.util.List;
|
||||
|
||||
public class NoiseFunction2 implements Function {
|
||||
private FastNoiseLite gen;
|
||||
private final Cache cache = new Cache();
|
||||
private FastNoiseLite gen;
|
||||
|
||||
@Override
|
||||
public int getNumberOfArguments() {
|
||||
@@ -34,6 +34,7 @@ public class NoiseFunction2 implements Function {
|
||||
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];
|
||||
@@ -41,10 +42,10 @@ public class NoiseFunction2 implements Function {
|
||||
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];
|
||||
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];
|
||||
}
|
||||
|
||||
@@ -30,6 +30,36 @@ import java.util.Random;
|
||||
* Populates Flora and Trees
|
||||
*/
|
||||
public class FloraPopulator extends GaeaBlockPopulator {
|
||||
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))) {
|
||||
Tree tree = biome.getDecorator().getTrees().get(random);
|
||||
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
|
||||
if(! range.isInRange(block.getY())) continue;
|
||||
try {
|
||||
Location l = block.getLocation();
|
||||
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(! event.isCancelled()) tree.plant(l, random, Terra.getInstance());
|
||||
} catch(NullPointerException ignore) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int offset(Random r, int i) {
|
||||
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
|
||||
}
|
||||
|
||||
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
for(int y : check) {
|
||||
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
|
||||
blocks.add(chunk.getBlock(x, y + 1, z));
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
|
||||
@@ -70,34 +100,4 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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))) {
|
||||
Tree tree = biome.getDecorator().getTrees().get(random);
|
||||
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
|
||||
if(! range.isInRange(block.getY())) continue;
|
||||
try {
|
||||
Location l = block.getLocation();
|
||||
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(! event.isCancelled()) tree.plant(l, random, Terra.getInstance());
|
||||
} catch(NullPointerException ignore) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int offset(Random r, int i) {
|
||||
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
|
||||
}
|
||||
|
||||
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
for(int y : check) {
|
||||
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
|
||||
blocks.add(chunk.getBlock(x, y + 1, z));
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ public class Vector2 implements Cloneable {
|
||||
return x;
|
||||
}
|
||||
|
||||
public Vector2 setX(double x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Z component
|
||||
*
|
||||
@@ -36,6 +41,11 @@ public class Vector2 implements Cloneable {
|
||||
return z;
|
||||
}
|
||||
|
||||
public Vector2 setZ(double z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply X and Z components by a value.
|
||||
*
|
||||
@@ -164,14 +174,4 @@ public class Vector2 implements Cloneable {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 setX(double x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector2 setZ(double z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,12 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Rectangle extends Polygon {
|
||||
private Vector2 min;
|
||||
private Vector2 max;
|
||||
private final Vector2 min;
|
||||
private final Vector2 max;
|
||||
|
||||
public Rectangle(Vector2 min, Vector2 max) {
|
||||
this.max = new Vector2(Math.min(min.getX(), max.getX()), Math.min(min.getZ(), max.getZ()));
|
||||
this.min = new Vector2(Math.max(min.getX(), max.getX()), Math.max(min.getZ(), max.getZ()));
|
||||
;
|
||||
}
|
||||
|
||||
public Rectangle(Vector2 center, double xRadius, double zRadius) {
|
||||
|
||||
@@ -8,6 +8,11 @@ import java.util.List;
|
||||
public abstract class VoxelGeometry {
|
||||
public List<Vector> geometry = new ArrayList<>();
|
||||
|
||||
public static VoxelGeometry getBlank() {
|
||||
return new VoxelGeometry() {
|
||||
};
|
||||
}
|
||||
|
||||
public List<Vector> getGeometry() {
|
||||
return geometry;
|
||||
}
|
||||
@@ -19,9 +24,4 @@ public abstract class VoxelGeometry {
|
||||
public void merge(VoxelGeometry other) {
|
||||
geometry.addAll(other.geometry);
|
||||
}
|
||||
|
||||
public static VoxelGeometry getBlank() {
|
||||
return new VoxelGeometry() {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,15 +47,6 @@ public class Structure implements Serializable {
|
||||
private final HashSet<StructureContainedBlock> spawns;
|
||||
private final HashSet<StructureContainedInventory> inventories;
|
||||
|
||||
@NotNull
|
||||
public static Structure load(@NotNull File f) throws IOException {
|
||||
try {
|
||||
return fromFile(f);
|
||||
} catch(ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException("Provided file does not contain a GaeaStructure.");
|
||||
}
|
||||
}
|
||||
|
||||
public Structure(@NotNull Location l1, @NotNull Location l2, @NotNull String id) throws InitializationException {
|
||||
int centerX = - 1, centerZ = - 1;
|
||||
this.id = id;
|
||||
@@ -126,6 +117,45 @@ public class Structure implements Serializable {
|
||||
structureInfo = new StructureInfo(l2.getBlockX() - l1.getBlockX() + 1, l2.getBlockY() - l1.getBlockY() + 1, l2.getBlockZ() - l1.getBlockZ() + 1, new Vector2(centerX, centerZ));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Structure load(@NotNull File f) throws IOException {
|
||||
try {
|
||||
return fromFile(f);
|
||||
} catch(ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException("Provided file does not contain a GaeaStructure.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a structure from a file.
|
||||
*
|
||||
* @param f File to load from
|
||||
* @return The structure loaded
|
||||
* @throws IOException If file access error occurs
|
||||
* @throws ClassNotFoundException If structure data is invalid.
|
||||
*/
|
||||
@NotNull
|
||||
private static Structure fromFile(@NotNull File f) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
return (Structure) o;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Structure fromStream(@NotNull InputStream f) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(f);
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
return (Structure) o;
|
||||
}
|
||||
|
||||
private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
oos.writeObject(o);
|
||||
oos.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GaeaStructureInfo object
|
||||
*
|
||||
@@ -305,36 +335,6 @@ public class Structure implements Serializable {
|
||||
toFile(this, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a structure from a file.
|
||||
*
|
||||
* @param f File to load from
|
||||
* @return The structure loaded
|
||||
* @throws IOException If file access error occurs
|
||||
* @throws ClassNotFoundException If structure data is invalid.
|
||||
*/
|
||||
@NotNull
|
||||
private static Structure fromFile(@NotNull File f) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
return (Structure) o;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Structure fromStream(@NotNull InputStream f) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(f);
|
||||
Object o = ois.readObject();
|
||||
ois.close();
|
||||
return (Structure) o;
|
||||
}
|
||||
|
||||
private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
oos.writeObject(o);
|
||||
oos.close();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return id;
|
||||
@@ -386,10 +386,6 @@ public class Structure implements Serializable {
|
||||
this.degrees = degrees;
|
||||
}
|
||||
|
||||
public int getDegrees() {
|
||||
return degrees;
|
||||
}
|
||||
|
||||
public static Rotation fromDegrees(int deg) {
|
||||
switch(Math.floorMod(deg, 360)) {
|
||||
case 0:
|
||||
@@ -405,6 +401,10 @@ public class Structure implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public int getDegrees() {
|
||||
return degrees;
|
||||
}
|
||||
|
||||
public Rotation inverse() {
|
||||
switch(this) {
|
||||
case NONE:
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.io.Serializable;
|
||||
public class StructureContainedBlock implements Serializable {
|
||||
public static final long serialVersionUID = 6143969483382710947L;
|
||||
private final SerializableBlockData bl;
|
||||
private transient BlockData data;
|
||||
private final Pull pull;
|
||||
private final int pullOffset;
|
||||
private final int x;
|
||||
@@ -25,6 +24,7 @@ public class StructureContainedBlock implements Serializable {
|
||||
private final int z;
|
||||
private final SerializableBlockState state;
|
||||
private final StructureSpawnRequirement requirement;
|
||||
private transient BlockData data;
|
||||
|
||||
public StructureContainedBlock(int x, int y, int z, BlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull, int pullOffset) {
|
||||
if(state instanceof Sign) {
|
||||
@@ -93,6 +93,6 @@ public class StructureContainedBlock implements Serializable {
|
||||
}
|
||||
|
||||
public enum Pull {
|
||||
UP, NONE, DOWN;
|
||||
UP, NONE, DOWN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ 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;
|
||||
@@ -50,8 +49,6 @@ public enum StructureSpawnRequirement implements Serializable {
|
||||
private static final long serialVersionUID = - 175639605885943679L;
|
||||
private static final transient Map<World, FastNoiseLite> noiseMap = new HashMap<>();
|
||||
|
||||
public abstract boolean matches(World w, int x, int y, int z);
|
||||
|
||||
public static void putNoise(World w, FastNoiseLite noise) {
|
||||
noiseMap.putIfAbsent(w, noise);
|
||||
}
|
||||
@@ -72,4 +69,6 @@ public enum StructureSpawnRequirement implements Serializable {
|
||||
putNoise(w, gen);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean matches(World w, int x, int y, int z);
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ import org.bukkit.entity.EntityType;
|
||||
import org.polydev.gaea.math.MathUtil;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -24,6 +22,7 @@ public class EntityFeature implements Feature {
|
||||
private final Set<Material> in;
|
||||
private final Set<Material> stand;
|
||||
private final int inSize;
|
||||
|
||||
public EntityFeature(EntityType type, Range amount, int attempts, Set<Material> stand, Set<Material> in, int inSize) {
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
@@ -33,6 +32,10 @@ public class EntityFeature implements Feature {
|
||||
this.inSize = inSize;
|
||||
}
|
||||
|
||||
private static boolean isInChunk(Chunk c, Location l) {
|
||||
return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Structure structure, Location l, Chunk chunk) {
|
||||
Random random = new Random(MathUtil.getCarverChunkSeed(chunk.getX(), chunk.getZ(), chunk.getWorld().getSeed()));
|
||||
@@ -49,8 +52,8 @@ public class EntityFeature implements Feature {
|
||||
|
||||
for(int i = 0; i < amountSpawn && i < attempts; i++) {
|
||||
int yv = y.get(random);
|
||||
Location attempt = l.clone().add(x.get(random)-cx, yv, z.get(random)-cz);
|
||||
if(!isInChunk(chunk, attempt)) continue; // Don't attempt spawn if not in current chunk.
|
||||
Location attempt = l.clone().add(x.get(random) - cx, yv, z.get(random) - cz);
|
||||
if(! isInChunk(chunk, attempt)) continue; // Don't attempt spawn if not in current chunk.
|
||||
|
||||
boolean canSpawn = false;
|
||||
while(yv >= 0 && attempt.getBlockY() >= l.getBlockY()) { // Go down, see if valid spawns exist.
|
||||
@@ -59,9 +62,10 @@ public class EntityFeature implements Feature {
|
||||
attempt.subtract(0, 1, 0);
|
||||
yv--;
|
||||
|
||||
if(!stand.contains(on.getType())) continue;
|
||||
if(! stand.contains(on.getType())) continue;
|
||||
|
||||
for(int j = 1; j < inSize + 1; j++) if(! in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
|
||||
for(int j = 1; j < inSize + 1; j++)
|
||||
if(! in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
|
||||
|
||||
if(canSpawn) break;
|
||||
}
|
||||
@@ -72,10 +76,6 @@ public class EntityFeature implements Feature {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInChunk(Chunk c, Location l) {
|
||||
return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Structure structure, Location l, Random random) {
|
||||
int amountSpawn = amount.get(random);
|
||||
@@ -90,7 +90,7 @@ public class EntityFeature implements Feature {
|
||||
|
||||
for(int i = 0; i < amountSpawn && i < attempts; i++) {
|
||||
int yv = y.get(random);
|
||||
Location attempt = l.clone().add(x.get(random)-cx, yv, z.get(random)-cz);
|
||||
Location attempt = l.clone().add(x.get(random) - cx, yv, z.get(random) - cz);
|
||||
|
||||
boolean canSpawn = false;
|
||||
while(yv >= 0 && attempt.getBlockY() >= l.getBlockY()) { // Go down, see if valid spawns exist.
|
||||
@@ -99,9 +99,10 @@ public class EntityFeature implements Feature {
|
||||
attempt.subtract(0, 1, 0);
|
||||
yv--;
|
||||
|
||||
if(!stand.contains(on.getType())) continue;
|
||||
if(! stand.contains(on.getType())) continue;
|
||||
|
||||
for(int j = 1; j < inSize + 1; j++) if(! in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
|
||||
for(int j = 1; j < inSize + 1; j++)
|
||||
if(! in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
|
||||
|
||||
if(canSpawn) break;
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ import java.util.Random;
|
||||
|
||||
public interface Feature {
|
||||
void apply(Structure structure, Location l, Chunk chunk);
|
||||
|
||||
void apply(Structure structure, Location l, Random random);
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ public enum StructureTypeEnum {
|
||||
RUINED_PORTAL(StructureType.RUINED_PORTAL),
|
||||
BASTION_REMNANT(StructureType.BASTION_REMNANT);
|
||||
|
||||
private final StructureType type;
|
||||
|
||||
StructureTypeEnum(StructureType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private final StructureType type;
|
||||
|
||||
public StructureType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user