修复了部分情况下伐木任务寻路异常的问题

修复了伐木任务可能存在的不能完整砍伐的问题
修复了指南针的异常,改用床用来寻找玩家出生点
This commit is contained in:
xypp
2025-06-04 02:07:47 +08:00
parent 4d774a875f
commit 135f495849
9 changed files with 61 additions and 10 deletions

View File

@@ -165,10 +165,10 @@ dependencies {
// http://www.gradle.org/docs/current/userguide/dependency_management.html
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
compileOnly fg.deobf("curse.maven:touhou-little-maid-355044:6440955")
compileOnly fg.deobf("curse.maven:touhou-little-maid-355044:6596061")
compileOnly fg.deobf("curse.maven:playerrevive-266890:6048921")
compileOnly fg.deobf("curse.maven:creativecore-257814:6383884")
runtimeOnly fg.deobf("curse.maven:touhou-little-maid-355044:6440955")
runtimeOnly fg.deobf("curse.maven:touhou-little-maid-355044:6596061")
runtimeOnly fg.deobf("curse.maven:maid-storage-manager-1210244:6455832")
runtimeOnly fg.deobf("curse.maven:playerrevive-266890:6048921")
runtimeOnly fg.deobf("curse.maven:creativecore-257814:6383884")

View File

@@ -38,7 +38,7 @@ mod_name=maid useful task
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.3.3
mod_version=1.3.4
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@@ -45,9 +45,11 @@ public class BlockUpScheduleBehavior extends Behavior<EntityMaid> {
if (context.getStatus() == BlockUpContext.STATUS.DOWN) {
MemoryUtil.setTarget(maid, context.getTargetPos(), 0.5f);
MemoryUtil.setCurrent(maid, CurrentWork.BLOCKUP_DOWN);
} else {
} else if (maid.canPathReach(context.getStartPos())) {
MemoryUtil.setTarget(maid, context.getStartPos(), 0.5f);
MemoryUtil.setCurrent(maid, CurrentWork.BLOCKUP_UP);
} else {
context.clearStartTarget();
}
} else if (!context.isOnLine(maid.blockPosition()) || context.getStartPos().equals(context.getTargetPos())) {
context.clearStartTarget();

View File

@@ -10,6 +10,7 @@ import studio.fantasyit.maid_useful_task.memory.CurrentWork;
import studio.fantasyit.maid_useful_task.task.IMaidBlockDestroyTask;
import studio.fantasyit.maid_useful_task.util.Conditions;
import studio.fantasyit.maid_useful_task.util.MemoryUtil;
import studio.fantasyit.maid_useful_task.util.PosUtils;
import java.util.List;
@@ -57,6 +58,7 @@ public class DestoryBlockMoveBehavior extends MaidCenterMoveToBlockTask {
for (int dy = 0; dy < task.reachDistance(); dy = dy <= 0 ? 1 - dy : -dy) {
for (int dz = 0; dz < task.reachDistance(); dz = dz <= 0 ? 1 - dz : -dz) {
BlockPos pos = mb.offset(dx, dy, dz);
if (!PosUtils.isSafePos(serverLevel, pos)) continue;
if (!Conditions.isGlobalValidTarget(entityMaid, pos, targetPos)) continue;
if (pos.distSqr(targetPos) > task.reachDistance() * task.reachDistance()) continue;
if (entityMaid.isWithinRestriction(pos) && pathfindingBFS.canPathReach(pos)) {
@@ -78,7 +80,7 @@ public class DestoryBlockMoveBehavior extends MaidCenterMoveToBlockTask {
@Override
protected @NotNull MaidPathFindingBFS getOrCreateArrivalMap(@NotNull ServerLevel worldIn, @NotNull EntityMaid maid) {
if (this.pathfindingBFS == null)
if(maid.hasRestriction())
if (maid.hasRestriction())
this.pathfindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, 14, (int) maid.getRestrictRadius());
else
this.pathfindingBFS = new MaidPathFindingBFS(maid.getNavigation().getNodeEvaluator(), worldIn, maid, 14);

View File

@@ -62,8 +62,9 @@ public interface IMaidBlockDestroyTask {
for (int dz : dv) {
if (dx == 0 && dy == 0 && dz == 0) continue;
BlockPos target = pos.offset(dx, dy, dz);
if (Math.abs(target.getX() - standPos.getX()) > maxDXZ || Math.abs(target.getZ() - standPos.getZ()) > maxDXZ)
continue;
// if (Math.abs(target.getX() - standPos.getX()) > maxDXZ || Math.abs(target.getZ() - standPos.getZ()) > maxDXZ)
// continue;
//上代码不明所以,删除待查
if (target.distSqr(standPos) > reachDistance() * reachDistance()) continue;
if (marked.contains(target)) continue;
if (!shouldDestroyBlock(maid, target)) continue;

View File

@@ -51,6 +51,7 @@ public interface IMaidBlockUpTask {
while (!level.getBlockState(ground).canBeReplaced()) ground.move(0, 1, 0);
if (notAvailable.isVis(ground)) continue;
//地面基本判断
if (!PosUtils.isSafePos(level, ground)) continue;
if (!PosUtils.isFourSideAir(level, ground.immutable())) continue;
if (!pathFindingBFS.canPathReach(ground)) continue;
boolean valid = true;

View File

@@ -4,14 +4,18 @@ import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.mojang.datafixers.util.Pair;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.StructureTags;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.behavior.BehaviorControl;
import net.minecraft.world.item.CompassItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.MapItem;
@@ -83,11 +87,36 @@ public class MaidLocateTask implements IMaidTask, IMaidFindTargetTask {
}
}
} else if (maid.getMainHandItem().is(Items.COMPASS)) {
target = MemoryUtil.getCommonBlockCache(maid);
if (target == null) {
GlobalPos globalPos;
if (CompassItem.isLodestoneCompass(itemStack)) {
globalPos = CompassItem.getLodestonePosition(itemStack.getOrCreateTag());
} else {
globalPos = CompassItem.getSpawnPosition(level);
}
if (globalPos != null && level.dimension().equals(globalPos.dimension())) {
MemoryUtil.setCommonBlockCache(maid, globalPos.pos());
target = globalPos.pos();
}
}
} else if (maid.getMainHandItem().is(ItemTags.BEDS)) {
target = MemoryUtil.getCommonBlockCache(maid);
if (target == null) {
LivingEntity owner = maid.getOwner();
if (owner != null) {
target = owner.getSleepingPos().orElse(maid.level().getSharedSpawnPos());
if (owner instanceof ServerPlayer player) {
if (player.getRespawnDimension().equals(level.dimension())) {
target = player.getRespawnPosition();
if (target == null) {
GlobalPos globalRespawn = CompassItem.getSpawnPosition(level);
if (globalRespawn != null && level.dimension().equals(globalRespawn.dimension())) {
target = globalRespawn.pos();
}
}
}
if (target == null) {
MemoryUtil.setCommonBlockCache(maid, target);
}
}
}
} else if (maid.getMainHandItem().is(Items.FILLED_MAP)) {
@@ -130,3 +159,4 @@ public class MaidLocateTask implements IMaidTask, IMaidFindTargetTask {
MemoryUtil.clearCommonBlockCache(maid);
}
}

View File

@@ -14,7 +14,7 @@ import java.util.Optional;
public class Conditions {
public static boolean hasReachedValidTargetOrReset(EntityMaid maid) {
return hasReachedValidTargetOrReset(maid, 2);
return hasReachedValidTargetOrReset(maid, 2.5f);
}
public static boolean hasReachedValidTargetOrReset(EntityMaid maid, float closeEnough) {

View File

@@ -2,6 +2,8 @@ package studio.fantasyit.maid_useful_task.util;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.shapes.CollisionContext;
public class PosUtils {
public static boolean isFourSideAir(BlockGetter level, BlockPos pos) {
@@ -11,4 +13,17 @@ public class PosUtils {
level.getBlockState(pos.east()).isAir() &&
level.getBlockState(pos.west()).isAir();
}
static protected boolean isEmptyBlockPos(Level level, BlockPos pos) {
return level.getBlockState(pos).isAir() || level.getBlockState(pos).getCollisionShape(
level,
pos,
CollisionContext.empty()
).isEmpty();
}
static public boolean isSafePos(Level level, BlockPos pos) {
return isEmptyBlockPos(level, pos)
&& isEmptyBlockPos(level, pos.above())
&& !isEmptyBlockPos(level, pos.below());
}
}