pull versions out to Versions config

This commit is contained in:
dfsek
2021-12-19 15:30:50 -07:00
parent 2a965e847f
commit aeb0372d59
13 changed files with 36 additions and 231 deletions

View File

@@ -1,37 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.config.loaders.config;
import com.dfsek.tectonic.api.loader.ConfigLoader;
import com.dfsek.tectonic.api.loader.type.TypeLoader;
import java.lang.reflect.AnnotatedType;
import java.util.Map;
import com.dfsek.terra.api.structure.StructureSpawn;
import com.dfsek.terra.math.GridSpawn;
@SuppressWarnings("unchecked")
public class GridSpawnLoader implements TypeLoader<StructureSpawn> {
@Override
public StructureSpawn load(AnnotatedType type, Object o, ConfigLoader configLoader) {
Map<String, Integer> map = (Map<String, Integer>) o;
return new GridSpawn(map.get("width"), map.get("padding"), map.getOrDefault("salt", 0));
}
}

View File

@@ -1,86 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.math;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.dfsek.terra.api.util.PopulationUtil;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.util.FastRandom;
/**
* Class to procedurally determine the spawn point of an object based on a grid with padding between cells.
*/
public class GridSpawn implements com.dfsek.terra.api.structure.StructureSpawn {
private final int separation;
private final int width;
private final int salt;
public GridSpawn(int width, int separation, int salt) {
this.separation = separation;
this.width = width;
this.salt = salt;
}
@Override
public Vector3 getNearestSpawn(int x, int z, long seed) {
int structureChunkX = x / (width + 2 * separation);
int structureChunkZ = z / (width + 2 * separation);
List<Vector3> zones = new ArrayList<>(9);
for(int xi = structureChunkX - 1; xi <= structureChunkX + 1; xi++) {
for(int zi = structureChunkZ - 1; zi <= structureChunkZ + 1; zi++) {
zones.add(getChunkSpawn(xi, zi, seed));
}
}
Vector3 shortest = zones.get(0);
Vector3 compare = new Vector3(x, 0, z);
for(Vector3 v : zones) {
if(compare.distanceSquared(shortest) > compare.distanceSquared(v)) shortest = v.clone();
}
return shortest;
}
/**
* Get the X/Z coordinates of the spawn point in the nearest Chunk (not Minecraft chunk)
*
* @param structureChunkX Chunk X coordinate
* @param structureChunkZ Chunk Z coordinate
* @param seed Seed for RNG
*
* @return Vector representing spawnpoint
*/
public Vector3 getChunkSpawn(int structureChunkX, int structureChunkZ, long seed) {
Random r = new FastRandom(PopulationUtil.getCarverChunkSeed(structureChunkX, structureChunkZ, seed + salt));
int offsetX = r.nextInt(width);
int offsetZ = r.nextInt(width);
int sx = structureChunkX * (width + 2 * separation) + offsetX;
int sz = structureChunkZ * (width + 2 * separation) + offsetZ;
return new Vector3(sx, 0, sz);
}
public int getWidth() {
return width;
}
public int getSeparation() {
return separation;
}
}

View File

@@ -1,86 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.util;
import org.apache.commons.rng.core.source64.XoRoShiRo128PlusPlus;
import java.io.Serial;
import java.util.Random;
import java.util.SplittableRandom;
public class FastRandom extends Random {
@Serial
private static final long serialVersionUID = 4571946470190183260L;
private XoRoShiRo128PlusPlus random;
public FastRandom() {
super();
SplittableRandom randomseed = new SplittableRandom();
this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong());
}
public FastRandom(long seed) {
super(seed);
SplittableRandom randomseed = new SplittableRandom(seed);
this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong());
}
@Override
public synchronized void setSeed(long seed) {
SplittableRandom randomseed = new SplittableRandom(seed);
this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong());
}
@Override
public void nextBytes(byte[] bytes) {
random.nextBytes(bytes);
}
@Override
public int nextInt() {
return random.nextInt();
}
@Override
public int nextInt(int bound) {
return random.nextInt(bound);
}
@Override
public long nextLong() {
return random.nextLong();
}
@Override
public boolean nextBoolean() {
return random.nextBoolean();
}
@Override
public float nextFloat() {
return (float) random.nextDouble();
}
@Override
public double nextDouble() {
return random.nextDouble();
}
}