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

@@ -5,6 +5,7 @@ import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
/**
* Interface to be implemented for world manipulation.
@@ -20,7 +21,7 @@ public interface WorldHandle {
* @param player Player to get locations for
* @return Pair of locations.
*/
default Pair<Location, Location> getSelectedLocation(Player player) {
default Pair<Vector3, Vector3> getSelectedLocation(Player player) {
throw new UnsupportedOperationException("Cannot get selection on this platform.");
}
}

View File

@@ -2,7 +2,6 @@ package com.dfsek.terra.api.structure;
import com.dfsek.terra.api.structure.buffer.Buffer;
import com.dfsek.terra.api.structure.rotation.Rotation;
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;
@@ -14,17 +13,18 @@ public interface Structure {
* Paste the structure at a location
*
* @param location Location to paste structure
* @param world
* @param rotation Rotation of structure
* @return Whether generation was successful
*/
@SuppressWarnings("try")
boolean generate(Location location, Random random, Rotation rotation);
boolean generate(Vector3 location, World world, Random random, Rotation rotation);
@SuppressWarnings("try")
boolean generate(Location location, Chunk chunk, Random random, Rotation rotation);
boolean generate(Vector3 location, World world, Chunk chunk, Random random, Rotation rotation);
@SuppressWarnings("try")
boolean test(Location location, Random random, Rotation rotation);
boolean test(Vector3 location, World world, Random random, Rotation rotation);
@SuppressWarnings("try")
boolean generate(Buffer buffer, World world, Random random, Rotation rotation, int recursions);

View File

@@ -163,5 +163,5 @@ public interface Vector3 extends Cloneable {
Vector3 subtract(Vector3 end);
public Vector3 clone();
Vector3 clone();
}

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.api.world;
import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import java.util.List;
@@ -9,5 +8,5 @@ import java.util.List;
public interface Flora {
List<Vector3> getValidSpawnsAt(Chunk chunk, int x, int z, Range check);
boolean plant(Location l);
boolean plant(Vector3 l, World world);
}

View File

@@ -20,7 +20,7 @@ public interface World extends Handle {
Chunk getChunkAt(int x, int z);
default Chunk getChunkAt(Location location) {
default Chunk getChunkAt(Vector3 location) {
return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);
}
@@ -50,7 +50,7 @@ public interface World extends Handle {
return getBlockState(position.getBlockX(), position.getBlockY(), position.getBlockZ());
}
Entity spawnEntity(Location location, EntityType entityType);
Entity spawnEntity(Vector3 location, EntityType entityType);
int getMinHeight();

View File

@@ -16,10 +16,6 @@ public interface BiomeProvider {
return getBiome(vector3.getBlockX(), vector3.getBlockZ());
}
default TerraBiome getBiome(Location location) {
return getBiome(location.getBlockX(), location.getBlockZ());
}
interface BiomeProviderBuilder {
BiomeProvider build(long seed);
}

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;
}

View File

@@ -15,6 +15,6 @@ public class FixChunkCommand implements CommandTemplate {
@Override
public void execute(CommandSender sender) {
Player player = (Player) sender;
BukkitChunkGeneratorWrapper.fixChunk(player.world().getChunkAt(player.position().toLocation(player.world())));
BukkitChunkGeneratorWrapper.fixChunk(player.world().getChunkAt(player.position()));
}
}

View File

@@ -5,7 +5,7 @@ import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.handle.WorldHandle;
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.bukkit.structure.WorldEditUtil;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData;
@@ -26,7 +26,7 @@ public class BukkitWorldHandle implements WorldHandle {
}
@Override
public Pair<Location, Location> getSelectedLocation(Player player) {
public Pair<Vector3, Vector3> getSelectedLocation(Player player) {
org.bukkit.Location[] locations = WorldEditUtil.getSelectionLocations(BukkitAdapter.adapt(player));
return Pair.of(BukkitAdapter.adapt(locations[0]), BukkitAdapter.adapt(locations[1]));
}

View File

@@ -24,9 +24,9 @@ public class PaperListener implements Listener {
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getWorld()));
TerraStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(tw.getConfig().getLocatable().get(name));
if(config != null) {
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getOrigin()), 0, 500, location -> {
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getOrigin().toVector()), tw.getWorld(), 0, 500, location -> {
if(location != null)
e.setResult(BukkitAdapter.adapt(location.toLocation(BukkitAdapter.adapt(e.getWorld()))));
e.setResult(BukkitAdapter.adapt(location).toLocation(e.getWorld()));
main.getDebugLogger().info("Location: " + location);
}, main);
finder.run(); // Do this synchronously.

View File

