mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-24 00:56:38 +00:00
compile structure addon
This commit is contained in:
@@ -2,34 +2,103 @@ package com.dfsek.terra.addons.structure.command;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.structure.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||
import com.dfsek.terra.api.util.PopulationUtil;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class AsyncStructureFinder extends AsyncFeatureFinder<ConfiguredStructure> {
|
||||
public class AsyncStructureFinder implements Runnable {
|
||||
protected final BiomeProvider provider;
|
||||
protected final ConfiguredStructure target;
|
||||
protected final int startRadius;
|
||||
protected final int maxRadius;
|
||||
protected final int centerX;
|
||||
protected final int centerZ;
|
||||
protected final World world;
|
||||
private final Consumer<Vector3> callback;
|
||||
protected int searchSize = 1;
|
||||
protected final TerraPlugin main;
|
||||
public AsyncStructureFinder(BiomeProvider provider, ConfiguredStructure target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
|
||||
super(provider, target, origin, world, startRadius, maxRadius, callback, main);
|
||||
setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation());
|
||||
//setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation());
|
||||
this.provider = provider;
|
||||
this.target = target;
|
||||
this.main = main;
|
||||
this.startRadius = startRadius;
|
||||
this.maxRadius = maxRadius;
|
||||
this.centerX = origin.getBlockX();
|
||||
this.centerZ = origin.getBlockZ();
|
||||
this.world = world;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 finalizeVector(Vector3 orig) {
|
||||
return target.getSpawn().getChunkSpawn(orig.getBlockX(), orig.getBlockZ(), world.getSeed());
|
||||
return orig;//target.getSpawn().getChunkSpawn(orig.getBlockX(), orig.getBlockZ(), world.getSeed());
|
||||
}
|
||||
|
||||
public boolean isValid(int x, int z, ConfiguredStructure target) {
|
||||
//Vector3 spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed());
|
||||
//if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(target)) return false;
|
||||
//Random random = new Random(PopulationUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed()));
|
||||
//return target.getStructure().get(random).test(spawn.setY(target.getSpawnStart().get(random)), world, random, Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int x, int z, ConfiguredStructure target) {
|
||||
Vector3 spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed());
|
||||
if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(target)) return false;
|
||||
Random random = new Random(PopulationUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed()));
|
||||
return target.getStructure().get(random).test(spawn.setY(target.getSpawnStart().get(random)), world, random, Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
public void run() {
|
||||
int x = centerX;
|
||||
int z = centerZ;
|
||||
|
||||
x /= searchSize;
|
||||
z /= searchSize;
|
||||
|
||||
int run = 1;
|
||||
boolean toggle = true;
|
||||
boolean found = false;
|
||||
|
||||
main:
|
||||
for(int i = startRadius; i < maxRadius; i++) {
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(isValid(x, z, target)) {
|
||||
found = true;
|
||||
break main;
|
||||
}
|
||||
if(toggle) x += 1;
|
||||
else x -= 1;
|
||||
}
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(isValid(x, z, target)) {
|
||||
found = true;
|
||||
break main;
|
||||
}
|
||||
if(toggle) z += 1;
|
||||
else z -= 1;
|
||||
}
|
||||
run++;
|
||||
toggle = !toggle;
|
||||
}
|
||||
Vector3 finalSpawn = found ? finalizeVector(new Vector3(x, 0, z)) : null;
|
||||
callback.accept(finalSpawn);
|
||||
}
|
||||
|
||||
public ConfiguredStructure getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public BiomeProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public int getSearchSize() {
|
||||
return searchSize;
|
||||
}
|
||||
|
||||
public void setSearchSize(int searchSize) {
|
||||
this.searchSize = searchSize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Pool {
|
||||
* @param pool The JSON Object to instantiate from.
|
||||
*/
|
||||
public Pool(JSONObject pool, TerraPlugin main) {
|
||||
entries = new ProbabilityCollectionImpl<>();
|
||||
entries = new ProbabilityCollection<>();
|
||||
Object amount = pool.get("rolls");
|
||||
if(amount instanceof Long) {
|
||||
max = FastMath.toIntExact((Long) amount);
|
||||
|
||||
Reference in New Issue
Block a user