mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Improve finding by allowing minimal distance & randomization
This commit is contained in:
parent
13532a1f0a
commit
636fddd642
@ -34,7 +34,9 @@ public class CommandFind implements DecreeExecutor {
|
||||
@Decree(description = "Find a biome")
|
||||
public void biome(
|
||||
@Param(description = "The biome to look for")
|
||||
IrisBiome biome
|
||||
IrisBiome biome,
|
||||
@Param(description = "The distance away from you to start searching. -1 for random, 0 for closest", defaultValue = "0")
|
||||
int distance
|
||||
) {
|
||||
Engine e = engine();
|
||||
|
||||
@ -43,13 +45,15 @@ public class CommandFind implements DecreeExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
e.gotoBiome(biome, player());
|
||||
e.gotoBiome(biome, player(), distance == -1 ? 0 : distance, distance == -1);
|
||||
}
|
||||
|
||||
@Decree(description = "Find a region")
|
||||
public void region(
|
||||
@Param(description = "The region to look for")
|
||||
IrisRegion region
|
||||
IrisRegion region,
|
||||
@Param(description = "The distance away from you to start searching. -1 for random, 0 for closest", defaultValue = "0")
|
||||
int distance
|
||||
) {
|
||||
Engine e = engine();
|
||||
|
||||
@ -58,13 +62,15 @@ public class CommandFind implements DecreeExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
e.gotoRegion(region, player());
|
||||
e.gotoRegion(region, player(), distance == -1 ? 0 : distance, distance == -1);
|
||||
}
|
||||
|
||||
@Decree(description = "Find a structure")
|
||||
public void structure(
|
||||
@Param(description = "The structure to look for")
|
||||
IrisJigsawStructure structure
|
||||
IrisJigsawStructure structure,
|
||||
@Param(description = "The distance away from you to start searching. -1 for random, 0 for closest", defaultValue = "0")
|
||||
int distance
|
||||
) {
|
||||
Engine e = engine();
|
||||
|
||||
@ -73,13 +79,15 @@ public class CommandFind implements DecreeExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
e.gotoJigsaw(structure, player());
|
||||
e.gotoJigsaw(structure, player(), distance == -1 ? 0 : distance, distance == -1);
|
||||
}
|
||||
|
||||
@Decree(description = "Find an object")
|
||||
public void object(
|
||||
@Param(description = "The object to look for", customHandler = ObjectHandler.class)
|
||||
String object
|
||||
String object,
|
||||
@Param(description = "The distance away from you to start searching. -1 for random, 0 for closest", defaultValue = "0")
|
||||
int distance
|
||||
) {
|
||||
Engine e = engine();
|
||||
|
||||
@ -88,6 +96,6 @@ public class CommandFind implements DecreeExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
e.gotoObject(object, player());
|
||||
e.gotoObject(object, player(), distance == -1 ? 0 : distance, distance == -1);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class INMS {
|
||||
return "BUKKIT";
|
||||
}
|
||||
|
||||
private static final INMSBinding bind() {
|
||||
private static INMSBinding bind() {
|
||||
String code = getNMSTag();
|
||||
Iris.info("Locating NMS Binding for " + code);
|
||||
|
||||
|
@ -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) {
|
||||
default void gotoBiome(IrisBiome biome, Player player, int distance, boolean random) {
|
||||
Set<String> regionKeys = getDimension()
|
||||
.getAllRegions(this).stream()
|
||||
.filter((i) -> i.getAllBiomes(this).contains(biome))
|
||||
@ -783,13 +783,13 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
&& lb.matches(engine, chunk);
|
||||
|
||||
if (!regionKeys.isEmpty()) {
|
||||
locator.find(player);
|
||||
locator.find(player, distance, random);
|
||||
} else {
|
||||
player.sendMessage(C.RED + biome.getName() + " is not in any defined regions!");
|
||||
}
|
||||
}
|
||||
|
||||
default void gotoJigsaw(IrisJigsawStructure s, Player player) {
|
||||
default void gotoJigsaw(IrisJigsawStructure s, Player player, int distance, boolean random) {
|
||||
if (s.getLoadKey().equals(getDimension().getStronghold())) {
|
||||
KList<Position2> p = getDimension().getStrongholds(getSeedManager().getSpawn());
|
||||
|
||||
@ -826,7 +826,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);
|
||||
Locator.jigsawStructure(s.getLoadKey()).find(player, distance, random);
|
||||
} else {
|
||||
Set<String> biomeKeys = getDimension().getAllBiomes(this).stream()
|
||||
.filter((i) -> i.getJigsawStructures()
|
||||
@ -853,7 +853,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
};
|
||||
|
||||
if (!regionKeys.isEmpty()) {
|
||||
locator.find(player);
|
||||
locator.find(player, distance, random);
|
||||
} else {
|
||||
player.sendMessage(C.RED + s.getLoadKey() + " is not in any defined regions, biomes or dimensions!");
|
||||
}
|
||||
@ -861,7 +861,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
|
||||
}
|
||||
|
||||
default void gotoObject(String s, Player player) {
|
||||
default void gotoObject(String s, Player player, int distance, boolean random) {
|
||||
Set<String> biomeKeys = getDimension().getAllBiomes(this).stream()
|
||||
.filter((i) -> i.getObjects().stream().anyMatch((f) -> f.getPlace().contains(s)))
|
||||
.map(IrisRegistrant::getLoadKey)
|
||||
@ -884,19 +884,19 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
};
|
||||
|
||||
if (!regionKeys.isEmpty()) {
|
||||
locator.find(player);
|
||||
locator.find(player, distance, random);
|
||||
} else {
|
||||
player.sendMessage(C.RED + s + " is not in any defined regions or biomes!");
|
||||
}
|
||||
}
|
||||
|
||||
default void gotoRegion(IrisRegion r, Player player) {
|
||||
default void gotoRegion(IrisRegion r, Player player, int distance, boolean random) {
|
||||
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);
|
||||
Locator.region(r.getLoadKey()).find(player, distance, random);
|
||||
}
|
||||
|
||||
default void cleanupMantleChunk(int x, int z) {
|
||||
|
@ -57,16 +57,17 @@ public interface Locator<T> {
|
||||
}
|
||||
}
|
||||
|
||||
default void find(Player player) {
|
||||
find(player, 30_000);
|
||||
default void find(Player player, int distance, boolean random) {
|
||||
find(player, 30_000, distance, random);
|
||||
}
|
||||
|
||||
default void find(Player player, long timeout) {
|
||||
default void find(Player player, long timeout, int distance, boolean random) {
|
||||
AtomicLong checks = new AtomicLong();
|
||||
long ms = M.ms();
|
||||
new SingleJob("Searching", () -> {
|
||||
try {
|
||||
Position2 at = find(IrisToolbelt.access(player.getWorld()).getEngine(), new Position2(player.getLocation().getBlockX() >> 4, player.getLocation().getBlockZ() >> 4), timeout, checks::set).get();
|
||||
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();
|
||||
|
||||
if (at != null) {
|
||||
J.s(() -> player.teleport(new Location(player.getWorld(), (at.getX() << 4) + 8,
|
||||
@ -96,26 +97,28 @@ public interface Locator<T> {
|
||||
}.execute(new VolmitSender(player));
|
||||
}
|
||||
|
||||
default Future<Position2> find(Engine engine, Position2 pos, long timeout, Consumer<Integer> checks) throws WrongEngineBroException {
|
||||
default Future<Position2> find(Engine engine, Position2 location, long timeout, Consumer<Integer> checks, int distance, boolean random) throws WrongEngineBroException {
|
||||
if (engine.isClosed()) {
|
||||
throw new WrongEngineBroException();
|
||||
}
|
||||
|
||||
cancelSearch();
|
||||
|
||||
int fdistance = distance >> 4;
|
||||
return MultiBurst.burst.completeValue(() -> {
|
||||
Position2 pos = random ? new Position2(M.irand(-29*10^6, 29*10^6), M.irand(-29*10^6, 29*10^6)) : new Position2(location.getX(), location.getZ());
|
||||
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<Position2> foundPos = new AtomicReference<>();
|
||||
PrecisionStopwatch px = PrecisionStopwatch.start();
|
||||
LocatorCanceller.cancel = () -> stop.set(true);
|
||||
AtomicReference<Position2> next = new AtomicReference<>(cursor);
|
||||
Spiraler s = new Spiraler(100000, 100000, (x, z) -> next.set(new Position2(x, z)));
|
||||
s.setOffset(cursor.getX(), cursor.getZ());
|
||||
AtomicReference<Position2> next = new AtomicReference<>(pos);
|
||||
Spiraler s = new Spiraler(50000, 50000, (x, z) -> next.set(new Position2((M.r(0.5) ? -1 : 1) * (x + fdistance), (M.r(0.5) ? -1 : 1) * (z + fdistance))));
|
||||
|
||||
s.setOffset(pos.getX(), pos.getZ());
|
||||
s.next();
|
||||
while (!found.get() && !stop.get() && px.getMilliseconds() < timeout) {
|
||||
BurstExecutor e = burst.burst(tc);
|
||||
|
@ -80,7 +80,7 @@ public class Position2 {
|
||||
}
|
||||
|
||||
public double distance(Position2 center) {
|
||||
return Math.pow(center.getX() - x, 2) + Math.pow(center.getZ() - z, 2);
|
||||
return Math.sqrt(Math.pow(center.getX() - x, 2) + Math.pow(center.getZ() - z, 2));
|
||||
}
|
||||
|
||||
public Position2 add(int x, int z) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user