@@ -40,9 +40,9 @@ public class SpigotListener implements Listener {
TerraStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(tw.getConfig().getLocatable().get("STRONGHOLD"));
if(config != null) {
main.getDebugLogger().info("Overriding Ender Signal...");
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()), 0, 500, location -> {
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation().toVector()), tw.getWorld(), 0, 500, location -> {
if(location != null)
signal.setTargetLocation(BukkitAdapter.adapt(location.toLocation(BukkitAdapter.adapt(signal.getWorld()))));
signal.setTargetLocation(BukkitAdapter.adapt(location).toLocation(e.getLocation().getWorld()));
main.getDebugLogger().info("Location: " + location);
}, main);
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.

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;
@@ -75,8 +75,8 @@ public class BukkitWorld implements World {
}
@Override
public Entity spawnEntity(Location location, EntityType entityType) {
return new BukkitEntity(delegate.spawnEntity(BukkitAdapter.adapt(location), ((BukkitEntityType) entityType).getHandle()));
public Entity spawnEntity(Vector3 location, EntityType entityType) {
return new BukkitEntity(delegate.spawnEntity(BukkitAdapter.adapt(location).toLocation(delegate), ((BukkitEntityType) entityType).getHandle()));
}
@Override

View File

@@ -118,7 +118,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
TerraStructure located = pack.getRegistry(TerraStructure.class).get(pack.getLocatable().get(name));
if(located != null) {
CompletableFuture<BlockPos> result = new CompletableFuture<>();
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center), terraWorld.getWorld(), 0, 500, location -> {
result.complete(FabricAdapter.adapt(location));
}, TerraFabricPlugin.getInstance());
finder.run(); // Do this synchronously.

View File

@@ -4,7 +4,7 @@ import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.handle.WorldHandle;
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.fabric.block.FabricBlockData;
import com.dfsek.terra.fabric.util.FabricAdapter;
import com.dfsek.terra.fabric.util.WorldEditUtil;
@@ -39,7 +39,7 @@ public class FabricWorldHandle implements WorldHandle {
}
@Override
public Pair<Location, Location> getSelectedLocation(Player player) {
public Pair<Vector3, Vector3> getSelectedLocation(Player player) {
try {
Class.forName("com.sk89q.worldedit.WorldEdit");
} catch(ClassNotFoundException e) {

View File

@@ -4,6 +4,7 @@ import com.dfsek.terra.api.block.BlockData;
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;
@@ -64,7 +65,7 @@ public abstract class ChunkRegionMixin {
}
@SuppressWarnings("deprecation")
public Entity terraWorld$spawnEntity(Location location, EntityType entityType) {
public Entity terraWorld$spawnEntity(Vector3 location, EntityType entityType) {
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(((ChunkRegion) (Object) this).toServerWorld());
entity.setPos(location.getX(), location.getY(), location.getZ());
((ChunkRegion) (Object) this).spawnEntity(entity);

View File

@@ -4,6 +4,7 @@ import com.dfsek.terra.api.block.BlockData;
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;
@@ -53,7 +54,7 @@ public abstract class ServerWorldMixin {
((ServerWorld) (Object) this).setBlockState(pos, ((FabricBlockData) data).getHandle(), physics ? 3 : 1042);
}
public Entity terra$spawnEntity(Location location, EntityType entityType) {
public Entity terra$spawnEntity(Vector3 location, EntityType entityType) {
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(((ServerWorld) (Object) this));
entity.setPos(location.getX(), location.getY(), location.getZ());
((ServerWorld) (Object) this).spawnEntity(entity);

View File

@@ -3,7 +3,9 @@ package com.dfsek.terra.fabric.util;
import com.dfsek.terra.api.entity.Player;
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 com.dfsek.terra.vector.Vector3Impl;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector3;
@@ -12,7 +14,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;
public final class WorldEditUtil {
public static Pair<Location, Location> getSelection(Player player) {
public static Pair<Vector3, Vector3> getSelection(Player player) {
WorldEdit worldEdit = WorldEdit.getInstance();
try {
Region selection = worldEdit.getSessionManager()
@@ -20,8 +22,8 @@ public final class WorldEditUtil {
.getSelection(com.sk89q.worldedit.fabric.FabricAdapter.adapt((World) player.world()));
BlockVector3 min = selection.getMinimumPoint();
BlockVector3 max = selection.getMaximumPoint();
LocationImpl l1 = new LocationImpl(player.world(), min.getBlockX(), min.getBlockY(), min.getBlockZ());
LocationImpl l2 = new LocationImpl(player.world(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
Vector3 l1 = new Vector3Impl(min.getBlockX(), min.getBlockY(), min.getBlockZ());
Vector3 l2 = new Vector3Impl(max.getBlockX(), max.getBlockY(), max.getBlockZ());
return Pair.of(l1, l2);
} catch(IncompleteRegionException e) {
throw new IllegalStateException("No selection has been made", e);

View File

@@ -1,14 +1,16 @@
package com.dfsek.terra.platform;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.vector.LocationImpl;
import java.util.Random;
public class RawTree implements Tree { // TODO: implement
@Override
public boolean plant(LocationImpl l, Random r) {
public boolean plant(Vector3 l, World world, Random r) {
return false;
}