mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 16:56:07 +00:00
reimplement locate command
This commit is contained in:
@@ -87,6 +87,11 @@ public class StructureScript {
|
||||
return buffer.succeeded();
|
||||
}
|
||||
|
||||
public boolean test(Location location, Random random, Rotation rotation) {
|
||||
StructureBuffer buffer = new StructureBuffer(location);
|
||||
return !block.apply(buffer, rotation, random, 0).equals(Block.ReturnLevel.FAIL);
|
||||
}
|
||||
|
||||
public void executeInBuffer(Buffer buffer, Random random, Rotation rotation, int recursions) {
|
||||
block.apply(buffer, rotation, random, recursions);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.api.math.MathUtil;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class AsyncStructureFinder extends AsyncFeatureFinder<TerraStructure> {
|
||||
public AsyncStructureFinder(TerraBiomeGrid grid, TerraStructure target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
|
||||
super(grid, target, origin, startRadius, maxRadius, callback, main);
|
||||
setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 finalizeVector(Vector3 orig) {
|
||||
return target.getSpawn().getChunkSpawn(orig.getBlockX(), orig.getBlockZ(), world.getSeed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int x, int z, TerraStructure target) {
|
||||
Location spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed()).toLocation(world);
|
||||
if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(target)) return false;
|
||||
Random random = new FastRandom(MathUtil.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)), random, Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,6 @@ import com.dfsek.terra.generation.items.TerraStructure;
|
||||
public class StructureFactory implements TerraFactory<StructureTemplate, TerraStructure> {
|
||||
@Override
|
||||
public TerraStructure build(StructureTemplate config, TerraPlugin main) throws LoadException {
|
||||
return new TerraStructure(config.getStructures(), config.getBound(), config.getY(), config.getSpawn(), config.getLoot(), config);
|
||||
return new TerraStructure(config.getStructures(), config.getY(), config.getSpawn(), config.getLoot(), config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,13 @@ import java.util.Map;
|
||||
// TODO: implementation
|
||||
public class TerraStructure {
|
||||
private final ProbabilityCollection<StructureScript> structure;
|
||||
private final Range bound;
|
||||
private final Range spawnStart;
|
||||
private final GridSpawn spawn;
|
||||
private final Map<Integer, LootTable> loot;
|
||||
private final StructureTemplate template;
|
||||
|
||||
public TerraStructure(ProbabilityCollection<StructureScript> structures, Range bound, Range spawnStart, GridSpawn spawn, Map<Integer, LootTable> loot, StructureTemplate template) {
|
||||
public TerraStructure(ProbabilityCollection<StructureScript> structures, Range spawnStart, GridSpawn spawn, Map<Integer, LootTable> loot, StructureTemplate template) {
|
||||
this.structure = structures;
|
||||
this.bound = bound;
|
||||
this.spawnStart = spawnStart;
|
||||
this.spawn = spawn;
|
||||
this.loot = loot;
|
||||
@@ -35,10 +33,6 @@ public class TerraStructure {
|
||||
return structure;
|
||||
}
|
||||
|
||||
public Range getBound() {
|
||||
return bound;
|
||||
}
|
||||
|
||||
public Range getSpawnStart() {
|
||||
return spawnStart;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user