mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-28 11:29:11 +00:00
* optimize async target finding * fix canContinueToUse * fix data race * fix TemptGoal start before search entity * fix AvoidEntityGoal doesn't create path * fix inactiveTick tickingTarget * default queueSize to 0 * default queueSize to 4096
2115 lines
97 KiB
Diff
2115 lines
97 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Sat, 29 Mar 2025 13:40:46 +0100
|
|
Subject: [PATCH] Async target finding
|
|
|
|
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index 24926aa7ed5c78b235659daf18b224b14beb744c..98af1ad020a003db66d7319f33d43deec315aec5 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -292,6 +292,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("Leaf Async Mob Spawn Thread"); // Pufferfish - optimize mob spawning // Leaf - Fix Pufferfish and Purpur patches - Unify thread name
|
|
public final Set<net.minecraft.world.entity.Entity> entitiesWithScheduledTasks = java.util.concurrent.ConcurrentHashMap.newKeySet(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (concurrent because plugins may schedule tasks async)
|
|
public java.util.concurrent.Semaphore serverLevelTickingSemaphore = null; // SparklyPaper - parallel world ticking
|
|
+ @Nullable public org.dreeam.leaf.async.ai.AsyncGoalThread asyncGoalThread; // Leaf - Async target finding
|
|
|
|
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
|
|
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
|
|
@@ -1088,6 +1089,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
org.dreeam.leaf.async.AsyncPlayerDataSaving.IO_POOL.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS);
|
|
} catch (java.lang.InterruptedException ignored) {}
|
|
// Leaf end - Async playerdata saving
|
|
+ // Leaf start - Async target finding
|
|
+ if (this.asyncGoalThread != null) {
|
|
+ try {
|
|
+ this.asyncGoalThread.join();
|
|
+ } catch (java.lang.InterruptedException ignored) {
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Async target finding
|
|
}
|
|
|
|
public String getLocalIp() {
|
|
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index 33dd16a26edd2974f04d9a868d3e58e8e3060032..0817ad4e16d8858b7d92e028d551e9184f357eb6 100644
|
|
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -255,6 +255,9 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
DedicatedServer.LOGGER.info("Using " + serverLevelTickingSemaphore.availablePermits() + " permits for parallel world ticking"); // SparklyPaper - parallel world ticking
|
|
}
|
|
// Leaf end - SparklyPaper - parallel world ticking mod (make configurable)
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ asyncGoalThread = new org.dreeam.leaf.async.ai.AsyncGoalThread(this);
|
|
+ }
|
|
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
|
|
|
|
// Gale start - Pufferfish - SIMD support
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index 90bdcd168ad5b1a940f81b191bd59a34d3a33070..fbfb35dad8b07c31f967d33fb04cfcfc94557d72 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -177,7 +177,16 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
private static final int EMPTY_TIME_NO_TICK = 300;
|
|
private static final int MAX_SCHEDULED_TICKS_PER_TICK = 65536;
|
|
- final List<ServerPlayer> players = Lists.newArrayList();
|
|
+ // Leaf start - Async target finding
|
|
+ final List<ServerPlayer> players;
|
|
+ {
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ this.players = Lists.newCopyOnWriteArrayList();
|
|
+ } else {
|
|
+ this.players = Lists.newArrayList();
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Async target finding
|
|
public final ServerChunkCache chunkSource;
|
|
private final MinecraftServer server;
|
|
public final net.minecraft.world.level.storage.PrimaryLevelData serverLevelData; // CraftBukkit - type
|
|
@@ -218,6 +227,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
private final alternate.current.wire.WireHandler wireHandler = new alternate.current.wire.WireHandler(this); // Paper - optimize redstone (Alternate Current)
|
|
public boolean hasRidableMoveEvent = false; // Purpur - Ridables
|
|
final List<ServerPlayer> realPlayers; // Leaves - skip
|
|
+ public final @Nullable org.dreeam.leaf.async.ai.AsyncGoalExecutor asyncGoalExecutor; // Leaf - Async target finding
|
|
|
|
public LevelChunk getChunkIfLoaded(int x, int z) {
|
|
return this.chunkSource.getChunkAtIfLoadedImmediately(x, z); // Paper - Use getChunkIfLoadedImmediately
|
|
@@ -335,6 +345,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.server).moonrise$executeMidTickTasks();
|
|
}
|
|
|
|
+ // Leaf start - Async target finding
|
|
+ public final void leafMidTickTasks() {
|
|
+ if (this.asyncGoalExecutor != null) this.asyncGoalExecutor.midTick();
|
|
+ }
|
|
+ // Leaf end - Async target finding
|
|
+
|
|
@Override
|
|
public final ChunkAccess moonrise$syncLoadNonFull(final int chunkX, final int chunkZ, final net.minecraft.world.level.chunk.status.ChunkStatus status) {
|
|
return this.moonrise$getChunkTaskScheduler().syncLoadNonFull(chunkX, chunkZ, status);
|
|
@@ -711,6 +727,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
this.preciseTime = this.serverLevelData.getDayTime(); // Purpur - Configurable daylight cycle
|
|
this.realPlayers = Lists.newArrayList(); // Leaves - skip
|
|
this.tickExecutor = java.util.concurrent.Executors.newSingleThreadExecutor(new org.dreeam.leaf.async.world.SparklyPaperServerLevelTickExecutorThreadFactory(getWorld().getName())); // SparklyPaper - parallel world ticking
|
|
+ // Leaf start - Async target finding
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ this.asyncGoalExecutor = new org.dreeam.leaf.async.ai.AsyncGoalExecutor(server.asyncGoalThread, this);
|
|
+ } else {
|
|
+ this.asyncGoalExecutor = null;
|
|
+ }
|
|
+ // Leaf end - Async target finding
|
|
}
|
|
|
|
// Paper start
|
|
@@ -855,12 +878,14 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
this.moonrise$midTickTasks(); // Paper - rewrite chunk system
|
|
// Gale end - Airplane - remove lambda from ticking guard - copied from guardEntityTick
|
|
+ this.leafMidTickTasks(); // Leaf - Async target finding
|
|
}
|
|
}
|
|
}
|
|
}
|
|
);
|
|
this.tickBlockEntities();
|
|
+ if (this.asyncGoalExecutor != null) this.asyncGoalExecutor.unpark(); // Leaf - Async target finding
|
|
}
|
|
|
|
// Paper - rewrite chunk system
|
|
@@ -1329,6 +1354,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
// Leaf end - SparklyPaper - parallel world ticking (only run mid-tick at the end of each tick / fixes concurrency bugs related to executeMidTickTasks)
|
|
// Paper end - rewrite chunk system
|
|
|
|
+ this.leafMidTickTasks(); // Leaf - Async target finding
|
|
}
|
|
|
|
private void tickBlock(BlockPos pos, Block block) {
|
|
@@ -1345,6 +1371,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
// Leaf end - SparklyPaper - parallel world ticking (only run mid-tick at the end of each tick / fixes concurrency bugs related to executeMidTickTasks)
|
|
// Paper end - rewrite chunk system
|
|
|
|
+ this.leafMidTickTasks(); // Leaf - Async target finding
|
|
}
|
|
|
|
// Paper start - log detailed entity tick information
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 90879616842cc61d15854b07f56f6fcb89f11074..f114a8f5143799d72e36e0a535888c5fb25213e1 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -243,6 +243,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
protected Vec3 stuckSpeedMultiplier = Vec3.ZERO;
|
|
@Nullable
|
|
private Entity.RemovalReason removalReason;
|
|
+ private volatile boolean isRemoved = false; // Leaf - volatile removal check
|
|
public static final float DEFAULT_BB_WIDTH = 0.6F;
|
|
public static final float DEFAULT_BB_HEIGHT = 1.8F;
|
|
public float moveDist;
|
|
@@ -5036,7 +5037,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
|
|
public final boolean isRemoved() {
|
|
- return this.removalReason != null;
|
|
+ // Leaf start - volatile removal check
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ return this.isRemoved;
|
|
+ } else {
|
|
+ return this.removalReason != null;
|
|
+ }
|
|
+ // Leaf end - volatile removal check
|
|
}
|
|
|
|
@Nullable
|
|
@@ -5063,6 +5070,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers
|
|
if (this.removalReason == null) {
|
|
this.removalReason = removalReason;
|
|
+ // Leaf start - volatile removal check
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled && this.removalReason != null) {
|
|
+ this.isRemoved = true;
|
|
+ }
|
|
+ // Leaf end - volatile removal check
|
|
}
|
|
|
|
if (this.removalReason.shouldDestroy()) {
|
|
@@ -5082,6 +5094,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
|
|
public void unsetRemoved() {
|
|
this.removalReason = null;
|
|
+ // Leaf start - volatile removal check
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ this.isRemoved = false;
|
|
+ }
|
|
+ // Leaf end - volatile removal check
|
|
}
|
|
|
|
// Paper start - Folia schedulers
|
|
diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
|
|
index 05d5cde42b7011091ef4ee874c0d9d5586ae3f10..bf021604e0c345ef72cbc55d4f8fe996d2d561f7 100644
|
|
--- a/net/minecraft/world/entity/Mob.java
|
|
+++ b/net/minecraft/world/entity/Mob.java
|
|
@@ -144,6 +144,10 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
private float restrictRadius = -1.0F;
|
|
public boolean aware = true; // CraftBukkit
|
|
public int ticksSinceLastInteraction; // Purpur - Entity lifespan
|
|
+ public boolean tickingTarget; // Leaf - Async target finding
|
|
+ public final org.dreeam.leaf.async.ai.Waker getGoalCtx() {
|
|
+ return tickingTarget ? this.targetSelector.ctx : this.goalSelector.ctx;
|
|
+ }
|
|
|
|
protected Mob(EntityType<? extends Mob> entityType, Level level) {
|
|
super(entityType, level);
|
|
@@ -225,12 +229,21 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
}
|
|
// Paper end - Skip AI during inactive ticks for non-aware mobs
|
|
boolean isThrottled = org.dreeam.leaf.config.modules.opt.ThrottleInactiveGoalSelectorTick.enabled && _pufferfish_inactiveTickDisableCounter++ % 20 != 0; // Pufferfish - throttle inactive goal selector ticking
|
|
+ this.tickingTarget = false; // Leaf
|
|
if (this.goalSelector.inactiveTick(this.activatedPriority, true) && !isThrottled) { // Pufferfish - pass activated priroity // Pufferfish - throttle inactive goal selector ticking
|
|
this.goalSelector.tick();
|
|
}
|
|
+ this.tickingTarget = true; // Leaf
|
|
if (this.targetSelector.inactiveTick(this.activatedPriority, true)) { // Pufferfish - pass activated priority
|
|
this.targetSelector.tick();
|
|
}
|
|
+ // Leaf start - Async target finding
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ if (this.targetSelector.ctxGoals != null || this.goalSelector.ctxGoals != null) {
|
|
+ ((ServerLevel) this.level()).asyncGoalExecutor.submit(this.getId());
|
|
+ }
|
|
+ }
|
|
+ // Leaf start - Async target finding
|
|
}
|
|
// Paper end
|
|
|
|
@@ -914,17 +927,28 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
// Paper end - Allow nerfed mobs to jump and float
|
|
this.sensing.tick();
|
|
int i = this.tickCount + this.getId();
|
|
+ // Leaf start - Async target finding
|
|
if (i % 2 != 0 && this.tickCount > 1) {
|
|
+ this.tickingTarget = true;
|
|
if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.targetSelector.tickRunningGoals(false);
|
|
+ this.tickingTarget = false;
|
|
if (this.goalSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.goalSelector.tickRunningGoals(false);
|
|
} else {
|
|
+ this.tickingTarget = true;
|
|
if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.targetSelector.tick();
|
|
+ this.tickingTarget = false;
|
|
if (this.goalSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.goalSelector.tick();
|
|
}
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ if (this.targetSelector.ctxGoals != null || this.goalSelector.ctxGoals != null) {
|
|
+ ((ServerLevel) this.level()).asyncGoalExecutor.submit(this.getId());
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Async target finding
|
|
|
|
this.navigation.tick();
|
|
this.customServerAiStep((ServerLevel)this.level());
|
|
diff --git a/net/minecraft/world/entity/ai/goal/AvoidEntityGoal.java b/net/minecraft/world/entity/ai/goal/AvoidEntityGoal.java
|
|
index 4b24bb47a53a46586a642f3fb2656b1b8b670bf2..5239f4dfeaed8adccceb2a6d6578308261f46628 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/AvoidEntityGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/AvoidEntityGoal.java
|
|
@@ -67,15 +67,24 @@ public class AvoidEntityGoal<T extends LivingEntity> extends Goal {
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
- this.toAvoid = getServerLevel(this.mob)
|
|
- .getNearestEntity(
|
|
- this.mob.level().getEntitiesOfClass(this.avoidClass, this.mob.getBoundingBox().inflate(this.maxDist, 3.0, this.maxDist), livingEntity -> true),
|
|
- this.avoidEntityTargeting,
|
|
- this.mob,
|
|
- this.mob.getX(),
|
|
- this.mob.getY(),
|
|
- this.mob.getZ()
|
|
- );
|
|
+ // Leaf start - Async Avoid Entity Finding
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ if (!poll()) {
|
|
+ getNearestEntityAsync();
|
|
+ return false;
|
|
+ }
|
|
+ } else {
|
|
+ this.toAvoid = getServerLevel(this.mob)
|
|
+ .getNearestEntity(
|
|
+ this.mob.level().getEntitiesOfClass(this.avoidClass, this.mob.getBoundingBox().inflate(this.maxDist, 3.0, this.maxDist), livingEntity -> true),
|
|
+ this.avoidEntityTargeting,
|
|
+ this.mob,
|
|
+ this.mob.getX(),
|
|
+ this.mob.getEyeY(),
|
|
+ this.mob.getZ()
|
|
+ );
|
|
+ }
|
|
+ // Leaf end - Async Avoid Entity Finding
|
|
if (this.toAvoid == null) {
|
|
return false;
|
|
} else {
|
|
@@ -91,6 +100,47 @@ public class AvoidEntityGoal<T extends LivingEntity> extends Goal {
|
|
}
|
|
}
|
|
|
|
+ // Leaf start - Async Avoid Entity Finding
|
|
+ private boolean poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof LivingEntity entity)) { return false; }
|
|
+ var serverLevel = getServerLevel(this.mob);
|
|
+ if (serverLevel == null || !entity.isAlive() || !this.avoidEntityTargeting.test(serverLevel, this.mob, entity)) {
|
|
+ return false;
|
|
+ }
|
|
+ this.toAvoid = (T) entity;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ private void getNearestEntityAsync() {
|
|
+ final var mob = this.mob;
|
|
+ final var ctx = mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final double x = mob.getX();
|
|
+ final double y = mob.getEyeY();
|
|
+ final double z = mob.getZ();
|
|
+ final var serverLevel = getServerLevel(mob);
|
|
+ final var avoidClass = this.avoidClass;
|
|
+ final var bound = mob.getBoundingBox().inflate(this.maxDist, 3.0, this.maxDist);
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob == null || mob.isRemoved() || !mob.isAlive() || mob.level() != serverLevel) {
|
|
+ return;
|
|
+ }
|
|
+ ctx.result = serverLevel.getNearestEntity(
|
|
+ serverLevel.getEntitiesOfClass(avoidClass, bound, livingEntity -> true),
|
|
+ avoidEntityTargeting,
|
|
+ mob,
|
|
+ x,
|
|
+ y,
|
|
+ z
|
|
+ );
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Avoid Entity Finding
|
|
+
|
|
@Override
|
|
public boolean canContinueToUse() {
|
|
return !this.pathNav.isDone();
|
|
diff --git a/net/minecraft/world/entity/ai/goal/BegGoal.java b/net/minecraft/world/entity/ai/goal/BegGoal.java
|
|
index 28ef40e8a645989ea181297069cf2bbe571f3082..5f1a0ccaed29324a24bfbea96c9dc3adfeb11ad5 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/BegGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/BegGoal.java
|
|
@@ -27,8 +27,54 @@ public class BegGoal extends Goal {
|
|
this.setFlags(EnumSet.of(Goal.Flag.LOOK));
|
|
}
|
|
|
|
+ // Leaf start - Async Target Finding
|
|
+ protected boolean poll() {
|
|
+ if (!(this.wolf.getGoalCtx().result() instanceof Player t)) { return false; }
|
|
+ if (t == null) {
|
|
+ return false;
|
|
+ }
|
|
+ ServerLevel serverLevel = getServerLevel(this.wolf);
|
|
+ if (serverLevel == null || !t.isAlive() || !playerHoldingInteresting(t)) {
|
|
+ return false;
|
|
+ }
|
|
+ this.player = t;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ private void findTargetAsync() {
|
|
+ final Wolf wolf = this.wolf;
|
|
+ final var ctx = wolf.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final ServerLevel serverLevel = getServerLevel(wolf);
|
|
+ final TargetingConditions begTargeting = this.begTargeting;
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (wolf.level() != serverLevel || wolf.isRemoved() || !wolf.isAlive()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ var player = serverLevel.getNearestPlayer(begTargeting, wolf);
|
|
+ if (player != null && playerHoldingInteresting(player)) {
|
|
+ ctx.result = player;
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
+
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async Target Finding
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ findTargetAsync();
|
|
+ return false;
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
this.player = this.level.getNearestPlayer(this.begTargeting, this.wolf);
|
|
return this.player != null && this.playerHoldingInteresting(this.player);
|
|
}
|
|
@@ -59,14 +105,16 @@ public class BegGoal extends Goal {
|
|
this.lookTime--;
|
|
}
|
|
|
|
- private boolean playerHoldingInteresting(Player player) {
|
|
+ // Leaf start - static
|
|
+ private static boolean playerHoldingInteresting(Player player) {
|
|
for (InteractionHand interactionHand : InteractionHand.values()) {
|
|
ItemStack itemInHand = player.getItemInHand(interactionHand);
|
|
- if (itemInHand.is(Items.BONE) || this.wolf.isFood(itemInHand)) {
|
|
+ if (itemInHand.is(Items.BONE) || itemInHand.is(net.minecraft.tags.ItemTags.WOLF_FOOD)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
+ // Leaf end - static
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/CatLieOnBedGoal.java b/net/minecraft/world/entity/ai/goal/CatLieOnBedGoal.java
|
|
index 4c46cd105cde3cbcde65a02ff691c3a8edd56c76..d26bebdc66bf30a30fba5c1ba70e71479aff68a1 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/CatLieOnBedGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/CatLieOnBedGoal.java
|
|
@@ -52,6 +52,14 @@ public class CatLieOnBedGoal extends MoveToBlockGoal {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
return level.isEmptyBlock(pos.above()) && level.getBlockState(pos).is(BlockTags.BEDS);
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.CatLie;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/CatSitOnBlockGoal.java b/net/minecraft/world/entity/ai/goal/CatSitOnBlockGoal.java
|
|
index 9954f49bc364969c7ccb37f4186fa2ab8710f6ae..b0a93215a7d5e8fe58331f261d7b4f87852cd4b2 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/CatSitOnBlockGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/CatSitOnBlockGoal.java
|
|
@@ -44,9 +44,11 @@ public class CatSitOnBlockGoal extends MoveToBlockGoal {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
if (!level.isEmptyBlock(pos.above())) {
|
|
return false;
|
|
} else {
|
|
+ // Leaf - Async search block
|
|
BlockState blockState = level.getBlockState(pos);
|
|
return blockState.is(Blocks.CHEST)
|
|
? ChestBlockEntity.getOpenCount(level, pos) < 1
|
|
@@ -54,4 +56,11 @@ public class CatSitOnBlockGoal extends MoveToBlockGoal {
|
|
|| blockState.is(BlockTags.BEDS, state -> state.getOptionalValue(BedBlock.PART).map(bedPart -> bedPart != BedPart.HEAD).orElse(true));
|
|
}
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.CatSit;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/FollowBoatGoal.java b/net/minecraft/world/entity/ai/goal/FollowBoatGoal.java
|
|
index 1fe4d1877ed52017d4d22ddb9b77f78e2b93dff9..ec52e6c8110876eb915485c54a8102c4afe460f6 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/FollowBoatGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/FollowBoatGoal.java
|
|
@@ -23,8 +23,54 @@ public class FollowBoatGoal extends Goal {
|
|
this.mob = mob;
|
|
}
|
|
|
|
+ // Leaf start - Async Target Finding
|
|
+ private boolean poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof Player t)) { return false; }
|
|
+ var serverLevel = getServerLevel(this.mob);
|
|
+ return serverLevel != null && t.isAlive() && !t.isSpectator() && (Mth.abs(t.xxa) > 0.0F || Mth.abs(t.zza) > 0.0F);
|
|
+ }
|
|
+
|
|
+ private void findTargetAsync() {
|
|
+ final PathfinderMob mob = this.mob;
|
|
+ final var ctx = mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final var bound = mob.getBoundingBox().inflate(5.0);
|
|
+ final var serverLevel = getServerLevel(mob);
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob.level() != serverLevel || mob.isRemoved() || !mob.isAlive()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ List<AbstractBoat> entitiesOfClass = serverLevel.getEntitiesOfClass(AbstractBoat.class, bound);
|
|
+ for (AbstractBoat abstractBoat : entitiesOfClass) {
|
|
+ Entity controllingPassenger = abstractBoat.getControllingPassenger();
|
|
+ if (controllingPassenger instanceof Player player
|
|
+ && (Mth.abs(player.xxa) > 0.0F || Mth.abs(player.zza) > 0.0F)) {
|
|
+ ctx.result = player;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async Target Finding
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+ if (this.following != null && (Mth.abs(this.following.xxa) > 0.0F || Mth.abs(this.following.zza) > 0.0F)) {
|
|
+ return true;
|
|
+ }
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ findTargetAsync();
|
|
+ return false;
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
List<AbstractBoat> entitiesOfClass = this.mob.level().getEntitiesOfClass(AbstractBoat.class, this.mob.getBoundingBox().inflate(5.0));
|
|
boolean flag = false;
|
|
|
|
@@ -37,7 +83,7 @@ public class FollowBoatGoal extends Goal {
|
|
}
|
|
}
|
|
|
|
- return this.following != null && (Mth.abs(this.following.xxa) > 0.0F || Mth.abs(this.following.zza) > 0.0F) || flag;
|
|
+ return flag; // Leaf - move above
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/world/entity/ai/goal/FollowMobGoal.java b/net/minecraft/world/entity/ai/goal/FollowMobGoal.java
|
|
index c9cf985173d3da9e84ce178f161e2fd5fb8ce472..0d123e6bac5748b6c5efd76f4c1e086cbf749783 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/FollowMobGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/FollowMobGoal.java
|
|
@@ -38,6 +38,15 @@ public class FollowMobGoal extends Goal {
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async Follow Mob Finding
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ getFollowingMobAsync();
|
|
+ return false;
|
|
+ }
|
|
+ // Leaf end - Async Follow Mob Finding
|
|
List<Mob> entitiesOfClass = this.mob.level().getEntitiesOfClass(Mob.class, this.mob.getBoundingBox().inflate(this.areaSize), this.followPredicate);
|
|
if (!entitiesOfClass.isEmpty()) {
|
|
for (Mob mob : entitiesOfClass) {
|
|
@@ -51,6 +60,45 @@ public class FollowMobGoal extends Goal {
|
|
return false;
|
|
}
|
|
|
|
+ // Leaf start - Async Follow Mob Finding
|
|
+ private boolean poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof Mob t)) { return false; }
|
|
+ var serverLevel = getServerLevel(this.mob);
|
|
+ if (serverLevel == null || !t.isAlive() || t.isInvisible()) {
|
|
+ return false;
|
|
+ }
|
|
+ this.followingMob = t;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ private void getFollowingMobAsync() {
|
|
+ final var mob = this.mob;
|
|
+ final var ctx = this.mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final var serverLevel = getServerLevel(mob);
|
|
+ final var bound = this.mob.getBoundingBox().inflate(this.areaSize);
|
|
+ final var followPredicate = this.followPredicate;
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob == null || mob.isRemoved() || !mob.isAlive() || mob.level() != serverLevel) {
|
|
+ return;
|
|
+ }
|
|
+ List<Mob> entitiesOfClass = serverLevel.getEntitiesOfClass(Mob.class, bound, followPredicate);
|
|
+ if (!entitiesOfClass.isEmpty()) {
|
|
+ for (final Mob follow : entitiesOfClass) {
|
|
+ if (!follow.isInvisible()) {
|
|
+ ctx.result = follow;
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Follow Mob Finding
|
|
+
|
|
@Override
|
|
public boolean canContinueToUse() {
|
|
return this.followingMob != null && !this.navigation.isDone() && this.mob.distanceToSqr(this.followingMob) > this.stopDistance * this.stopDistance;
|
|
diff --git a/net/minecraft/world/entity/ai/goal/FollowParentGoal.java b/net/minecraft/world/entity/ai/goal/FollowParentGoal.java
|
|
index 3093f03d4f298bf39fec8bad2b6c22518774aea8..ee42674761653cacc5045fcb60e314fbe25f390f 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/FollowParentGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/FollowParentGoal.java
|
|
@@ -19,11 +19,68 @@ public class FollowParentGoal extends Goal {
|
|
this.speedModifier = speedModifier;
|
|
}
|
|
|
|
+ // Leaf start - Async Target Finding
|
|
+ protected boolean poll() {
|
|
+ if (!(this.animal.getGoalCtx().result() instanceof Animal t)) { return false; }
|
|
+ var serverLevel = getServerLevel(animal);
|
|
+ if (serverLevel == null || !t.isAlive() || animal.distanceToSqr(t) < 9.0) {
|
|
+ return false;
|
|
+ }
|
|
+ this.parent = animal;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ private void findTargetAsync() {
|
|
+ final Animal animal = this.animal;
|
|
+ final var ctx = animal.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final var targetType = animal.getClass();
|
|
+ final var bound = animal.getBoundingBox().inflate(8.0, 4.0, 8.0);
|
|
+ final var serverLevel = getServerLevel(animal);
|
|
+ final var pos = animal.position();
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (animal.level() != serverLevel || animal.isRemoved() || !animal.isAlive()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ List<? extends Animal> entitiesOfClass = serverLevel.getEntitiesOfClass(targetType, bound);
|
|
+ Animal target = null;
|
|
+ double d = Double.MAX_VALUE;
|
|
+
|
|
+ for (Animal animal1 : entitiesOfClass) {
|
|
+ if (animal1.getAge() >= 0) {
|
|
+ double d1 = animal1.distanceToSqr(pos);
|
|
+ if (!(d1 > d)) {
|
|
+ d = d1;
|
|
+ target = animal1;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ if (target != null) {
|
|
+ ctx.result = target;
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
+
|
|
@Override
|
|
public boolean canUse() {
|
|
if (this.animal.getAge() >= 0) {
|
|
return false;
|
|
} else {
|
|
+ // Leaf start - Async Target Finding
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ findTargetAsync();
|
|
+ return false;
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
List<? extends Animal> entitiesOfClass = this.animal
|
|
.level()
|
|
.getEntitiesOfClass((Class<? extends Animal>)this.animal.getClass(), this.animal.getBoundingBox().inflate(8.0, 4.0, 8.0));
|
|
@@ -43,6 +100,7 @@ public class FollowParentGoal extends Goal {
|
|
if (animal == null) {
|
|
return false;
|
|
} else if (d < 9.0) {
|
|
+ // Leaf - Async Target Finding
|
|
return false;
|
|
} else {
|
|
this.parent = animal;
|
|
diff --git a/net/minecraft/world/entity/ai/goal/GoalSelector.java b/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
index e82e32407cec6109b9c3b0106295217f4a3f4aa2..32463fae3d3a58e71c4aae2d81b2a1b60fee7d69 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
@@ -26,6 +26,13 @@ public class GoalSelector {
|
|
private final ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<net.minecraft.world.entity.ai.goal.Goal.Flag> goalTypes = new ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<>(Goal.Flag.class); // Paper - remove streams from GoalSelector
|
|
private int curRate; // Paper - EAR 2
|
|
|
|
+ // Leaf start - Async target finding
|
|
+ public WrappedGoal @org.jetbrains.annotations.Nullable[] ctxGoals = null;
|
|
+ private int ctxIndex = 0;
|
|
+ private int ctxState = 0;
|
|
+ public final org.dreeam.leaf.async.ai.Waker ctx = new org.dreeam.leaf.async.ai.Waker();
|
|
+ // Leaf end - Async target finding
|
|
+
|
|
public void addGoal(int priority, Goal goal) {
|
|
this.availableGoals.add(new WrappedGoal(priority, goal));
|
|
}
|
|
@@ -85,7 +92,107 @@ public class GoalSelector {
|
|
return true;
|
|
}
|
|
|
|
+ public final boolean poll() {
|
|
+ if (this.ctxGoals == null || ctx.wake != null) {
|
|
+ return false;
|
|
+ }
|
|
+ if (ctxState == 0) {
|
|
+ while (ctxIndex < this.ctxGoals.length) {
|
|
+ WrappedGoal goal = this.ctxGoals[ctxIndex];
|
|
+ // entity tempt
|
|
+ if (goal.isRunning() && (goalContainsAnyFlags(goal, this.goalTypes) || !goal.canContinueToUse())) {
|
|
+ ctx.state = false;
|
|
+ if (ctx.wake != null) {
|
|
+ return true;
|
|
+ }
|
|
+ goal.stop();
|
|
+ }
|
|
+
|
|
+ ctxIndex++;
|
|
+ ctx.state = true;
|
|
+ }
|
|
+
|
|
+ this.lockedFlags.entrySet().removeIf(entry -> !entry.getValue().isRunning());
|
|
+
|
|
+ ctxIndex = 0;
|
|
+ ctx.state = true;
|
|
+ ctxState = 1;
|
|
+ }
|
|
+ if (ctxState == 1) {
|
|
+ while (ctxIndex < this.ctxGoals.length) {
|
|
+ WrappedGoal goal = this.ctxGoals[ctxIndex];
|
|
+ // entity and block
|
|
+ if (!goal.isRunning()
|
|
+ && !goalContainsAnyFlags(goal, this.goalTypes)
|
|
+ && goalCanBeReplacedForAllFlags(goal, this.lockedFlags)
|
|
+ ) {
|
|
+ if (goal.canUse()) {
|
|
+ long flagIterator = goal.getFlags().getBackingSet();
|
|
+ int wrappedGoalSize = goal.getFlags().size();
|
|
+ for (int i = 0; i < wrappedGoalSize; ++i) {
|
|
+ final Goal.Flag flag = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)];
|
|
+ flagIterator ^= ca.spottedleaf.concurrentutil.util.IntegerUtil.getTrailingBit(flagIterator);
|
|
+ WrappedGoal wrappedGoal1 = this.lockedFlags.getOrDefault(flag, NO_GOAL);
|
|
+ wrappedGoal1.stop();
|
|
+ this.lockedFlags.put(flag, goal);
|
|
+ }
|
|
+
|
|
+ goal.start();
|
|
+ }
|
|
+ ctx.state = false;
|
|
+ if (ctx.wake != null) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ // entity alert other
|
|
+ if (!ctx.state) {
|
|
+ switch (goal.getGoal()) {
|
|
+ case net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal t -> t.poll();
|
|
+ case net.minecraft.world.entity.ai.goal.target.ResetUniversalAngerTargetGoal t -> t.poll();
|
|
+ default -> {}
|
|
+ }
|
|
+ }
|
|
+ ctxIndex++;
|
|
+ ctx.state = true;
|
|
+ }
|
|
+
|
|
+ ctxIndex = 0;
|
|
+ ctx.state = true;
|
|
+ ctxState = 2;
|
|
+ }
|
|
+ if (ctxState == 2) {
|
|
+ while (ctxIndex < this.ctxGoals.length) {
|
|
+ WrappedGoal goal = this.ctxGoals[ctxIndex];
|
|
+ if (goal.isRunning()) {
|
|
+ goal.tick();
|
|
+ }
|
|
+ ctxIndex++;
|
|
+ }
|
|
+
|
|
+ ctxGoals = null;
|
|
+ ctxState = 0;
|
|
+ ctxIndex = 0;
|
|
+ ctx.state = true;
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ public final void wake() {
|
|
+ Runnable wake = ctx.wake;
|
|
+ if (wake != null) {
|
|
+ wake.run();
|
|
+ }
|
|
+ ctx.wake = null;
|
|
+ }
|
|
+
|
|
public void tick() {
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ if (this.ctxGoals == null) {
|
|
+ this.ctxGoals = this.availableGoals.toArray(new WrappedGoal[0]);
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+
|
|
for (WrappedGoal wrappedGoal : this.availableGoals) {
|
|
if (wrappedGoal.isRunning() && (goalContainsAnyFlags(wrappedGoal, this.goalTypes) || !wrappedGoal.canContinueToUse())) { // Paper - Perf: optimize goal types by removing streams
|
|
wrappedGoal.stop();
|
|
@@ -94,6 +201,7 @@ public class GoalSelector {
|
|
|
|
this.lockedFlags.entrySet().removeIf(entry -> !entry.getValue().isRunning());
|
|
|
|
+
|
|
for (WrappedGoal wrappedGoalx : this.availableGoals) {
|
|
// Paper start
|
|
if (!wrappedGoalx.isRunning() && !goalContainsAnyFlags(wrappedGoalx, this.goalTypes) && goalCanBeReplacedForAllFlags(wrappedGoalx, this.lockedFlags) && wrappedGoalx.canUse()) {
|
|
diff --git a/net/minecraft/world/entity/ai/goal/LlamaFollowCaravanGoal.java b/net/minecraft/world/entity/ai/goal/LlamaFollowCaravanGoal.java
|
|
index be59d0c27a83b329ec3f97c029cfb9c114e22472..239567f1ac82e17ec8f0624f1a33c1faa7ad13fe 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/LlamaFollowCaravanGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/LlamaFollowCaravanGoal.java
|
|
@@ -20,19 +20,94 @@ public class LlamaFollowCaravanGoal extends Goal {
|
|
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
|
|
}
|
|
|
|
+ // Leaf start - Async Target Finding
|
|
+ private @javax.annotation.Nullable Llama poll() {
|
|
+ if (!(this.llama.getGoalCtx().result() instanceof Llama t)) { return null; }
|
|
+ var serverLevel = getServerLevel(this.llama);
|
|
+ if (serverLevel == null || !t.isAlive()) {
|
|
+ return null;
|
|
+ }
|
|
+ return t;
|
|
+ }
|
|
+
|
|
+ private void findTargetAsync() {
|
|
+ final Llama llama = this.llama;
|
|
+ final var ctx = llama.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final var bound = llama.getBoundingBox().inflate(9.0, 4.0, 9.0);
|
|
+ final var serverLevel = getServerLevel(llama);
|
|
+ final var pos = llama.position();
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (llama.level() != serverLevel || llama.isRemoved() || !llama.isAlive()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ List<Entity> entities = serverLevel.getEntities(llama, bound, entity1 -> {
|
|
+ EntityType<?> type = entity1.getType();
|
|
+ return type == EntityType.LLAMA || type == EntityType.TRADER_LLAMA;
|
|
+ });
|
|
+ Llama target = null;
|
|
+ double d = Double.MAX_VALUE;
|
|
+
|
|
+ for (Entity entity : entities) {
|
|
+ Llama llama1 = (Llama)entity;
|
|
+ if (llama1.inCaravan() && !llama1.hasCaravanTail()) {
|
|
+ double d1 = llama1.distanceToSqr(pos);
|
|
+ if (!(d1 > d)) {
|
|
+ d = d1;
|
|
+ target = llama1;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (target == null) {
|
|
+ for (Entity entityx : entities) {
|
|
+ Llama llama1 = (Llama)entityx;
|
|
+ if (llama1.isLeashed() && !llama1.hasCaravanTail()) {
|
|
+ double d1 = llama1.distanceToSqr(pos);
|
|
+ if (!(d1 > d)) {
|
|
+ d = d1;
|
|
+ target = llama1;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ if (target != null) {
|
|
+ ctx.result = target;
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
@Override
|
|
public boolean canUse() {
|
|
if (!this.llama.level().purpurConfig.llamaJoinCaravans || !this.llama.shouldJoinCaravan) return false; // Purpur - Llama API // Purpur - Config to disable Llama caravans
|
|
if (!this.llama.isLeashed() && !this.llama.inCaravan()) {
|
|
+ // Leaf start - Async Target Finding
|
|
+ Llama llama = poll();
|
|
+ double d = Double.MAX_VALUE;
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ if (llama == null) {
|
|
+ findTargetAsync();
|
|
+ return false;
|
|
+ } else {
|
|
+ d = this.llama.distanceToSqr(llama);
|
|
+ }
|
|
+ } else {
|
|
+ // Leaf end - Async Target Finding
|
|
List<Entity> entities = this.llama.level().getEntities(this.llama, this.llama.getBoundingBox().inflate(9.0, 4.0, 9.0), entity1 -> {
|
|
EntityType<?> type = entity1.getType();
|
|
return type == EntityType.LLAMA || type == EntityType.TRADER_LLAMA;
|
|
});
|
|
- Llama llama = null;
|
|
- double d = Double.MAX_VALUE;
|
|
+ // Llama llama = null; // Leaf
|
|
+ // double d = Double.MAX_VALUE; // Leaf
|
|
|
|
for (Entity entity : entities) {
|
|
Llama llama1 = (Llama)entity;
|
|
+ // Leaf - Async Target Finding
|
|
if (llama1.inCaravan() && !llama1.hasCaravanTail()) {
|
|
double d1 = this.llama.distanceToSqr(llama1);
|
|
if (!(d1 > d)) {
|
|
@@ -45,6 +120,7 @@ public class LlamaFollowCaravanGoal extends Goal {
|
|
if (llama == null) {
|
|
for (Entity entityx : entities) {
|
|
Llama llama1 = (Llama)entityx;
|
|
+ // Leaf - Async Target Finding
|
|
if (llama1.isLeashed() && !llama1.hasCaravanTail()) {
|
|
double d1 = this.llama.distanceToSqr(llama1);
|
|
if (!(d1 > d)) {
|
|
@@ -54,6 +130,7 @@ public class LlamaFollowCaravanGoal extends Goal {
|
|
}
|
|
}
|
|
}
|
|
+ } // Leaf
|
|
|
|
if (llama == null) {
|
|
return false;
|
|
diff --git a/net/minecraft/world/entity/ai/goal/LookAtPlayerGoal.java b/net/minecraft/world/entity/ai/goal/LookAtPlayerGoal.java
|
|
index 6463c3c9b08d6058f2843c225b08a40fc30a960b..819f7947b0c9c546cf45b2effe72cfb597a99ce6 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/LookAtPlayerGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/LookAtPlayerGoal.java
|
|
@@ -48,32 +48,94 @@ public class LookAtPlayerGoal extends Goal {
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async look finding
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
if (this.mob.getRandom().nextFloat() >= this.probability) {
|
|
return false;
|
|
+ }
|
|
+ if (this.mob.getTarget() != null) {
|
|
+ this.lookAt = this.mob.getTarget();
|
|
+ }
|
|
+
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ getLookAsync();
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ ServerLevel serverLevel = getServerLevel(this.mob);
|
|
+ if (this.lookAtType == Player.class) {
|
|
+ this.lookAt = serverLevel.getNearestPlayer(this.lookAtContext, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ());
|
|
} else {
|
|
- if (this.mob.getTarget() != null) {
|
|
- this.lookAt = this.mob.getTarget();
|
|
- }
|
|
+ this.lookAt = serverLevel.getNearestEntity(
|
|
+ this.mob
|
|
+ .level()
|
|
+ .getEntitiesOfClass(this.lookAtType, this.mob.getBoundingBox().inflate(this.lookDistance, 3.0, this.lookDistance), livingEntity -> true),
|
|
+ this.lookAtContext,
|
|
+ this.mob,
|
|
+ this.mob.getX(),
|
|
+ this.mob.getEyeY(),
|
|
+ this.mob.getZ()
|
|
+ );
|
|
+ }
|
|
|
|
- ServerLevel serverLevel = getServerLevel(this.mob);
|
|
- if (this.lookAtType == Player.class) {
|
|
- this.lookAt = serverLevel.getNearestPlayer(this.lookAtContext, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ());
|
|
- } else {
|
|
- this.lookAt = serverLevel.getNearestEntity(
|
|
- this.mob
|
|
- .level()
|
|
- .getEntitiesOfClass(this.lookAtType, this.mob.getBoundingBox().inflate(this.lookDistance, 3.0, this.lookDistance), livingEntity -> true),
|
|
- this.lookAtContext,
|
|
- this.mob,
|
|
- this.mob.getX(),
|
|
- this.mob.getEyeY(),
|
|
- this.mob.getZ()
|
|
- );
|
|
- }
|
|
+ return this.lookAt != null;
|
|
+ // Leaf end - Async look finding
|
|
+ }
|
|
|
|
- return this.lookAt != null;
|
|
+ // Leaf start - Async look finding
|
|
+ protected boolean poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof LivingEntity t)) { return false; }
|
|
+ if (this.mob.getTarget() != null) {
|
|
+ this.lookAt = this.mob.getTarget();
|
|
+ return true;
|
|
+ }
|
|
+ ServerLevel serverLevel = getServerLevel(this.mob);
|
|
+ if (!t.isAlive() || !this.lookAtContext.test(serverLevel, this.mob, t)) {
|
|
+ return false;
|
|
}
|
|
+ this.lookAt = t;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ protected void getLookAsync() {
|
|
+ final var mob = this.mob;
|
|
+ final var ctx = mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final double x = mob.getX();
|
|
+ final double y = mob.getEyeY();
|
|
+ final double z = mob.getZ();
|
|
+ final var serverLevel = getServerLevel(mob);
|
|
+ final var bound = mob.getBoundingBox().inflate(this.lookDistance, 3.0, this.lookDistance);
|
|
+ final var lookAtContext = this.lookAtContext;
|
|
+ final var lookAtType = this.lookAtType;
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob == null || !mob.isAlive() || mob.level() != serverLevel) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (lookAtType == Player.class) {
|
|
+ ctx.result = serverLevel.getNearestPlayer(lookAtContext, mob, x, y, z);
|
|
+ } else {
|
|
+ ctx.result = serverLevel.getNearestEntity(
|
|
+ serverLevel
|
|
+ .getEntitiesOfClass(lookAtType, bound, livingEntity -> true),
|
|
+ lookAtContext,
|
|
+ mob,
|
|
+ x,
|
|
+ y,
|
|
+ z
|
|
+ );
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
}
|
|
+ // Leaf end - Async look finding
|
|
|
|
@Override
|
|
public boolean canContinueToUse() {
|
|
diff --git a/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java b/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
|
|
index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..99e6e7bac2b5af1b1abb1de6b51aed1f44e5e8b0 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
|
|
@@ -41,8 +41,69 @@ public abstract class MoveToBlockGoal extends Goal {
|
|
this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.JUMP));
|
|
}
|
|
|
|
+ // Leaf start - Async search block
|
|
+ protected boolean poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof BlockPos blockPos1)) { return false; }
|
|
+ if (!this.mob.level().hasChunkAt(blockPos1)
|
|
+ || !this.mob.isWithinRestriction(blockPos1)
|
|
+ || !this.isValidTarget(this.mob.level(), blockPos1)) {
|
|
+ return false;
|
|
+ }
|
|
+ this.blockPos = blockPos1;
|
|
+ this.mob.movingTarget = blockPos1 == BlockPos.ZERO ? null : blockPos1;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ protected void getBlockAsync() {
|
|
+ final var mob = this.mob;
|
|
+ final var ctx = mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final var serverLevel = getServerLevel(mob);
|
|
+ final TypeToCheck ty = this.typeToCheck();
|
|
+ final net.minecraft.world.level.block.Block toRemove;
|
|
+ if (this instanceof RemoveBlockGoal removeBlockGoal) {
|
|
+ toRemove = removeBlockGoal.blockToRemove;
|
|
+ } else {
|
|
+ toRemove = null;
|
|
+ }
|
|
+ final int verticalSearchStart = this.verticalSearchStart;
|
|
+ final int searchRange = this.searchRange;
|
|
+ final int verticalSearchRange = this.verticalSearchRange;
|
|
+ final BlockPos blockPos = mob.blockPosition();
|
|
+ final float restrictRadius = mob.getRestrictRadius();
|
|
+ final BlockPos restrictCenter = mob.getRestrictCenter();
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob == null || !mob.isAlive() || mob.level() != serverLevel) {
|
|
+ return;
|
|
+ }
|
|
+ findNearestBlockAsync(ctx, ty, toRemove, mob, serverLevel, verticalSearchStart, searchRange, verticalSearchRange, blockPos, restrictRadius, restrictCenter);
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting block", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+
|
|
+ protected enum TypeToCheck {
|
|
+ CatLie,
|
|
+ CatSit,
|
|
+ Drowned,
|
|
+ FoxEat,
|
|
+ RaidGarden,
|
|
+ RemoveBlock,
|
|
+ Strider,
|
|
+ TurtleToWater,
|
|
+ TurtleLay,
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
+
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async search block
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
if (this.nextStartTick > 0) {
|
|
this.nextStartTick--;
|
|
return false;
|
|
@@ -109,6 +170,10 @@ public abstract class MoveToBlockGoal extends Goal {
|
|
}
|
|
|
|
protected boolean findNearestBlock() {
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchBlock) {
|
|
+ getBlockAsync();
|
|
+ return false;
|
|
+ }
|
|
int i = this.searchRange;
|
|
int i1 = this.verticalSearchRange;
|
|
BlockPos blockPos = this.mob.blockPosition();
|
|
@@ -133,5 +198,104 @@ public abstract class MoveToBlockGoal extends Goal {
|
|
return false;
|
|
}
|
|
|
|
+ protected static boolean findNearestBlockAsync(
|
|
+ final org.dreeam.leaf.async.ai.Waker ctx,
|
|
+ final TypeToCheck ty,
|
|
+ @org.jetbrains.annotations.Nullable final net.minecraft.world.level.block.Block toRemove,
|
|
+ final PathfinderMob mob,
|
|
+ final net.minecraft.server.level.ServerLevel serverLevel,
|
|
+ final int verticalSearchStart,
|
|
+ final int searchRange,
|
|
+ final int verticalSearchRange,
|
|
+ final BlockPos blockPos,
|
|
+ final float restrictRadius,
|
|
+ final BlockPos restrictCenter
|
|
+ ) {
|
|
+ BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
|
+ for (int i2 = verticalSearchStart; i2 <= verticalSearchRange; i2 = i2 > 0 ? -i2 : 1 - i2) {
|
|
+ for (int i3 = 0; i3 < searchRange; i3++) {
|
|
+ for (int i4 = 0; i4 <= i3; i4 = i4 > 0 ? -i4 : 1 - i4) {
|
|
+ for (int i5 = i4 < i3 && i4 > -i3 ? i3 : 0; i5 <= i3; i5 = i5 > 0 ? -i5 : 1 - i5) {
|
|
+ mutableBlockPos.setWithOffset(blockPos, i4, i2 - 1, i5);
|
|
+ if (!serverLevel.hasChunkAt(mutableBlockPos)) continue;
|
|
+ if (isWithinRestriction(restrictRadius, restrictCenter, mutableBlockPos)
|
|
+ && isValidTargetAsync(ty, toRemove, mob, serverLevel, mutableBlockPos)) {
|
|
+ ctx.result = mutableBlockPos.immutable();
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ private static boolean isWithinRestriction(float restrictRadius, BlockPos restrictCenter, BlockPos pos) {
|
|
+ return restrictRadius == -1.0F || restrictCenter.distSqr(pos) < restrictRadius * restrictRadius;
|
|
+ }
|
|
+
|
|
protected abstract boolean isValidTarget(LevelReader level, BlockPos pos);
|
|
+
|
|
+ protected abstract TypeToCheck typeToCheck();
|
|
+
|
|
+ private static boolean isValidTargetAsync(
|
|
+ TypeToCheck ty,
|
|
+ @org.jetbrains.annotations.Nullable net.minecraft.world.level.block.Block blockToRemoveTy,
|
|
+ PathfinderMob mob,
|
|
+ LevelReader level,
|
|
+ BlockPos pos
|
|
+ ) {
|
|
+ switch (ty) {
|
|
+ case CatLie -> {
|
|
+ return level.isEmptyBlock(pos.above()) && level.getBlockState(pos).is(net.minecraft.tags.BlockTags.BEDS);
|
|
+ }
|
|
+ case CatSit -> {
|
|
+ if (!level.isEmptyBlock(pos.above())) {
|
|
+ return false;
|
|
+ } else {
|
|
+ var blockState = level.getBlockState(pos);
|
|
+ return blockState.is(net.minecraft.world.level.block.Blocks.CHEST)
|
|
+ ? net.minecraft.world.level.block.entity.ChestBlockEntity.getOpenCount(level, pos) < 1
|
|
+ : blockState.is(net.minecraft.world.level.block.Blocks.FURNACE) && blockState.getValue(net.minecraft.world.level.block.FurnaceBlock.LIT)
|
|
+ || blockState.is(net.minecraft.tags.BlockTags.BEDS, state -> state.getOptionalValue(net.minecraft.world.level.block.BedBlock.PART).map(bedPart -> bedPart != net.minecraft.world.level.block.state.properties.BedPart.HEAD).orElse(true));
|
|
+ }
|
|
+ }
|
|
+ case Drowned -> {
|
|
+ BlockPos blockPos = pos.above();
|
|
+ return level.isEmptyBlock(blockPos) && level.isEmptyBlock(blockPos.above()) && level.getBlockState(pos).entityCanStandOn(level, pos, mob);
|
|
+ }
|
|
+ case FoxEat -> {
|
|
+ var blockState = level.getBlockState(pos);
|
|
+ return blockState.is(net.minecraft.world.level.block.Blocks.SWEET_BERRY_BUSH) && blockState.getValue(net.minecraft.world.level.block.SweetBerryBushBlock.AGE) >= 2 || net.minecraft.world.level.block.CaveVines.hasGlowBerries(blockState);
|
|
+ }
|
|
+ case RaidGarden -> {
|
|
+ var blockState = level.getBlockState(pos);
|
|
+ if (blockState.is(net.minecraft.world.level.block.Blocks.FARMLAND)) {
|
|
+ blockState = level.getBlockState(pos.above());
|
|
+ return blockState.getBlock() instanceof net.minecraft.world.level.block.CarrotBlock carrot && carrot.isMaxAge(blockState);
|
|
+ } else {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ }
|
|
+ case RemoveBlock -> {
|
|
+ var chunk = level.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4); // Paper - Prevent AI rules from loading chunks
|
|
+ return chunk != null
|
|
+ && chunk.getBlockState(pos).is(blockToRemoveTy)
|
|
+ && chunk.getBlockState(pos.above()).isAir()
|
|
+ && chunk.getBlockState(pos.above(2)).isAir();
|
|
+ }
|
|
+ case Strider -> {
|
|
+ return level.getBlockState(pos).is(net.minecraft.world.level.block.Blocks.LAVA) && level.getBlockState(pos.above()).isPathfindable(net.minecraft.world.level.pathfinder.PathComputationType.LAND);
|
|
+ }
|
|
+ case TurtleToWater -> {
|
|
+ return level.getBlockState(pos).is(net.minecraft.world.level.block.Blocks.WATER);
|
|
+ }
|
|
+ case TurtleLay -> {
|
|
+ return level.isEmptyBlock(pos.above()) && net.minecraft.world.level.block.TurtleEggBlock.isSand(level, pos);
|
|
+ }
|
|
+ case null -> throw new IllegalStateException();
|
|
+ }
|
|
+ }
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/OfferFlowerGoal.java b/net/minecraft/world/entity/ai/goal/OfferFlowerGoal.java
|
|
index 3c274d917bca9de87abfb842f5f332e112a7a2d7..aa743d8f4ec0c1d78e5e58a7b5e36bca08b8b2ef 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/OfferFlowerGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/OfferFlowerGoal.java
|
|
@@ -19,10 +19,20 @@ public class OfferFlowerGoal extends Goal {
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async offer flower finding
|
|
if (!this.golem.level().isDay()) {
|
|
return false;
|
|
- } else if (this.golem.getRandom().nextInt(8000) != 0) {
|
|
+ }
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+ if (this.golem.getRandom().nextInt(8000) != 0) {
|
|
+ return false;
|
|
+ }
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ getVillagerAsync();
|
|
return false;
|
|
+ // Leaf end - Async offer flower finding
|
|
} else {
|
|
this.villager = getServerLevel(this.golem)
|
|
.getNearestEntity(
|
|
@@ -38,6 +48,47 @@ public class OfferFlowerGoal extends Goal {
|
|
}
|
|
}
|
|
|
|
+
|
|
+ // Leaf start - Async look finding
|
|
+ protected boolean poll() {
|
|
+ if (!(this.golem.getGoalCtx().result() instanceof Villager t)) { return false; }
|
|
+ var serverLevel = getServerLevel(this.golem);
|
|
+ if (!t.isAlive() || !OFFER_TARGER_CONTEXT.test(serverLevel, this.golem, t)) {
|
|
+ return false;
|
|
+ }
|
|
+ this.villager = t;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ protected void getVillagerAsync() {
|
|
+ final var golem = this.golem;
|
|
+ final var ctx = golem.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final double x = golem.getX();
|
|
+ final double y = golem.getEyeY();
|
|
+ final double z = golem.getZ();
|
|
+ final var serverLevel = getServerLevel(golem);
|
|
+ final var bound = golem.getBoundingBox().inflate(6.0, 2.0, 6.0);
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (golem == null || !golem.isAlive() || golem.level() != serverLevel) {
|
|
+ return;
|
|
+ }
|
|
+ ctx.result = serverLevel.getNearestEntity(
|
|
+ serverLevel.getEntitiesOfClass(Villager.class, bound, livingEntity -> true),
|
|
+ OFFER_TARGER_CONTEXT,
|
|
+ golem,
|
|
+ x,
|
|
+ y,
|
|
+ z
|
|
+ );
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async look finding
|
|
+
|
|
@Override
|
|
public boolean canContinueToUse() {
|
|
return this.tick > 0;
|
|
diff --git a/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java b/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java
|
|
index 95fa516910a3834bbd4db6d11279e13a1f0dac41..f7ddae601abbe9e22a35c7cb4f9763e61fa7ff81 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java
|
|
@@ -22,7 +22,7 @@ import net.minecraft.world.level.chunk.status.ChunkStatus;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
public class RemoveBlockGoal extends MoveToBlockGoal {
|
|
- private final Block blockToRemove;
|
|
+ protected final Block blockToRemove; // Leaf - Async search block
|
|
private final Mob removerMob;
|
|
private int ticksSinceReachedGoal;
|
|
private static final int WAIT_AFTER_BLOCK_FOUND = 20;
|
|
@@ -37,7 +37,14 @@ public class RemoveBlockGoal extends MoveToBlockGoal {
|
|
public boolean canUse() {
|
|
if (!getServerLevel(this.removerMob).purpurConfig.zombieBypassMobGriefing == !getServerLevel(this.removerMob).getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { // Purpur - Add mobGriefing bypass to everything affected
|
|
return false;
|
|
- } else if (this.nextStartTick > 0) {
|
|
+ }
|
|
+ // Leaf start - async search block
|
|
+ if (poll()) {
|
|
+ this.nextStartTick = reducedTickDelay(20);
|
|
+ return true;
|
|
+ }
|
|
+ // Leaf end - async search block
|
|
+ if (this.nextStartTick > 0) {
|
|
this.nextStartTick--;
|
|
return false;
|
|
} else if (this.findNearestBlock()) {
|
|
@@ -149,10 +156,18 @@ public class RemoveBlockGoal extends MoveToBlockGoal {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
ChunkAccess chunk = level.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4); // Paper - Prevent AI rules from loading chunks
|
|
return chunk != null
|
|
&& chunk.getBlockState(pos).is(this.blockToRemove)
|
|
&& chunk.getBlockState(pos.above()).isAir()
|
|
&& chunk.getBlockState(pos.above(2)).isAir();
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.RemoveBlock;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/TemptGoal.java b/net/minecraft/world/entity/ai/goal/TemptGoal.java
|
|
index f88f618d34fb343b31de3af1a875d6633703df71..37aa00347e9cf391e447cff775e4493b36e05beb 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/TemptGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/TemptGoal.java
|
|
@@ -36,12 +36,62 @@ public class TemptGoal extends Goal {
|
|
this.targetingConditions = TEMPT_TARGETING.copy().selector((entity, level) -> this.shouldFollow(entity));
|
|
}
|
|
|
|
+ // Leaf start - Async Tempt Finding
|
|
+ private boolean poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof Player t)) { return false; }
|
|
+ var serverLevel = getServerLevel(this.mob);
|
|
+ if (!t.isAlive() || !this.targetingConditions.range(this.mob.getAttributeValue(Attributes.TEMPT_RANGE)).test(serverLevel, this.mob, t)) {
|
|
+ return false;
|
|
+ }
|
|
+ this.player = t;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ private void getNearestPlayerAsync() {
|
|
+ final var mob = this.mob;
|
|
+ final var ctx = mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final var serverLevel = getServerLevel(mob);
|
|
+ final var conditions = this.targetingConditions
|
|
+ .range(mob.getAttributeValue(Attributes.TEMPT_RANGE))
|
|
+ .copy();
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob == null || mob.isRemoved() || !mob.isAlive() || mob.level() != serverLevel) {
|
|
+ return;
|
|
+ }
|
|
+ ctx.result = serverLevel.getNearestPlayer(conditions, mob);
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting player", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Tempt Finding
|
|
@Override
|
|
public boolean canUse() {
|
|
if (this.calmDown > 0) {
|
|
this.calmDown--;
|
|
return false;
|
|
} else {
|
|
+ // Leaf start - Async Tempt Finding
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ if (poll()) {
|
|
+ if (this.player != null) {
|
|
+ org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(this.mob, this.player, org.bukkit.event.entity.EntityTargetEvent.TargetReason.TEMPT);
|
|
+ if (event.isCancelled()) {
|
|
+ return false;
|
|
+ }
|
|
+ this.player = (event.getTarget() == null) ? null : ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle();
|
|
+ }
|
|
+ if (this.player != null) {
|
|
+ return true;
|
|
+ }
|
|
+ } else {
|
|
+ getNearestPlayerAsync();
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Async Tempt Finding
|
|
this.player = getServerLevel(this.mob)
|
|
.getNearestPlayer(this.targetingConditions.range(this.mob.getAttributeValue(Attributes.TEMPT_RANGE)), this.mob);
|
|
// CraftBukkit start
|
|
diff --git a/net/minecraft/world/entity/ai/goal/target/DefendVillageTargetGoal.java b/net/minecraft/world/entity/ai/goal/target/DefendVillageTargetGoal.java
|
|
index 4644f3f7af89623ca6218c0dd24bb6cd67db553b..921418da5f026edad4c78ba51127bb758c34bb9a 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/target/DefendVillageTargetGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/target/DefendVillageTargetGoal.java
|
|
@@ -16,7 +16,7 @@ public class DefendVillageTargetGoal extends TargetGoal {
|
|
private final IronGolem golem;
|
|
@Nullable
|
|
private LivingEntity potentialTarget;
|
|
- private final TargetingConditions attackTargeting = TargetingConditions.forCombat().range(64.0);
|
|
+ private static final TargetingConditions attackTargeting = TargetingConditions.forCombat().range(64.0); // Leaf - static
|
|
|
|
public DefendVillageTargetGoal(IronGolem golem) {
|
|
super(golem, false, true);
|
|
@@ -24,8 +24,63 @@ public class DefendVillageTargetGoal extends TargetGoal {
|
|
this.setFlags(EnumSet.of(Goal.Flag.TARGET));
|
|
}
|
|
|
|
+ // Leaf start - Async Target Finding
|
|
+ protected boolean poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof LivingEntity t)) { return false; }
|
|
+ ServerLevel serverLevel = getServerLevel(this.mob);
|
|
+ if (serverLevel == null || !t.isAlive() || !attackTargeting.test(serverLevel, golem, t)) {
|
|
+ return false;
|
|
+ }
|
|
+ if ((t instanceof Player player && (player.isSpectator() || player.isCreative()))) {
|
|
+ return false;
|
|
+ }
|
|
+ this.potentialTarget = t;
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ private void findTargetAsync() {
|
|
+ final IronGolem mob = this.golem;
|
|
+ final var ctx = mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ AABB bound = this.golem.getBoundingBox().inflate(10.0, 8.0, 10.0);
|
|
+ final ServerLevel serverLevel = getServerLevel(mob);
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob.level() != serverLevel || !mob.isAlive()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ List<Villager> nearbyEntities = serverLevel.getNearbyEntities(Villager.class, attackTargeting, mob, bound);
|
|
+ List<Player> nearbyPlayers = serverLevel.getNearbyPlayers(attackTargeting, mob, bound);
|
|
+
|
|
+ for (Villager villager : nearbyEntities) {
|
|
+ for (Player player : nearbyPlayers) {
|
|
+ int playerReputation = villager.getPlayerReputation(player);
|
|
+ if (playerReputation <= -100) {
|
|
+ ctx.result = player;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
+
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async target finding
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ this.findTargetAsync();
|
|
+ return false;
|
|
+ }
|
|
+ // Leaf end - Async target finding
|
|
AABB aabb = this.golem.getBoundingBox().inflate(10.0, 8.0, 10.0);
|
|
ServerLevel serverLevel = getServerLevel(this.golem);
|
|
List<? extends LivingEntity> nearbyEntities = serverLevel.getNearbyEntities(Villager.class, this.attackTargeting, this.golem, aabb);
|
|
@@ -42,6 +97,7 @@ public class DefendVillageTargetGoal extends TargetGoal {
|
|
}
|
|
}
|
|
|
|
+ // Leaf - Async target finding
|
|
return this.potentialTarget != null
|
|
&& (!(this.potentialTarget instanceof Player) || !this.potentialTarget.isSpectator() && !((Player)this.potentialTarget).isCreative());
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/target/HurtByTargetGoal.java b/net/minecraft/world/entity/ai/goal/target/HurtByTargetGoal.java
|
|
index 25fe78116ce01eeefe5c958423734195d27302eb..e19f2cb98c9669deb3a19114264668fbb29d3cc5 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/target/HurtByTargetGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/target/HurtByTargetGoal.java
|
|
@@ -73,6 +73,56 @@ public class HurtByTargetGoal extends TargetGoal {
|
|
protected void alertOthers() {
|
|
double followDistance = this.getFollowDistance();
|
|
AABB aabb = AABB.unitCubeFromLowerCorner(this.mob.position()).inflate(followDistance, 10.0, followDistance);
|
|
+
|
|
+ // Leaf start - async alert other
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.alertOther) {
|
|
+ final var self = this.mob;
|
|
+ final var ctx = self.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final var serverLevel = getServerLevel(self);
|
|
+ final var toIgnoreAlert = this.toIgnoreAlert;
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (self == null || self.level() != serverLevel) {
|
|
+ return;
|
|
+ }
|
|
+ var toAlert = new java.util.ArrayList<Mob>();
|
|
+ List<? extends Mob> entitiesOfClass = serverLevel
|
|
+ .getEntitiesOfClass(self.getClass(), aabb, EntitySelector.NO_SPECTATORS);
|
|
+ for (Mob mob : entitiesOfClass) {
|
|
+ if (self != mob
|
|
+ && mob.getTarget() == null
|
|
+ && (!(self instanceof TamableAnimal) || ((TamableAnimal) self).getOwner() == ((TamableAnimal) mob).getOwner())
|
|
+ && !mob.isAlliedTo(self.getLastHurtByMob())) {
|
|
+ if (toIgnoreAlert == null) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ boolean flag = false;
|
|
+
|
|
+ for (Class<?> clazz : toIgnoreAlert) {
|
|
+ if (mob.getClass() == clazz) {
|
|
+ flag = true;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (!flag) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ toAlert.add(mob);
|
|
+ }
|
|
+ }
|
|
+ ctx.result = toAlert;
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception alertOthers", e);
|
|
+ }
|
|
+ };
|
|
+ return;
|
|
+ }
|
|
+ // Leaf end - async alert other
|
|
+
|
|
List<? extends Mob> entitiesOfClass = this.mob
|
|
.level()
|
|
.getEntitiesOfClass((Class<? extends Mob>)this.mob.getClass(), aabb, EntitySelector.NO_SPECTATORS);
|
|
@@ -86,6 +136,7 @@ public class HurtByTargetGoal extends TargetGoal {
|
|
}
|
|
|
|
mob = (Mob)var5.next();
|
|
+ // Leaf - async alert other
|
|
if (this.mob != mob
|
|
&& mob.getTarget() == null
|
|
&& (!(this.mob instanceof TamableAnimal) || ((TamableAnimal)this.mob).getOwner() == ((TamableAnimal)mob).getOwner())
|
|
@@ -96,6 +147,7 @@ public class HurtByTargetGoal extends TargetGoal {
|
|
|
|
boolean flag = false;
|
|
|
|
+ // Leaf - async alert other
|
|
for (Class<?> clazz : this.toIgnoreAlert) {
|
|
if (mob.getClass() == clazz) {
|
|
flag = true;
|
|
@@ -113,6 +165,15 @@ public class HurtByTargetGoal extends TargetGoal {
|
|
}
|
|
}
|
|
|
|
+ // Leaf start - async alert other
|
|
+ public void poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof List toAlert)) { return; }
|
|
+ for (var livingEntity : toAlert) {
|
|
+ alertOther((Mob) livingEntity, this.mob.getLastHurtByMob());
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - async alert other
|
|
+
|
|
protected void alertOther(Mob mob, LivingEntity target) {
|
|
mob.setTarget(target, org.bukkit.event.entity.EntityTargetEvent.TargetReason.TARGET_ATTACKED_NEARBY_ENTITY, true); // CraftBukkit - reason
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/target/NearestAttackableTargetGoal.java b/net/minecraft/world/entity/ai/goal/target/NearestAttackableTargetGoal.java
|
|
index 41ee3cdc45ecc8376a2203ed588bb544ed377294..f07d0db481aecb8260c09eafef2c1cd582a8502c 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/target/NearestAttackableTargetGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/target/NearestAttackableTargetGoal.java
|
|
@@ -41,8 +41,53 @@ public class NearestAttackableTargetGoal<T extends LivingEntity> extends TargetG
|
|
this.targetConditions = TargetingConditions.forCombat().range(this.getFollowDistance()).selector(selector);
|
|
}
|
|
|
|
+ // Leaf start - Async Target Finding
|
|
+ protected boolean poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof LivingEntity t)) { return false; }
|
|
+ ServerLevel serverLevel = getServerLevel(this.mob);
|
|
+ if (serverLevel == null || !t.isAlive() || !this.getTargetConditions().test(serverLevel, this.mob, t)) {
|
|
+ return false;
|
|
+ }
|
|
+ this.target = t;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ private void findTargetAsync() {
|
|
+ final Mob mob = this.mob;
|
|
+ final var ctx = mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final double x = mob.getX();
|
|
+ final double y = mob.getEyeY();
|
|
+ final double z = mob.getZ();
|
|
+ final TargetingConditions targetConditions = this.getTargetConditions().copy();
|
|
+ final Class<T> targetType = this.targetType;
|
|
+ final AABB targetSearch = getTargetSearchArea(this.getFollowDistance());
|
|
+ final ServerLevel serverLevel = getServerLevel(mob);
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob.level() != serverLevel || mob.isRemoved() || !mob.isAlive()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (targetType != Player.class && targetType != ServerPlayer.class) {
|
|
+ ctx.result = serverLevel.getNearestEntity(mob.level().getEntitiesOfClass(targetType, targetSearch, entity -> entity != null && entity != mob && entity.isAlive()), targetConditions, mob, x,y,z);
|
|
+ } else {
|
|
+ ctx.result = serverLevel.getNearestPlayer(targetConditions, mob, x, y, z);
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception getting entities", e);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
+
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async target finding
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
+ // Leaf end - Async target finding
|
|
if (this.randomInterval > 0 && this.mob.getRandom().nextInt(this.randomInterval) != 0) {
|
|
return false;
|
|
} else {
|
|
@@ -57,6 +102,15 @@ public class NearestAttackableTargetGoal<T extends LivingEntity> extends TargetG
|
|
|
|
protected void findTarget() {
|
|
ServerLevel serverLevel = getServerLevel(this.mob);
|
|
+
|
|
+ // Leaf start - Async Target Finding
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ this.findTargetAsync();
|
|
+ this.target = null;
|
|
+ return;
|
|
+ }
|
|
+ // Leaf end - Async Target Finding
|
|
+
|
|
if (this.targetType != Player.class && this.targetType != ServerPlayer.class) {
|
|
this.target = serverLevel.getNearestEntity(
|
|
this.mob.level().getEntitiesOfClass(this.targetType, this.getTargetSearchArea(this.getFollowDistance()), entity -> true),
|
|
@@ -81,7 +135,7 @@ public class NearestAttackableTargetGoal<T extends LivingEntity> extends TargetG
|
|
this.target = target;
|
|
}
|
|
|
|
- private TargetingConditions getTargetConditions() {
|
|
+ protected TargetingConditions getTargetConditions() {
|
|
return this.targetConditions.range(this.getFollowDistance());
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/target/NearestHealableRaiderTargetGoal.java b/net/minecraft/world/entity/ai/goal/target/NearestHealableRaiderTargetGoal.java
|
|
index 4604a603c4ddd0a9242e859aaa5a511c2d4c4f84..7274dfb52ca4a08cdebcd04294cedc73460593e5 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/target/NearestHealableRaiderTargetGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/target/NearestHealableRaiderTargetGoal.java
|
|
@@ -23,7 +23,15 @@ public class NearestHealableRaiderTargetGoal<T extends LivingEntity> extends Nea
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
- if (this.cooldown > 0 || !this.mob.getRandom().nextBoolean()) {
|
|
+ // Leaf start - Async target finding
|
|
+ if (this.cooldown > 0) {
|
|
+ return false;
|
|
+ }
|
|
+ if (poll()) {
|
|
+ return ((Raider) this.mob).hasActiveRaid();
|
|
+ }
|
|
+ if (/*this.cooldown > 0 || */ !this.mob.getRandom().nextBoolean()) {
|
|
+ // Leaf end - Async target finding
|
|
return false;
|
|
} else if (!((Raider)this.mob).hasActiveRaid()) {
|
|
return false;
|
|
diff --git a/net/minecraft/world/entity/ai/goal/target/NonTameRandomTargetGoal.java b/net/minecraft/world/entity/ai/goal/target/NonTameRandomTargetGoal.java
|
|
index abf57494950f55bbd75f335f26736cb9e703c197..683722fbd07fcae9cdd72928ed25fd084202b57e 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/target/NonTameRandomTargetGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/target/NonTameRandomTargetGoal.java
|
|
@@ -20,6 +20,15 @@ public class NonTameRandomTargetGoal<T extends LivingEntity> extends NearestAtta
|
|
|
|
@Override
|
|
public boolean canContinueToUse() {
|
|
- return this.targetConditions != null ? this.targetConditions.test(getServerLevel(this.mob), this.mob, this.target) : super.canContinueToUse();
|
|
+ // Leaf start
|
|
+ if (this.target == null || !this.target.isAlive() || this.target.isRemoved()) {
|
|
+ return false;
|
|
+ }
|
|
+ var serverLevel = getServerLevel(this.mob);
|
|
+ if (serverLevel == null) {
|
|
+ return false;
|
|
+ }
|
|
+ return this.getTargetConditions().test(serverLevel, this.mob, this.target) && super.canContinueToUse();
|
|
+ // Leaf end
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/target/ResetUniversalAngerTargetGoal.java b/net/minecraft/world/entity/ai/goal/target/ResetUniversalAngerTargetGoal.java
|
|
index 61a7bb5f1760d47a13b6aafc123bcf3dff420860..93da18d921a1cf7d72f441d9415435ff9c417f1f 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/target/ResetUniversalAngerTargetGoal.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/target/ResetUniversalAngerTargetGoal.java
|
|
@@ -37,6 +37,34 @@ public class ResetUniversalAngerTargetGoal<T extends Mob & NeutralMob> extends G
|
|
this.lastHurtByPlayerTimestamp = this.mob.getLastHurtByMobTimestamp();
|
|
this.mob.forgetCurrentTargetAndRefreshUniversalAnger();
|
|
if (this.alertOthersOfSameType) {
|
|
+ // Leaf start - async alert other
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.alertOther) {
|
|
+ final var mob = this.mob;
|
|
+ final var ctx = mob.getGoalCtx();
|
|
+ if (!ctx.state) return;
|
|
+ final var serverLevel = getServerLevel(mob);
|
|
+ final double followRange = this.mob.getAttributeValue(Attributes.FOLLOW_RANGE);
|
|
+ final AABB aabb = AABB.unitCubeFromLowerCorner(this.mob.position()).inflate(followRange, 10.0, followRange);
|
|
+ ctx.wake = () -> {
|
|
+ try {
|
|
+ if (mob == null || serverLevel != mob.level() || !mob.isAlive()) {
|
|
+ return;
|
|
+ }
|
|
+ var entities = serverLevel.getEntitiesOfClass(mob.getClass(), aabb, EntitySelector.NO_SPECTATORS);
|
|
+ List<NeutralMob> toStop = new java.util.ArrayList<>(entities.size());
|
|
+ for (Mob entity : entities) {
|
|
+ if (entity != mob) {
|
|
+ toStop.add((NeutralMob) entity);
|
|
+ }
|
|
+ }
|
|
+ ctx.result = toStop;
|
|
+ } catch (Exception e) {
|
|
+ org.dreeam.leaf.async.ai.AsyncGoalExecutor.LOGGER.error("Exception alertOthers forgetCurrentTargetAndRefreshUniversalAnger", e);
|
|
+ }
|
|
+ };
|
|
+ return;
|
|
+ }
|
|
+ // Leaf end - async alert other
|
|
this.getNearbyMobsOfSameType()
|
|
.stream()
|
|
.filter(mob -> mob != this.mob)
|
|
@@ -47,7 +75,17 @@ public class ResetUniversalAngerTargetGoal<T extends Mob & NeutralMob> extends G
|
|
super.start();
|
|
}
|
|
|
|
+ // Leaf start - async alert other
|
|
+ public void poll() {
|
|
+ if (!(this.mob.getGoalCtx().result() instanceof List toStop)) { return; }
|
|
+ for (var neutralMob : toStop) {
|
|
+ ((NeutralMob)neutralMob).forgetCurrentTargetAndRefreshUniversalAnger();
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - async alert other
|
|
+
|
|
private List<? extends Mob> getNearbyMobsOfSameType() {
|
|
+ // Leaf - async alert other
|
|
double attributeValue = this.mob.getAttributeValue(Attributes.FOLLOW_RANGE);
|
|
AABB aabb = AABB.unitCubeFromLowerCorner(this.mob.position()).inflate(attributeValue, 10.0, attributeValue);
|
|
return this.mob.level().getEntitiesOfClass((Class<? extends Mob>)this.mob.getClass(), aabb, EntitySelector.NO_SPECTATORS);
|
|
diff --git a/net/minecraft/world/entity/ai/sensing/Sensing.java b/net/minecraft/world/entity/ai/sensing/Sensing.java
|
|
index 002d3c0d8b1107a275020d5c582c37e9a5c536ee..3f8c18f4040f4929df79ba85906330b150720cb0 100644
|
|
--- a/net/minecraft/world/entity/ai/sensing/Sensing.java
|
|
+++ b/net/minecraft/world/entity/ai/sensing/Sensing.java
|
|
@@ -32,9 +32,21 @@ public class Sensing {
|
|
// Gale end - Petal - reduce line of sight updates - expiring entity id lists
|
|
}
|
|
|
|
+ // Leaf start - async target finding
|
|
public void tick() {
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ synchronized (this) {
|
|
+ tick1();
|
|
+ }
|
|
+ } else {
|
|
+ tick1();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void tick1() {
|
|
+ // Leaf end - async target finding
|
|
if (this.expiring == null) { // Gale - Petal - reduce line of sight updates
|
|
- this.seen.clear();
|
|
+ this.seen.clear();
|
|
// Gale start - Petal - reduce line of sight updates
|
|
} else {
|
|
var expiringNow = this.expiring[this.nextToExpireIndex];
|
|
@@ -62,7 +74,19 @@ public class Sensing {
|
|
// Gale end - Petal - reduce line of sight updates
|
|
}
|
|
|
|
+ // Leaf start - async target finding
|
|
public boolean hasLineOfSight(Entity entity) {
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
|
|
+ synchronized (this) {
|
|
+ return hasLineOfSight1(entity);
|
|
+ }
|
|
+ } else {
|
|
+ return hasLineOfSight1(entity);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private boolean hasLineOfSight1(Entity entity) {
|
|
+ // Leaf end - async target finding
|
|
int id = entity.getId();
|
|
// Gale start - Petal - reduce line of sight cache lookups - merge sets
|
|
int cached = this.seen.get(id);
|
|
diff --git a/net/minecraft/world/entity/animal/Fox.java b/net/minecraft/world/entity/animal/Fox.java
|
|
index 90452f0945e761077608692877677f522d38bccd..9e380f5b4dcedb115f8893dd382f28ea05fab121 100644
|
|
--- a/net/minecraft/world/entity/animal/Fox.java
|
|
+++ b/net/minecraft/world/entity/animal/Fox.java
|
|
@@ -849,13 +849,18 @@ public class Fox extends Animal implements VariantHolder<Fox.Variant> {
|
|
return false;
|
|
} else {
|
|
ServerLevel serverLevel = getServerLevel(Fox.this.level());
|
|
+ // Leaf start
|
|
+ if (serverLevel == null) {
|
|
+ return false;
|
|
+ }
|
|
+ // Leaf end
|
|
|
|
for (UUID uuid : Fox.this.getTrustedUUIDs()) {
|
|
if (serverLevel.getEntity(uuid) instanceof LivingEntity livingEntity) {
|
|
this.trustedLastHurt = livingEntity;
|
|
this.trustedLastHurtBy = livingEntity.getLastHurtByMob();
|
|
int lastHurtByMobTimestamp = livingEntity.getLastHurtByMobTimestamp();
|
|
- return lastHurtByMobTimestamp != this.timestamp && this.canAttack(this.trustedLastHurtBy, this.targetConditions);
|
|
+ return lastHurtByMobTimestamp != this.timestamp && this.canAttack(this.trustedLastHurtBy, this.getTargetConditions()); // Leaf
|
|
}
|
|
}
|
|
|
|
@@ -1032,6 +1037,7 @@ public class Fox extends Animal implements VariantHolder<Fox.Variant> {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
BlockState blockState = level.getBlockState(pos);
|
|
return blockState.is(Blocks.SWEET_BERRY_BUSH) && blockState.getValue(SweetBerryBushBlock.AGE) >= 2 || CaveVines.hasGlowBerries(blockState);
|
|
}
|
|
@@ -1097,6 +1103,13 @@ public class Fox extends Animal implements VariantHolder<Fox.Variant> {
|
|
Fox.this.setSitting(false);
|
|
super.start();
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.FoxEat;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
|
|
class FoxFloatGoal extends FloatGoal {
|
|
diff --git a/net/minecraft/world/entity/animal/Panda.java b/net/minecraft/world/entity/animal/Panda.java
|
|
index 0a6a3060f3690ab2d8439d66e6fd6f0c5dc20688..d3466ebc9d0a57d0dcefa98d65fe42d8c827e6d3 100644
|
|
--- a/net/minecraft/world/entity/animal/Panda.java
|
|
+++ b/net/minecraft/world/entity/animal/Panda.java
|
|
@@ -991,31 +991,39 @@ public class Panda extends Animal {
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
+ // Leaf start - Async look finding
|
|
+ if (poll()) {
|
|
+ return true;
|
|
+ }
|
|
if (this.mob.getRandom().nextFloat() >= this.probability) {
|
|
return false;
|
|
- } else {
|
|
- if (this.lookAt == null) {
|
|
- ServerLevel serverLevel = getServerLevel(this.mob);
|
|
- if (this.lookAtType == Player.class) {
|
|
- this.lookAt = serverLevel.getNearestPlayer(this.lookAtContext, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ());
|
|
- } else {
|
|
- this.lookAt = serverLevel.getNearestEntity(
|
|
- this.mob
|
|
- .level()
|
|
- .getEntitiesOfClass(
|
|
- this.lookAtType, this.mob.getBoundingBox().inflate(this.lookDistance, 3.0, this.lookDistance), entity -> true
|
|
- ),
|
|
- this.lookAtContext,
|
|
- this.mob,
|
|
- this.mob.getX(),
|
|
- this.mob.getEyeY(),
|
|
- this.mob.getZ()
|
|
- );
|
|
- }
|
|
+ }
|
|
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
|
+ getLookAsync();
|
|
+ return false;
|
|
+ }
|
|
+ if (this.lookAt == null) {
|
|
+ ServerLevel serverLevel = getServerLevel(this.mob);
|
|
+ if (this.lookAtType == Player.class) {
|
|
+ this.lookAt = serverLevel.getNearestPlayer(this.lookAtContext, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ());
|
|
+ } else {
|
|
+ this.lookAt = serverLevel.getNearestEntity(
|
|
+ this.mob
|
|
+ .level()
|
|
+ .getEntitiesOfClass(
|
|
+ this.lookAtType, this.mob.getBoundingBox().inflate(this.lookDistance, 3.0, this.lookDistance), entity -> true
|
|
+ ),
|
|
+ this.lookAtContext,
|
|
+ this.mob,
|
|
+ this.mob.getX(),
|
|
+ this.mob.getEyeY(),
|
|
+ this.mob.getZ()
|
|
+ );
|
|
}
|
|
-
|
|
- return this.panda.canPerformAction() && this.lookAt != null;
|
|
}
|
|
+
|
|
+ return this.panda.canPerformAction() && this.lookAt != null;
|
|
+ // Leaf end - Async look finding
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/world/entity/animal/Rabbit.java b/net/minecraft/world/entity/animal/Rabbit.java
|
|
index da5b32a17283e540615373097acc511d928aeff5..a9cc92d2ae2b1548b27288c190a3f99799dcefbe 100644
|
|
--- a/net/minecraft/world/entity/animal/Rabbit.java
|
|
+++ b/net/minecraft/world/entity/animal/Rabbit.java
|
|
@@ -642,7 +642,13 @@ public class Rabbit extends Animal implements VariantHolder<Rabbit.Variant> {
|
|
this.wantsToRaid = this.rabbit.wantsMoreFood();
|
|
}
|
|
|
|
- return super.canUse();
|
|
+ // Leaf start
|
|
+ if (this.wantsToRaid && !this.canRaid) {
|
|
+ return super.canUse();
|
|
+ } else {
|
|
+ return false;
|
|
+ }
|
|
+ // Leaf end
|
|
}
|
|
|
|
@Override
|
|
@@ -684,6 +690,7 @@ public class Rabbit extends Animal implements VariantHolder<Rabbit.Variant> {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
BlockState blockState = level.getBlockState(pos);
|
|
if (blockState.is(Blocks.FARMLAND) && this.wantsToRaid && !this.canRaid) {
|
|
blockState = level.getBlockState(pos.above());
|
|
@@ -692,9 +699,17 @@ public class Rabbit extends Animal implements VariantHolder<Rabbit.Variant> {
|
|
return true;
|
|
}
|
|
}
|
|
+ // Leaf - Async search block
|
|
|
|
return false;
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.RaidGarden;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
|
|
public static enum Variant implements StringRepresentable {
|
|
diff --git a/net/minecraft/world/entity/animal/Turtle.java b/net/minecraft/world/entity/animal/Turtle.java
|
|
index 10477fea8fcd70bf0c1ba4b6e1113625be690e68..65bbfc7d0078465faa6f18ff2f611d813fea310a 100644
|
|
--- a/net/minecraft/world/entity/animal/Turtle.java
|
|
+++ b/net/minecraft/world/entity/animal/Turtle.java
|
|
@@ -527,8 +527,16 @@ public class Turtle extends Animal {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
return level.getBlockState(pos).is(Blocks.WATER);
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.TurtleToWater;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
|
|
static class TurtleLayEggGoal extends MoveToBlockGoal {
|
|
@@ -584,8 +592,16 @@ public class Turtle extends Animal {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
return level.isEmptyBlock(pos.above()) && TurtleEggBlock.isSand(level, pos);
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.TurtleLay;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
|
|
static class TurtleMoveControl extends org.purpurmc.purpur.controller.MoveControllerWASD { // Purpur - Ridables
|
|
diff --git a/net/minecraft/world/entity/animal/Wolf.java b/net/minecraft/world/entity/animal/Wolf.java
|
|
index 7cb292de6b27fa4ba3c5fce526a4e939c576789f..856bfeaa91a476c1008909ac35f76dfe0b792c9c 100644
|
|
--- a/net/minecraft/world/entity/animal/Wolf.java
|
|
+++ b/net/minecraft/world/entity/animal/Wolf.java
|
|
@@ -672,6 +672,7 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
|
|
|
|
@Override
|
|
public boolean isFood(ItemStack stack) {
|
|
+ // Leaf - Async target finding
|
|
return stack.is(ItemTags.WOLF_FOOD);
|
|
}
|
|
|
|
diff --git a/net/minecraft/world/entity/monster/Drowned.java b/net/minecraft/world/entity/monster/Drowned.java
|
|
index d44ed0d6a672a0b1eb0a8781e3e094096a2b753d..d1b13080e88f4b409f5393be7f2591d72af9aabb 100644
|
|
--- a/net/minecraft/world/entity/monster/Drowned.java
|
|
+++ b/net/minecraft/world/entity/monster/Drowned.java
|
|
@@ -393,6 +393,7 @@ public class Drowned extends Zombie implements RangedAttackMob {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
BlockPos blockPos = pos.above();
|
|
return level.isEmptyBlock(blockPos) && level.isEmptyBlock(blockPos.above()) && level.getBlockState(pos).entityCanStandOn(level, pos, this.drowned);
|
|
}
|
|
@@ -408,6 +409,13 @@ public class Drowned extends Zombie implements RangedAttackMob {
|
|
public void stop() {
|
|
super.stop();
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.Drowned;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
|
|
static class DrownedGoToWaterGoal extends Goal {
|
|
diff --git a/net/minecraft/world/entity/monster/Strider.java b/net/minecraft/world/entity/monster/Strider.java
|
|
index ae4ee948971e931e4fdc4ec2187f5182195c626c..7b878761eefc41fa735ef67c4a6dcbe92e9a2004 100644
|
|
--- a/net/minecraft/world/entity/monster/Strider.java
|
|
+++ b/net/minecraft/world/entity/monster/Strider.java
|
|
@@ -570,8 +570,16 @@ public class Strider extends Animal implements ItemSteerable, Saddleable {
|
|
|
|
@Override
|
|
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
|
+ // Leaf - Async search block
|
|
return level.getBlockState(pos).is(Blocks.LAVA) && level.getBlockState(pos.above()).isPathfindable(PathComputationType.LAND);
|
|
}
|
|
+
|
|
+ // Leaf start - Async search block
|
|
+ @Override
|
|
+ protected TypeToCheck typeToCheck() {
|
|
+ return TypeToCheck.Strider;
|
|
+ }
|
|
+ // Leaf end - Async search block
|
|
}
|
|
|
|
static class StriderPathNavigation extends GroundPathNavigation {
|
|
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
|
index ac7729d1caa80155697bfe0e8646e4eda5d1780e..d2851eb4c3e7eb2a1976075e2df0edb33b1c411d 100644
|
|
--- a/net/minecraft/world/level/Level.java
|
|
+++ b/net/minecraft/world/level/Level.java
|
|
@@ -1548,6 +1548,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
|
this.moonrise$midTickTasks();
|
|
}
|
|
// Leaf end - SparklyPaper - parallel world ticking (only run mid-tick at the end of each tick / fixes concurrency bugs related to executeMidTickTasks) - do not bother with condition work / make configurable
|
|
+ ((ServerLevel) this).leafMidTickTasks(); // Leaf - Async target finding
|
|
// Paper end - rewrite chunk system
|
|
}
|
|
}
|
|
@@ -1817,9 +1818,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
|
|
|
@Override
|
|
public List<Entity> getEntities(@Nullable Entity entity, AABB boundingBox, Predicate<? super Entity> predicate) {
|
|
- if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
|
|
- ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread((ServerLevel)this, boundingBox, "Cannot getEntities asynchronously"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
- List<Entity> list = Lists.newArrayList();
|
|
+ // Leaf start - Async target finding
|
|
+ // if (org.dreeam.leaf.config.modules.async.SparklyPaperParallelWorldTicking.enabled) // Leaf start - SparklyPaper - parallel world ticking mod (make configurable)
|
|
+ // ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread((ServerLevel)this, boundingBox, "Cannot getEntities asynchronously"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
+ // Leaf end - Async target finding
|
|
+
|
|
+ // List<Entity> list = Lists.newArrayList(); // Leaf - unused
|
|
|
|
// Paper start - rewrite chunk system
|
|
final List<Entity> ret = new java.util.ArrayList<>();
|