[AUTO] Clean & reformat

This commit is contained in:
dfsek 2020-11-16 23:39:18 -07:00
parent 9a403805c9
commit 2750d46a98
10 changed files with 168 additions and 169 deletions

View File

@ -24,14 +24,6 @@ public class TerraWorld {
private final WorldConfig worldConfig;
private boolean safe;
public static void loadWorld(WorldConfig w) {
loaded.put(w.getWorldID(), w);
}
public static synchronized TerraWorld getWorld(World w) {
return map.computeIfAbsent(w, TerraWorld::new);
}
private TerraWorld(World w) {
safe = true;
worldConfig = loaded.get(w.getName());
@ -87,6 +79,14 @@ public class TerraWorld {
grid = new TerraBiomeGrid(w, config.freq1, config.freq2, zone, config, erosion);
}
public static void loadWorld(WorldConfig w) {
loaded.put(w.getWorldID(), w);
}
public static synchronized TerraWorld getWorld(World w) {
return map.computeIfAbsent(w, TerraWorld::new);
}
public static synchronized void invalidate() {
map.clear();
for(WorldConfig config : loaded.values()) {
@ -98,6 +98,10 @@ public class TerraWorld {
return map.size();
}
public static boolean isTerraWorld(World w) {
return w.getGenerator() instanceof TerraChunkGenerator;
}
public TerraBiomeGrid getGrid() {
return grid;
}
@ -117,8 +121,4 @@ public class TerraWorld {
public boolean isSafe() {
return safe;
}
public static boolean isTerraWorld(World w) {
return w.getGenerator() instanceof TerraChunkGenerator;
}
}

View File

@ -40,6 +40,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 CarvingData carve(int chunkX, int chunkZ, World w) {
CarvingData c = new CarvingData(chunkX, chunkZ);
@ -68,10 +72,6 @@ public class SimplexCarver extends Carver {
return c;
}
private static double acot(double x) {
return Math.PI / 2 - Math.atan(x);
}
@Override
public Worm getWorm(long l, Vector vector) {
return null;

View File

@ -21,16 +21,6 @@ public class LoadCommand extends PlayerCommand implements DebugCommand {
super(parent);
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return true;
}
@Override
public String getName() {
return "load";
}
public static List<String> getStructureNames() {
List<String> names = new ArrayList<>();
File structureDir = new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures");
@ -45,6 +35,16 @@ public class LoadCommand extends PlayerCommand implements DebugCommand {
return names;
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return true;
}
@Override
public String getName() {
return "load";
}
@Override
public List<org.polydev.gaea.command.Command> getSubCommands() {
return Arrays.asList(new LoadRawCommand(this), new LoadFullCommand(this, true), new LoadFullCommand(this, false));

View File

@ -194,30 +194,6 @@ public class ConfigPack extends YamlConfiguration {
LangUtil.log("config-pack.loaded", Level.INFO, getID(), String.valueOf((System.nanoTime() - l) / 1000000D));
}
public String getID() {
return id;
}
public Map<String, Double> getDefinedVariables() {
return definedVariables;
}
public Map<String, BiomeConfig> getBiomes() {
return biomes;
}
public StructureConfig getStructure(String id) {
return structures.get(id);
}
public BiomeGridConfig getBiomeGrid(String id) {
return grids.get(id);
}
public Map<String, NoiseConfig> getNoiseBuilders() {
return noiseBuilders;
}
public static synchronized void loadAll(JavaPlugin main) {
configs.clear();
File file = new File(main.getDataFolder(), "packs");
@ -252,6 +228,30 @@ public class ConfigPack extends YamlConfiguration {
return configs.get(id);
}
public String getID() {
return id;
}
public Map<String, Double> getDefinedVariables() {
return definedVariables;
}
public Map<String, BiomeConfig> getBiomes() {
return biomes;
}
public StructureConfig getStructure(String id) {
return structures.get(id);
}
public BiomeGridConfig getBiomeGrid(String id) {
return grids.get(id);
}
public Map<String, NoiseConfig> getNoiseBuilders() {
return noiseBuilders;
}
public Map<StructureTypeEnum, StructureConfig> getLocatable() {
return locatable;
}

View File

@ -77,12 +77,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
}
@Override
public void attachProfiler(WorldProfiler p) {
super.attachProfiler(p);
popMan.attachProfiler(p);
}
private static Palette<BlockData> getPalette(int x, int y, int z, BiomeConfig c, ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) {
Palette<BlockData> slant = ((WorldGenerator) c.getBiome().getGenerator()).getSlantPalette(y);
if(slant != null) {
@ -138,6 +132,12 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
}
}
@Override
public void attachProfiler(WorldProfiler p) {
super.attachProfiler(p);
popMan.attachProfiler(p);
}
@Override
@SuppressWarnings("try")
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) {

View File

@ -49,41 +49,6 @@ public class NoiseBuilder {
return noise;
}
public NoiseBuilder setFrequency(double frequency) {
this.frequency = frequency;
return this;
}
public NoiseBuilder setFractalGain(double fractalGain) {
this.fractalGain = fractalGain;
return this;
}
public NoiseBuilder setFractalLacunarity(double fractalLacunarity) {
this.fractalLacunarity = fractalLacunarity;
return this;
}
public NoiseBuilder setFractalType(FastNoiseLite.FractalType fractalType) {
this.fractalType = fractalType;
return this;
}
public NoiseBuilder setOctaves(int octaves) {
this.octaves = octaves;
return this;
}
public NoiseBuilder setPingPong(double pingPong) {
this.pingPong = pingPong;
return this;
}
public NoiseBuilder setWeightedStrength(double weightedStrength) {
this.weightedStrength = weightedStrength;
return this;
}
public FastNoiseLite.NoiseType getType() {
return type;
}
@ -93,21 +58,6 @@ public class NoiseBuilder {
return this;
}
public NoiseBuilder setCellularDistanceFunction(FastNoiseLite.CellularDistanceFunction cellularDistanceFunction) {
this.cellularDistanceFunction = cellularDistanceFunction;
return this;
}
public NoiseBuilder setCellularReturnType(FastNoiseLite.CellularReturnType cellularReturnType) {
this.cellularReturnType = cellularReturnType;
return this;
}
public NoiseBuilder setCellularJitter(double cellularJitter) {
this.cellularJitter = cellularJitter;
return this;
}
public int getSeedOffset() {
return seedOffset;
}
@ -116,71 +66,121 @@ public class NoiseBuilder {
this.seedOffset = seedOffset;
}
public NoiseBuilder setDomainWarpAmp(double domainWarpAmp) {
this.domainWarpAmp = domainWarpAmp;
public FastNoiseLite.CellularDistanceFunction getCellularDistanceFunction() {
return cellularDistanceFunction;
}
public NoiseBuilder setCellularDistanceFunction(FastNoiseLite.CellularDistanceFunction cellularDistanceFunction) {
this.cellularDistanceFunction = cellularDistanceFunction;
return this;
}
public FastNoiseLite.CellularReturnType getCellularReturnType() {
return cellularReturnType;
}
public NoiseBuilder setCellularReturnType(FastNoiseLite.CellularReturnType cellularReturnType) {
this.cellularReturnType = cellularReturnType;
return this;
}
public FastNoiseLite.DomainWarpType getDomainWarpType() {
return domainWarpType;
}
public NoiseBuilder setDomainWarpType(FastNoiseLite.DomainWarpType domainWarpType) {
this.domainWarpType = domainWarpType;
return this;
}
public NoiseBuilder setRotationType3D(FastNoiseLite.RotationType3D rotationType3D) {
this.rotationType3D = rotationType3D;
return this;
}
public FastNoiseLite.CellularDistanceFunction getCellularDistanceFunction() {
return cellularDistanceFunction;
}
public FastNoiseLite.CellularReturnType getCellularReturnType() {
return cellularReturnType;
}
public FastNoiseLite.DomainWarpType getDomainWarpType() {
return domainWarpType;
}
public double getCellularJitter() {
return cellularJitter;
}
public NoiseBuilder setCellularJitter(double cellularJitter) {
this.cellularJitter = cellularJitter;
return this;
}
public double getDomainWarpAmp() {
return domainWarpAmp;
}
public NoiseBuilder setDomainWarpAmp(double domainWarpAmp) {
this.domainWarpAmp = domainWarpAmp;
return this;
}
public double getFractalGain() {
return fractalGain;
}
public NoiseBuilder setFractalGain(double fractalGain) {
this.fractalGain = fractalGain;
return this;
}
public double getFractalLacunarity() {
return fractalLacunarity;
}
public NoiseBuilder setFractalLacunarity(double fractalLacunarity) {
this.fractalLacunarity = fractalLacunarity;
return this;
}
public double getFrequency() {
return frequency;
}
public NoiseBuilder setFrequency(double frequency) {
this.frequency = frequency;
return this;
}
public double getPingPong() {
return pingPong;
}
public NoiseBuilder setPingPong(double pingPong) {
this.pingPong = pingPong;
return this;
}
public double getWeightedStrength() {
return weightedStrength;
}
public NoiseBuilder setWeightedStrength(double weightedStrength) {
this.weightedStrength = weightedStrength;
return this;
}
public int getOctaves() {
return octaves;
}
public NoiseBuilder setOctaves(int octaves) {
this.octaves = octaves;
return this;
}
public FastNoiseLite.FractalType getFractalType() {
return fractalType;
}
public NoiseBuilder setFractalType(FastNoiseLite.FractalType fractalType) {
this.fractalType = fractalType;
return this;
}
public FastNoiseLite.RotationType3D getRotationType3D() {
return rotationType3D;
}
public NoiseBuilder setRotationType3D(FastNoiseLite.RotationType3D rotationType3D) {
this.rotationType3D = rotationType3D;
return this;
}
}

View File

@ -28,14 +28,12 @@ public class WorldGenerator extends Generator {
private final Palette<BlockData>[] slantPalettes;
private final boolean preventSmooth;
private boolean elevationInterpolation = true;
private final Expression noiseExp;
private final Scope s = new Scope();
private final Variable xVar = s.getVariable("x");
private final Variable yVar = s.getVariable("y");
private final Variable zVar = s.getVariable("z");
private boolean elevationInterpolation = true;
@SuppressWarnings({"rawtypes", "unchecked"})
public WorldGenerator(long seed, String equation, String elevateEquation, Map<String, Double> userVariables, Map<String, NoiseConfig> noiseBuilders, Palette[] palettes, Palette[] slantPalettes, boolean preventSmooth) {

View File

@ -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;
}
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;
}
private static int offset(Random r, int i) {
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
}
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
@ -71,34 +101,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;
}
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;
}
private static int offset(Random r, int i) {
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
}
}

View File

@ -144,6 +144,12 @@ public class Structure implements Serializable {
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();
}
public StructureContainedBlock[][][] getRawStructure() {
return structure;
}
@ -328,12 +334,6 @@ public class Structure implements Serializable {
toFile(this, f);
}
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;

View File

@ -12,6 +12,7 @@ import org.bukkit.entity.EntityType;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.math.Range;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
@ -32,6 +33,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()));
@ -75,10 +80,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);
@ -114,7 +115,7 @@ public class EntityFeature implements Feature {
}
if(canSpawn) {
Debug.info("Spawning entity at " + attempt);
l.getWorld().spawnEntity(attempt.add(0.5, 1, 0.5), type); // Add 0.5 to X & Z so entity spawns in center of block.
Objects.requireNonNull(l.getWorld()).spawnEntity(attempt.add(0.5, 1, 0.5), type); // Add 0.5 to X & Z so entity spawns in center of block.
}
}
}