diff --git a/src/main/java/com/volmit/iris/core/commands/CommandFind.java b/src/main/java/com/volmit/iris/core/commands/CommandFind.java index ea93fe116..1592eba81 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandFind.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandFind.java @@ -34,9 +34,7 @@ public class CommandFind implements DecreeExecutor { @Decree(description = "Find a biome") public void biome( @Param(description = "The biome to look for") - IrisBiome biome, - @Param(description = "The distance away from you to start searching. -1 for random, 0 for closest", defaultValue = "0") - int distance + IrisBiome biome ) { Engine e = engine(); @@ -45,15 +43,13 @@ public class CommandFind implements DecreeExecutor { return; } - e.gotoBiome(biome, player(), distance == -1 ? 0 : distance, distance == -1); + e.gotoBiome(biome, player()); } @Decree(description = "Find a region") public void region( @Param(description = "The region to look for") - IrisRegion region, - @Param(description = "The distance away from you to start searching. -1 for random, 0 for closest", defaultValue = "0") - int distance + IrisRegion region ) { Engine e = engine(); @@ -62,15 +58,13 @@ public class CommandFind implements DecreeExecutor { return; } - e.gotoRegion(region, player(), distance == -1 ? 0 : distance, distance == -1); + e.gotoRegion(region, player()); } @Decree(description = "Find a structure") public void structure( @Param(description = "The structure to look for") - IrisJigsawStructure structure, - @Param(description = "The distance away from you to start searching. -1 for random, 0 for closest", defaultValue = "0") - int distance + IrisJigsawStructure structure ) { Engine e = engine(); @@ -79,15 +73,13 @@ public class CommandFind implements DecreeExecutor { return; } - e.gotoJigsaw(structure, player(), distance == -1 ? 0 : distance, distance == -1); + e.gotoJigsaw(structure, player()); } @Decree(description = "Find an object") public void object( @Param(description = "The object to look for", customHandler = ObjectHandler.class) - String object, - @Param(description = "The distance away from you to start searching. -1 for random, 0 for closest", defaultValue = "0") - int distance + String object ) { Engine e = engine(); @@ -96,6 +88,6 @@ public class CommandFind implements DecreeExecutor { return; } - e.gotoObject(object, player(), distance == -1 ? 0 : distance, distance == -1); + e.gotoObject(object, player()); } } diff --git a/src/main/java/com/volmit/iris/core/nms/INMS.java b/src/main/java/com/volmit/iris/core/nms/INMS.java index 03713e0e4..f624fa418 100644 --- a/src/main/java/com/volmit/iris/core/nms/INMS.java +++ b/src/main/java/com/volmit/iris/core/nms/INMS.java @@ -52,7 +52,7 @@ public class INMS { return "BUKKIT"; } - private static INMSBinding bind() { + private static final INMSBinding bind() { String code = getNMSTag(); Iris.info("Locating NMS Binding for " + code); diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index 79e73d5ca..9d22085e6 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -771,7 +771,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat return getBiomeOrMantle(l.getBlockX(), l.getBlockY(), l.getBlockZ()); } - default void gotoBiome(IrisBiome biome, Player player, int distance, boolean random) { + default void gotoBiome(IrisBiome biome, Player player) { Set regionKeys = getDimension() .getAllRegions(this).stream() .filter((i) -> i.getAllBiomes(this).contains(biome)) @@ -783,13 +783,17 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat && lb.matches(engine, chunk); if (!regionKeys.isEmpty()) { +<<<<<<< HEAD locator.find(player, Math.abs(distance), random); +======= + locator.find(player); +>>>>>>> parent of 636fddd... Improve finding by allowing minimal distance & randomization } else { player.sendMessage(C.RED + biome.getName() + " is not in any defined regions!"); } } - default void gotoJigsaw(IrisJigsawStructure s, Player player, int distance, boolean random) { + default void gotoJigsaw(IrisJigsawStructure s, Player player) { if (s.getLoadKey().equals(getDimension().getStronghold())) { KList p = getDimension().getStrongholds(getSeedManager().getSpawn()); @@ -826,7 +830,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat if (getDimension().getJigsawStructures().stream() .map(IrisJigsawStructurePlacement::getStructure) .collect(Collectors.toSet()).contains(s.getLoadKey())) { - Locator.jigsawStructure(s.getLoadKey()).find(player, distance, random); + Locator.jigsawStructure(s.getLoadKey()).find(player); } else { Set biomeKeys = getDimension().getAllBiomes(this).stream() .filter((i) -> i.getJigsawStructures() @@ -853,7 +857,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat }; if (!regionKeys.isEmpty()) { - locator.find(player, distance, random); + locator.find(player); } else { player.sendMessage(C.RED + s.getLoadKey() + " is not in any defined regions, biomes or dimensions!"); } @@ -861,7 +865,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat } - default void gotoObject(String s, Player player, int distance, boolean random) { + default void gotoObject(String s, Player player) { Set biomeKeys = getDimension().getAllBiomes(this).stream() .filter((i) -> i.getObjects().stream().anyMatch((f) -> f.getPlace().contains(s))) .map(IrisRegistrant::getLoadKey) @@ -884,19 +888,19 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat }; if (!regionKeys.isEmpty()) { - locator.find(player, distance, random); + locator.find(player); } else { player.sendMessage(C.RED + s + " is not in any defined regions or biomes!"); } } - default void gotoRegion(IrisRegion r, Player player, int distance, boolean random) { + default void gotoRegion(IrisRegion r, Player player) { if (!getDimension().getAllRegions(this).contains(r)) { player.sendMessage(C.RED + r.getName() + " is not defined in the dimension!"); return; } - Locator.region(r.getLoadKey()).find(player, distance, random); + Locator.region(r.getLoadKey()).find(player); } default void cleanupMantleChunk(int x, int z) { diff --git a/src/main/java/com/volmit/iris/engine/framework/Locator.java b/src/main/java/com/volmit/iris/engine/framework/Locator.java index f7fa3b00f..592e06069 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Locator.java +++ b/src/main/java/com/volmit/iris/engine/framework/Locator.java @@ -58,17 +58,16 @@ public interface Locator { } } - default void find(Player player, int distance, boolean random) { - find(player, 30_000, distance, random); + default void find(Player player) { + find(player, 30_000); } - default void find(Player player, long timeout, int distance, boolean random) { + default void find(Player player, long timeout) { AtomicLong checks = new AtomicLong(); long ms = M.ms(); new SingleJob("Searching", () -> { try { - Position2 from = new Position2(player.getLocation().getBlockX() >> 4, player.getLocation().getBlockZ() >> 4); - Position2 at = find(IrisToolbelt.access(player.getWorld()).getEngine(), from, timeout, checks::set, distance, random).get(); + Position2 at = find(IrisToolbelt.access(player.getWorld()).getEngine(), new Position2(player.getLocation().getBlockX() >> 4, player.getLocation().getBlockZ() >> 4), timeout, checks::set).get(); if (at != null) { J.s(() -> player.teleport(new Location(player.getWorld(), (at.getX() << 4) + 8, @@ -98,31 +97,41 @@ public interface Locator { }.execute(new VolmitSender(player)); } - default Future find(Engine engine, Position2 location, long timeout, Consumer checks, int distance, boolean random) throws WrongEngineBroException { + default Future find(Engine engine, Position2 pos, long timeout, Consumer checks) throws WrongEngineBroException { if (engine.isClosed()) { throw new WrongEngineBroException(); } cancelSearch(); +<<<<<<< HEAD int fdistance = distance >> 4; Position2 pos = random ? new Position2(M.irand(-29_000_000, 29_000_000) >> 4, M.irand(-29_000_000, 29_000_000) >> 4) : new Position2(location.getX(), location.getZ()); if (random) { Iris.info("Randomly finding location from: " + pos); } +======= +>>>>>>> parent of 636fddd... Improve finding by allowing minimal distance & randomization return MultiBurst.burst.completeValue(() -> { int tc = IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism()) * 17; MultiBurst burst = MultiBurst.burst; AtomicBoolean found = new AtomicBoolean(false); + Position2 cursor = pos; AtomicInteger searched = new AtomicInteger(); AtomicBoolean stop = new AtomicBoolean(false); AtomicReference foundPos = new AtomicReference<>(); PrecisionStopwatch px = PrecisionStopwatch.start(); LocatorCanceller.cancel = () -> stop.set(true); +<<<<<<< HEAD AtomicReference next = new AtomicReference<>(pos); Spiraler s = new Spiraler(50000, 50000, (x, z) -> next.set(new Position2(pos.getX() + (M.r(0.5) ? -1 : 1) * (x + fdistance), pos.getZ() + (M.r(0.5) ? -1 : 1) * (z + fdistance)))); s.setOffset(pos.getX(), pos.getZ()); +======= + AtomicReference next = new AtomicReference<>(cursor); + Spiraler s = new Spiraler(100000, 100000, (x, z) -> next.set(new Position2(x, z))); + s.setOffset(cursor.getX(), cursor.getZ()); +>>>>>>> parent of 636fddd... Improve finding by allowing minimal distance & randomization s.next(); while (!found.get() && !stop.get() && px.getMilliseconds() < timeout) { BurstExecutor e = burst.burst(tc); diff --git a/src/main/java/com/volmit/iris/util/math/Position2.java b/src/main/java/com/volmit/iris/util/math/Position2.java index 6dcaf68fd..279d5076f 100644 --- a/src/main/java/com/volmit/iris/util/math/Position2.java +++ b/src/main/java/com/volmit/iris/util/math/Position2.java @@ -80,7 +80,7 @@ public class Position2 { } public double distance(Position2 center) { - return Math.sqrt(Math.pow(center.getX() - x, 2) + Math.pow(center.getZ() - z, 2)); + return Math.pow(center.getX() - x, 2) + Math.pow(center.getZ() - z, 2); } public Position2 add(int x, int z) {