From 702fa18a5414e3a135801948b6eed72d4092fd9f Mon Sep 17 00:00:00 2001 From: tartaric_acid Date: Mon, 8 Jan 2024 21:46:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=83=A8=E5=88=86=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/ai/brain/task/MaidBedTask.java | 6 +++- .../ai/brain/task/MaidCollectHoneyTask.java | 6 +++- .../ai/brain/task/MaidFindGomokuTask.java | 36 ------------------- .../entity/ai/brain/task/MaidGomokuTask.java | 6 +++- .../entity/ai/brain/task/MaidJoyTask.java | 6 +++- 5 files changed, 20 insertions(+), 40 deletions(-) delete mode 100644 src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidFindGomokuTask.java diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidBedTask.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidBedTask.java index c73e0866d..7fd295d68 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidBedTask.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidBedTask.java @@ -35,7 +35,7 @@ public MaidBedTask(float movementSpeed, int closeEnoughDist) { @Override protected boolean checkExtraStartConditions(ServerLevel worldIn, EntityMaid maid) { - if (super.checkExtraStartConditions(worldIn, maid) && maid.getVehicle() == null && !maid.isInSittingPose()) { + if (super.checkExtraStartConditions(worldIn, maid) && this.maidStateConditions(maid)) { BlockPos bedPos = findBed(worldIn, maid); if (bedPos != null && maid.isWithinRestriction(bedPos)) { if (bedPos.distToCenterSqr(maid.position()) < this.closeEnoughDist) { @@ -74,4 +74,8 @@ private BlockPos findBed(ServerLevel world, EntityMaid maid) { return poiManager.getInRange(type -> type.get().equals(InitPoi.MAID_BED.get()), blockPos, range, PoiManager.Occupancy.ANY) .map(PoiRecord::getPos).min(Comparator.comparingDouble(pos -> pos.distSqr(blockPos))).orElse(null); } + + private boolean maidStateConditions(EntityMaid maid) { + return !maid.isInSittingPose() && !maid.isSleeping() && !maid.isLeashed() && !maid.isPassenger(); + } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidCollectHoneyTask.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidCollectHoneyTask.java index 280a8c23b..1ad3848d0 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidCollectHoneyTask.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidCollectHoneyTask.java @@ -45,7 +45,7 @@ public MaidCollectHoneyTask(float speed, int closeEnoughDist) { @Override protected boolean checkExtraStartConditions(ServerLevel worldIn, EntityMaid maid) { - if (super.checkExtraStartConditions(worldIn, maid)) { + if (super.checkExtraStartConditions(worldIn, maid) && this.maidStateConditions(maid)) { BlockPos beehivePos = findBeehive(worldIn, maid); if (beehivePos != null && maid.isWithinRestriction(beehivePos)) { if (beehivePos.distToCenterSqr(maid.position()) < this.closeEnoughDist) { @@ -135,4 +135,8 @@ private boolean canCollectHoney(ServerLevel world, BlockPos hivePos) { public void resetHoneyLevel(Level level, BlockState state, BlockPos pos) { level.setBlock(pos, state.setValue(BeehiveBlock.HONEY_LEVEL, 0), Block.UPDATE_ALL); } + + private boolean maidStateConditions(EntityMaid maid) { + return !maid.isInSittingPose() && !maid.isSleeping() && !maid.isLeashed() && !maid.isPassenger(); + } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidFindGomokuTask.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidFindGomokuTask.java deleted file mode 100644 index de49ef5ed..000000000 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidFindGomokuTask.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task; - -import com.github.tartaricacid.touhoulittlemaid.block.BlockJoy; -import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid; -import com.github.tartaricacid.touhoulittlemaid.tileentity.TileEntityGomoku; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; - -public class MaidFindGomokuTask extends MaidMoveToBlockTask { - public MaidFindGomokuTask(float movementSpeed) { - super(movementSpeed); - } - - @Override - protected boolean shouldMoveTo(ServerLevel worldIn, EntityMaid entityIn, BlockPos pos) { - BlockState blockstate = worldIn.getBlockState(pos); - return blockstate.getBlock() instanceof BlockJoy && !this.isOccupied(worldIn, pos); - } - - @Override - protected void start(ServerLevel worldIn, EntityMaid maid, long gameTimeIn) { - if (maid.getVehicle() == null && !maid.isInSittingPose()) { - this.searchForDestination(worldIn, maid); - } - } - - private boolean isOccupied(ServerLevel worldIn, BlockPos pos) { - BlockEntity te = worldIn.getBlockEntity(pos); - if (te instanceof TileEntityGomoku gomoku) { - return worldIn.getEntity(gomoku.getSitId()) != null; - } - return true; - } -} diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidGomokuTask.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidGomokuTask.java index 0c441acea..5151bc309 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidGomokuTask.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidGomokuTask.java @@ -34,7 +34,7 @@ public MaidGomokuTask(float movementSpeed, int closeEnoughDist) { @Override protected boolean checkExtraStartConditions(ServerLevel worldIn, EntityMaid maid) { - if (super.checkExtraStartConditions(worldIn, maid) && maid.getVehicle() == null && !maid.isInSittingPose()) { + if (super.checkExtraStartConditions(worldIn, maid) && this.maidStateConditions(maid)) { BlockPos gomokuPos = findGomoku(worldIn, maid); if (gomokuPos != null && maid.isWithinRestriction(gomokuPos)) { if (gomokuPos.distToCenterSqr(maid.position()) < this.closeEnoughDist) { @@ -81,4 +81,8 @@ private boolean isOccupied(ServerLevel worldIn, BlockPos pos) { } return true; } + + private boolean maidStateConditions(EntityMaid maid) { + return !maid.isInSittingPose() && !maid.isSleeping() && !maid.isLeashed() && !maid.isPassenger(); + } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidJoyTask.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidJoyTask.java index 34bf3e36b..1a290362d 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidJoyTask.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/brain/task/MaidJoyTask.java @@ -34,7 +34,7 @@ public MaidJoyTask(float movementSpeed, int closeEnoughDist) { @Override protected boolean checkExtraStartConditions(ServerLevel worldIn, EntityMaid maid) { - if (super.checkExtraStartConditions(worldIn, maid) && maid.getVehicle() == null && !maid.isInSittingPose()) { + if (super.checkExtraStartConditions(worldIn, maid) && this.maidStateConditions(maid)) { BlockPos joyPos = findJoy(worldIn, maid); if (joyPos != null && maid.isWithinRestriction(joyPos)) { if (joyPos.distToCenterSqr(maid.position()) < this.closeEnoughDist) { @@ -81,4 +81,8 @@ private boolean isOccupied(ServerLevel worldIn, BlockPos pos) { } return true; } + + private boolean maidStateConditions(EntityMaid maid) { + return !maid.isInSittingPose() && !maid.isSleeping() && !maid.isLeashed() && !maid.isPassenger(); + } }