begin removing Location

This commit is contained in:
dfsek
2021-06-25 13:27:56 -07:00
parent 4306b179bb
commit 56029851f0
31 changed files with 77 additions and 73 deletions

View File

@@ -32,7 +32,6 @@ import com.dfsek.terra.api.structures.script.builders.UnaryStringFunctionBuilder
import com.dfsek.terra.api.structures.script.builders.ZeroArgFunctionBuilder;
import com.dfsek.terra.api.structures.structure.buffer.DirectBuffer;
import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
@@ -115,30 +114,30 @@ public class StructureScript implements Structure {
@Override
@SuppressWarnings("try")
public boolean generate(Location location, Random random, Rotation rotation) {
public boolean generate(Vector3 location, World world, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript:" + id)) {
StructureBuffer buffer = new StructureBuffer(location.toVector());
boolean level = applyBlock(new TerraImplementationArguments(buffer, rotation, random, location.getWorld(), 0));
buffer.paste(location.toVector(), location.getWorld());
StructureBuffer buffer = new StructureBuffer(location);
boolean level = applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, 0));
buffer.paste(location, world);
return level;
}
}
@Override
@SuppressWarnings("try")
public boolean generate(Location location, Chunk chunk, Random random, Rotation rotation) {
public boolean generate(Vector3 location, World world, Chunk chunk, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_chunk:" + id)) {
StructureBuffer buffer = computeBuffer(location.toVector(), location.getWorld(), random, rotation);
buffer.paste(location.toVector(), chunk);
StructureBuffer buffer = computeBuffer(location, world, random, rotation);
buffer.paste(location, chunk);
return buffer.succeeded();
}
}
@Override
@SuppressWarnings("try")
public boolean test(Location location, Random random, Rotation rotation) {
public boolean test(Vector3 location, World world, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_test:" + id)) {
StructureBuffer buffer = computeBuffer(location.toVector(), location.getWorld(), random, rotation);
StructureBuffer buffer = computeBuffer(location, world, random, rotation);
return buffer.succeeded();
}
}

View File

@@ -21,7 +21,7 @@ public class BufferedEntity implements BufferedItem {
@Override
public void paste(Vector3 origin, World world) {
Entity entity = world.spawnEntity(origin.clone().add(0.5, 0, 0.5).toLocation(world), type);
Entity entity = world.spawnEntity(origin.clone().add(0.5, 0, 0.5), type);
main.getEventManager().callEvent(new EntitySpawnEvent(entity.world().getTerraGenerator().getConfigPack(), entity));
}
}

View File

