9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00
This commit is contained in:
Dreeam
2025-04-17 02:45:56 -04:00
parent 502701329c
commit dff5b11bd9
8 changed files with 147 additions and 226 deletions

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Async Block Finding
diff --git a/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java b/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..135506968893cd164c4d416ce4d356e9f0ed3977 100644
index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..007da9cb39ff76285c52ce0abdff60997acdff0f 100644
--- a/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
+++ b/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
@@ -20,6 +20,18 @@ public abstract class MoveToBlockGoal extends Goal {
@@ -31,70 +31,62 @@ index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..135506968893cd164c4d416ce4d356e9
super.stop();
this.blockPos = BlockPos.ZERO;
this.mob.movingTarget = null;
+ // Leaf start - Reset async state on goal stop
+ // Leaf start - Async Block Finding - Reset async state on goal stop
+ this.candidateBlocks.clear();
+ this.asyncSearchInProgress = false;
+ // Leaf end
+ // Leaf end - Async Block Finding - Reset async state on goal stop
}
// Paper end
@@ -53,23 +69,28 @@ public abstract class MoveToBlockGoal extends Goal {
@@ -53,23 +69,23 @@ public abstract class MoveToBlockGoal extends Goal {
}
protected int nextStartTick(PathfinderMob creature) {
- return reducedTickDelay(200 + creature.getRandom().nextInt(200));
+ // Use the static method from the Goal class directly
+ return Goal.reducedTickDelay(200 + creature.getRandom().nextInt(200));
+ return Goal.reducedTickDelay(200 + creature.getRandom().nextInt(200)); // Leaf - Async Block Finding - Use the static method from the Goal class directly
}
@Override
public boolean canContinueToUse() {
- return this.tryTicks >= -this.maxStayTicks && this.tryTicks <= 1200 && this.isValidTarget(this.mob.level(), this.blockPos);
+ return this.tryTicks >= -this.maxStayTicks && this.tryTicks <= 1200 && this.blockPos != BlockPos.ZERO && this.isValidTarget(this.mob.level(), this.blockPos);
+ return this.tryTicks >= -this.maxStayTicks && this.tryTicks <= 1200 && this.blockPos != BlockPos.ZERO && this.isValidTarget(this.mob.level(), this.blockPos); // Leaf - Async Block Finding
}
@Override
public void start() {
- this.moveMobToBlock();
+ if (this.blockPos != BlockPos.ZERO) {
+ this.moveMobToBlock();
+ }
+ if (this.blockPos != BlockPos.ZERO) this.moveMobToBlock(); // Leaf - Async Block Finding
this.tryTicks = 0;
this.maxStayTicks = this.mob.getRandom().nextInt(this.mob.getRandom().nextInt(1200) + 1200) + 1200;
}
protected void moveMobToBlock() {
- this.mob.getNavigation().moveTo(this.blockPos.getX() + 0.5, this.blockPos.getY() + 1, this.blockPos.getZ() + 0.5, this.speedModifier);
+ if (this.blockPos != BlockPos.ZERO) {
+ this.mob.getNavigation().moveTo(this.blockPos.getX() + 0.5, this.blockPos.getY() + 1, this.blockPos.getZ() + 0.5, this.speedModifier);
+ }
+ if (this.blockPos != BlockPos.ZERO) this.mob.getNavigation().moveTo(this.blockPos.getX() + 0.5, this.blockPos.getY() + 1, this.blockPos.getZ() + 0.5, this.speedModifier); // Leaf - Async Block Finding
}
public double acceptedDistance() {
@@ -77,7 +98,7 @@ public abstract class MoveToBlockGoal extends Goal {
@@ -77,7 +93,7 @@ public abstract class MoveToBlockGoal extends Goal {
}
protected BlockPos getMoveToTarget() {
- return this.blockPos.above();
+ return this.blockPos != BlockPos.ZERO ? this.blockPos.above() : BlockPos.ZERO;
+ return this.blockPos != BlockPos.ZERO ? this.blockPos.above() : BlockPos.ZERO; // Leaf - Async Block Finding
}
@Override
@@ -87,7 +108,13 @@ public abstract class MoveToBlockGoal extends Goal {
@@ -87,7 +103,10 @@ public abstract class MoveToBlockGoal extends Goal {
@Override
public void tick() {
+ if (this.blockPos == BlockPos.ZERO) {
+ return;
+ }
+
+ if (this.blockPos == BlockPos.ZERO) return; // Leaf - Async Block Finding
BlockPos moveToTarget = this.getMoveToTarget();
+ if (moveToTarget == BlockPos.ZERO) return;
+ if (moveToTarget == BlockPos.ZERO) return; // Leaf - Async Block Finding
+
if (!moveToTarget.closerToCenterThan(this.mob.position(), this.acceptedDistance())) {
this.reachedTarget = false;
this.tryTicks++;
@@ -109,20 +136,90 @@ public abstract class MoveToBlockGoal extends Goal {
@@ -109,20 +128,90 @@ public abstract class MoveToBlockGoal extends Goal {
}
protected boolean findNearestBlock() {
@@ -139,7 +131,6 @@ index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..135506968893cd164c4d416ce4d356e9
+ }
+
+ return false;
+ // Leaf end - Async Block Finding
+ }
+
+ private void generateCandidateBlocks(BlockPos center, int searchRange, int verticalRange, int verticalStart) {
@@ -168,10 +159,11 @@ index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..135506968893cd164c4d416ce4d356e9
+ }
+
+ protected boolean findNearestBlockSync() {
+ // Leaf end - Async Block Finding
int i = this.searchRange;
int i1 = this.verticalSearchRange;
- BlockPos blockPos = this.mob.blockPosition();
+ BlockPos blockPosOrigin = this.mob.blockPosition();
+ BlockPos blockPosOrigin = this.mob.blockPosition(); // Leaf - Async Block Finding
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (int i2 = this.verticalSearchStart; i2 <= i1; i2 = i2 > 0 ? -i2 : 1 - i2) {
@@ -179,19 +171,13 @@ index 3f080b15543bf8c5fa0774b62d7f12e13b82511a..135506968893cd164c4d416ce4d356e9
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);
+ mutableBlockPos.setWithOffset(blockPosOrigin, i4, i2 - 1, i5);
+ mutableBlockPos.setWithOffset(blockPosOrigin, i4, i2 - 1, i5); // Leaf - Async Block Finding
if (!this.mob.level().hasChunkAt(mutableBlockPos)) continue; // Gale - Airplane - block goal does not load chunks - if this block isn't loaded, continue
if (this.mob.isWithinRestriction(mutableBlockPos) && this.isValidTarget(this.mob.level(), mutableBlockPos)) {
- this.blockPos = mutableBlockPos;
- this.mob.movingTarget = mutableBlockPos == BlockPos.ZERO ? null : mutableBlockPos.immutable(); // Paper
+ this.blockPos = mutableBlockPos.immutable();
+ this.mob.movingTarget = this.blockPos == BlockPos.ZERO ? null : this.blockPos; // Paper
+ this.blockPos = mutableBlockPos.immutable(); // Leaf - Async Block Finding
+ this.mob.movingTarget = this.blockPos == BlockPos.ZERO ? null : this.blockPos; // Paper // Leaf - Async Block Finding
return true;
}
}
@@ -134,4 +231,5 @@ public abstract class MoveToBlockGoal extends Goal {
}
protected abstract boolean isValidTarget(LevelReader level, BlockPos pos);
+
}