mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
improve plugin compatibility
This commit is contained in:
@@ -1086,10 +1086,10 @@ index 6463c3c9b08d6058f2843c225b08a40fc30a960b..98c2b4a298ada4b02afa55f991791d86
|
||||
@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..9b8453ce2bc2cafca7c670d79b40434e7c93afca 100644
|
||||
index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..52e353ff7865cc187d83ada4e93dc955ead2a578 100644
|
||||
--- a/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
|
||||
+++ b/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
|
||||
@@ -41,8 +41,60 @@ public abstract class MoveToBlockGoal extends Goal {
|
||||
@@ -41,14 +41,67 @@ public abstract class MoveToBlockGoal extends Goal {
|
||||
this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.JUMP));
|
||||
}
|
||||
|
||||
@@ -1137,6 +1137,7 @@ index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..9b8453ce2bc2cafca7c670d79b40434e
|
||||
+ Strider,
|
||||
+ TurtleToWater,
|
||||
+ TurtleLay,
|
||||
+ Unknown,
|
||||
+ }
|
||||
+ // Leaf end - Async search block
|
||||
+
|
||||
@@ -1150,20 +1151,32 @@ index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..9b8453ce2bc2cafca7c670d79b40434e
|
||||
if (this.nextStartTick > 0) {
|
||||
this.nextStartTick--;
|
||||
return false;
|
||||
@@ -109,6 +161,12 @@ public abstract class MoveToBlockGoal extends Goal {
|
||||
} else {
|
||||
this.nextStartTick = this.nextStartTick(this.mob);
|
||||
- return this.findNearestBlock();
|
||||
+ return this.findNearestBlockAsync(); // Leaf - Async search block
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean findNearestBlock() {
|
||||
+ // Leaf start - Async search block
|
||||
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchBlock) {
|
||||
@@ -108,6 +161,17 @@ public abstract class MoveToBlockGoal extends Goal {
|
||||
return this.reachedTarget;
|
||||
}
|
||||
|
||||
+ // Leaf start - Async search block
|
||||
+ protected boolean findNearestBlockAsync() {
|
||||
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchBlock
|
||||
+ && this.typeToCheck() != TypeToCheck.Unknown) {
|
||||
+ getBlockAsync();
|
||||
+ return false;
|
||||
+ }
|
||||
+ // Leaf end - Async search block
|
||||
+ return findNearestBlock();
|
||||
+ }
|
||||
+ // Leaf end - Async search block
|
||||
+
|
||||
protected boolean findNearestBlock() {
|
||||
int i = this.searchRange;
|
||||
int i1 = this.verticalSearchRange;
|
||||
BlockPos blockPos = this.mob.blockPosition();
|
||||
@@ -133,5 +191,105 @@ public abstract class MoveToBlockGoal extends Goal {
|
||||
@@ -133,5 +197,108 @@ public abstract class MoveToBlockGoal extends Goal {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1206,7 +1219,9 @@ index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..9b8453ce2bc2cafca7c670d79b40434e
|
||||
protected abstract boolean isValidTarget(LevelReader level, BlockPos pos);
|
||||
+
|
||||
+ // Leaf start - Async search block
|
||||
+ protected abstract TypeToCheck typeToCheck();
|
||||
+ protected TypeToCheck typeToCheck() {
|
||||
+ return TypeToCheck.Unknown;
|
||||
+ }
|
||||
+
|
||||
+ private static boolean isValidTargetAsync(
|
||||
+ TypeToCheck type,
|
||||
@@ -1264,6 +1279,7 @@ index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..9b8453ce2bc2cafca7c670d79b40434e
|
||||
+ case TurtleLay -> {
|
||||
+ return level.isEmptyBlock(pos.above()) && net.minecraft.world.level.block.TurtleEggBlock.isSand(level, pos);
|
||||
+ }
|
||||
+ case Unknown -> throw new IllegalStateException();
|
||||
+ case null -> throw new IllegalStateException();
|
||||
+ }
|
||||
+ // Leaf end - Async search block
|
||||
@@ -1333,10 +1349,10 @@ index 3c274d917bca9de87abfb842f5f332e112a7a2d7..2491b84641443ecfb8afc3b179e1cf80
|
||||
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 c67a88c9c77ece7c85ffb169ac96da4f28291228..14d9b492ba431d534e0c6a567d0b7700b4c8a02d 100644
|
||||
index c67a88c9c77ece7c85ffb169ac96da4f28291228..93bf51c9299354be2a581618bd31d2c4cc7c1d30 100644
|
||||
--- a/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java
|
||||
+++ b/net/minecraft/world/entity/ai/goal/RemoveBlockGoal.java
|
||||
@@ -37,7 +37,14 @@ public class RemoveBlockGoal extends MoveToBlockGoal {
|
||||
@@ -37,10 +37,17 @@ 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;
|
||||
@@ -1351,7 +1367,11 @@ index c67a88c9c77ece7c85ffb169ac96da4f28291228..14d9b492ba431d534e0c6a567d0b7700
|
||||
+ if (this.nextStartTick > 0) {
|
||||
this.nextStartTick--;
|
||||
return false;
|
||||
} else if (this.findNearestBlock()) {
|
||||
- } else if (this.findNearestBlock()) {
|
||||
+ } else if (this.findNearestBlockAsync()) { // Leaf - async search block
|
||||
this.nextStartTick = reducedTickDelay(20);
|
||||
return true;
|
||||
} else {
|
||||
@@ -151,8 +158,15 @@ public class RemoveBlockGoal extends MoveToBlockGoal {
|
||||
protected boolean isValidTarget(LevelReader level, BlockPos pos) {
|
||||
ChunkAccess chunk = level.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4); // Paper - Prevent AI rules from loading chunks
|
||||
@@ -1604,10 +1624,10 @@ index 25fe78116ce01eeefe5c958423734195d27302eb..e306c1cfc44878ea130d8046b31cf617
|
||||
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 85eae0a14f7a417dfd8c911079d05354a98e5834..f59d5c9be0eb10f5b5192442e1850900d71a31e9 100644
|
||||
index 85eae0a14f7a417dfd8c911079d05354a98e5834..745ef9ea16171d8dad3082878f8883031bd79a84 100644
|
||||
--- a/net/minecraft/world/entity/ai/goal/target/NearestAttackableTargetGoal.java
|
||||
+++ b/net/minecraft/world/entity/ai/goal/target/NearestAttackableTargetGoal.java
|
||||
@@ -41,8 +41,43 @@ public class NearestAttackableTargetGoal<T extends LivingEntity> extends TargetG
|
||||
@@ -41,12 +41,52 @@ public class NearestAttackableTargetGoal<T extends LivingEntity> extends TargetG
|
||||
this.targetConditions = TargetingConditions.forCombat().range(this.getFollowDistance()).selector(selector);
|
||||
}
|
||||
|
||||
@@ -1620,7 +1640,12 @@ index 85eae0a14f7a417dfd8c911079d05354a98e5834..f59d5c9be0eb10f5b5192442e1850900
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ private void findTargetAsync() {
|
||||
+ protected void findTargetAsync() {
|
||||
+ if (!org.dreeam.leaf.config.modules.async.AsyncTargetFinding.searchEntity) {
|
||||
+ this.findTarget();
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ final Mob mob = this.mob;
|
||||
+ final var ctx = mob.getGoalCtx();
|
||||
+ if (!ctx.state) return;
|
||||
@@ -1651,27 +1676,16 @@ index 85eae0a14f7a417dfd8c911079d05354a98e5834..f59d5c9be0eb10f5b5192442e1850900
|
||||
if (this.randomInterval > 0 && this.mob.getRandom().nextInt(this.randomInterval) != 0) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -57,6 +92,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),
|
||||
- this.findTarget();
|
||||
+ this.findTargetAsync(); // Leaf - Async target finding
|
||||
return this.target != null;
|
||||
}
|
||||
}
|
||||
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
|
||||
index 4604a603c4ddd0a9242e859aaa5a511c2d4c4f84..84c7b89e7c894c0f544cf0ffcf9dff3f6a5919cc 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
|
||||
@@ -23,12 +23,20 @@ public class NearestHealableRaiderTargetGoal<T extends LivingEntity> extends Nea
|
||||
|
||||
@Override
|
||||
public boolean canUse() {
|
||||
@@ -1688,6 +1702,12 @@ index 4604a603c4ddd0a9242e859aaa5a511c2d4c4f84..7274dfb52ca4a08cdebcd04294cedc73
|
||||
return false;
|
||||
} else if (!((Raider)this.mob).hasActiveRaid()) {
|
||||
return false;
|
||||
} else {
|
||||
- this.findTarget();
|
||||
+ this.findTargetAsync(); // Leaf - Async target finding
|
||||
return this.target != null;
|
||||
}
|
||||
}
|
||||
diff --git a/net/minecraft/world/entity/ai/goal/target/NonTameRandomTargetGoal.java b/net/minecraft/world/entity/ai/goal/target/NonTameRandomTargetGoal.java
|
||||
index abf57494950f55bbd75f335f26736cb9e703c197..efd2418f56c36e7850edde483a2a4906dd622441 100644
|
||||
--- a/net/minecraft/world/entity/ai/goal/target/NonTameRandomTargetGoal.java
|
||||
|
||||
Reference in New Issue
Block a user