@@ -3,6 +3,7 @@ package com.dfsek.terra.api.world.locate;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import org.jetbrains.annotations.NotNull;
@@ -14,8 +15,8 @@ import java.util.function.Consumer;
*/
public class AsyncBiomeFinder extends AsyncFeatureFinder<TerraBiome> {
public AsyncBiomeFinder(BiomeProvider provider, TerraBiome target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
super(provider, target, origin, startRadius, maxRadius, callback, main);
public AsyncBiomeFinder(BiomeProvider provider, TerraBiome target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
super(provider, target, origin, world, startRadius, maxRadius, callback, main);
}
/**

View File

@@ -22,7 +22,7 @@ public abstract class AsyncFeatureFinder<T> implements Runnable {
protected int searchSize = 1;
protected final TerraPlugin main;
public AsyncFeatureFinder(BiomeProvider provider, T target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
public AsyncFeatureFinder(BiomeProvider provider, T target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
this.provider = provider;
this.target = target;
this.main = main;
@@ -30,7 +30,7 @@ public abstract class AsyncFeatureFinder<T> implements Runnable {
this.maxRadius = maxRadius;
this.centerX = origin.getBlockX();
this.centerZ = origin.getBlockZ();
this.world = origin.getWorld();
this.world = world;
this.callback = callback;
}

View File

@@ -6,6 +6,7 @@ import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.util.PopulationUtil;
import com.dfsek.terra.api.vector.Location;
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 com.dfsek.terra.world.population.items.TerraStructure;
@@ -16,8 +17,8 @@ import java.util.Random;
import java.util.function.Consumer;
public class AsyncStructureFinder extends AsyncFeatureFinder<TerraStructure> {
public AsyncStructureFinder(BiomeProvider provider, TerraStructure target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
super(provider, target, origin, startRadius, maxRadius, callback, main);
public AsyncStructureFinder(BiomeProvider provider, TerraStructure 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());
}
@@ -28,9 +29,9 @@ public class AsyncStructureFinder extends AsyncFeatureFinder<TerraStructure> {
@Override
public boolean isValid(int x, int z, TerraStructure target) {
Location spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed()).toLocation(world);
Vector3 spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed());
if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(target)) return false;
Random random = new FastRandom(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)), random, Rotation.fromDegrees(90 * random.nextInt(4)));
return target.getStructure().get(random).test(spawn.setY(target.getSpawnStart().get(random)), world, random, Rotation.fromDegrees(90 * random.nextInt(4)));
}
}

View File

@@ -41,7 +41,7 @@ public class CarverCache {
List<Worm.WormPoint> points = new GlueList<>();
for(int i = 0; i < carving.getLength(); i++) {
carving.step();
TerraBiome biome = provider.getBiome(carving.getRunning().toLocation(w));
TerraBiome biome = provider.getBiome(carving.getRunning());
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(CarverCache.this.carver)) { // Stop if we enter a biome this carver is not present in
return Collections.emptyList();
}

View File

@@ -64,7 +64,7 @@ public class BiomeLocateCommand implements CommandTemplate {
Player player = (Player) sender;
new Thread(new AsyncBiomeFinder(main.getWorld(player.world()).getBiomeProvider(), biome, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())).toLocation(player.world()), 0, radius, location -> {
new Thread(new AsyncBiomeFinder(main.getWorld(player.world()).getBiomeProvider(), biome, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.world(), 0, radius, location -> {
if(location != null) {
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3Impl(0, player.position().getY(), 0)).distance(player.position())));
if(teleport) {

View File

@@ -16,6 +16,7 @@ import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.injection.annotations.Inject;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.vector.LocationImpl;
import java.io.BufferedWriter;
@@ -45,10 +46,10 @@ public class StructureExportCommand implements CommandTemplate {
public void execute(CommandSender sender) {
Player player = (Player) sender;
Pair<Location, Location> l = main.getWorldHandle().getSelectedLocation(player);
Pair<Vector3, Vector3> l = main.getWorldHandle().getSelectedLocation(player);
Location l1 = l.getLeft();
Location l2 = l.getRight();
Vector3 l1 = l.getLeft();
Vector3 l2 = l.getRight();
StringBuilder scriptBuilder = new StringBuilder("id \"" + id + "\";\nnum y = 0;\n");
@@ -59,7 +60,7 @@ public class StructureExportCommand implements CommandTemplate {
for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) {
for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) {
for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) {
BlockState state = l1.getWorld().getBlockState(x, y, z);
BlockState state = player.world().getBlockState(x, y, z);
if(state instanceof Sign) {
Sign sign = (Sign) state;
if(sign.getLine(0).equals("[TERRA]") && sign.getLine(1).equals("[CENTER]")) {
@@ -76,9 +77,9 @@ public class StructureExportCommand implements CommandTemplate {
for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) {
for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) {
BlockData data = l1.getWorld().getBlockData(x, y, z);
BlockData data = player.world().getBlockData(x, y, z);
if(data.isStructureVoid()) continue;
BlockState state = l1.getWorld().getBlockState(x, y, z);
BlockState state = player.world().getBlockState(x, y, z);
if(state instanceof Sign) {
Sign sign = (Sign) state;
if(sign.getLine(0).equals("[TERRA]")) {

View File

@@ -79,9 +79,9 @@ public class StructureLoadCommand implements CommandTemplate {
return;
}
if(this.chunk) {
script.generate(player.position().toLocation(player.world()), player.world().getChunkAt(player.position().toLocation(player.world())), random, r);
script.generate(player.position(), player.world(), player.world().getChunkAt(player.position()), random, r);
} else {
script.generate(player.position().toLocation(player.world()), random, r);
script.generate(player.position(), player.world(), random, r);
}
long l = System.nanoTime() - t;

View File

@@ -62,7 +62,7 @@ public class StructureLocateCommand implements CommandTemplate {
public void execute(CommandSender sender) {
Player player = (Player) sender;
new Thread(new AsyncStructureFinder(main.getWorld(player.world()).getBiomeProvider(), structure, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())).toLocation(player.world()), 0, radius, location -> {
new Thread(new AsyncStructureFinder(main.getWorld(player.world()).getBiomeProvider(), structure, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.world(), 0, radius, location -> {
if(location != null) {
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", structure.getTemplate().getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3Impl(0, player.position().getY(), 0)).distance(player.position())));
if(teleport) {

View File

@@ -4,7 +4,7 @@ import com.dfsek.terra.api.block.BlockData;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
@@ -52,7 +52,7 @@ public class DummyWorld implements World {
}
@Override
public Entity spawnEntity(Location location, EntityType entityType) {
public Entity spawnEntity(Vector3 location, EntityType entityType) {
throw new UnsupportedOperationException("Cannot spawn entity in DummyWorld");
}

View File

@@ -7,6 +7,7 @@ import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.util.PopulationUtil;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.World;
@@ -40,12 +41,12 @@ public class StructurePopulator implements TerraBlockPopulator, Chunkified {
BiomeProvider provider = tw.getBiomeProvider();
WorldConfig config = tw.getConfig();
for(TerraStructure conf : config.getRegistry(TerraStructure.class).entries()) {
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
Vector3 spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed());
if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(conf))
continue;
Random random = new FastRandom(PopulationUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed()));
conf.getStructure().get(random).generate(spawn.setY(conf.getSpawnStart().get(random)), chunk, random, Rotation.fromDegrees(90 * random.nextInt(4)));
conf.getStructure().get(random).generate(spawn.setY(conf.getSpawnStart().get(random)), world, chunk, random, Rotation.fromDegrees(90 * random.nextInt(4)));
}
}
}

View File

@@ -23,6 +23,6 @@ public class FloraLayer extends PlaceableLayer<Flora> {
int cx = chunk.getX() << 4;
int cz = chunk.getZ() << 4;
Flora item = layer.get(noise, coords.getX() + cx, coords.getZ() + cz);
item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(block -> item.plant(block.toLocation(chunk.getWorld()).add(cx, 0, cz)));
item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(block -> item.plant(block.add(cx, 0, cz), chunk.getWorld()));
}
}

View File

@@ -10,7 +10,6 @@ import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.util.GlueList;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.Flora;
@@ -69,7 +68,7 @@ public class TerraFlora implements Flora {
for(int y : range) {
if(y > 255 || y < 0) continue;
current = current.add(0, search.equals(Search.UP) ? 1 : -1, 0);
if((spawnBlacklist != spawnable.contains(chunk.getBlock(current.getBlockX(), current.getBlockY(), current.getBlockZ()).getBlockType())) && isIrrigated(current.add(0, irrigableOffset, 0), chunk.getWorld()) && valid(size, current.clone().add(cx, 0, cz), chunk.getWorld())) {
if((spawnBlacklist != spawnable.contains(chunk.getBlock(current.getBlockX(), current.getBlockY(), current.getBlockZ()).getBlockType())) && isIrrigated(current.clone().add(cx, irrigableOffset, cz), chunk.getWorld()) && valid(size, current.clone().add(cx, 0, cz), chunk.getWorld())) {
blocks.add(current.clone());
if(maxPlacements > 0 && blocks.size() >= maxPlacements) break;
}
@@ -96,12 +95,12 @@ public class TerraFlora implements Flora {
@Override
public boolean plant(Location location) {
public boolean plant(Vector3 location, World world) {
boolean doRotation = testRotation.size() > 0;
int size = floraPalette.getSize();
int c = ceiling ? -1 : 1;
List<BlockFace> faces = doRotation ? getFaces(location.clone().add(0, c, 0).toVector(), location.getWorld()) : new GlueList<>();
List<BlockFace> faces = doRotation ? getFaces(location.clone().add(0, c, 0), world) : new GlueList<>();
if(doRotation && faces.size() == 0) return false; // Don't plant if no faces are valid.
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
@@ -119,7 +118,7 @@ public class TerraFlora implements Flora {
((Rotatable) data).setRotation(oneFace);
}
}
location.getWorld().setBlockData(location.toVector().add(0, i + c, 0), data, physics);
world.setBlockData(location.clone().add(0, i + c, 0), data, physics);
}
return true;
}