diff --git a/src/main/java/com/minecolonies/api/colony/buildings/IBuilding.java b/src/main/java/com/minecolonies/api/colony/buildings/IBuilding.java index 6d43ec265de..24f59884f30 100755 --- a/src/main/java/com/minecolonies/api/colony/buildings/IBuilding.java +++ b/src/main/java/com/minecolonies/api/colony/buildings/IBuilding.java @@ -516,10 +516,4 @@ default void writeToItemStack(final ItemStack stack) getColony().writeToItemStack(stack); new BuildingId(getID()).writeToItemStack(stack); } - - /** - * Get the standing position for a building. - * @return the standing pos. - */ - BlockPos getStandingPosition(); } diff --git a/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java b/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java index 784a91b9988..bb0e2792208 100755 --- a/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java +++ b/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java @@ -14,7 +14,6 @@ import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateStateMachine; import com.minecolonies.api.entity.citizen.citizenhandlers.*; import com.minecolonies.api.entity.other.MinecoloniesMinecart; -import com.minecolonies.api.entity.pathfinding.proxy.IWalkToProxy; import com.minecolonies.api.entity.pathfinding.registry.IPathNavigateRegistry; import com.minecolonies.api.inventory.InventoryCitizen; import com.minecolonies.api.sounds.EventType; @@ -560,15 +559,6 @@ public boolean checkCanDropLoot() */ public abstract ILocation getLocation(); - /** - * Checks if a worker is at his working site. If he isn't, sets it's path to the location - * - * @param site the place where he should walk to - * @param range Range to check in - * @return True if worker is at site, otherwise false. - */ - public abstract boolean isWorkerAtSiteWithMove(@NotNull BlockPos site, int range); - /** * Getter for the citizendata. Tries to get it from the colony is the data is null. * @@ -599,13 +589,6 @@ public boolean checkCanDropLoot() */ public abstract void playMoveAwaySound(); - /** - * Get the path proxy of the citizen. - * - * @return the proxy. - */ - public abstract IWalkToProxy getProxy(); - /** * Decrease the saturation of the citizen for 1 action. */ diff --git a/src/main/java/com/minecolonies/api/util/BlockPosUtil.java b/src/main/java/com/minecolonies/api/util/BlockPosUtil.java index d18c6c8e5f6..ad77571ca2f 100755 --- a/src/main/java/com/minecolonies/api/util/BlockPosUtil.java +++ b/src/main/java/com/minecolonies/api/util/BlockPosUtil.java @@ -1,7 +1,6 @@ package com.minecolonies.api.util; import com.ldtteam.structurize.util.BlockUtils; -import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.api.util.constant.ColonyConstants; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -14,7 +13,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.Mob; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -671,31 +669,6 @@ public static boolean setBlock(@NotNull final Level worldIn, @NotNull final Bloc return worldIn.setBlock(coords, state, flag); } - /** - * @param living A living entity. - * @param destination chunk coordinates to check moving to. - * @return True when XYZ is found, an set moving to, otherwise false. - */ - public static boolean tryMoveBaseCitizenEntityToXYZ(@NotNull final AbstractEntityCitizen living, @NotNull final BlockPos destination) - { - if (!(living instanceof LivingEntity)) - { - return false; - } - - return EntityUtils.tryMoveLivingToXYZ(living, destination.getX(), destination.getY(), destination.getZ()); - } - - /** - * @param living A living entity. - * @param destination chunk coordinates to check moving to. - * @return True when XYZ is found, an set moving to, otherwise false. - */ - public static boolean tryMoveLivingToXYZ(@NotNull final Mob living, @NotNull final BlockPos destination) - { - return EntityUtils.tryMoveLivingToXYZ(living, destination.getX(), destination.getY(), destination.getZ()); - } - /** * Create a method for using a {@link BlockPos}. * diff --git a/src/main/java/com/minecolonies/api/util/EntityUtils.java b/src/main/java/com/minecolonies/api/util/EntityUtils.java index 0664563bba7..2f555ed169e 100755 --- a/src/main/java/com/minecolonies/api/util/EntityUtils.java +++ b/src/main/java/com/minecolonies/api/util/EntityUtils.java @@ -1,11 +1,11 @@ package com.minecolonies.api.util; import com.ldtteam.structurize.util.BlockUtils; -import com.minecolonies.api.crafting.ItemStorage; -import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; +import com.minecolonies.api.entity.other.AbstractFastMinecoloniesEntity; import com.minecolonies.api.items.ModTags; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.SurfaceType; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.tags.BlockTags; @@ -17,7 +17,6 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; import net.neoforged.neoforge.common.util.FakePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -216,6 +215,7 @@ private static boolean checkValidSpawn(@NotNull final BlockGetter world, final B || SurfaceType.getSurfaceType(world, world.getBlockState(pos.below(2)), pos.below(2)) == SurfaceType.WALKABLE; } + // TODO: Move out movement stuff /** * Sets the movement of the entity to specific point. Returns true if direction is set, otherwise false. @@ -239,27 +239,15 @@ public static boolean tryMoveLivingToXYZ(@NotNull final Mob living, final int x, * @param y y-coordinate * @param z z-coordinate * @param speedFactor Speedfactor to modify base speed with - * @return True if the path is set to destination, otherwise false + * @return true if arrived */ public static boolean tryMoveLivingToXYZ(@NotNull final Mob living, final int x, final int y, final int z, final double speedFactor) { - return living.getNavigation().moveTo(x, y, z, speedFactor); - } - - /** - * {@link #isLivingAtSiteWithMove(LivingEntity, int, int, int)} - * - * @param entity entity to check - * @param x X-coordinate - * @param y Y-coordinate - * @param z Z-coordinate - * @return True if entity is at site, otherwise false - */ - public static boolean isLivingAtSiteWithMove(@NotNull final LivingEntity entity, final int x, final int y, final int z) - { - //Default range of 3 works better - //Range of 2 get some entitys stuck - return isLivingAtSiteWithMove(entity, x, y, z, DEFAULT_MOVE_RANGE); + if (living instanceof AbstractFastMinecoloniesEntity entity) + { + return EntityNavigationUtils.walkToPos(entity, new BlockPos(x, y, z), 4, true, speedFactor); + } + return true; } /** @@ -300,34 +288,6 @@ public static boolean isLivingAtSiteWithMove(@NotNull final LivingEntity entity, return EntityUtils.isLivingAtSite(entity, x, y, z, range); } - /** - * Checks if a certain entity is in the world at a certain position already. - * - * @param entity the entity. - * @param world the world. - * @param placer the entity to get the itemstacks from to check. - * @return true if there. - */ - public static boolean isEntityAtPosition(final Entity entity, final Level world, final Entity placer) - { - final List existingReq = ItemStackUtils.getListOfStackForEntity(entity, placer); - final BlockPos pos = BlockPos.containing(entity.getX(), entity.getY(), entity.getZ()); - return world.getEntitiesOfClass(Entity.class, AABB.encapsulatingFullBlocks(pos.offset(1, 1, 1), pos.offset(-1, -1, -1))) - .stream() - .anyMatch(ent -> ent.getX() == entity.getX() && ent.getY() == entity.getY() && ent.getZ() == entity.getZ() && ItemStackUtils.getListOfStackForEntity(entity, placer) - .equals(existingReq)); - } - - public static boolean isEntityAtPosition(final Entity entity, final Level world, final AbstractEntityCitizen entityCitizen) - { - if (entity != null) - { - return EntityUtils.isEntityAtPosition(entity, world, (Entity) entityCitizen); - } - - return false; - } - /** * Returns whether or not the entity is within a specific range of his working site. * diff --git a/src/main/java/com/minecolonies/api/util/ItemStackUtils.java b/src/main/java/com/minecolonies/api/util/ItemStackUtils.java index 33044b80816..dfeec8475df 100755 --- a/src/main/java/com/minecolonies/api/util/ItemStackUtils.java +++ b/src/main/java/com/minecolonies/api/util/ItemStackUtils.java @@ -1,6 +1,5 @@ package com.minecolonies.api.util; -import com.google.common.collect.Lists; import com.google.gson.JsonParser; import com.minecolonies.api.advancements.AdvancementTriggers; import com.minecolonies.api.colony.ICitizenData; @@ -33,13 +32,11 @@ import net.minecraft.tags.ItemTags; import net.minecraft.tags.TagKey; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.decoration.ArmorStand; import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.world.entity.player.Player; import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.*; -import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.Level; @@ -130,80 +127,6 @@ private ItemStackUtils() */ } - /** - * Get the entity of an entityInfo object. - * - * @param entityData the input. - * @param world the world. - * @return the output object or null. - */ - @Nullable - public static Entity getEntityFromEntityInfoOrNull(final CompoundTag entityData, final Level world) - { - try - { - final Optional> type = EntityType.by(entityData); - if (type.isPresent()) - { - final Entity entity = type.get().create(world); - if (entity != null) - { - entity.load(entityData); - return entity; - } - } - } - catch (final RuntimeException e) - { - Log.getLogger().info("Couldn't restore entitiy", e); - return null; - } - return null; - } - - /** - * Adds entities to the builder building if he needs it. - * - * @param entityData the entity info object. - * @param world the world. - * @param placer the entity placer. - * @return a list of stacks. - */ - public static List getListOfStackForEntityInfo(final CompoundTag entityData, final Level world, final Entity placer) - { - if (entityData != null) - { - final Entity entity = getEntityFromEntityInfoOrNull(entityData, world); - if (entity != null) - { - if (EntityUtils.isEntityAtPosition(entity, world, placer)) - { - return Collections.emptyList(); - } - return getListOfStackForEntity(entity, placer); - } - } - return Collections.emptyList(); - } - - /** - * Adds entities to the builder building if he needs it. - * - * @param entityData the entity info object. - * @param world the world. - * @param placer the entity placer. - * @return a list of stacks. - */ - public static List getListOfStackForEntityInfo(final CompoundTag entityData, final Level world, final AbstractEntityCitizen placer) - { - if (placer != null) - { - return getListOfStackForEntityInfo(entityData, world, (Entity) placer); - } - - return Lists.newArrayList(); - } - /** * Adds entities to the builder building if he needs it. * @@ -929,7 +852,7 @@ public static void consumeFood(final ItemStack foodStack, final AbstractEntityCi } /** - * Given an {@link Ingredient}, tries to produce a reasonable friendly UI name for its contents. + * Given an {@link net.minecraft.world.item.crafting.Ingredient}, tries to produce a reasonable friendly UI name for its contents. * @param ingredient the ingredient to check. * @return the friendly name. */ diff --git a/src/main/java/com/minecolonies/core/colony/CitizenData.java b/src/main/java/com/minecolonies/core/colony/CitizenData.java index 40ae258dc22..e2b5911ddf6 100755 --- a/src/main/java/com/minecolonies/core/colony/CitizenData.java +++ b/src/main/java/com/minecolonies/core/colony/CitizenData.java @@ -2030,7 +2030,7 @@ public BlockPos getHomePosition() @Nullable final IBuilding homeBuilding = getHomeBuilding(); if (homeBuilding != null) { - return homeBuilding.getStandingPosition(); + return homeBuilding.getPosition(); } if (colony != null) @@ -2038,7 +2038,7 @@ public BlockPos getHomePosition() final IBuilding tavern = colony.getBuildingManager().getFirstBuildingMatching(b -> b.getBuildingType() == ModBuildings.tavern.get()); if (tavern != null) { - return tavern.getStandingPosition(); + return tavern.getPosition(); } else if (colony.getBuildingManager().getTownHall() != null) { diff --git a/src/main/java/com/minecolonies/core/colony/buildings/AbstractBuilding.java b/src/main/java/com/minecolonies/core/colony/buildings/AbstractBuilding.java index 6f651769af2..fbc61fdbc4d 100644 --- a/src/main/java/com/minecolonies/core/colony/buildings/AbstractBuilding.java +++ b/src/main/java/com/minecolonies/core/colony/buildings/AbstractBuilding.java @@ -1049,61 +1049,6 @@ public void resetGuardBuildingNear() this.recheckGuardBuildingNear = true; } - @Override - public BlockPos getStandingPosition() - { - if (cachedStandingPosition == null) - { - if (!WorldUtil.isEntityBlockLoaded(colony.getWorld(), getPosition())) - { - return getPosition(); - } - - BlockPos bestPos = getPosition(); - int bestScore = 0; - - //Return true if the building is null to stall the worker - for (final Direction dir : Direction.Plane.HORIZONTAL) - { - final BlockPos currentPos = getPosition().relative(dir); - final BlockState hereState = colony.getWorld().getBlockState(currentPos); - // Check air here and air above. - if ((!hereState.getBlock().properties().hasCollision || hereState.is(BlockTags.WOOL_CARPETS)) - && !colony.getWorld().getBlockState(currentPos.above()).getBlock().properties().hasCollision - && BlockUtils.isAnySolid(colony.getWorld().getBlockState(currentPos.below()))) - { - int localScore = BEST_STANDING_SCORE; - if (colony.getWorld().canSeeSky(currentPos)) - { - // More critical - localScore-=2; - } - if (colony.getWorld().getBlockState(getPosition()).getValue(AbstractBlockHut.FACING) == dir) - { - // Less critical - localScore--; - } - - if (localScore == BEST_STANDING_SCORE) - { - cachedStandingPosition = currentPos; - return cachedStandingPosition; - } - - if (localScore > bestScore) - { - bestScore = localScore; - bestPos = currentPos; - } - } - } - - // prefer default rotation of the building facing this. - cachedStandingPosition = bestPos; - } - return cachedStandingPosition == null ? getPosition() : cachedStandingPosition; - } - //------------------------- Starting Required Tools/Item handling -------------------------// @Override diff --git a/src/main/java/com/minecolonies/core/colony/events/raid/pirateEvent/ShipBasedRaiderUtils.java b/src/main/java/com/minecolonies/core/colony/events/raid/pirateEvent/ShipBasedRaiderUtils.java index 7176a93b890..19029af6848 100644 --- a/src/main/java/com/minecolonies/core/colony/events/raid/pirateEvent/ShipBasedRaiderUtils.java +++ b/src/main/java/com/minecolonies/core/colony/events/raid/pirateEvent/ShipBasedRaiderUtils.java @@ -416,7 +416,7 @@ public static List createWaypoints(final Level world, final Path path, { final BlockPos point = path.getNode(i).asBlockPos(); if (lastPoint.distManhattan(point) > spacing - && world.getBlockState(point).isAir()) + && world.getBlockState(point).isAir() && world.getBlockState(point.above()).isAir()) { wayPoints.add(point); lastPoint = point; diff --git a/src/main/java/com/minecolonies/core/entity/ai/combat/AttackMoveAI.java b/src/main/java/com/minecolonies/core/entity/ai/combat/AttackMoveAI.java index 9684880dc19..65f4cb70772 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/combat/AttackMoveAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/combat/AttackMoveAI.java @@ -6,8 +6,10 @@ import com.minecolonies.api.entity.ai.statemachine.states.IState; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition; +import com.minecolonies.api.entity.other.AbstractFastMinecoloniesEntity; import com.minecolonies.api.util.DamageSourceKeys; -import com.minecolonies.core.entity.pathfinding.navigation.AbstractAdvancedPathNavigate; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; +import com.minecolonies.core.entity.pathfinding.navigation.MinecoloniesAdvancedPathNavigate; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.LivingEntity; @@ -211,6 +213,7 @@ protected int getAttackDelay() */ protected PathResult moveInAttackPosition(final LivingEntity target) { - return ((AbstractAdvancedPathNavigate) user.getNavigation()).moveToLivingEntity(target, 1d); + EntityNavigationUtils.walkToPos((AbstractFastMinecoloniesEntity) user, target.blockPosition(), 1, false); + return ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).getPathResult(); } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenAvoidEntity.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenAvoidEntity.java index ef363b9d2c8..f1acde761b3 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenAvoidEntity.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenAvoidEntity.java @@ -5,9 +5,10 @@ import com.minecolonies.api.entity.ai.statemachine.states.CitizenAIState; import com.minecolonies.api.entity.ai.statemachine.states.IState; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.api.util.CompatibilityUtils; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; +import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -173,9 +174,11 @@ private boolean performMoveAway() { if ((moveAwayPath == null || !moveAwayPath.isInProgress()) && citizen.getNavigation().isDone()) { - moveAwayPath = - citizen.getNavigation() - .moveAwayFromXYZ(citizen.blockPosition().offset(rand.nextInt(2), 0, rand.nextInt(2)), distanceFromEntity + getMoveAwayDist(citizen), nearSpeed, true); + EntityNavigationUtils.walkAwayFrom(citizen, + citizen.blockPosition().offset(rand.nextInt(2), 0, rand.nextInt(2)), + (int) (distanceFromEntity + getMoveAwayDist(citizen)), + nearSpeed); + moveAwayPath = citizen.getNavigation().getPathResult(); return true; } return false; @@ -248,7 +251,7 @@ public void reset() safeTime = 0; if (startingPos != null) { - citizen.getNavigation().tryMoveToBlockPos(startingPos, 1); + EntityNavigationUtils.walkToPos(citizen, startingPos, 1, true); } closestLivingEntity = null; moveAwayPath = null; diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenChild.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenChild.java index 0c1d4fa9eb6..442f7936918 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenChild.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenChild.java @@ -1,5 +1,6 @@ package com.minecolonies.core.entity.ai.minimal; +import com.minecolonies.api.colony.buildings.IBuilding; import com.minecolonies.api.entity.ai.IStateAI; import com.minecolonies.api.entity.ai.statemachine.AIEventTarget; import com.minecolonies.api.entity.ai.statemachine.AITarget; @@ -8,11 +9,12 @@ import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.ai.statemachine.states.IState; import com.minecolonies.api.entity.citizen.AbstractCivilianEntity; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.api.util.CompatibilityUtils; import com.minecolonies.api.util.MessageUtils; import com.minecolonies.core.colony.eventhooks.citizenEvents.CitizenGrownUpEvent; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; +import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -92,7 +94,7 @@ public boolean isOkayToEat() /** * The blockpos the child is visiting */ - private BlockPos visitHutPos; + private IBuilding visitingHut; /** * The path for visiting the hut @@ -195,13 +197,13 @@ private IState followingEntity() if (actionTimer <= 0 || followTarget.get() == null) { // run back to start position - child.getNavigation().moveToXYZ(followStart.getX(), followStart.getY(), followStart.getZ(), 1.0d); + EntityNavigationUtils.walkToPos(child, followStart, 2, true); setDelayForNextAction(); return CitizenAIState.IDLE; } - child.getNavigation().moveToLivingEntity(followTarget.get(), 1.0d); + EntityNavigationUtils.walkToPos(child, followTarget.get().blockPosition(), 2, false); return State.FOLLOWING; } @@ -216,7 +218,7 @@ private IState visitHuts() if (visitingPath == null && child.getCitizenColonyHandler().getColonyOrRegister() != null) { // Visiting huts for 3min. - if (actionTimer <= 0 && visitHutPos == null) + if (actionTimer <= 0 && visitingHut == null) { actionTimer = 3 * 60 * 20; } @@ -225,10 +227,11 @@ private IState visitHuts() index = rand.nextInt(index); - final List buildings = new ArrayList<>(child.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuildings().keySet()); - visitHutPos = buildings.get(index); + final List buildings = new ArrayList<>(child.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuildings().values()); + visitingHut = buildings.get(index); - visitingPath = child.getNavigation().moveToXYZ(visitHutPos.getX(), visitHutPos.getY(), visitHutPos.getZ(), 1.0d); + EntityNavigationUtils.walkToBuilding(child, visitingHut); + visitingPath = child.getNavigation().getPathResult(); } actionTimer -= 120; @@ -238,7 +241,8 @@ private IState visitHuts() // Path got interrupted by sth if (visitingPath != null && !visitingPath.isInProgress()) { - visitingPath = child.getNavigation().moveToXYZ(visitHutPos.getX(), visitHutPos.getY(), visitHutPos.getZ(), 1.0d); + EntityNavigationUtils.walkToBuilding(child, visitingHut); + visitingPath = child.getNavigation().getPathResult(); } return State.VISITING; @@ -246,7 +250,7 @@ private IState visitHuts() child.getNavigation().stop(); visitingPath = null; - visitHutPos = null; + visitingHut = null; setDelayForNextAction(); return CitizenAIState.IDLE; diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenWander.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenWander.java index ddf6b7ec51c..d45e6c47ba0 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenWander.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAICitizenWander.java @@ -10,6 +10,7 @@ import com.minecolonies.core.entity.ai.workers.education.EntityAIStudy; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.entity.other.SittingEntity; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.tileentities.TileEntityColonyBuilding; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.EquipmentSlot; @@ -92,7 +93,7 @@ private IState readABook() if (walkTo != null) { - if (!citizen.isWorkerAtSiteWithMove(walkTo, 3)) + if (!EntityNavigationUtils.walkToPos(citizen, walkTo, 3, true)) { return READ_A_BOOK; } @@ -129,7 +130,7 @@ private IState goToLeisureSite() return CitizenAIState.IDLE; } - if (!citizen.isWorkerAtSiteWithMove(leisureSite, 3)) + if (!EntityNavigationUtils.walkToPos(citizen, leisureSite, 3, true)) { return GO_TO_LEISURE_SITE; } @@ -146,7 +147,7 @@ private IState wanderAtLeisureSite() return CitizenAIState.IDLE; } - if (walkTo != null && !citizen.isWorkerAtSiteWithMove(walkTo, 3)) + if (walkTo != null && !EntityNavigationUtils.walkToPos(citizen, walkTo, 3, true)) { return WANDER_AT_LEISURE_SITE; } @@ -161,8 +162,7 @@ private IState wanderAtLeisureSite() { if (walkTo == null && citizen.getRandom().nextBoolean()) { - citizen.getNavigation() - .moveToRandomPos(10, DEFAULT_SPEED, ((IBlueprintDataProviderBE) blockEntity).getInWorldCorners()); + EntityNavigationUtils.walkToRandomPosWithin(citizen, 10, DEFAULT_SPEED, ((IBlueprintDataProviderBE) blockEntity).getInWorldCorners()); } if (walkTo == null && blockEntity instanceof TileEntityColonyBuilding && ((TileEntityColonyBuilding) blockEntity).getBuilding() instanceof BuildingLibrary && citizen.getRandom().nextInt(100) < 5) @@ -223,7 +223,7 @@ private IState decide() } } - citizen.getNavigation().moveToRandomPos(10, this.speed); + EntityNavigationUtils.walkToRandomPos(citizen, 10, this.speed); return CitizenAIState.IDLE; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIEatTask.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIEatTask.java index f11ab5def36..c0de4baba78 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIEatTask.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIEatTask.java @@ -18,6 +18,7 @@ import com.minecolonies.core.colony.jobs.JobCook; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.entity.other.SittingEntity; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.network.messages.client.ItemParticleEffectMessage; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -48,11 +49,6 @@ public class EntityAIEatTask implements IStateAI */ private static final int MINUTES_WAITING_TIME = 2; - /** - * Min distance in blocks to placeToPath block. - */ - private static final int MIN_DISTANCE_TO_RESTAURANT = 2; - /** * Time required to eat in seconds. */ @@ -245,7 +241,7 @@ private EatingState getFoodYourself() final IBuilding cookBuilding = colony.getBuildingManager().getBuilding(restaurantPos); if (cookBuilding instanceof BuildingCook) { - if (!citizen.isWorkerAtSiteWithMove(cookBuilding.getPosition(), MIN_DISTANCE_TO_RESTAURANT)) + if (!EntityNavigationUtils.walkToBuilding(citizen, cookBuilding)) { return GET_FOOD_YOURSELF; } @@ -296,7 +292,7 @@ private EatingState goToEatingPlace() } } - if (citizen.isWorkerAtSiteWithMove(eatPos, 2)) + if (EntityNavigationUtils.walkToPos(citizen, eatPos, 2, true)) { SittingEntity.sitDown(eatPos, citizen, TICKS_SECOND * 60); // Delay till they start eating @@ -384,7 +380,7 @@ private EatingState goToHut() return SEARCH_RESTAURANT; } - if (citizen.isWorkerAtSiteWithMove(buildingWorker.getPosition(), MIN_DISTANCE_TO_RESTAURANT)) + if (EntityNavigationUtils.walkToBuilding(citizen, buildingWorker)) { final int slot = FoodUtils.getBestFoodForCitizen(citizen.getInventoryCitizen(), citizen.getCitizenData(), null); if (slot != -1) @@ -419,7 +415,7 @@ private EatingState goToRestaurant() { return WAIT_FOR_FOOD; } - else if (!citizen.isWorkerAtSiteWithMove(restaurantPos, MIN_DISTANCE_TO_RESTAURANT)) + else if (!EntityNavigationUtils.walkToBuilding(citizen, building)) { return GO_TO_RESTAURANT; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIMournCitizen.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIMournCitizen.java index 3daf3b2f70f..5c4bd25894b 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIMournCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAIMournCitizen.java @@ -6,7 +6,6 @@ import com.minecolonies.api.entity.ai.statemachine.states.CitizenAIState; import com.minecolonies.api.entity.ai.statemachine.states.IState; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition; -import com.minecolonies.core.tileentities.TileEntityNamedGrave; import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.MathUtils; import com.minecolonies.api.util.Tuple; @@ -14,6 +13,8 @@ import com.minecolonies.core.colony.buildings.modules.GraveyardManagementModule; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingGraveyard; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; +import com.minecolonies.core.tileentities.TileEntityNamedGrave; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.Entity; @@ -71,7 +72,7 @@ public enum MourningState implements IState /** * The position of the graveyard. */ - private BlockPos graveyard; + private IBuilding graveyard; /** * Position of the grave to walk to. @@ -110,13 +111,13 @@ public EntityAIMournCitizen(final EntityCitizen citizen, final double speed) */ private IState walkToTownHall() { - final BlockPos pos = getMournLocation(); - if (pos == null) + final IBuilding building = getMournLocation(); + if (building == null) { return CitizenAIState.IDLE; } - if (!citizen.isWorkerAtSiteWithMove(pos, 3)) + if (!EntityNavigationUtils.walkToBuilding(citizen, building)) { return MourningState.WALKING_TO_TOWNHALL; } @@ -136,7 +137,7 @@ private IState walkToGraveyard() return MourningState.DECIDE; } - if (!citizen.isWorkerAtSiteWithMove(graveyard, 3)) + if (!EntityNavigationUtils.walkToBuilding(citizen, graveyard)) { return MourningState.WALKING_TO_GRAVEYARD; } @@ -157,13 +158,6 @@ private IState wanderAtGraveyard() return MourningState.DECIDE; } - final IBuilding graveyardBuilding = citizen.getCitizenColonyHandler().getColonyOrRegister().getBuildingManager().getBuilding(graveyard); - if (!(graveyardBuilding instanceof BuildingGraveyard)) - { - graveyard = null; - return MourningState.DECIDE; - } - if (!citizen.getNavigation().isDone()) { return MourningState.WANDER_AT_GRAVEYARD; @@ -172,12 +166,12 @@ private IState wanderAtGraveyard() // Wander around randomly. if (MathUtils.RANDOM.nextInt(100) < 90) { - citizen.getNavigation().moveToRandomPos(10, DEFAULT_SPEED, graveyardBuilding.getCorners()); + EntityNavigationUtils.walkToRandomPosWithin(citizen, 10, DEFAULT_SPEED, graveyard.getCorners()); return MourningState.WANDER_AT_GRAVEYARD; } // Try find the grave of one of the diseased. - final Set> gravePositions = ((BuildingGraveyard) graveyardBuilding).getGravePositions(); + final Set> gravePositions = ((BuildingGraveyard) graveyard).getGravePositions(); for (final Tuple gravePos : gravePositions) { if (WorldUtil.isBlockLoaded(citizen.level(), gravePos.getA())) @@ -219,7 +213,7 @@ private IState walkToGrave() return MourningState.DECIDE; } - if (!citizen.isWorkerAtSiteWithMove(gravePos, 3)) + if (!EntityNavigationUtils.walkToPosInBuilding(citizen, gravePos, graveyard, 3)) { return MourningState.WALK_TO_GRAVE; } @@ -234,7 +228,7 @@ private IState walkToGrave() */ private IState wander() { - citizen.getNavigation().moveToRandomPos(10, this.speed); + EntityNavigationUtils.walkToRandomPos(citizen, 10, this.speed); return CitizenAIState.IDLE; } @@ -300,7 +294,7 @@ private IState decide() GraveyardManagementModule.class).hasRestingCitizen(citizen.getCitizenData().getCitizenMournHandler().getDeceasedCitizens())); if (graveyardBuilding != null) { - this.graveyard = graveyardBuilding.getPosition(); + this.graveyard = graveyardBuilding; } } @@ -312,7 +306,7 @@ private IState decide() citizen.getLookControl().setLookAt(citizen.getX(), citizen.getY() - 10, citizen.getZ(), (float) citizen.getMaxHeadYRot(), (float) citizen.getMaxHeadXRot()); - if (BlockPosUtil.getDistance2D(this.citizen.blockPosition(), getMournLocation()) > MIN_DESTINATION_TO_LOCATION) + if (getMournLocation() != null && BlockPosUtil.getDistance2D(this.citizen.blockPosition(), getMournLocation().getPosition()) > MIN_DESTINATION_TO_LOCATION) { return MourningState.WALKING_TO_TOWNHALL; } @@ -332,14 +326,14 @@ public void reset() * * @return blockPos of the location to mourn at */ - protected BlockPos getMournLocation() + protected IBuilding getMournLocation() { final IColony colony = citizen.getCitizenColonyHandler().getColonyOrRegister(); if (colony != null && colony.getBuildingManager().hasTownHall()) { - return colony.getBuildingManager().getTownHall().getStandingPosition(); + return colony.getBuildingManager().getTownHall(); } - return citizen.getCitizenData().getHomePosition(); + return citizen.getCitizenData().getHomeBuilding(); } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java index 6764fe00ade..3c82ea4ca39 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISickTask.java @@ -15,9 +15,9 @@ import com.minecolonies.api.util.SoundUtils; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingHospital; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; -import com.minecolonies.core.datalistener.DiseasesListener; import com.minecolonies.core.datalistener.model.Disease; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.network.messages.client.CircleParticleEffectMessage; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; @@ -112,7 +112,7 @@ public enum DiseaseState implements IState /** * Restaurant to which the citizen should path. */ - private BlockPos placeToPath; + private BlockPos bestHospital; /** * Instantiates this task. @@ -157,7 +157,7 @@ private boolean isSick() */ public DiseaseState wander() { - citizen.getNavigation().moveToRandomPos(10, 0.6D); + EntityNavigationUtils.walkToRandomPos(citizen, 10, 0.6D); return CHECK_FOR_CURE; } @@ -213,7 +213,7 @@ private DiseaseState findEmptyBed() } } - if (citizen.isWorkerAtSiteWithMove(usedBed, 3)) + if (EntityNavigationUtils.walkToPosInBuilding(citizen, usedBed, hospital, 3)) { waitingTicks++; if (!citizen.getCitizenSleepHandler().trySleep(usedBed)) @@ -314,9 +314,9 @@ private void cure() private IState waitForCure() { final IColony colony = citizenData.getColony(); - placeToPath = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); + bestHospital = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); - if (placeToPath == null) + if (bestHospital == null) { return SEARCH_HOSPITAL; } @@ -351,7 +351,7 @@ else if (state == CitizenAIState.IDLE) } } - if (!citizen.getCitizenSleepHandler().isAsleep() && BlockPosUtil.getDistance2D(placeToPath, citizen.blockPosition()) > MINIMUM_DISTANCE_TO_HOSPITAL) + if (!citizen.getCitizenSleepHandler().isAsleep() && BlockPosUtil.getDistance2D(bestHospital, citizen.blockPosition()) > MINIMUM_DISTANCE_TO_HOSPITAL) { return GO_TO_HOSPITAL; } @@ -379,7 +379,7 @@ private IState goToHut() return SEARCH_HOSPITAL; } - if (citizen.getCitizenSleepHandler().isAsleep() || citizen.isWorkerAtSiteWithMove(buildingWorker.getPosition(), MIN_DIST_TO_HUT)) + if (citizen.getCitizenSleepHandler().isAsleep() || EntityNavigationUtils.walkToBuilding(citizen, buildingWorker)) { return SEARCH_HOSPITAL; } @@ -394,12 +394,12 @@ private IState goToHut() private IState goToHospital() { citizen.getCitizenData().getCitizenDiseaseHandler().setSleepsAtHospital(false); - if (placeToPath == null) + if (bestHospital == null) { return SEARCH_HOSPITAL; } - if (citizen.getCitizenSleepHandler().isAsleep() || (citizen.getNavigation().isDone() && citizen.isWorkerAtSiteWithMove(placeToPath, MIN_DIST_TO_HOSPITAL))) + if (citizen.getCitizenSleepHandler().isAsleep() || EntityNavigationUtils.walkToPos(citizen, bestHospital, MIN_DIST_TO_HOSPITAL, true)) { return WAIT_FOR_CURE; } @@ -415,9 +415,9 @@ private IState searchHospital() { final IColony colony = citizenData.getColony(); final Disease disease = citizen.getCitizenData().getCitizenDiseaseHandler().getDisease(); - placeToPath = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); + bestHospital = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class); - if (placeToPath == null) + if (bestHospital == null) { if (disease == null) { @@ -481,7 +481,7 @@ private void reset() citizen.releaseUsingItem(); citizen.stopUsingItem(); citizen.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); - placeToPath = null; + bestHospital = null; citizen.getCitizenData().getCitizenDiseaseHandler().setSleepsAtHospital(false); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISleep.java b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISleep.java index f7ab0566677..02b15013b1a 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISleep.java +++ b/src/main/java/com/minecolonies/core/entity/ai/minimal/EntityAISleep.java @@ -16,6 +16,7 @@ import com.minecolonies.core.colony.buildings.AbstractBuilding; import com.minecolonies.core.colony.buildings.modules.BuildingModules; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.network.messages.client.SleepingParticleMessage; import net.minecraft.core.BlockPos; import net.minecraft.tags.BlockTags; @@ -199,7 +200,7 @@ private void findBedAndTryToSleep() usedBed = homePos; } - if (citizen.isWorkerAtSiteWithMove(usedBed, 3)) + if (EntityNavigationUtils.walkToPosInBuilding(citizen, usedBed, citizen.getCitizenData().getHomeBuilding(), 5)) { bedTicks++; if (!citizen.getCitizenSleepHandler().trySleep(usedBed)) @@ -236,10 +237,14 @@ private IState sleep() */ private void goHome() { - final BlockPos pos = citizen.getCitizenData().getHomePosition(); - if (pos != null && !citizen.isWorkerAtSiteWithMove(pos, 2) && citizen.getPose() == Pose.SLEEPING) + final IBuilding home = citizen.getCitizenData().getHomeBuilding(); + if (home != null) { - citizen.setPose(Pose.STANDING); + EntityNavigationUtils.walkToBuilding(citizen, home); + } + else + { + EntityNavigationUtils.walkToPos(citizen, citizen.getCitizenData().getHomePosition(), 4, true); } final int chance = citizen.getRandom().nextInt(CHANCE); diff --git a/src/main/java/com/minecolonies/core/entity/ai/visitor/EntityAIVisitor.java b/src/main/java/com/minecolonies/core/entity/ai/visitor/EntityAIVisitor.java index 7e23950942f..e8638069a8a 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/visitor/EntityAIVisitor.java +++ b/src/main/java/com/minecolonies/core/entity/ai/visitor/EntityAIVisitor.java @@ -7,13 +7,13 @@ import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.api.util.DamageSourceKeys; -import com.minecolonies.api.util.Log; import com.minecolonies.api.util.WorldUtil; import com.minecolonies.core.colony.VisitorData; import com.minecolonies.core.colony.buildings.DefaultBuildingInstance; import com.minecolonies.core.colony.buildings.modules.BuildingModules; import com.minecolonies.core.colony.buildings.modules.TavernBuildingModule; import com.minecolonies.core.entity.other.SittingEntity; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.entity.visitor.VisitorCitizen; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; @@ -121,7 +121,7 @@ private boolean doFight() return true; } - if (citizen.isWorkerAtSiteWithMove(target.blockPosition(), 2) && citizen.hasLineOfSight(target)) + if (EntityNavigationUtils.walkToPos(citizen, target.blockPosition(), 2, false) && citizen.hasLineOfSight(target)) { citizen.swing(InteractionHand.MAIN_HAND); target.hurt(target.level().damageSources().source(DamageSourceKeys.VISITOR), 10.0f); @@ -142,7 +142,7 @@ private boolean wander() return true; } - citizen.getNavigation().moveToRandomPos(10, 0.6D); + EntityNavigationUtils.walkToRandomPos(citizen, 10, 0.6D); return false; } @@ -175,14 +175,14 @@ private VisitorState decide() if (pos != null) { ((VisitorData) citizen.getCitizenData()).setSittingPosition(pos); - citizen.isWorkerAtSiteWithMove(pos, 1); + EntityNavigationUtils.walkToPosInBuilding(citizen, pos, tavern, 3); actionTimeoutCounter = citizen.getRandom().nextInt(2500) + 3000; return VisitorState.SITTING; } } else if (random == 2) { - citizen.getNavigation().moveToRandomPos(10, 0.6D); + EntityNavigationUtils.walkToRandomPos(citizen, 10, 0.6D); actionTimeoutCounter = citizen.getCitizenColonyHandler().getColonyOrRegister().isDay() ? citizen.getRandom().nextInt(1000) + 1000 : 300; return VisitorState.WANDERING; } @@ -209,7 +209,7 @@ private boolean sit() } final BlockPos moveTo = ((VisitorData) citizen.getCitizenData()).getSittingPosition(); - if (citizen.isWorkerAtSiteWithMove(moveTo, 1)) + if (EntityNavigationUtils.walkToPosInBuilding(citizen, moveTo, tavern, 3)) { SittingEntity.sitDown(moveTo, citizen, actionTimeoutCounter); } @@ -257,16 +257,6 @@ private Entity getTarget() return target; } - /** - * Handles any exceptions for this AI. - * - * @param e exception to handle - */ - private void onException(final RuntimeException e) - { - Log.getLogger().warn("Visitor AI of:" + citizen.getName() + " threw an Exception:", e); - } - /** * Resets saved data of internal logic */ diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java index e1ed002e1fe..4e44d7dd3ce 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java @@ -35,6 +35,7 @@ import com.minecolonies.core.colony.jobs.AbstractJob; import com.minecolonies.core.colony.jobs.JobDeliveryman; import com.minecolonies.core.colony.requestsystem.resolvers.StationRequestResolver; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy; import com.minecolonies.core.tileentities.TileEntityRack; @@ -71,6 +72,7 @@ import static com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_ENTITY_WORKER_INVENTORYFULLCHEST; import static com.minecolonies.api.util.constant.TranslationConstants.WORKER_AI_EXCEPTION; import static com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract.RENDER_META_WORKING; +import static com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils.WOKR_IN_BUILDING_DIST; /** * This class provides basic ai functionality. @@ -276,13 +278,13 @@ public void setWalkTo(final BlockPos walkto) } /** - * Special walk state.. + * Only used for command-triggered walking * * @return IDLE once arrived. */ private IAIState walkToState() { - if (walkToBlock(walkTo, DEFAULT_RANGE_FOR_DELAY)) + if (!walkWithProxy(walkTo, DEFAULT_RANGE_FOR_DELAY)) { return getState(); } @@ -315,7 +317,7 @@ private IAIState getNeededItem() walkTo = pos; } - if (walkToBlock(walkTo) && pickUpCounter++ < PICKUP_ATTEMPTS) + if (!walkToWorkPos(walkTo) && pickUpCounter++ < PICKUP_ATTEMPTS) { return getState(); } @@ -597,7 +599,7 @@ private IAIState lookForRequests() } final ILocation pickupLocation = resolver instanceof StationRequestResolver ? resolver.getLocation() : building.getLocation(); - if (walkToBlock(pickupLocation.getInDimensionLocation()) || !WorldUtil.isBlockLoaded(world, pickupLocation.getInDimensionLocation())) + if (!walkToWorkPos(pickupLocation.getInDimensionLocation()) || !WorldUtil.isBlockLoaded(world, pickupLocation.getInDimensionLocation())) { return NEEDS_ITEM; } @@ -768,9 +770,9 @@ public int getTotalRequiredAmount(final ItemStack deliveredItemStack) } /** - * Walk the worker to it's building chest. Please return immediately if this returns true. + * Walk the worker to it's work building. * - * @return false if the worker is at his building + * @return true on arrival */ protected final boolean walkToBuilding() { @@ -779,13 +781,68 @@ protected final boolean walkToBuilding() { return true; } - final BlockPos standingPos = ownBuilding.getStandingPosition(); - int range = 2; - if (standingPos.equals(ownBuilding.getPosition())) + + return EntityNavigationUtils.walkToBuilding(worker, ownBuilding); + } + + /** + * Walk the worker to the given building. + * + * @return true while walking + */ + protected final boolean walkToWorkPos(final BlockPos pos) + { + if (pos == null) + { + return true; + } + + return EntityNavigationUtils.walkToPosInBuilding(worker, pos, building, WOKR_IN_BUILDING_DIST); + } + + /** + * Walk the worker to the given building. + * + * @return true while walking + */ + protected final boolean walkToBuilding(final IBuilding building) + { + if (building == null) { - range = 3; + return true; } - return walkToBlock(ownBuilding.getStandingPosition(), range); + + return EntityNavigationUtils.walkToBuilding(worker, building); + } + + /** + * Walk the worker to the safe position + * + * @return false while walking + */ + protected final boolean walkToSafePos(final BlockPos pos) + { + return EntityNavigationUtils.walkToPos(worker, pos, 4, true); + } + + /** + * Walk the worker to the unsafe position + * + * @return false while walking + */ + protected final boolean walkToUnSafePos(final BlockPos pos) + { + return EntityNavigationUtils.walkToPos(worker, pos, 4, false); + } + + /** + * Walk the worker to the unsafe position + * + * @return false while walking + */ + protected final boolean walkToUnSafePos(final BlockPos pos, final int distance) + { + return EntityNavigationUtils.walkToPos(worker, pos, distance, false); } /** @@ -818,9 +875,9 @@ public boolean checkAndTransferFromHut(@Nullable final ItemStack is) * @param stand where to walk to * @return true while walking to the block */ - protected final boolean walkToBlock(@NotNull final BlockPos stand) + protected final boolean walkWithProxy(@NotNull final BlockPos stand) { - return walkToBlock(stand, DEFAULT_RANGE_FOR_DELAY); + return walkWithProxy(stand, DEFAULT_RANGE_FOR_DELAY); } /** @@ -830,7 +887,7 @@ protected final boolean walkToBlock(@NotNull final BlockPos stand) * @param range how close we need to be * @return true while walking to the block */ - protected final boolean walkToBlock(@NotNull final BlockPos stand, final int range) + protected final boolean walkWithProxy(@NotNull final BlockPos stand, final int range) { if (proxy == null) { @@ -1017,7 +1074,7 @@ private boolean checkForNeededTool(@NotNull final EquipmentTypeEntry toolType, f } delay += DELAY_RECHECK; - return walkToBuilding() || !retrieveToolInHut(toolType, minimalLevel); + return !walkToBuilding() || !retrieveToolInHut(toolType, minimalLevel); } /** @@ -1090,7 +1147,7 @@ private IAIState dumpInventory() return afterDump(); } - if (!worker.isWorkerAtSiteWithMove(building.getPosition(), DEFAULT_RANGE_FOR_DELAY)) + if (!walkToBuilding()) { setDelay(WALK_DELAY); return INVENTORY_FULL; @@ -1169,7 +1226,7 @@ public IAIState afterDump() @SuppressWarnings("PMD.PrematureDeclaration") private boolean dumpOneMoreSlot() { - if (walkToBlock(getBuildingToDump().getPosition())) + if (!walkToWorkPos(getBuildingToDump().getPosition())) { return true; } @@ -1788,11 +1845,11 @@ private IAIState bePaused() final int percent = worker.getRandom().nextInt(ONE_HUNDRED_PERCENT); if (percent < VISIT_BUILDING_CHANCE) { - worker.getNavigation().tryMoveToBlockPos(building.getPosition(), worker.getRandom().nextBoolean() ? DEFAULT_SPEED * 1.5D : DEFAULT_SPEED * 2.2D); + walkToBuilding(); } else if (percent < WANDER_CHANCE) { - worker.getNavigation().moveToRandomPos(10, DEFAULT_SPEED); + EntityNavigationUtils.walkToRandomPos(worker, 10, DEFAULT_SPEED); } return null; diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java index 21dd5f88b0e..fb5684193e6 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java @@ -5,8 +5,8 @@ import com.minecolonies.core.MineColonies; import com.minecolonies.core.colony.buildings.AbstractBuilding; import com.minecolonies.core.colony.jobs.AbstractJob; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.util.citizenutils.CitizenItemUtils; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; @@ -89,16 +89,6 @@ public abstract class AbstractEntityAIInteract, B ex @Nullable private List items; - /** - * The current path to the random position - */ - private PathResult pathResult; - - /** - * The backup factor of the path. - */ - protected int pathBackupFactor = 1; - /** * Block mining delay base */ @@ -294,7 +284,7 @@ private boolean checkMiningLocation(@NotNull final BlockPos blockToMine, @NotNul return true; } - if (walkToBlock(safeStand) && MathUtils.twoDimDistance(worker.blockPosition(), safeStand) > MIN_WORKING_RANGE) + if (safeStand != null && walkWithProxy(safeStand) && MathUtils.twoDimDistance(worker.blockPosition(), safeStand) > MIN_WORKING_RANGE) { return true; } @@ -397,7 +387,7 @@ public void gatherItems() if (worker.getNavigation().isDone() || worker.getNavigation().getPath() == null) { final BlockPos pos = getAndRemoveClosestItemPosition(); - worker.isWorkerAtSiteWithMove(pos, ITEM_PICKUP_RANGE); + EntityNavigationUtils.walkToPos(worker, pos, 2, false); return; } @@ -446,83 +436,6 @@ private BlockPos getAndRemoveClosestItemPosition() return items.remove(index); } - /** - * Search for a random position to go to, anchored around the citizen. - * - * @param range the max range - * @return null until position was found. - */ - protected BlockPos findRandomPositionToWalkTo(final int range) - { - return findRandomPositionToWalkTo(range, worker.blockPosition()); - } - - /** - * Search for a random position to go to. - * - * @param range the max range - * @param pos position we want to find a random position around in the given range - * @return null until position was found. - */ - protected BlockPos findRandomPositionToWalkTo(final int range, final BlockPos pos) - { - if (pathResult == null) - { - pathBackupFactor = 1; - pathResult = getRandomNavigationPath(range, pos); - } - else if (pathResult.failedToReachDestination()) - { - pathBackupFactor++; - pathResult = getRandomNavigationPath(range * pathBackupFactor, pos); - } - - if (pathResult == null) - { - return null; - } - - if (pathResult.isPathReachingDestination()) - { - final BlockPos resultPos = pathResult.getPath().getEndNode().asBlockPos(); - pathResult = null; - return resultPos; - } - - if (pathResult.isCancelled()) - { - pathResult = null; - return null; - } - - if (pathBackupFactor > 10) - { - pathResult = null; - return null; - } - - return null; - } - - /** - * Get a navigator to find a certain position. - * - * @param range the max range. - * @param pos the position to - * @return the navigator. - */ - protected PathResult getRandomNavigationPath(final int range, final BlockPos pos) - { - if (pos == null || pos == worker.blockPosition()) - { - return worker.getNavigation().moveToRandomPos(range, 1.0D); - } - else - { - return worker.getNavigation().moveToRandomPosAroundX(range, 1.0D, pos); - } - } - /** * Reset the gathering items to null. */ diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java index ded27e694e8..adf34dd39ad 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIStructure.java @@ -323,16 +323,7 @@ public IAIState afterStructureLoading() * @param currentBlock the current block it is working on. * @return true while walking to the site. */ - public boolean walkToConstructionSite(final BlockPos currentBlock) - { - if (workFrom == null) - { - workFrom = getWorkingPosition(currentBlock); - } - - //The miner shouldn't search for a save position. Just let him build from where he currently is. - return worker.isWorkerAtSiteWithMove(workFrom, STANDARD_WORKING_RANGE) || MathUtils.twoDimDistance(worker.blockPosition(), workFrom) < MIN_WORKING_RANGE; - } + public abstract boolean walkToConstructionSite(final BlockPos currentBlock); /** * Checks for blocks that need to be treated as deco diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIUsesFurnace.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIUsesFurnace.java index ec58b0e8651..1447cf8380b 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIUsesFurnace.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIUsesFurnace.java @@ -180,7 +180,7 @@ protected BlockPos getPositionOfOvenToRetrieveFuelFrom() */ public IAIState startWorking() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } @@ -393,7 +393,7 @@ private IAIState retrieveSmeltableFromFurnace() return START_WORKING; } - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -426,7 +426,7 @@ private IAIState retrieveUsedFuel() return START_WORKING; } - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -468,7 +468,7 @@ private IAIState fillUpFurnace() return START_WORKING; } - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java index 50e81665fb1..01af8fb722d 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/builder/EntityAIStructureBuilder.java @@ -145,7 +145,7 @@ public boolean isAfterDumpPickupAllowed() private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } @@ -230,7 +230,7 @@ else if (gotoPath.isDone()) return false; } - if (walkToBlock(workFrom)) + if (!walkToSafePos(workFrom)) { return false; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java index 093c2b3ab7e..6e24ab414ff 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java @@ -23,6 +23,7 @@ import com.minecolonies.core.colony.jobs.AbstractJobCrafter; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.network.messages.client.BlockParticleEffectMessage; import com.minecolonies.core.network.messages.client.LocalizedParticleEffectMessage; @@ -145,7 +146,7 @@ protected IAIState decide() if (building.isInBuilding(worker.blockPosition()) && ColonyConstants.rand.nextInt(20) != 0) { setDelay(TICKS_20 * 20); - worker.getNavigation().moveToRandomPos(10, DEFAULT_SPEED, building.getCorners()); + EntityNavigationUtils.walkToRandomPosWithin(worker, 10, DEFAULT_SPEED, building.getCorners()); } else { @@ -160,7 +161,7 @@ protected IAIState decide() return IDLE; } - if (walkToBuilding()) + if (!walkToBuilding()) { return START_WORKING; } @@ -393,7 +394,7 @@ protected IAIState craft() return GET_RECIPE; } - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAIRequestSmelter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAIRequestSmelter.java index 6946a4cebc4..936a04b6455 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAIRequestSmelter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAIRequestSmelter.java @@ -378,7 +378,7 @@ private IAIState addFuelToFurnace() return START_WORKING; } - if (fuelPos == null || walkToBlock(fuelPos)) + if (fuelPos == null || !walkToWorkPos(fuelPos)) { return getState(); } @@ -533,7 +533,7 @@ private IAIState retrieveSmeltableFromFurnace() return START_WORKING; } - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -585,7 +585,7 @@ private IAIState retrieveUsedFuel() return START_WORKING; } - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -737,7 +737,7 @@ private IAIState fillUpFurnace() } if (toTransfer > 0) { - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -813,7 +813,7 @@ protected IAIState craft() possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getCleanedInput().get(0).getItemStack())); } - if (walkToBuilding()) + if (!walkToBuilding()) { setDelay(AbstractEntityAIBasic.STANDARD_DELAY); return getState(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIConcreteMixer.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIConcreteMixer.java index 691e7980eed..b06591ba4d2 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIConcreteMixer.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIConcreteMixer.java @@ -8,12 +8,12 @@ import com.minecolonies.api.util.Tuple; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingConcreteMixer; import com.minecolonies.core.colony.jobs.JobConcreteMixer; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.ConcretePowderBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; -import net.minecraft.core.Direction; -import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.ConcretePowderBlock; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; @@ -80,7 +80,7 @@ private IAIState placePowder() return START_WORKING; } - if (walkToBlock(posToPlace)) + if (!walkToWorkPos(posToPlace)) { return getState(); } @@ -109,7 +109,7 @@ private IAIState harvestConcrete() return START_WORKING; } - if (walkToBlock(posToMine)) + if (!walkToWorkPos(posToMine)) { return getState(); } @@ -170,7 +170,7 @@ protected IAIState decide() return performMixingWork(); } - if (walkTo == null && walkToBuilding()) + if (walkTo == null && !walkToBuilding()) { return START_WORKING; } @@ -208,7 +208,7 @@ protected IAIState craft() return GET_RECIPE; } - if (walkTo == null && walkToBuilding()) + if (walkTo == null && !walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkAlchemist.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkAlchemist.java index b1c20691774..154d3d55f77 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkAlchemist.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkAlchemist.java @@ -15,12 +15,16 @@ import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; import com.minecolonies.api.equipment.ModEquipmentTypes; import com.minecolonies.api.items.ModItems; -import com.minecolonies.api.util.*; +import com.minecolonies.api.util.InventoryUtils; +import com.minecolonies.api.util.ItemStackUtils; +import com.minecolonies.api.util.Tuple; +import com.minecolonies.api.util.WorldUtil; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingAlchemist; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobAlchemist; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.network.messages.client.BlockParticleEffectMessage; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundSource; @@ -149,7 +153,7 @@ else if (world.isEmptyBlock(randomSoil.above())) if (WorldUtil.isBlockLoaded(world, walkTo) && world.getBlockState(walkTo).getBlock() == Blocks.SOUL_SAND) { - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return HARVEST_NETHERWART; } @@ -239,7 +243,7 @@ private IAIState harvestMistleToe() if (WorldUtil.isBlockLoaded(world, walkTo) && world.getBlockState(walkTo).getBlock() instanceof LeavesBlock) { - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return HARVEST_MISTLETOE; } @@ -297,7 +301,7 @@ protected IAIState decide() if (building.isInBuilding(worker.blockPosition())) { setDelay(TICKS_20 * 20); - worker.getNavigation().moveToRandomPos(10, DEFAULT_SPEED, building.getCorners()); + EntityNavigationUtils.walkToRandomPosWithin(worker, 10, DEFAULT_SPEED, building.getCorners()); } else { @@ -307,7 +311,7 @@ protected IAIState decide() return IDLE; } - if (walkToBuilding()) + if (!walkToBuilding()) { return START_WORKING; } @@ -576,7 +580,7 @@ private IAIState addFuelToBrewingStand() return START_WORKING; } - if (fuelPos == null || walkToBlock(fuelPos)) + if (fuelPos == null || !walkToWorkPos(fuelPos)) { return getState(); } @@ -717,7 +721,7 @@ private IAIState retrieveBrewableFromBrewingStand() return START_WORKING; } - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -779,7 +783,7 @@ private IAIState retrieveUsedFuel() return START_WORKING; } - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -926,7 +930,7 @@ private IAIState fillUpBrewingStand() } if (toTransfer > 0) { - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -985,7 +989,7 @@ else if (isEmpty(((BrewingStandBlockEntity) entity).getItem(INGREDIENT_SLOT))) } if (toTransfer > 0) { - if (walkToBlock(walkTo)) + if (!walkToWorkPos(walkTo)) { return getState(); } @@ -1026,7 +1030,7 @@ else if (!(world.getBlockState(walkTo).getBlock() instanceof BrewingStandBlock)) @Override protected IAIState craft() { - if (walkToBuilding()) + if (!walkToBuilding()) { setDelay(STANDARD_DELAY); return getState(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkCrusher.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkCrusher.java index cc8ef9364a9..0033a578421 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkCrusher.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkCrusher.java @@ -6,13 +6,14 @@ import com.minecolonies.api.entity.ai.statemachine.AITarget; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.api.util.SoundUtils; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingCrusher; import com.minecolonies.core.colony.jobs.JobCrusher; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.network.messages.client.LocalizedParticleEffectMessage; import com.minecolonies.core.util.WorkerUtil; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.InteractionHand; @@ -77,7 +78,7 @@ protected IAIState decide() if (building.isInBuilding(worker.blockPosition())) { setDelay(TICKS_20 * 20); - worker.getNavigation().moveToRandomPos(10, DEFAULT_SPEED, building.getCorners()); + EntityNavigationUtils.walkToRandomPosWithin(worker, 10, DEFAULT_SPEED, building.getCorners()); } else { @@ -92,7 +93,7 @@ protected IAIState decide() return IDLE; } - if (walkToBuilding()) + if (!walkToBuilding()) { return START_WORKING; } @@ -113,7 +114,7 @@ protected IAIState decide() */ protected IAIState crush() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } @@ -208,7 +209,7 @@ protected IAIState craft() return GET_RECIPE; } - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkSifter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkSifter.java index 17987dd4562..a9692b4b9cc 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkSifter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkSifter.java @@ -12,14 +12,12 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingSifter; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobSifter; -import com.minecolonies.core.entity.ai.workers.crafting.AbstractEntityAICrafting; import com.minecolonies.core.network.messages.client.LocalizedParticleEffectMessage; import com.minecolonies.core.util.WorkerUtil; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.InteractionHand; -import net.minecraft.sounds.SoundEvents; import net.minecraft.network.chat.Component; - +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; @@ -103,7 +101,7 @@ protected IAIState sift() return IDLE; } - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java index dee2f982caa..e0b1715e773 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIStudy.java @@ -12,7 +12,6 @@ import com.minecolonies.core.datalistener.StudyItemListener; import com.minecolonies.core.datalistener.StudyItemListener.StudyItem; import com.minecolonies.core.entity.ai.workers.AbstractEntityAISkill; -import com.minecolonies.core.entity.pathfinding.navigation.PathfindingAIHelper; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.InteractionHand; @@ -107,7 +106,7 @@ private IAIState study() studyPos = building.getRandomBookShelf(); } - if (PathfindingAIHelper.walkCloseToXNearY(worker, studyPos, building.getPosition(), 7)) + if (!walkToWorkPos(studyPos)) { setDelay(WALK_DELAY); return getState(); @@ -185,7 +184,7 @@ private IAIState study() */ private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkPupil.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkPupil.java index 4d7873a7f8a..053ff62f272 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkPupil.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkPupil.java @@ -8,9 +8,10 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingSchool; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobPupil; -import com.minecolonies.core.entity.other.SittingEntity; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.other.SittingEntity; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.network.messages.client.CircleParticleEffectMessage; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; @@ -25,6 +26,7 @@ import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; import static com.minecolonies.api.research.util.ResearchConstants.TEACHING; +import static com.minecolonies.api.util.constant.Constants.DEFAULT_SPEED; import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND; import static com.minecolonies.api.util.constant.TranslationConstants.PUPIL_NO_CARPET; @@ -55,11 +57,6 @@ public class EntityAIWorkPupil extends AbstractEntityAIInteract getExpectedBuildingClass() */ private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkResearcher.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkResearcher.java index 976acb9d692..972e8aed1d1 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkResearcher.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkResearcher.java @@ -7,7 +7,6 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingUniversity; import com.minecolonies.core.colony.jobs.JobResearch; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; -import com.minecolonies.core.entity.pathfinding.navigation.PathfindingAIHelper; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import org.jetbrains.annotations.NotNull; @@ -68,7 +67,7 @@ private IAIState study() studyPos = building.getRandomBookShelf(); } - if (PathfindingAIHelper.walkCloseToXNearY(worker, studyPos, building.getPosition(), 7)) + if (!walkToWorkPos(studyPos)) { return getState(); } @@ -104,7 +103,7 @@ private IAIState study() */ private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkTeacher.java b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkTeacher.java index cb8a5237f13..522e688d1f5 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkTeacher.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/education/EntityAIWorkTeacher.java @@ -13,11 +13,11 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingSchool; import com.minecolonies.core.colony.jobs.JobPupil; import com.minecolonies.core.colony.jobs.JobTeacher; -import com.minecolonies.core.entity.other.SittingEntity; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.entity.other.SittingEntity; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -118,7 +118,7 @@ private IAIState teach() } worker.getCitizenData().setVisibleStatus(TEACHING_ICON); - if (walkToBlock(pupilToTeach.blockPosition())) + if (!walkToWorkPos(pupilToTeach.blockPosition())) { return getState(); } @@ -202,7 +202,7 @@ public Class getExpectedBuildingClass() */ private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java index 44438aa6b84..7186a04d491 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java @@ -90,7 +90,7 @@ public AbstractEntityAIFight(@NotNull final J job) */ protected IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java index 00eba35afb5..0fd9eb9f702 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIGuard.java @@ -5,7 +5,6 @@ import com.minecolonies.api.colony.IColonyManager; import com.minecolonies.api.colony.buildings.IBuilding; import com.minecolonies.api.colony.buildings.IGuardBuilding; -import com.minecolonies.api.colony.buildings.modules.ISettingsModule; import com.minecolonies.api.colony.jobs.ModJobs; import com.minecolonies.api.colony.permissions.Action; import com.minecolonies.api.colony.requestsystem.location.ILocation; @@ -22,14 +21,15 @@ import com.minecolonies.api.util.InventoryUtils; import com.minecolonies.api.util.LookHandler; import com.minecolonies.core.colony.buildings.AbstractBuildingGuards; +import com.minecolonies.core.colony.buildings.modules.BuildingModules; import com.minecolonies.core.colony.buildings.modules.EntityListModule; -import com.minecolonies.core.colony.buildings.modules.MinerLevelManagementModule; import com.minecolonies.core.colony.buildings.modules.settings.GuardTaskSetting; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingMiner; import com.minecolonies.core.colony.jobs.AbstractJobGuard; import com.minecolonies.core.entity.ai.workers.util.MinerLevel; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.entity.other.SittingEntity; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.network.messages.client.SleepingParticleMessage; import com.minecolonies.core.util.TeleportHelper; import net.minecraft.core.BlockPos; @@ -48,7 +48,8 @@ import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; import static com.minecolonies.api.research.util.ResearchConstants.*; import static com.minecolonies.api.util.constant.Constants.*; -import static com.minecolonies.api.util.constant.GuardConstants.*; +import static com.minecolonies.api.util.constant.GuardConstants.GUARD_FOLLOW_LOSE_RANGE; +import static com.minecolonies.api.util.constant.GuardConstants.GUARD_FOLLOW_TIGHT_RANGE; import static com.minecolonies.core.colony.buildings.AbstractBuildingGuards.HOSTILE_LIST; /** @@ -248,7 +249,7 @@ private IAIState wakeUpGuard() // Move into range if (BlockPosUtil.getDistanceSquared(sleepingCitizen.blockPosition(), worker.blockPosition()) > 2.25) { - worker.getNavigation().moveToLivingEntity(sleepingCitizen, 1.0); + walkToUnSafePos(sleepingCitizen.blockPosition()); } else { @@ -401,7 +402,7 @@ private IAIState flee() } } - if (walkToBuilding()) + if (!walkToBuilding()) { return GUARD_FLEE; } @@ -425,7 +426,7 @@ private IAIState guard() */ public void guardMovement() { - worker.isWorkerAtSiteWithMove(buildingGuards.getGuardPos(), GUARD_POS_RANGE); + walkToSafePos(buildingGuards.getGuardPos()); } /** @@ -441,14 +442,7 @@ private IAIState follow() return null; } - if (buildingGuards.isTightGrouping()) - { - worker.isWorkerAtSiteWithMove(buildingGuards.getPositionToFollow(), GUARD_FOLLOW_TIGHT_RANGE); - } - else - { - worker.isWorkerAtSiteWithMove(buildingGuards.getPositionToFollow(), GUARD_FOLLOW_LOSE_RANGE); - } + walkToUnSafePos(buildingGuards.getPositionToFollow(), buildingGuards.isTightGrouping() ? GUARD_FOLLOW_TIGHT_RANGE : GUARD_FOLLOW_LOSE_RANGE); return null; } @@ -466,7 +460,7 @@ protected int getActionsDoneUntilDumping() private IAIState rally(final ILocation location) { final ICitizenData citizenData = worker.getCitizenData(); - if (!worker.isWorkerAtSiteWithMove(location.getInDimensionLocation() + if (!walkToUnSafePos(location.getInDimensionLocation() .offset(randomGenerator.nextInt(GUARD_FOLLOW_TIGHT_RANGE) - GUARD_FOLLOW_TIGHT_RANGE / 2, 0, randomGenerator.nextInt(GUARD_FOLLOW_TIGHT_RANGE) - GUARD_FOLLOW_TIGHT_RANGE / 2), @@ -507,20 +501,21 @@ public IAIState patrol() { if (buildingGuards.requiresManualTarget()) { - if (currentPatrolPoint == null || worker.isWorkerAtSiteWithMove(currentPatrolPoint, 3)) + if (currentPatrolPoint == null || walkToSafePos(currentPatrolPoint)) { - if (worker.getRandom().nextInt(5) <= 1) - { - currentPatrolPoint = buildingGuards.getColony().getBuildingManager().getRandomBuilding(b -> true); - } - else + currentPatrolPoint = null; + if (!EntityNavigationUtils.walkToRandomPos(worker, 20, 1.0)) { - currentPatrolPoint = findRandomPositionToWalkTo(20); + return getState(); } - if (currentPatrolPoint != null) + if (worker.getRandom().nextInt(5) <= 1) { - setNextPatrolTarget(currentPatrolPoint); + currentPatrolPoint = buildingGuards.getColony().getBuildingManager().getRandomBuilding(b -> true); + if (currentPatrolPoint != null) + { + walkToSafePos(currentPatrolPoint); + } } } } @@ -531,7 +526,7 @@ public IAIState patrol() currentPatrolPoint = buildingGuards.getNextPatrolTarget(false); } - if (currentPatrolPoint != null && (worker.isWorkerAtSiteWithMove(currentPatrolPoint, 3))) + if (currentPatrolPoint != null && (walkToSafePos(currentPatrolPoint))) { buildingGuards.arrivedAtPatrolPoint(worker); } @@ -550,7 +545,7 @@ public IAIState patrolMine() { return PREPARING; } - if (currentPatrolPoint == null || worker.isWorkerAtSiteWithMove(currentPatrolPoint, 2)) + if (currentPatrolPoint == null || walkToSafePos(currentPatrolPoint)) { final IBuilding building = buildingGuards.getColony().getBuildingManager().getBuilding(buildingGuards.getMinePos()); if (building != null) @@ -558,7 +553,7 @@ public IAIState patrolMine() if (building instanceof BuildingMiner) { final BuildingMiner buildingMiner = (BuildingMiner) building; - final MinerLevel level = buildingMiner.getFirstModuleOccurance(MinerLevelManagementModule.class).getCurrentLevel(); + final MinerLevel level = buildingMiner.getModule(BuildingModules.MINER_LEVELS).getCurrentLevel(); if (level == null) { setNextPatrolTarget(buildingMiner.getPosition()); @@ -570,12 +565,12 @@ public IAIState patrolMine() } else { - buildingGuards.getFirstModuleOccurance(ISettingsModule.class).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL); + buildingGuards.getModule(BuildingModules.GUARD_SETTINGS).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL); } } else { - buildingGuards.getFirstModuleOccurance(ISettingsModule.class).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL); + buildingGuards.getModule(BuildingModules.GUARD_SETTINGS).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL); } } return null; diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/DruidCombatAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/DruidCombatAI.java index 511bce9c548..5a1f6f72a73 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/DruidCombatAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/DruidCombatAI.java @@ -2,12 +2,9 @@ import com.google.common.collect.ImmutableList; import com.minecolonies.api.colony.guardtype.registry.ModGuardTypes; +import com.minecolonies.api.entity.ai.combat.threat.IThreatTableEntity; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine; import com.minecolonies.api.entity.citizen.Skill; -import com.minecolonies.api.entity.ai.combat.threat.IThreatTableEntity; -import com.minecolonies.core.entity.pathfinding.PathfindingUtils; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; -import com.minecolonies.core.entity.pathfinding.PathingOptions; import com.minecolonies.api.items.ModItems; import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.InventoryUtils; @@ -15,11 +12,17 @@ import com.minecolonies.core.colony.buildings.modules.settings.GuardTaskSetting; import com.minecolonies.core.colony.jobs.AbstractJobGuard; import com.minecolonies.core.colony.jobs.JobDruid; -import com.minecolonies.core.entity.other.DruidPotionEntity; import com.minecolonies.core.entity.ai.combat.AttackMoveAI; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.other.DruidPotionEntity; +import com.minecolonies.core.entity.pathfinding.PathfindingUtils; +import com.minecolonies.core.entity.pathfinding.PathingOptions; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.entity.pathfinding.navigation.MinecoloniesAdvancedPathNavigate; -import com.minecolonies.core.entity.pathfinding.pathjobs.*; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobCanSee; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveToLocation; +import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.Holder; import net.minecraft.core.component.DataComponents; import net.minecraft.world.InteractionHand; @@ -117,7 +120,7 @@ protected void doAttack(final LivingEntity target) if (user.getRandom().nextInt(FLEE_CHANCE) == 0 && !((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getTask().equals(GuardTaskSetting.GUARD)) { - user.getNavigation().moveAwayFromLivingEntity(target, getAttackDistance() / 2.0, getCombatMovementSpeed()); + EntityNavigationUtils.walkAwayFrom(user, target.blockPosition(), (int) (getAttackDistance() / 2.0), getCombatMovementSpeed()); } } else diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIDruid.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIDruid.java index 2c84251e2ae..49f9606adbe 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIDruid.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIDruid.java @@ -1,6 +1,7 @@ package com.minecolonies.core.entity.ai.workers.guard; import com.minecolonies.api.items.ModItems; +import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.InventoryUtils; import com.minecolonies.core.colony.buildings.AbstractBuildingGuards; import com.minecolonies.core.colony.jobs.JobDruid; @@ -67,16 +68,17 @@ public void guardMovement() { if (worker.getRandom().nextInt(3) < 1) { - worker.isWorkerAtSiteWithMove(buildingGuards.getGuardPos(), 3); + walkToSafePos(buildingGuards.getGuardPos()); return; } - if (worker.isWorkerAtSiteWithMove(buildingGuards.getGuardPos(), 10) || Math.abs(buildingGuards.getGuardPos().getY() - worker.blockPosition().getY()) > 3) + if ((BlockPosUtil.dist(buildingGuards.getGuardPos(), worker.blockPosition()) <= 10 || walkToSafePos(buildingGuards.getGuardPos())) + || Math.abs(buildingGuards.getGuardPos().getY() - worker.blockPosition().getY()) > 3) { // Moves the druid randomly to close edges, for better vision to mobs ((MinecoloniesAdvancedPathNavigate) worker.getNavigation()).setPathJob(new PathJobWalkRandomEdge(world, buildingGuards.getGuardPos(), 20, worker), - null, - 1.0, true); + null, + 1.0, true); } } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIRanger.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIRanger.java index 1b0039eeeb6..3011b57aff8 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIRanger.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/EntityAIRanger.java @@ -1,6 +1,7 @@ package com.minecolonies.core.entity.ai.workers.guard; import com.minecolonies.api.equipment.ModEquipmentTypes; +import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.InventoryUtils; import com.minecolonies.core.colony.buildings.AbstractBuildingGuards; import com.minecolonies.core.colony.jobs.JobRanger; @@ -66,11 +67,12 @@ public void guardMovement() { if (worker.getRandom().nextInt(3) < 1) { - worker.isWorkerAtSiteWithMove(buildingGuards.getGuardPos(), 3); + walkToSafePos(buildingGuards.getGuardPos()); return; } - if (worker.isWorkerAtSiteWithMove(buildingGuards.getGuardPos(), 10) || Math.abs(buildingGuards.getGuardPos().getY() - worker.blockPosition().getY()) > 3) + if ((BlockPosUtil.dist(buildingGuards.getGuardPos(), worker.blockPosition()) <= 10 || walkToSafePos(buildingGuards.getGuardPos())) + || Math.abs(buildingGuards.getGuardPos().getY() - worker.blockPosition().getY()) > 3) { // Moves the ranger randomly to close edges, for better vision to mobs ((MinecoloniesAdvancedPathNavigate) worker.getNavigation()).setPathJob(new PathJobWalkRandomEdge(world, buildingGuards.getGuardPos(), 20, worker), diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java index 4efb9fea24d..bba0bbe07c8 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java @@ -11,14 +11,15 @@ import com.minecolonies.api.equipment.ModEquipmentTypes; import com.minecolonies.api.util.*; import com.minecolonies.api.util.constant.ColonyConstants; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.MineColonies; import com.minecolonies.core.colony.jobs.AbstractJobGuard; import com.minecolonies.core.entity.ai.combat.AttackMoveAI; import com.minecolonies.core.entity.ai.combat.CombatUtils; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; +import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.component.DataComponents; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.chat.contents.TranslatableContents; @@ -298,7 +299,8 @@ protected int getAttackDelay() @Override protected PathResult moveInAttackPosition(final LivingEntity target) { - return user.getNavigation().moveToXYZ(target.getX(), target.getY(), target.getZ(), getCombatMovementSpeed()); + EntityNavigationUtils.walkToPos(user, target.blockPosition(), (int) getAttackDistance(), false, getCombatMovementSpeed()); + return user.getNavigation().getPathResult(); } /** diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java index 54dde8a99ae..deed0e893d3 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java @@ -17,6 +17,7 @@ import com.minecolonies.core.entity.other.CustomArrowEntity; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.PathingOptions; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.entity.pathfinding.navigation.MinecoloniesAdvancedPathNavigate; import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobCanSee; import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation; @@ -142,7 +143,7 @@ protected void doAttack(final LivingEntity target) if (user.getRandom().nextInt(FLEE_CHANCE) == 0 && !((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getTask().equals(GuardTaskSetting.GUARD)) { - user.getNavigation().moveAwayFromLivingEntity(target, getAttackDistance() / 2.0, getCombatMovementSpeed()); + EntityNavigationUtils.walkAwayFrom(user, target.blockPosition(), (int) (getAttackDistance() / 2.0), getCombatMovementSpeed()); } } else diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/AbstractEntityAITraining.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/AbstractEntityAITraining.java index a68094698f1..d21d8042f4b 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/AbstractEntityAITraining.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/AbstractEntityAITraining.java @@ -5,6 +5,7 @@ import com.minecolonies.core.colony.buildings.AbstractBuilding; import com.minecolonies.core.colony.jobs.AbstractJob; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import net.minecraft.core.BlockPos; import org.jetbrains.annotations.NotNull; @@ -93,19 +94,12 @@ public IAIState decide() */ private IAIState wander() { - if (currentPathingTarget == null) + if (!EntityNavigationUtils.walkToRandomPosWithin(worker, 20, 0.6, building.getCorners())) { - currentPathingTarget = getWanderPosition(); return getState(); } - if (!walkToBlock(currentPathingTarget)) - { - currentPathingTarget = null; - return DECIDE; - } - - return TRAINING_WANDER; + return DECIDE; } /** @@ -115,34 +109,13 @@ private IAIState wander() */ private IAIState pathToTarget() { - if (walkToBlock(currentPathingTarget, 2)) + if (!walkToWorkPos(currentPathingTarget)) { return getState(); } return stateAfterPathing; } - /** - * Get a wander position within the archer training camp to walk to. - * - * @return the position or the location of the hut chest if not found. - */ - private BlockPos getWanderPosition() - { - final BlockPos pos = findRandomPositionToWalkTo(20); - if (pos == null) - { - return null; - } - - if (building.isInBuilding(pos)) - { - return pos; - } - - return building.getPosition(); - } - /** * Reduces the attack delay by the given Tickrate */ diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAICombatTraining.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAICombatTraining.java index 4e98efbe600..bcf5fb04d47 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAICombatTraining.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAICombatTraining.java @@ -10,12 +10,13 @@ import com.minecolonies.api.util.SoundUtils; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingCombatAcademy; import com.minecolonies.core.colony.jobs.JobCombatTraining; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.util.WorkerUtil; -import net.minecraft.world.item.Items; -import net.minecraft.world.InteractionHand; -import net.minecraft.sounds.SoundEvents; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.Items; import org.jetbrains.annotations.NotNull; import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; @@ -145,7 +146,7 @@ private IAIState trainWithPartner() return COMBAT_TRAINING; } - if (BlockPosUtil.getDistance2D(worker.blockPosition(), trainingPartner.blockPosition()) > MIN_DISTANCE_TO_TRAIN && walkToBlock(trainingPartner.blockPosition())) + if (BlockPosUtil.getDistance2D(worker.blockPosition(), trainingPartner.blockPosition()) > MIN_DISTANCE_TO_TRAIN && !walkToWorkPos(trainingPartner.blockPosition())) { return KNIGHT_TRAIN_WITH_PARTNER; } @@ -198,7 +199,7 @@ private IAIState attack() trainingPartner.hurt(world.damageSources().source(DamageSourceKeys.TRAINING, worker), 0.0F); CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); } - worker.getNavigation().moveAwayFromXYZ(trainingPartner.blockPosition(), 4.0, 1.0, true); + EntityNavigationUtils.walkAwayFrom(worker, trainingPartner.blockPosition(), 4, 1.0); targetCounter++; if (targetCounter > building.getBuildingLevel() * ACTIONS_PER_BUILDING_LEVEL) diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIQuarrier.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIQuarrier.java index 7dd60a42ff1..d617352732f 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIQuarrier.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIQuarrier.java @@ -16,7 +16,6 @@ import com.minecolonies.api.entity.ai.statemachine.AITarget; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; -import com.minecolonies.core.entity.ai.workers.util.LayerBlueprintIterator; import com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding; import com.minecolonies.api.util.*; import com.minecolonies.core.colony.buildings.AbstractBuildingStructureBuilder; @@ -27,7 +26,9 @@ import com.minecolonies.core.colony.workorders.WorkOrderMiner; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIStructureWithWorkOrder; import com.minecolonies.core.entity.ai.workers.util.BuildingStructureHandler; +import com.minecolonies.core.entity.ai.workers.util.LayerBlueprintIterator; import com.minecolonies.core.entity.ai.workers.util.WorkerLoadOnlyStructureHandler; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; @@ -125,7 +126,7 @@ private IAIState startWorkingAtOwnBuilding() return IDLE; } - if (walkToBlock(quarry.getPosition())) + if (!walkToBuilding(quarry)) { return getState(); } @@ -666,35 +667,29 @@ public boolean walkToConstructionSite(final BlockPos currentBlock) { if (workFrom == null) { - workFrom = findRandomPositionToWalkTo(5, currentBlock); - if (workFrom == null && pathBackupFactor > 10) + if (EntityNavigationUtils.walkToRandomPosAround(worker, currentBlock, 5, 1.0)) { workFrom = worker.blockPosition(); } return false; } - if (BlockPosUtil.getDistance(worker.blockPosition(), currentBlock) <= 5 + 5 * pathBackupFactor) + if (BlockPosUtil.getDistance(worker.blockPosition(), currentBlock) <= 5 + 5) { return true; } - if (walkToBlock(workFrom)) + if (!walkToSafePos(workFrom)) { return false; } - if (BlockPosUtil.getDistance(worker.blockPosition(), currentBlock) > 5 + 5 * pathBackupFactor) + if (BlockPosUtil.getDistance(worker.blockPosition(), currentBlock) > 5 + 5) { workFrom = null; return false; } - if (pathBackupFactor > 1) - { - pathBackupFactor--; - } - return true; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIStructureMiner.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIStructureMiner.java index 1cc1a7647b3..cb763ef9556 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIStructureMiner.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIStructureMiner.java @@ -48,6 +48,8 @@ import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; import static com.minecolonies.api.research.util.ResearchConstants.MORE_ORES; +import static com.minecolonies.api.util.constant.CitizenConstants.MIN_WORKING_RANGE; +import static com.minecolonies.api.util.constant.CitizenConstants.STANDARD_WORKING_RANGE; import static com.minecolonies.api.util.constant.Constants.ONE_HUNDRED_PERCENT; import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND; import static com.minecolonies.api.util.constant.StatisticsConstants.*; @@ -176,7 +178,7 @@ public Class getExpectedBuildingClass() private IAIState startWorkingAtOwnBuilding() { worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING); - if ((building.getLadderLocation() == null || worker.getY() >= building.getPosition().getY()) && walkToBuilding()) + if ((building.getLadderLocation() == null || worker.getY() >= building.getPosition().getY()) && !walkToBuilding()) { return START_WORKING; } @@ -311,7 +313,7 @@ private BlockPos getSurroundingOreOrDefault(final BlockPos pos) @NotNull private IAIState goToLadder() { - if (walkToLadder()) + if (!walkToLadder()) { return MINER_WALKING_TO_LADDER; } @@ -320,7 +322,18 @@ private IAIState goToLadder() private boolean walkToLadder() { - return walkToBlock(building.getLadderLocation()); + return walkToWorkPos(building.getLadderLocation()); + } + + public boolean walkToConstructionSite(final BlockPos currentBlock) + { + if (workFrom == null) + { + workFrom = getWorkingPosition(currentBlock); + } + + //The miner shouldn't search for a save position. Just let him build from where he currently is. + return walkWithProxy(workFrom, STANDARD_WORKING_RANGE) || MathUtils.twoDimDistance(worker.blockPosition(), workFrom) < MIN_WORKING_RANGE; } @NotNull @@ -630,7 +643,7 @@ private BlockPos getNextBlockInShaftToMine() @NotNull private IAIState doShaftBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return MINER_BUILDING_SHAFT; } @@ -733,7 +746,7 @@ else if (vectorZ == 1) return MINER_MINING_SHAFT; } - if ((workingNode.getStatus() == MineNode.NodeStatus.AVAILABLE || workingNode.getStatus() == MineNode.NodeStatus.IN_PROGRESS) && !walkToBlock(standingPosition)) + if ((workingNode.getStatus() == MineNode.NodeStatus.AVAILABLE || workingNode.getStatus() == MineNode.NodeStatus.IN_PROGRESS) && !walkWithProxy(standingPosition)) { workingNode.setRotationMirror(rotMir); return executeStructurePlacement(workingNode, standingPosition); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java index 038afe821a7..e296026ca2e 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java @@ -5,8 +5,8 @@ import com.minecolonies.api.entity.ai.statemachine.AITarget; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; -import com.minecolonies.api.items.ModTags; import com.minecolonies.api.equipment.ModEquipmentTypes; +import com.minecolonies.api.items.ModTags; import com.minecolonies.api.util.*; import com.minecolonies.api.util.constant.ColonyConstants; import com.minecolonies.api.util.constant.Constants; @@ -17,13 +17,13 @@ import com.minecolonies.core.colony.jobs.JobLumberjack; import com.minecolonies.core.entity.ai.workers.crafting.AbstractEntityAICrafting; import com.minecolonies.core.entity.ai.workers.util.Tree; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.navigation.MinecoloniesAdvancedPathNavigate; import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveToWithPassable; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.core.entity.pathfinding.pathresults.TreePathResult; import com.minecolonies.core.util.WorkerUtil; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; @@ -222,7 +222,7 @@ protected IAIState decide() return getState(); } - if (walkToBuilding()) + if (!walkToBuilding()) { return START_WORKING; } @@ -267,7 +267,7 @@ private boolean isStackLog(@Nullable final ItemStack stack) */ private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } @@ -392,7 +392,7 @@ private IAIState findTree() final BlockPos endPos = building.getEndRestriction(); pathResult = worker.getNavigation() - .moveToTree(startPos, + .walkToTree(startPos, endPos, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), @@ -402,7 +402,7 @@ private IAIState findTree() else { pathResult = worker.getNavigation() - .moveToTree(SEARCH_RANGE + searchIncrement, + .walkToTree(SEARCH_RANGE + searchIncrement, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), @@ -852,7 +852,7 @@ private boolean plantSapling(@NotNull final BlockPos location) worker.swing(worker.getUsedItemHand()); } - if (timeWaited >= MAX_WAITING_TIME / 2 && !checkedInHut && !walkToBuilding()) + if (timeWaited >= MAX_WAITING_TIME / 2 && !checkedInHut && walkToBuilding()) { checkAndTransferFromHut(job.getTree().getSapling()); checkedInHut = true; diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java index 78536e856fc..ad577d8f57a 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java @@ -23,9 +23,9 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingNetherWorker; import com.minecolonies.core.colony.jobs.JobNetherWorker; import com.minecolonies.core.entity.ai.workers.crafting.AbstractEntityAICrafting; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.items.ItemAdventureToken; import com.minecolonies.core.util.TeleportHelper; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; @@ -308,7 +308,7 @@ protected IAIState decide() setDelay(120); return IDLE; } - if (walkTo != null || walkToBuilding()) + if (walkTo != null || !walkToBuilding()) { return getState(); } @@ -379,7 +379,7 @@ protected IAIState leaveForNether() final BlockState block = world.getBlockState(portal); if (block.is(Blocks.NETHER_PORTAL)) { - if (walkToBlock(portal, 1)) + if (!walkToWorkPos(portal)) { return getState(); } @@ -417,7 +417,7 @@ protected IAIState stayInNether() { //Ensure we stay put in the portal final BlockPos portal = building.getPortalLocation(); - if (portal != null && walkToBlock(portal, 1)) + if (portal != null && !walkToWorkPos(portal)) { return getState(); } @@ -680,7 +680,7 @@ protected IAIState returnFromNether() return NETHER_CLOSEPORTAL; } - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } @@ -701,7 +701,7 @@ protected IAIState openPortal() final BlockPos portal = building.getPortalLocation(); if (portal != null && currentRecipeStorage != null) { - if (walkToBlock(portal, 1)) + if (!walkToWorkPos(portal)) { return getState(); } @@ -735,7 +735,7 @@ protected IAIState closePortal() if (block.is(Blocks.NETHER_PORTAL)) { - if (walkToBlock(portal, 1)) + if (!walkToWorkPos(portal)) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkBeekeeper.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkBeekeeper.java index bb8acd292de..380b94a01cc 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkBeekeeper.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkBeekeeper.java @@ -181,7 +181,7 @@ private IAIState prepareForHerding() */ private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { setDelay(2); return getState(); @@ -349,7 +349,7 @@ private IAIState harvestHoney() building.removeHive(hive); return PREPARING; } - if (walkToBlock(hive)) + if (!walkToWorkPos(hive)) { return getState(); } @@ -404,17 +404,17 @@ else if (!building.getHarvestTypes().equals(BuildingBeekeeper.HONEYCOMB) && item * Lets the herder walk to the animal. * * @param animal the animal to walk to. - * @return true if the herder is walking to the animal. + * @return false if the herder is walking to the animal. */ public boolean walkingToAnimal(final Animal animal) { if (animal != null) { - return walkToBlock(animal.blockPosition()); + return walkToWorkPos(animal.blockPosition()); } else { - return false; + return true; } } @@ -473,7 +473,7 @@ private void breedTwoAnimals(final Animal animalOne, final Animal animalTwo) for (final Animal animal : animalsToBreed) { - if (!animal.isInLove() && !walkingToAnimal(animal)) + if (!animal.isInLove() && walkingToAnimal(animal)) { animal.setInLove(null); worker.swing(InteractionHand.MAIN_HAND); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java index a682e335406..a43cb5020d6 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java @@ -17,8 +17,8 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingComposter; import com.minecolonies.core.colony.jobs.JobComposter; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.tileentities.TileEntityBarrel; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; @@ -135,7 +135,7 @@ private IAIState accelerateBarrels() */ private IAIState getMaterials() { - if (walkToBuilding()) + if (!walkToBuilding()) { setDelay(2); return getState(); @@ -201,7 +201,7 @@ private IAIState decideWhatToDo() { worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING); - if (walkToBuilding()) + if (!walkToBuilding()) { setDelay(2); return getState(); @@ -264,7 +264,7 @@ private IAIState fillBarrels() return GET_MATERIALS; } } - if (walkToBlock(currentTarget)) + if (!walkToWorkPos(currentTarget)) { setDelay(2); return getState(); @@ -295,7 +295,7 @@ private IAIState fillBarrels() private IAIState harvestBarrels() { - if (walkToBlock(currentTarget)) + if (!walkToWorkPos(currentTarget)) { setDelay(2); return getState(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java index 8d697967c2f..37ab03467d5 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java @@ -28,10 +28,10 @@ import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobFarmer; import com.minecolonies.core.entity.ai.workers.crafting.AbstractEntityAICrafting; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.items.ItemCrop; import com.minecolonies.core.network.messages.client.CompostParticleMessage; import com.minecolonies.core.util.AdvancementUtils; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; @@ -64,8 +64,8 @@ import static com.minecolonies.api.util.constant.CitizenConstants.BLOCK_BREAK_SOUND_RANGE; import static com.minecolonies.api.util.constant.Constants.STACKSIZE; import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND; -import static com.minecolonies.api.util.constant.StatisticsConstants.*; import static com.minecolonies.api.util.constant.EquipmentLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD; +import static com.minecolonies.api.util.constant.StatisticsConstants.*; import static com.minecolonies.api.util.constant.TranslationConstants.NO_FREE_FIELDS; import static com.minecolonies.core.colony.buildings.modules.BuildingModules.STATS_MODULE; @@ -336,7 +336,7 @@ private IAIState canGoPlanting(@NotNull final FarmField farmField) return FARMER_PLANT; } - if (walkToBuilding()) + if (!walkToBuilding()) { return PREPARING; } @@ -518,7 +518,7 @@ private IAIState workAtField() final BlockPos position = farmField.getPosition().below().south(workingOffset.getZ()).east(workingOffset.getX()); // Still moving to the block - if (walkToBlock(position.above())) + if (!walkToSafePos(position.above())) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java index 3214079b48e..37be27c25d6 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java @@ -14,13 +14,14 @@ import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobFisherman; import com.minecolonies.core.entity.ai.workers.AbstractEntityAISkill; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; +import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.entity.other.NewBobberEntity; import com.minecolonies.core.entity.pathfinding.Pathfinding; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobFindWater; import com.minecolonies.core.entity.pathfinding.pathresults.WaterPathResult; import com.minecolonies.core.util.WorkerUtil; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; @@ -180,7 +181,7 @@ public Class getExpectedBuildingClass() */ private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } @@ -272,7 +273,7 @@ private IAIState getToWater() return FISHERMAN_SEARCHING_WATER; } - if (walkToWater()) + if (!walkToWater()) { return getState(); } @@ -286,7 +287,7 @@ private IAIState getToWater() */ private boolean walkToWater() { - return job.getWater() != null && walkToBlock(job.getWater().getB()); + return job.getWater() != null && walkToSafePos(job.getWater().getB()); } /** diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFlorist.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFlorist.java index 893bba8bd8c..7c22ab16e02 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFlorist.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFlorist.java @@ -153,7 +153,7 @@ private IAIState decide() worker.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); final long distance = BlockPosUtil.getDistance2D(worker.blockPosition(), building.getPosition()); - if (distance > MAX_DISTANCE && walkToBuilding()) + if (distance > MAX_DISTANCE && !walkToBuilding()) { return DECIDE; } @@ -209,7 +209,7 @@ private IAIState compost() worker.getCitizenData().setVisibleStatus(GARDENING); - if (walkToBlock(compostPosition)) + if (!walkToWorkPos(compostPosition)) { return getState(); } @@ -251,7 +251,7 @@ private IAIState harvest() worker.getCitizenData().setVisibleStatus(GARDENING); - if (walkToBlock(harvestPosition)) + if (!walkToWorkPos(harvestPosition)) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkPlanter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkPlanter.java index ca15bff21b8..49b9ed57b4c 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkPlanter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkPlanter.java @@ -14,7 +14,6 @@ import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; import com.minecolonies.api.util.InventoryUtils; import com.minecolonies.api.util.Tuple; -import com.minecolonies.api.util.constant.CitizenConstants; import com.minecolonies.api.util.constant.TypeConstants; import com.minecolonies.api.util.constant.translation.RequestSystemTranslationConstants; import com.minecolonies.core.colony.buildings.modules.FieldsModule; @@ -166,7 +165,7 @@ private IAIState moveToField() return PLANTATION_PICK_FIELD; } - if (walkToBlock(currentPlantationField.getPosition(), CitizenConstants.DEFAULT_RANGE_FOR_DELAY)) + if (!walkToSafePos(currentPlantationField.getPosition())) { return getState(); } @@ -208,7 +207,7 @@ private IAIState decideFieldWork() private IAIState workField() { IPlantationModule planterModule = activeModuleResult.getModule(); - if (!Objects.isNull(activeModuleResult.getActionPosition()) && walkToBlock(planterModule.getPositionToWalkTo(world, activeModuleResult.getActionPosition()))) + if (!Objects.isNull(activeModuleResult.getActionPosition()) && !walkToSafePos(planterModule.getPositionToWalkTo(world, activeModuleResult.getActionPosition()))) { return PLANTATION_WORK_FIELD; } @@ -263,7 +262,7 @@ else if (handlerResult.equals(ActionHandlerResult.NEEDS_ITEM)) */ private IAIState returnToBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/AbstractEntityAIHerder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/AbstractEntityAIHerder.java index f8301e46309..5451bcfd9ea 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/AbstractEntityAIHerder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/AbstractEntityAIHerder.java @@ -34,8 +34,8 @@ import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*; import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND; -import static com.minecolonies.api.util.constant.StatisticsConstants.ITEM_USED; import static com.minecolonies.api.util.constant.EquipmentLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD; +import static com.minecolonies.api.util.constant.StatisticsConstants.ITEM_USED; import static com.minecolonies.core.colony.buildings.modules.BuildingModules.STATS_MODULE; /** @@ -281,7 +281,7 @@ protected boolean canBreedChildren() */ private IAIState startWorkingAtOwnBuilding() { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } @@ -568,7 +568,7 @@ private IAIState pickupItems() { final List items = searchForItemsInArea(); - if (!items.isEmpty() && walkToBlock(items.get(0).blockPosition(), 1)) + if (!items.isEmpty() && walkWithProxy(items.get(0).blockPosition(), 1)) { return getState(); } @@ -614,11 +614,11 @@ public boolean walkingToAnimal(final Animal animal) { if (animal != null) { - return walkToBlock(animal.blockPosition()); + return walkToWorkPos(animal.blockPosition()); } else { - return false; + return true; } } @@ -636,7 +636,7 @@ private boolean breedTwoAnimals() { it.remove(); } - else if (walkingToAnimal(animal)) + else if (!walkingToAnimal(animal)) { break; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkCowboy.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkCowboy.java index 3827d6ecafb..b6348165907 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkCowboy.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkCowboy.java @@ -146,7 +146,7 @@ private IAIState milkCows() if (!worker.getCitizenInventoryHandler().hasItemInInventory(building.getMilkInputItem().getItem())) { if (InventoryUtils.hasBuildingEnoughElseCount(building, new ItemStorage(building.getMilkInputItem()), 1) > 0 - && !walkToBuilding()) + && walkToBuilding()) { checkAndTransferFromHut(building.getMilkInputItem()); } @@ -196,7 +196,7 @@ private IAIState milkMooshrooms() if (!worker.getCitizenInventoryHandler().hasItemInInventory(Items.BOWL)) { if (InventoryUtils.hasBuildingEnoughElseCount(building, new ItemStorage(new ItemStack(Items.BOWL, 1)), 1) > 0 - && !walkToBuilding()) + && walkToBuilding()) { checkAndTransferFromHut(new ItemStack(Items.BOWL, 1)); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkCook.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkCook.java index cf750142182..6037e807dc6 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkCook.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkCook.java @@ -179,7 +179,7 @@ private IAIState serveFoodToCitizen() return getState(); } - if (walkToBlock(citizenToServe.peek().blockPosition())) + if (!walkToWorkPos(citizenToServe.peek().blockPosition())) { return getState(); } @@ -264,7 +264,7 @@ private IAIState serveFoodToPlayer() return START_WORKING; } - if (walkToBlock(playerToServe.peek().blockPosition())) + if (!walkToWorkPos(playerToServe.peek().blockPosition())) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java index c9e902e5ca6..7c0a33198ef 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java @@ -12,10 +12,6 @@ import com.minecolonies.api.entity.ai.statemachine.AITarget; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; -import com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; -import com.minecolonies.core.tileentities.TileEntityColonyBuilding; -import com.minecolonies.core.tileentities.TileEntityRack; import com.minecolonies.api.util.InventoryUtils; import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.api.util.Log; @@ -29,6 +25,9 @@ import com.minecolonies.core.colony.requestsystem.requests.StandardRequests.DeliveryRequest; import com.minecolonies.core.colony.requestsystem.requests.StandardRequests.PickupRequest; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.tileentities.TileEntityColonyBuilding; +import com.minecolonies.core.tileentities.TileEntityRack; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -160,11 +159,6 @@ private IAIState pickup() worker.getCitizenData().setVisibleStatus(DELIVERING); final BlockPos pickupTarget = currentTask.getRequester().getLocation().getInDimensionLocation(); - if (pickupTarget != BlockPos.ZERO && !worker.isWorkerAtSiteWithMove(pickupTarget, MIN_DISTANCE_TO_WAREHOUSE)) - { - return PICKUP; - } - final IBuilding pickupBuilding = building.getColony().getBuildingManager().getBuilding(pickupTarget); if (pickupBuilding == null) { @@ -172,6 +166,11 @@ private IAIState pickup() return START_WORKING; } + if (!walkToBuilding(pickupBuilding)) + { + return PICKUP; + } + if (pickupFromBuilding(pickupBuilding)) { this.alreadyKept = new ArrayList<>(); @@ -297,7 +296,7 @@ private IAIState dump() return START_WORKING; } - if (!worker.isWorkerAtSiteWithMove(warehouse.getPosition(), MIN_DISTANCE_TO_WAREHOUSE)) + if (!walkToBuilding(warehouse)) { setDelay(WALK_DELAY); return DUMPING; @@ -345,22 +344,18 @@ private IAIState deliver() return START_WORKING; } - if (!worker.isWorkerAtSiteWithMove(targetBuildingLocation.getInDimensionLocation(), MIN_DISTANCE_TO_WAREHOUSE)) - { - setDelay(WALK_DELAY); - return DELIVERY; - } - - final BlockEntity tileEntity = world.getBlockEntity(targetBuildingLocation.getInDimensionLocation()); - - if (!(tileEntity instanceof TileEntityColonyBuilding) || ((AbstractTileEntityColonyBuilding) tileEntity).getBuilding() == null) + final IBuilding targetBuilding = worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(targetBuildingLocation.getInDimensionLocation()); + if (targetBuilding == null) { - // TODO: Non-Colony deliveries are unsupported yet. Fix that at some point in time. job.finishRequest(true); return START_WORKING; } - final IBuilding targetBuilding = ((AbstractTileEntityColonyBuilding) tileEntity).getBuilding(); + if (!walkToBuilding(targetBuilding)) + { + setDelay(WALK_DELAY); + return DELIVERY; + } boolean success = true; boolean extracted = false; @@ -522,7 +517,7 @@ private IAIState prepareDelivery() return START_WORKING; } - if (walkToBlock(location.getInDimensionLocation())) + if (!walkToSafePos(location.getInDimensionLocation())) { return PREPARE_DELIVERY; } @@ -598,7 +593,7 @@ private IAIState decide() if (currentTask == null) { // If there are no deliveries/pickups pending, just loiter around the warehouse. - if (!worker.isWorkerAtSiteWithMove(getAndCheckWareHouse().getPosition(), MIN_DISTANCE_TO_WAREHOUSE)) + if (!walkToBuilding(getAndCheckWareHouse())) { setDelay(WALK_DELAY); return START_WORKING; diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkEnchanter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkEnchanter.java index 7d79daf17aa..af20e779c3e 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkEnchanter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkEnchanter.java @@ -2,6 +2,7 @@ import com.minecolonies.api.colony.ICitizenData; import com.minecolonies.api.colony.IColonyManager; +import com.minecolonies.api.colony.buildings.IBuilding; import com.minecolonies.api.colony.interactionhandling.ChatPriority; import com.minecolonies.api.colony.requestsystem.token.IToken; import com.minecolonies.api.crafting.IRecipeStorage; @@ -11,7 +12,7 @@ import com.minecolonies.api.entity.citizen.Skill; import com.minecolonies.api.items.ModItems; import com.minecolonies.api.util.*; -import com.minecolonies.core.colony.buildings.AbstractBuilding; +import com.minecolonies.core.colony.buildings.modules.BuildingModules; import com.minecolonies.core.colony.buildings.modules.EnchanterStationsModule; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingEnchanter; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; @@ -21,19 +22,19 @@ import com.minecolonies.core.network.messages.client.StreamParticleEffectMessage; import com.minecolonies.core.util.WorkerUtil; import it.unimi.dsi.fastutil.objects.Object2IntMap; +import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.component.DataComponents; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.world.InteractionHand; -import net.minecraft.core.BlockPos; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.ItemEnchantments; import net.minecraft.world.phys.Vec3; -import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -119,7 +120,7 @@ public EntityAIWorkEnchanter(@NotNull final JobEnchanter job) protected IAIState decide() { worker.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); - if (walkToBuilding()) + if (!walkToBuilding()) { return START_WORKING; } @@ -139,7 +140,7 @@ protected IAIState decide() if (getPrimarySkillLevel() < building.getBuildingLevel() * MANA_REQ_PER_LEVEL) { final BuildingEnchanter enchanterBuilding = building; - final EnchanterStationsModule module = enchanterBuilding.getFirstModuleOccurance(EnchanterStationsModule.class); + final EnchanterStationsModule module = enchanterBuilding.getModule(BuildingModules.ENCHANTER_STATIONS); if (module.getBuildingsToGatherFrom().isEmpty()) { if (worker.getCitizenData() != null) @@ -294,13 +295,12 @@ private IAIState gatherAndDrain() return IDLE; } - if (walkToBlock(job.getPosToDrainFrom())) + final IBuilding buildingWorker = building.getColony().getBuildingManager().getBuilding(job.getPosToDrainFrom()); + if (!walkToBuilding(buildingWorker)) { return getState(); } - final AbstractBuilding buildingWorker = building.getColony().getBuildingManager().getBuilding(job.getPosToDrainFrom(), AbstractBuilding.class); - if (buildingWorker == null) { resetDraining(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkHealer.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkHealer.java index 3eeacf32964..950e6235bd8 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkHealer.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkHealer.java @@ -10,7 +10,10 @@ import com.minecolonies.api.entity.ai.statemachine.AITarget; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.api.util.*; +import com.minecolonies.api.util.BlockPosUtil; +import com.minecolonies.api.util.InventoryUtils; +import com.minecolonies.api.util.Tuple; +import com.minecolonies.api.util.WorldUtil; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingHospital; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobHealer; @@ -20,9 +23,9 @@ import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.network.messages.client.CircleParticleEffectMessage; import com.minecolonies.core.network.messages.client.StreamParticleEffectMessage; -import net.minecraft.world.entity.player.Player; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Player; import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; @@ -98,7 +101,7 @@ public EntityAIWorkHealer(@NotNull final JobHealer job) */ private IAIState decide() { - if (walkToBuilding()) + if (!walkToBuilding()) { return DECIDE; } @@ -248,7 +251,7 @@ private IAIState requestCure() } final EntityCitizen citizen = (EntityCitizen) data.getEntity().get(); - if (walkToBlock(citizen.blockPosition())) + if (!walkToSafePos(citizen.blockPosition())) { return REQUEST_CURE; } @@ -318,7 +321,7 @@ private IAIState cure() } final EntityCitizen citizen = (EntityCitizen) data.getEntity().get(); - if (walkToBlock(data.getEntity().get().blockPosition())) + if (!walkToSafePos(data.getEntity().get().blockPosition())) { return CURE; } @@ -396,7 +399,7 @@ private IAIState freeCure() } final EntityCitizen citizen = (EntityCitizen) data.getEntity().get(); - if (walkToBlock(citizen.blockPosition())) + if (!walkToSafePos(citizen.blockPosition())) { progressTicks = 0; return FREE_CURE; @@ -434,7 +437,7 @@ private IAIState curePlayer() return DECIDE; } - if (walkToBlock(playerToHeal.blockPosition())) + if (!walkToUnSafePos(playerToHeal.blockPosition())) { return getState(); } @@ -464,7 +467,7 @@ private IAIState wander() } final EntityCitizen citizen = (EntityCitizen) remotePatient.getEntity().get(); - if (walkToBlock(remotePatient.getEntity().get().blockPosition())) + if (!walkToUnSafePos(remotePatient.getEntity().get().blockPosition())) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java index c1ddfec32fe..4ecb9bfd243 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java @@ -9,8 +9,6 @@ import com.minecolonies.api.entity.citizen.Skill; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; import com.minecolonies.api.equipment.ModEquipmentTypes; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; -import com.minecolonies.core.tileentities.TileEntityGrave; import com.minecolonies.api.util.InventoryUtils; import com.minecolonies.api.util.MessageUtils; import com.minecolonies.api.util.Tuple; @@ -18,8 +16,11 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingGraveyard; import com.minecolonies.core.colony.jobs.JobUndertaker; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.network.messages.client.VanillaParticleMessage; +import com.minecolonies.core.tileentities.TileEntityGrave; import com.minecolonies.core.util.AdvancementUtils; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleTypes; @@ -114,7 +115,7 @@ private IAIState startWorking() @Nullable final BlockPos currentGrave = building.getGraveToWorkOn(); if (currentGrave != null) { - if (walkToBuilding()) + if (!walkToBuilding()) { return getState(); } @@ -142,7 +143,7 @@ private IAIState wander() { if (building.isInBuilding(worker.blockPosition())) { - worker.getNavigation().moveToRandomPos(10, DEFAULT_SPEED, building.getCorners()); + EntityNavigationUtils.walkToRandomPosWithin(worker, 10, DEFAULT_SPEED, building.getCorners()); } else { @@ -175,7 +176,7 @@ private IAIState emptyGrave() @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn(); // Still moving to the block - if (walkToBlock(gravePos, 3)) + if (walkWithProxy(gravePos, 3)) { return getState(); } @@ -236,7 +237,7 @@ private IAIState digGrave() } // Still moving to the block - if (walkToBlock(gravePos, 3)) + if (walkWithProxy(gravePos, 3)) { return getState(); } @@ -310,7 +311,7 @@ private IAIState tryResurrect() } // Still moving to the block - if (walkToBlock(gravePos, 3)) + if (walkWithProxy(gravePos, 3)) { return getState(); } @@ -441,7 +442,7 @@ private IAIState buryCitizen() return IDLE; } - if (walkToBlock(burialPos.getA(), 4)) + if (walkWithProxy(burialPos.getA(), 4)) { return getState(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/util/BuildingStructureHandler.java b/src/main/java/com/minecolonies/core/entity/ai/workers/util/BuildingStructureHandler.java index c9eb2d0dbf5..1dabcb0722c 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/util/BuildingStructureHandler.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/util/BuildingStructureHandler.java @@ -15,6 +15,7 @@ import com.minecolonies.core.colony.buildings.AbstractBuildingStructureBuilder; import com.minecolonies.core.colony.jobs.AbstractJobStructure; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIStructure; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.util.WorkerUtil; import net.minecraft.core.BlockPos; import net.minecraft.tags.ItemTags; @@ -35,7 +36,6 @@ import java.util.concurrent.Future; import java.util.function.Function; -import static com.minecolonies.api.util.constant.CitizenConstants.RUN_AWAY_SPEED; import static com.minecolonies.api.util.constant.StatisticsConstants.BLOCKS_PLACED; /** @@ -182,7 +182,7 @@ public void prePlacementLogic(final BlockPos worldPos, final BlockState blockSta && Mth.floor(structureAI.getWorker().getZ()) == worldPos.getZ() && structureAI.getWorker().getNavigation().isDone()) { - structureAI.getWorker().getNavigation().moveAwayFromXYZ(worldPos, RUN_AWAY_SPEED, 1, true); + EntityNavigationUtils.walkAwayFrom(structureAI.getWorker(), worldPos, 1, 1.0); } structureAI.getWorker().swing(InteractionHand.MAIN_HAND); diff --git a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java index 5eb1abc01fb..a8a331bebbd 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java @@ -26,7 +26,6 @@ import com.minecolonies.api.entity.citizen.citizenhandlers.*; import com.minecolonies.api.entity.citizen.happiness.ExpirationBasedHappinessModifier; import com.minecolonies.api.entity.citizen.happiness.StaticHappinessSupplier; -import com.minecolonies.api.entity.pathfinding.proxy.IWalkToProxy; import com.minecolonies.api.inventory.InventoryCitizen; import com.minecolonies.api.inventory.container.ContainerCitizenInventory; import com.minecolonies.api.items.ModItems; @@ -53,9 +52,8 @@ import com.minecolonies.core.entity.ai.workers.CitizenAI; import com.minecolonies.core.entity.ai.workers.guard.AbstractEntityAIGuard; import com.minecolonies.core.entity.citizen.citizenhandlers.*; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.entity.pathfinding.navigation.MovementHandler; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; -import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy; import com.minecolonies.core.event.EventHandler; import com.minecolonies.core.event.TextureReloadListener; import com.minecolonies.core.network.messages.client.ItemParticleEffectMessage; @@ -63,8 +61,8 @@ import com.minecolonies.core.network.messages.client.colony.ColonyViewCitizenViewMessage; import com.minecolonies.core.network.messages.client.colony.PlaySoundForCitizenMessage; import com.minecolonies.core.network.messages.server.colony.OpenInventoryMessage; -import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.util.TeleportHelper; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.registries.BuiltInRegistries; @@ -104,9 +102,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.time.Clock; -import java.time.LocalDate; -import java.time.Month; import java.util.*; import static com.minecolonies.api.research.util.ResearchConstants.*; @@ -145,10 +140,7 @@ public class EntityCitizen extends AbstractEntityCitizen implements IThreatTable * It's citizen Id. */ private int citizenId = 0; - /** - * The Walk to proxy (Shortest path through intermediate blocks). - */ - private IWalkToProxy proxy; + /** * Reference to the data representation inside the colony. */ @@ -183,11 +175,6 @@ public class EntityCitizen extends AbstractEntityCitizen implements IThreatTable */ private final CitizenCombatTracker combatTracker; - /** - * The path-result of trying to move away - */ - private PathResult moveAwayPath; - /** * IsChild flag */ @@ -533,7 +520,7 @@ private InteractionResult directPlayerInteraction(final Player player, final Int if (!level().isClientSide()) { MessageUtils.format(MESSAGE_INTERACTION_OUCH, getCitizenData().getName()).sendTo(player); - getNavigation().moveAwayFromLivingEntity(player, 5, 1); + EntityNavigationUtils.walkAwayFrom(this, player.blockPosition(), 5, 1); setJumping(true); } @@ -952,23 +939,6 @@ public ILocation getLocation() return location; } - /** - * Checks if a worker is at his working site. If he isn't, sets it's path to the location - * - * @param site the place where he should walk to - * @param range Range to check in - * @return True if worker is at site, otherwise false. - */ - @Override - public boolean isWorkerAtSiteWithMove(@NotNull final BlockPos site, final int range) - { - if (proxy == null) - { - proxy = new EntityCitizenWalkToProxy(this); - } - return proxy.walkToBlock(site, range, true); - } - /** * Getter for the citizendata. Tries to get it from the colony is the data is null. * @@ -1075,17 +1045,6 @@ public void playMoveAwaySound() } } - /** - * Get the path proxy of the citizen. - * - * @return the proxy. - */ - @Override - public IWalkToProxy getProxy() - { - return proxy; - } - /** * Decrease the saturation of the citizen for 1 action. */ @@ -1473,10 +1432,12 @@ private void performMoveAway(@Nullable final Entity attacker) if (!(attacker instanceof LivingEntity) && (!(getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard) || getCitizenJobHandler().getColonyJob().canAIBeInterrupted())) { - if (moveAwayPath == null || !moveAwayPath.isInProgress()) - { - moveAwayPath = this.getNavigation().moveAwayFromLivingEntity(this, 5, INITIAL_RUN_SPEED_AVOID); - } + EntityNavigationUtils.walkAwayFrom(this, blockPosition(), 5, INITIAL_RUN_SPEED_AVOID); + return; + } + + if (attacker == null) + { return; } @@ -1489,10 +1450,7 @@ private void performMoveAway(@Nullable final Entity attacker) citizenAI.addTransition(new AIOneTimeEventTarget<>(CitizenAIState.FLEE)); callForHelp(attacker, MAX_GUARD_CALL_RANGE); - if (moveAwayPath == null || !moveAwayPath.isInProgress()) - { - moveAwayPath = this.getNavigation().moveAwayFromLivingEntity(attacker, 15, INITIAL_RUN_SPEED_AVOID); - } + EntityNavigationUtils.walkAwayFrom(this, attacker.blockPosition(), 15, INITIAL_RUN_SPEED_AVOID); } @Override diff --git a/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenary.java b/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenary.java index 767813b9c8e..a4878aa8629 100755 --- a/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenary.java +++ b/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenary.java @@ -15,6 +15,7 @@ import com.minecolonies.core.entity.ai.minimal.EntityAIInteractToggleAble; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.entity.pathfinding.navigation.AbstractAdvancedPathNavigate; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.entity.pathfinding.navigation.MinecoloniesAdvancedPathNavigate; import com.minecolonies.core.entity.pathfinding.proxy.GeneralEntityWalkToProxy; import com.minecolonies.core.entity.pathfinding.navigation.MinecoloniesAdvancedPathNavigate; @@ -259,11 +260,11 @@ private boolean spawnEvent() playSound(MercenarySounds.mercenaryCelebrate, 2.0f, 1.0f); if (blockPosition().equals(first)) { - getNavigation().tryMoveToBlockPos(last, 0.5); + EntityNavigationUtils.walkToPos(this, last, 2, true, 0.5); } else { - getNavigation().tryMoveToBlockPos(first, 0.5); + EntityNavigationUtils.walkToPos(this, first, 2, true, 0.5); } return false; diff --git a/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenaryAI.java b/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenaryAI.java index 433bbc58d24..fbdd9db8a42 100755 --- a/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenaryAI.java +++ b/src/main/java/com/minecolonies/core/entity/mobs/EntityMercenaryAI.java @@ -5,14 +5,16 @@ import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateStateMachine; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.api.sounds.MercenarySounds; import com.minecolonies.api.util.*; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; +import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.ai.goal.Goal; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.InteractionHand; -import net.minecraft.core.BlockPos; import net.neoforged.neoforge.items.IItemHandler; + import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -226,8 +228,8 @@ private boolean fighting() if (attackPath == null || !attackPath.isInProgress()) { - entity.getNavigation().moveToLivingEntity(entity.getTarget(), 1); - entity.getLookControl().setLookAt(entity.getTarget(), 180f, 180f); + EntityNavigationUtils.walkToPos(entity, entity.getTarget().blockPosition(), false); + entity.getLookControl().setLookAt(entity.getTarget()); } final int distance = BlockPosUtil.getMaxDistance2D(entity.blockPosition(), entity.getTarget().blockPosition()); diff --git a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/CampWalkAI.java b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/CampWalkAI.java index 80881ec96d4..b65682b0f4b 100644 --- a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/CampWalkAI.java +++ b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/CampWalkAI.java @@ -7,6 +7,7 @@ import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition; import com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMonster; import com.minecolonies.api.entity.pathfinding.IPathJob; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.BlockPos; import net.minecraft.util.Tuple; @@ -23,16 +24,6 @@ public class CampWalkAI implements IStateAI */ private final AbstractEntityMinecoloniesMonster entity; - /** - * Target block we're walking to - */ - private BlockPos targetBlock = null; - - /** - * Walk timer - */ - private long walkTimer = 0; - /** * Random path result. */ @@ -46,57 +37,21 @@ public class CampWalkAI implements IStateAI public CampWalkAI(final AbstractEntityMinecoloniesMonster raider, final ITickRateStateMachine stateMachine) { this.entity = raider; - stateMachine.addTransition(new TickingTransition<>(CombatAIStates.NO_TARGET, this::walk, () -> null, 80)); + stateMachine.addTransition(new TickingTransition<>(CombatAIStates.NO_TARGET, this::walk, () -> null, TICKS_SECOND * 30)); } /** - * Walk raider towards the colony or campfires - * + * Walk camp mob randomly */ private boolean walk() { - if (targetBlock == null || entity.level().getGameTime() > walkTimer) + if (spawnCenterBoxCache == null) { - targetBlock = findRandomPositionToWalkTo(); - walkTimer = entity.level().getGameTime() + TICKS_SECOND * 30; - } - else - { - entity.getNavigation().moveToXYZ(targetBlock.getX(), targetBlock.getY(), targetBlock.getZ(),1.1); - randomPathResult = null; + final BlockPos startPos = entity.getSpawnPos() == null ? entity.blockPosition() : entity.getSpawnPos(); + spawnCenterBoxCache = new Tuple<>(startPos.offset(-10, -5, -10), startPos.offset(10, 5, 10)); } + EntityNavigationUtils.walkToRandomPosWithin(entity, 10, 0.6, spawnCenterBoxCache); return false; } - - protected BlockPos findRandomPositionToWalkTo() - { - if (randomPathResult == null || randomPathResult.failedToReachDestination()) - { - if (spawnCenterBoxCache == null) - { - final BlockPos startPos = entity.getSpawnPos() == null ? entity.blockPosition() : entity.getSpawnPos(); - spawnCenterBoxCache = new Tuple<>(startPos.offset(-10,-5,-10), startPos.offset(10,5,10)); - } - - randomPathResult = entity.getNavigation().moveToRandomPos(10, 0.9, spawnCenterBoxCache); - if (randomPathResult != null) - { - randomPathResult.getJob().getPathingOptions().withCanEnterDoors(true).withToggleCost(0).withNonLadderClimbableCost(0); - } - } - - if (randomPathResult.isPathReachingDestination()) - { - return randomPathResult.getPath().getEndNode().asBlockPos(); - } - - if (randomPathResult.isCancelled()) - { - randomPathResult = null; - return null; - } - - return null; - } } diff --git a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderMeleeAI.java b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderMeleeAI.java index b9dc8f667b4..f5b18237210 100644 --- a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderMeleeAI.java +++ b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderMeleeAI.java @@ -4,11 +4,11 @@ import com.minecolonies.api.entity.ai.statemachine.states.IState; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine; import com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMonster; -import com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesRaider; import com.minecolonies.api.util.SoundUtils; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.entity.ai.combat.AttackMoveAI; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.contents.TranslatableContents; @@ -84,8 +84,12 @@ protected int getAttackDelay() @Override protected PathResult moveInAttackPosition(final LivingEntity target) { - return user.getNavigation() - .moveToXYZ(target.getX(), target.getY(), target.getZ(), user.getDifficulty() < ADD_SPEED_DIFFICULTY ? BASE_COMBAT_SPEED : BASE_COMBAT_SPEED * BONUS_SPEED); + EntityNavigationUtils.walkToPos(user, + target.blockPosition(), + (int) getAttackDistance(), + false, + user.getDifficulty() < ADD_SPEED_DIFFICULTY ? BASE_COMBAT_SPEED : BASE_COMBAT_SPEED * BONUS_SPEED); + return user.getNavigation().getPathResult(); } @Override diff --git a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderRangedAI.java b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderRangedAI.java index 511134c82bf..0d9da955c39 100644 --- a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderRangedAI.java +++ b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderRangedAI.java @@ -4,7 +4,6 @@ import com.minecolonies.api.entity.ai.statemachine.states.IState; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine; import com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMonster; -import com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesRaider; import com.minecolonies.api.entity.mobs.ICustomAttackSound; import com.minecolonies.api.entity.mobs.IRangedMobEntity; import com.minecolonies.api.util.EntityUtils; @@ -12,6 +11,7 @@ import com.minecolonies.core.entity.ai.combat.CombatUtils; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.entity.other.CustomArrowEntity; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; @@ -186,7 +186,8 @@ protected boolean checkForTarget() @Override protected PathResult moveInAttackPosition(final LivingEntity target) { - return user.getNavigation().moveToXYZ(target.getX(), target.getY(), target.getZ(), COMBAT_MOVEMENT_SPEED); + EntityNavigationUtils.walkToPos(user, target.blockPosition(), (int) getAttackDistance(), false, COMBAT_MOVEMENT_SPEED); + return user.getNavigation().getPathResult(); } @Override diff --git a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderWalkAI.java b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderWalkAI.java index cedc5c070c7..e3e50b09031 100644 --- a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderWalkAI.java +++ b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderWalkAI.java @@ -1,5 +1,6 @@ package com.minecolonies.core.entity.mobs.aitasks; +import com.minecolonies.api.colony.buildings.IBuilding; import com.minecolonies.api.colony.colonyEvents.EventStatus; import com.minecolonies.api.colony.colonyEvents.IColonyEvent; import com.minecolonies.api.colony.colonyEvents.IColonyRaidEvent; @@ -9,13 +10,10 @@ import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine; import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition; import com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesRaider; -import com.minecolonies.api.entity.pathfinding.IPathJob; -import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.Log; -import com.minecolonies.core.colony.buildings.AbstractBuilding; import com.minecolonies.core.colony.events.raid.HordeRaidEvent; import com.minecolonies.core.colony.events.raid.pirateEvent.ShipBasedRaiderUtils; -import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; +import com.minecolonies.core.entity.pathfinding.navigation.EntityNavigationUtils; import net.minecraft.core.BlockPos; import java.util.List; @@ -43,14 +41,9 @@ public class RaiderWalkAI implements IStateAI private long walkTimer = 0; /** - * Random path result. + * Building the raider is checking out */ - private PathResult randomPathResult; - - /** - * If we are currently trying to move to a random block. - */ - private boolean walkInBuildingState = false; + private IBuilding walkInBuilding = null; public RaiderWalkAI(final AbstractEntityMinecoloniesRaider raider, final ITickRateStateMachine stateMachine) { @@ -87,43 +80,27 @@ private boolean walk() final List wayPoints = ((IColonyRaidEvent) event).getWayPoints(); final BlockPos moveToPos = ShipBasedRaiderUtils.chooseWaypointFor(wayPoints, raider.blockPosition(), targetBlock); - raider.getNavigation().moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), !moveToPos.equals(targetBlock) && moveToPos.distManhattan(wayPoints.get(0)) > 50 ? 1.8 : 1.1); - walkInBuildingState = false; - randomPathResult = null; + EntityNavigationUtils.walkToPos(raider, moveToPos, 4, false, !moveToPos.equals(targetBlock) && moveToPos.distManhattan(wayPoints.get(0)) > 50 ? 1.8 : 1.1); + walkInBuilding = null; } - else if (walkInBuildingState) + else if (walkInBuilding != null) { - final BlockPos moveToPos = findRandomPositionToWalkTo(); - if (moveToPos != null) + if (EntityNavigationUtils.walkToRandomPosWithin(raider, 10, 0.7, walkInBuilding.getCorners()) + && raider.getRandom().nextDouble() < 0.25) { - if (moveToPos == BlockPos.ZERO) - { - walkInBuildingState = false; - targetBlock = null; - return false; - } - raider.getNavigation().moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), 0.9); - if (raider.blockPosition().distSqr(moveToPos) < 4) - { - if (raider.getRandom().nextDouble() < 0.25) - { - walkInBuildingState = false; - targetBlock = null; - } - else - { - randomPathResult = null; - walkTimer = raider.level().getGameTime() + TICKS_SECOND * 60; - findRandomPositionToWalkTo(); - } - } + walkInBuilding = null; + targetBlock = null; + } + + if (raider.getNavigation().getPathResult() != null) + { + raider.getNavigation().getPathResult().getJob().getPathingOptions().withCanEnterDoors(true).withToggleCost(0).withNonLadderClimbableCost(0); } } else if (raider.blockPosition().distSqr(targetBlock) < 25) { - findRandomPositionToWalkTo(); walkTimer = raider.level().getGameTime() + TICKS_SECOND * 30; - walkInBuildingState = true; + walkInBuilding = raider.getColony().getBuildingManager().getBuilding(targetBlock); } else if (raider.getNavigation().isDone() || raider.getNavigation().getDesiredPos() == null) { @@ -139,54 +116,13 @@ else if (raider.getNavigation().isDone() || raider.getNavigation().getDesiredPos } } - raider.getNavigation() - .moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), !moveToPos.equals(targetBlock) && moveToPos.distManhattan(wayPoints.get(0)) > 50 ? 1.8 : 1.1); + EntityNavigationUtils.walkToPos(raider, moveToPos, 7, true, !moveToPos.equals(targetBlock) && moveToPos.distManhattan(wayPoints.get(0)) > 50 ? 1.8 : 1.1); } } return false; } - protected BlockPos findRandomPositionToWalkTo() - { - if (randomPathResult == null || randomPathResult.failedToReachDestination()) - { - if (raider.getColony().getBuildingManager().getBuilding(targetBlock) instanceof AbstractBuilding building - && building.getBuildingLevel() > 0 - && !building.getCorners().getA().equals(building.getCorners().getB())) - { - randomPathResult = raider.getNavigation().moveToRandomPos(10, 0.9, building.getCorners()); - if (randomPathResult != null) - { - randomPathResult.getJob().getPathingOptions().withCanEnterDoors(true).withToggleCost(0).withNonLadderClimbableCost(0); - } - } - else - { - return BlockPos.ZERO; - } - } - - if (randomPathResult == null) - { - return null; - } - - - if (randomPathResult.isPathReachingDestination()) - { - return randomPathResult.getPath().getEndNode().asBlockPos(); - } - - if (randomPathResult.isCancelled()) - { - randomPathResult = null; - return null; - } - - return null; - } - /** * Chooses and walks to a random campfire */ @@ -205,15 +141,7 @@ private void walkToCampFire() } walkTimer = raider.level().getGameTime() + raider.level().random.nextInt(1000); - final BlockPos posAroundCampfire = BlockPosUtil.getRandomPosition(raider.level(), - campFire, - BlockPos.ZERO, - 3, - 6); - if (posAroundCampfire != null && posAroundCampfire != BlockPos.ZERO) - { - raider.getNavigation().moveToXYZ(posAroundCampfire.getX(), posAroundCampfire.getY(), posAroundCampfire.getZ(), 1.0); - } + EntityNavigationUtils.walkToRandomPosAround(raider, campFire, 10, 0.7); } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/AbstractAdvancedPathNavigate.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/AbstractAdvancedPathNavigate.java index 4741a7fb26f..8b2a8688af2 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/AbstractAdvancedPathNavigate.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/AbstractAdvancedPathNavigate.java @@ -6,6 +6,7 @@ import com.minecolonies.api.entity.pathfinding.IStuckHandler; import com.minecolonies.core.entity.pathfinding.PathingOptions; import com.minecolonies.core.entity.pathfinding.pathjobs.AbstractPathJob; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveCloseToXNearY; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.core.entity.pathfinding.pathresults.TreePathResult; import net.minecraft.core.BlockPos; @@ -61,7 +62,7 @@ public BlockPos getDestination() * @param safeDestination if the destination is save and should be set. * @return the result of the pathing. */ - public abstract PathResult moveAwayFromXYZ(final BlockPos currentPosition, final double range, final double speed, final boolean safeDestination); + protected abstract PathResult walkAwayFrom(final BlockPos currentPosition, final double range, final double speed, final boolean safeDestination); /** * Try to move to a certain position. @@ -72,7 +73,7 @@ public BlockPos getDestination() * @param speed the speed to walk. * @return the PathResult. */ - public abstract PathResult moveToXYZ(final double x, final double y, final double z, final double speed); + protected abstract PathResult walkTo(final BlockPos pos, final double speed, final boolean safeDestination); /** * Used to path away from a ourEntity. @@ -82,7 +83,7 @@ public BlockPos getDestination() * @param combatMovementSpeed the speed to run at. * @return the result of the pathing. */ - public abstract PathResult moveAwayFromLivingEntity(final Entity target, final double distance, final double combatMovementSpeed); + protected abstract PathResult moveAwayFromLivingEntity(final Entity target, final double distance, final double combatMovementSpeed); /** * Attempt to move to a specific pos. @@ -91,7 +92,7 @@ public BlockPos getDestination() * @param speed the speed. * @return true if successful. */ - public abstract boolean tryMoveToBlockPos(final BlockPos position, final double speed); + protected abstract boolean walkTo(final BlockPos position, final double speed); /** * Attemps to move in the given direction, walking at least range blocks @@ -102,7 +103,7 @@ public BlockPos getDestination() * @return */ @Nullable - public abstract PathResult moveTowards(BlockPos towards, double range, double speedFactor); + protected abstract PathResult walkTowards(BlockPos towards, double range, double speedFactor); /** * Used to path towards a random pos. @@ -111,7 +112,7 @@ public BlockPos getDestination() * @param speed the speed to run at. * @return the result of the pathing. */ - public abstract PathResult moveToRandomPos(final double range, final double speed); + protected abstract PathResult walkToRandomPos(final int range, final double speed); /** * Used to path towards a random pos. @@ -121,7 +122,24 @@ public BlockPos getDestination() * @param pos the pos to circle around. * @return the result of the pathing. */ - public abstract PathResult moveToRandomPosAroundX(final int range, final double speed, final BlockPos pos); + protected abstract PathResult walkToRandomPosAround(final int range, final double speed, final BlockPos pos); + + /** + * Walks towards the desired position, while trying to not steer too far from the nearby position + * + * @param desiredPosition + * @param nearbyPosition + * @param distToDesired + * @param speedFactor + * @param safeDestination + * @return + */ + protected abstract PathResult walkCloseToXNearY( + BlockPos desiredPosition, + BlockPos nearbyPosition, + int distToDesired, + double speedFactor, + boolean safeDestination); /** * Used to path towards a random pos within some restrictions @@ -131,7 +149,7 @@ public BlockPos getDestination() * @param corners the corners they can't leave. * @return the result of the pathing. */ - public abstract PathResult moveToRandomPos( + protected abstract PathResult walkToRandomPos( final int range, final double speed, final net.minecraft.util.Tuple corners); @@ -145,7 +163,7 @@ public abstract PathResult moveToRandomPos( * @param excludedTrees the trees which should be cut. * @return the result of the search. */ - public abstract TreePathResult moveToTree( + public abstract TreePathResult walkToTree( final BlockPos startRestriction, final BlockPos endRestriction, final double speed, @@ -161,16 +179,16 @@ public abstract TreePathResult moveToTree( * @param excludedTrees the trees which should be cut. * @return the result of the search. */ - public abstract TreePathResult moveToTree(final int range, final double speed, final List excludedTrees, final int dyntreesize, final IColony colony); + public abstract TreePathResult walkToTree(final int range, final double speed, final List excludedTrees, final int dyntreesize, final IColony colony); /** - * Used to move a living ourEntity with a speed. + * Used to walk a living ourEntity with a speed. * * @param e the ourEntity. * @param speed the speed. * @return the result. */ - public abstract PathResult moveToLivingEntity(@NotNull final Entity e, final double speed); + protected abstract PathResult walkToEntity(@NotNull final Entity e, final double speed); /** * Get the pathing options diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/EntityNavigationUtils.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/EntityNavigationUtils.java new file mode 100644 index 00000000000..c4f3c5be86e --- /dev/null +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/EntityNavigationUtils.java @@ -0,0 +1,289 @@ +package com.minecolonies.core.entity.pathfinding.navigation; + +import com.minecolonies.api.colony.buildings.IBuilding; +import com.minecolonies.api.entity.other.AbstractFastMinecoloniesEntity; +import com.minecolonies.api.util.BlockPosUtil; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveCloseToXNearY; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveToLocation; +import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobRandomPos; +import net.minecraft.core.BlockPos; +import net.minecraft.util.Tuple; + +public class EntityNavigationUtils +{ + /** + * Distance to consider being near a building block as reached + */ + public static int BUILDING_REACH_DIST = 4; + + /** + * Distance to consider being near a block inside a building as reached + */ + public static int WOKR_IN_BUILDING_DIST = 7; + + /** + * Distance which counts as reached + */ + public static double REACHED_DIST = 1.5; + + /** + * Tries to walk close to a given pos, staying near another position. + * + * @param entity + * @param desiredPosition + * @param nearbyPosition + * @param distToDesired + * @return True when arrived + */ + public static boolean walkCloseToXNearY( + final AbstractFastMinecoloniesEntity entity, final BlockPos desiredPosition, + final BlockPos nearbyPosition, + final int distToDesired, final boolean safeDestination) + { + return walkCloseToXNearY(entity, desiredPosition, nearbyPosition, distToDesired, safeDestination, 1.0); + } + + /** + * Tries to walk close to a given pos, staying near another position. + * + * @return True when arrived + */ + public static boolean walkCloseToXNearY( + final AbstractFastMinecoloniesEntity entity, final BlockPos desiredPosition, + final BlockPos nearbyPosition, + final int distToDesired, final boolean safeDestination, final double speedFactor) + { + final MinecoloniesAdvancedPathNavigate nav = ((MinecoloniesAdvancedPathNavigate) entity.getNavigation()); + + // Three cases + // 1. Navigation Finished + // 2. Navigation is progressing towards a previous task + // 3. Navigation did not try once + boolean isOnRightTask = (nav.getPathResult() != null + && PathJobMoveCloseToXNearY.isJobFor(nav.getPathResult().getJob(), desiredPosition, nearbyPosition, distToDesired)); + + if (nav.isDone() || !isOnRightTask) + { + if (isOnRightTask) + { + // Check distance once navigation is done, to let the entity walk + if (BlockPosUtil.dist(entity.blockPosition(), desiredPosition) <= distToDesired) + { + nav.stop(); + return true; + } + } + else if (BlockPosUtil.dist(entity.blockPosition(), desiredPosition) <= REACHED_DIST) + { + nav.stop(); + return true; + } + + nav.walkCloseToXNearY(desiredPosition, nearbyPosition, 1, speedFactor, safeDestination); + } + + return false; + } + + /** + * Walks to a position within a building + * + * @return True when arrived + */ + public static boolean walkToPosInBuilding( + final AbstractFastMinecoloniesEntity entity, final BlockPos destination, final IBuilding building, final int reachDistance) + { + if (building == null) + { + return walkToPos(entity, destination, reachDistance, true); + } + + Tuple corners = building.getCorners(); + final BlockPos center = + new BlockPos((corners.getA().getX() + corners.getB().getX()) / 2, building.getPosition().getY(), (corners.getA().getZ() + corners.getB().getZ()) / 2); + + return walkCloseToXNearY(entity, destination, center, reachDistance, true); + } + + /** + * Walks to a position within a building + * + * @return True when arrived + */ + public static boolean walkToBuilding( + final AbstractFastMinecoloniesEntity entity, final IBuilding building) + { + if (building == null) + { + return true; + } + + return walkToPosInBuilding(entity, building.getPosition(), building, BUILDING_REACH_DIST); + } + + /** + * Walks to a given position + * + * @return True when arrived + */ + public static boolean walkToPos( + final AbstractFastMinecoloniesEntity entity, final BlockPos desiredPosition, final boolean safeDestination) + { + return walkToPos(entity, desiredPosition, BUILDING_REACH_DIST, safeDestination, 1.0); + } + + /** + * Walks to a given position + * + * @return True when arrived + */ + public static boolean walkToPos( + final AbstractFastMinecoloniesEntity entity, final BlockPos desiredPosition, + final int distToDesired, final boolean safeDestination) + { + return walkToPos(entity, desiredPosition, distToDesired, safeDestination, 1.0); + } + + /** + * Walks to a given position + * + * @return True when arrived + */ + public static boolean walkToPos( + final AbstractFastMinecoloniesEntity entity, final BlockPos desiredPosition, + final int distToDesired, final boolean safeDestination, final double speedFactor) + { + final MinecoloniesAdvancedPathNavigate nav = ((MinecoloniesAdvancedPathNavigate) entity.getNavigation()); + + boolean isOnRightTask = (nav.getPathResult() != null + && PathJobMoveToLocation.isJobFor(nav.getPathResult().getJob(), desiredPosition)); + + if (nav.isDone() || !isOnRightTask) + { + if (isOnRightTask) + { + // Check distance once navigation is done, to let the entity walk + if (BlockPosUtil.dist(entity.blockPosition(), desiredPosition) <= distToDesired) + { + nav.stop(); + return true; + } + } + else if (BlockPosUtil.dist(entity.blockPosition(), desiredPosition) <= REACHED_DIST) + { + nav.stop(); + return true; + } + + nav.walkTo(desiredPosition, speedFactor, safeDestination); + } + + return false; + } + + /** + * Walks away from a given position + * + * @return True when arrived + */ + public static boolean walkAwayFrom(final AbstractFastMinecoloniesEntity entity, final BlockPos avoid, final int distance, final double speed) + { + final MinecoloniesAdvancedPathNavigate nav = ((MinecoloniesAdvancedPathNavigate) entity.getNavigation()); + boolean isOnRightTask = (nav.getPathResult() != null && PathJobMoveAwayFromLocation.isJobFor(nav.getPathResult().getJob(), distance, avoid)); + + if (nav.isDone() || !isOnRightTask) + { + if (isOnRightTask) + { + // Check distance once navigation is done, to let the entity walk + if (BlockPosUtil.dist(entity.blockPosition(), avoid) >= distance) + { + nav.stop(); + return true; + } + } + else if (BlockPosUtil.dist(entity.blockPosition(), avoid) >= REACHED_DIST) + { + nav.stop(); + return true; + } + + nav.walkAwayFrom(avoid, distance, speed, false); + } + + return false; + } + + /** + * Walks to a random position a given distance away + * + * @return True when arrived + */ + public static boolean walkToRandomPos(final AbstractFastMinecoloniesEntity entity, final int range, final double speedFactor) + { + final MinecoloniesAdvancedPathNavigate nav = ((MinecoloniesAdvancedPathNavigate) entity.getNavigation()); + boolean isOnRightTask = (nav.getPathResult() != null && nav.getPathResult().getJob() instanceof PathJobRandomPos); + + if (nav.isDone() || !isOnRightTask) + { + if (isOnRightTask) + { + nav.stop(); + return true; + } + + nav.walkToRandomPos(range, speedFactor); + } + + return false; + } + + /** + * Walks to a random position a given distance away within the provided box + * + * @return True when arrived + */ + public static boolean walkToRandomPosWithin(final AbstractFastMinecoloniesEntity entity, final int range, final double speedFactor, final Tuple corners) + { + final MinecoloniesAdvancedPathNavigate nav = ((MinecoloniesAdvancedPathNavigate) entity.getNavigation()); + boolean isOnRightTask = (nav.getPathResult() != null && nav.getPathResult().getJob() instanceof PathJobRandomPos); + + if (nav.isDone() || !isOnRightTask) + { + if (isOnRightTask) + { + nav.stop(); + return true; + } + + nav.walkToRandomPos(range, speedFactor, corners); + } + + return false; + } + + /** + * Walks to a random position a given distance away around the provided center + * + * @return True when arrived + */ + public static boolean walkToRandomPosAround(final AbstractFastMinecoloniesEntity entity, final BlockPos center, final int range, final double speedFactor) + { + final MinecoloniesAdvancedPathNavigate nav = ((MinecoloniesAdvancedPathNavigate) entity.getNavigation()); + boolean isOnRightTask = (nav.getPathResult() != null && PathJobRandomPos.isJobFor(nav.getPathResult().getJob(), center, range)); + + if (nav.isDone() || !isOnRightTask) + { + if (isOnRightTask) + { + nav.stop(); + return true; + } + + nav.walkToRandomPosAround(range, speedFactor, center); + } + + return false; + } +} diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java index ff00e4369cc..9073e00238e 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/MinecoloniesAdvancedPathNavigate.java @@ -7,7 +7,6 @@ import com.minecolonies.api.entity.other.MinecoloniesMinecart; import com.minecolonies.api.entity.pathfinding.IStuckHandler; import com.minecolonies.api.util.*; -import com.minecolonies.api.util.constant.ColonyConstants; import com.minecolonies.core.entity.pathfinding.PathFindingStatus; import com.minecolonies.core.entity.pathfinding.PathPointExtended; import com.minecolonies.core.entity.pathfinding.Pathfinding; @@ -58,12 +57,7 @@ public class MinecoloniesAdvancedPathNavigate extends AbstractAdvancedPathNaviga public static final double MIN_SPEED_ALLOWED = 0.1; @Nullable - private PathResult pathResult; - - /** - * The world time when a path was added. - */ - private long pathStartTime = 0; + private PathResult pathResult; /** * Spawn pos of minecart. @@ -144,7 +138,7 @@ public BlockPos getDestination() } @Nullable - public PathResult moveAwayFromXYZ(final BlockPos avoid, final double range, final double speedFactor, final boolean safeDestination) + protected PathResult walkAwayFrom(final BlockPos avoid, final double range, final double speedFactor, final boolean safeDestination) { @NotNull final BlockPos start = PathfindingUtils.prepareStart(ourEntity); @@ -158,7 +152,7 @@ public PathResult moveAwayFromXYZ(final BlockPos avoid, final d @Nullable @Override - public PathResult moveTowards(final BlockPos towards, final double range, final double speedFactor) + protected PathResult walkTowards(final BlockPos towards, final double range, final double speedFactor) { return setPathJob(new PathJobMoveTowards(CompatibilityUtils.getWorldFromEntity(ourEntity), PathfindingUtils.prepareStart(ourEntity), @@ -168,37 +162,29 @@ public PathResult moveTowards(final BlockPos towards, final dou } @Nullable - public PathResult moveToRandomPos(final double range, final double speedFactor) + protected PathResult walkToRandomPos(final int range, final double speedFactor) { - if (pathResult != null && pathResult.isInProgress() && pathResult.getJob() instanceof PathJobRandomPos) - { - return pathResult; - } - - desiredPos = BlockPos.ZERO; - final int theRange = (int) (mob.getRandom().nextInt((int) range) + range / 2); @NotNull final BlockPos start = PathfindingUtils.prepareStart(ourEntity); - - return setPathJob(new PathJobRandomPos(CompatibilityUtils.getWorldFromEntity(ourEntity), + final PathResult result = setPathJob(new PathJobRandomPos(CompatibilityUtils.getWorldFromEntity(ourEntity), start, - theRange, + range, (int) ourEntity.getAttribute(Attributes.FOLLOW_RANGE).getValue(), + ourEntity), null, speedFactor, true); - } - @Nullable - public PathResult moveToRandomPosAroundX(final int range, final double speedFactor, final BlockPos pos) - { - if (pathResult != null - && pathResult.isInProgress() - && pathResult.getJob() instanceof PathJobRandomPos - && ((((PathJobRandomPos) pathResult.getJob()).posAndRangeMatch(range, pos)))) + if (result == null) { - return pathResult; + return null; } - desiredPos = BlockPos.ZERO; - final PathResult result = setPathJob(new PathJobRandomPos(CompatibilityUtils.getWorldFromEntity(ourEntity), + result.getJob().getPathingOptions().withToggleCost(1).withJumpCost(1).withDropCost(1).canDrop = false; + return result; + } + + @Nullable + protected PathResult walkToRandomPosAround(final int range, final double speedFactor, final BlockPos pos) + { + final PathResult result = setPathJob(new PathJobRandomPos(CompatibilityUtils.getWorldFromEntity(ourEntity), PathfindingUtils.prepareStart(ourEntity), 3, (int) ourEntity.getAttribute(Attributes.FOLLOW_RANGE).getValue(), @@ -210,28 +196,21 @@ public PathResult moveToRandomPosAroundX(final int range, final return null; } - result.getJob().getPathingOptions().withToggleCost(1).withJumpCost(1).withDropCost(1); + result.getJob().getPathingOptions().withToggleCost(1).withJumpCost(1).withDropCost(1).canDrop = false; return result; } @Override - public PathResult moveToRandomPos( + protected PathResult walkToRandomPos( final int range, final double speedFactor, final net.minecraft.util.Tuple corners) { - if (pathResult != null && pathResult.isInProgress() && pathResult.getJob() instanceof PathJobRandomPos) - { - return pathResult; - } - - desiredPos = BlockPos.ZERO; - final int theRange = (mob.getRandom().nextInt(range) + range / 2); @NotNull final BlockPos start = PathfindingUtils.prepareStart(ourEntity); - final PathResult result = setPathJob(new PathJobRandomPos(CompatibilityUtils.getWorldFromEntity(ourEntity), + final PathResult result = setPathJob(new PathJobRandomPos(CompatibilityUtils.getWorldFromEntity(ourEntity), start, - theRange, + range, (int) ourEntity.getAttribute(Attributes.FOLLOW_RANGE).getValue(), ourEntity, corners.getA(), @@ -242,12 +221,24 @@ public PathResult moveToRandomPos( return null; } - result.getJob().getPathingOptions().withJumpCost(1).withDropCost(1); + result.getJob().getPathingOptions().withJumpCost(1).withDropCost(1).canDrop = false; return result; } + @Override + protected PathResult walkCloseToXNearY( + final BlockPos desiredPosition, + final BlockPos nearbyPosition, + final int distToDesired, + final double speedFactor, + final boolean safeDestination) + { + PathJobMoveCloseToXNearY pathJob = new PathJobMoveCloseToXNearY(ourEntity.level(), desiredPosition, nearbyPosition, 1, ourEntity); + return setPathJob(pathJob, desiredPosition, speedFactor, safeDestination); + } + @Nullable - public PathResult setPathJob( + public PathResult setPathJob( @NotNull final AbstractPathJob job, final BlockPos dest, final double speedFactor, final boolean safeDestination) @@ -258,6 +249,18 @@ public PathResult setPathJob( } stop(); + if (dest != null && !dest.equals(BlockPos.ZERO)) + { + if (job.getStart().distSqr(dest) > 500 * 500) + { + Log.getLogger() + .error( + "Entity: " + ourEntity.getDisplayName().getString() + " is trying to walk too far! distance:" + Math.sqrt(job.getStart().distSqr(dest)) + " from:" + + job.getStart() + " to:" + + dest, new Exception()); + return null; + } + } this.destination = dest; this.originalDestination = dest; @@ -281,7 +284,7 @@ public PathResult setPathJob( job.setPathingOptions(getPathingOptions()); pathResult = job.getResult(); pathResult.startJob(Pathfinding.getExecutor()); - return pathResult; + return (PathResult) pathResult; } @Override @@ -438,56 +441,23 @@ public static double getSmartGroundY(final BlockGetter world, final BlockPos.Mut } @Nullable - public PathResult moveToXYZ(final double x, final double y, final double z, final double speedFactor) + protected PathResult walkTo(final BlockPos desiredPos, final double speedFactor, final boolean safeDestination) { - final int newX = Mth.floor(x); - final int newY = (int) y; - final int newZ = Mth.floor(z); - - if (pathResult != null && pathResult.getJob() instanceof PathJobMoveToLocation) - { - if (pathResult.isComputing()) - { - return pathResult; - } - - if (((destination != null && BlockPosUtil.equals(destination, newX, newY, newZ)) || (originalDestination != null && BlockPosUtil.equals(originalDestination, - newX, - newY, - newZ)))) - { - if (pathResult.getStatus() == IN_PROGRESS_FOLLOWING || ColonyConstants.rand.nextInt(20) != 0) - { - return pathResult; - } - } - } - @NotNull final BlockPos start = PathfindingUtils.prepareStart(ourEntity); - desiredPos = new BlockPos(newX, newY, newZ); - - if (start.distSqr(desiredPos) > 500 * 500) - { - Log.getLogger() - .error( - "Entity: " + ourEntity.getDisplayName().getString() + " is trying to walk too far! distance:" + Math.sqrt(start.distSqr(desiredPos)) + " from:" + start + " to:" - + desiredPos, new Exception()); - return null; - } - return setPathJob( new PathJobMoveToLocation(CompatibilityUtils.getWorldFromEntity(ourEntity), start, desiredPos, (int) ourEntity.getAttribute(Attributes.FOLLOW_RANGE).getValue(), ourEntity), - desiredPos, speedFactor, true); + desiredPos, speedFactor, safeDestination); } + @Deprecated(since = "Do not use, always returns true, vanilla override") @Override - public boolean tryMoveToBlockPos(final BlockPos pos, final double speedFactor) + public boolean walkTo(final BlockPos pos, final double speedFactor) { - moveToXYZ(pos.getX(), pos.getY(), pos.getZ(), speedFactor); + walkTo(pos, speedFactor, false); return true; } @@ -586,31 +556,25 @@ public void setSpeedModifier(final double speedFactor) walkSpeedFactor = speedFactor; } - /** - * Deprecated - try to use BlockPos instead - */ + @Deprecated(since = "Do not use, always returns true, vanilla override") @Override public boolean moveTo(final double x, final double y, final double z, final double speedFactor) { - if (x == 0 && y == 0 && z == 0) - { - return false; - } - - moveToXYZ(x, y, z, speedFactor); + walkTo(BlockPos.containing(x, y, z), speedFactor, false); return true; } @Override public boolean moveTo(final Entity entityIn, final double speedFactor) { - return tryMoveToBlockPos(entityIn.blockPosition(), speedFactor); + return walkTo(entityIn.blockPosition(), speedFactor); } // Removes stupid vanilla stuff, causing our pathpoints to occasionally be replaced by vanilla ones. @Override protected void trimPath() {} + @Deprecated(since = "Do not use, always returns true, vanilla override") @Override public boolean moveTo(@Nullable final Path path, final double speedFactor) { @@ -619,7 +583,6 @@ public boolean moveTo(@Nullable final Path path, final double speedFactor) super.stop(); return false; } - pathStartTime = level.getGameTime(); return super.moveTo(convertPath(path), speedFactor); } @@ -1115,7 +1078,7 @@ public void stop() } @Override - public TreePathResult moveToTree( + public TreePathResult walkToTree( final BlockPos startRestriction, final BlockPos endRestriction, final double speed, @@ -1141,7 +1104,7 @@ public TreePathResult moveToTree( } @Override - public TreePathResult moveToTree(final int range, final double speed, final List excludedTrees, final int dyntreesize, final IColony colony) + public TreePathResult walkToTree(final int range, final double speed, final List excludedTrees, final int dyntreesize, final IColony colony) { @NotNull BlockPos start = PathfindingUtils.prepareStart(ourEntity); final BlockPos buildingPos = ((AbstractEntityCitizen) mob).getCitizenColonyHandler().getWorkBuilding().getPosition(); @@ -1157,16 +1120,16 @@ public TreePathResult moveToTree(final int range, final double speed, final List @Nullable @Override - public PathResult moveToLivingEntity(@NotNull final Entity e, final double speed) + public PathResult walkToEntity(@NotNull final Entity e, final double speed) { - return moveToXYZ(e.getX(), e.getY(), e.getZ(), speed); + return walkTo(e.blockPosition(), speed, false); } @Nullable @Override - public PathResult moveAwayFromLivingEntity(@NotNull final Entity e, final double distance, final double speed) + public PathResult moveAwayFromLivingEntity(@NotNull final Entity e, final double distance, final double speed) { - return moveAwayFromXYZ(e.blockPosition(), distance, speed, true); + return walkAwayFrom(e.blockPosition(), distance, speed, true); } @Override diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathfindingAIHelper.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathfindingAIHelper.java deleted file mode 100644 index 17d6488cc13..00000000000 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathfindingAIHelper.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.minecolonies.core.entity.pathfinding.navigation; - -import com.minecolonies.api.entity.other.AbstractFastMinecoloniesEntity; -import com.minecolonies.api.util.BlockPosUtil; -import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveCloseToXNearY; -import net.minecraft.core.BlockPos; - -public class PathfindingAIHelper -{ - /** - * Tries to walk close to a given pos, staying near another position. - * - * @param entity - * @param desiredPosition - * @param nearbyPosition - * @param distToDesired - * @return True while walking, false when reached - */ - public static boolean walkCloseToXNearY( - final AbstractFastMinecoloniesEntity entity, final BlockPos desiredPosition, - final BlockPos nearbyPosition, - final int distToDesired) - { - final MinecoloniesAdvancedPathNavigate nav = ((MinecoloniesAdvancedPathNavigate) entity.getNavigation()); - - // Three cases - // 1. Navigation Finished - // 2. Navigation is progressing towards a previous task - // 3. Navigation did not try once - boolean isOnRightTask = (nav.getPathResult() != null - && nav.getPathResult().getJob() instanceof PathJobMoveCloseToXNearY job - && job.nearbyPosition.equals(nearbyPosition) - && job.desiredPosition.equals(desiredPosition)); - - if (nav.isDone() || !isOnRightTask) - { - if (isOnRightTask) - { - // Check distance once navigation is done, to let the entity walk - if (BlockPosUtil.dist(entity.blockPosition(), desiredPosition) < distToDesired) - { - nav.stop(); - return false; - } - } - - PathJobMoveCloseToXNearY pathJob = new PathJobMoveCloseToXNearY(entity.level(), desiredPosition, nearbyPosition, 1, entity); - nav.setPathJob(pathJob, desiredPosition, 1.0, false); - } - - return true; - } -} diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathingStuckHandler.java b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathingStuckHandler.java index cfbead29540..0b5d11290de 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathingStuckHandler.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/navigation/PathingStuckHandler.java @@ -149,6 +149,7 @@ public static PathingStuckHandler createStuckHandler() @Override public void checkStuck(final AbstractAdvancedPathNavigate navigator) { + // TODO: rework to allow paths to nonsafe locations still benefit from non-teleport options(skip ahead, reset path etc) if (navigator.getDesiredPos() == null || navigator.getDesiredPos().equals(BlockPos.ZERO)) { resetGlobalStuckTimers(); @@ -338,7 +339,7 @@ private void tryUnstuck(final AbstractAdvancedPathNavigate navigator) navigator.stop(); final int range = ColonyConstants.rand.nextInt(20) + Math.min(100, Math.max(20, BlockPosUtil.distManhattan(navigator.ourEntity.blockPosition(), prevDestination))); - navigator.moveTowards(navigator.getOurEntity().blockPosition().relative(movingAwayDir, 40), range, 1.0f); + navigator.walkTowards(navigator.getOurEntity().blockPosition().relative(movingAwayDir, 40), range, 1.0f); movingAwayDir = movingAwayDir.getClockWise(); navigator.setPauseTicks(range * TICKS_PER_BLOCK); return; diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java index 2118e597d45..c43b559c84b 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java @@ -148,7 +148,7 @@ public abstract class AbstractPathJob implements Callable, IPathJob /** * Heuristic modifier */ - private double heuristicMod = 1; + private double heuristicMod = 2; /** * First node @@ -191,6 +191,10 @@ public AbstractPathJob(final Level world, @NotNull final BlockPos start, int ran result.setJob(this); this.entity = entity; + if (entity != null && entity.getNavigation() instanceof IDynamicHeuristicNavigator navigator) + { + heuristicMod = 1 + navigator.getAvgHeuristicModifier(); + } } /** @@ -217,6 +221,10 @@ protected AbstractPathJob(final Level actualWorld, final LevelReader chunkCache, result.setJob(this); this.entity = entity; + if (entity != null && entity.getNavigation() instanceof IDynamicHeuristicNavigator navigator) + { + heuristicMod = 1 + navigator.getAvgHeuristicModifier(); + } } /** @@ -255,6 +263,10 @@ public AbstractPathJob(final Level world, @NotNull final BlockPos start, @NotNul this.result = result; result.setJob(this); this.entity = entity; + if (entity != null && entity.getNavigation() instanceof IDynamicHeuristicNavigator navigator) + { + heuristicMod = 1 + navigator.getAvgHeuristicModifier(); + } } /** @@ -284,7 +296,7 @@ public final Path call() */ private MNode getAndSetupStartNode() { - final MNode startNode = new MNode(null, start.getX(), start.getY(), start.getZ(), 0, computeHeuristic(start.getX(), start.getY(), start.getZ())); + final MNode startNode = new MNode(null, start.getX(), start.getY(), start.getZ(), 0, computeHeuristic(start.getX(), start.getY(), start.getZ()) * heuristicMod); if (PathfindingUtils.isLadder(cachedBlockLookup.getBlockState(start.getX(), start.getY(), start.getZ()), pathingOptions)) { diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java index 582ff0d55c8..0e10ffa7080 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveAwayFromLocation.java @@ -135,4 +135,19 @@ public BlockPos getDestination() { return preferredDirection; } + + /** + * Helper to compare if the given move away job matches the input parameters + * + * @return true if the given job is the same + */ + public static boolean isJobFor(final AbstractPathJob job, final int avoidDistance, final BlockPos toAvoid) + { + if (job instanceof PathJobMoveAwayFromLocation pathJob) + { + return pathJob.avoidDistance == avoidDistance && pathJob.avoid.equals(toAvoid); + } + + return false; + } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java index 66db7c3cad8..ac43838b65b 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveCloseToXNearY.java @@ -60,7 +60,7 @@ protected boolean isAtDestination(@NotNull final MNode n) return false; } - return BlockPosUtil.distManhattan(desiredPosition, n.x, n.y, n.z) < distToDesired + return BlockPosUtil.distManhattan(desiredPosition, n.x, n.y, n.z) <= distToDesired && SurfaceType.getSurfaceType(world, cachedBlockLookup.getBlockState(n.x, n.y - 1, n.z), tempWorldPos.set(n.x, n.y - 1, n.z), getPathingOptions()) == SurfaceType.WALKABLE; } @@ -105,4 +105,19 @@ public BlockPos getDestination() { return desiredPosition; } + + /** + * Helper to compare if the given move close to X near Y job matches the input parameters + * + * @return true if the given job is the same + */ + public static boolean isJobFor(final AbstractPathJob job, final BlockPos desiredPosition, final BlockPos nearbyPosition, final int distance) + { + if (job instanceof PathJobMoveCloseToXNearY pathJob) + { + return pathJob.nearbyPosition.equals(desiredPosition) && pathJob.nearbyPosition.equals(nearbyPosition) && pathJob.distToDesired == distance; + } + + return false; + } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveToLocation.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveToLocation.java index a7097d8cc90..53421e1ff3c 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveToLocation.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobMoveToLocation.java @@ -6,7 +6,6 @@ import com.minecolonies.core.entity.pathfinding.MNode; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.SurfaceType; -import com.minecolonies.core.entity.pathfinding.navigation.IDynamicHeuristicNavigator; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Mob; @@ -28,11 +27,6 @@ public class PathJobMoveToLocation extends AbstractPathJob implements IDestinati // 0 = exact match private float destinationSlack = DESTINATION_SLACK_NONE; - /** - * Modifier to the heuristics - */ - private double heuristicModifier = 1; - /** * Prepares the PathJob for the path finding system. * @@ -49,13 +43,6 @@ public PathJobMoveToLocation(final Level world, @NotNull final BlockPos start, @ maxNodes += range; this.destination = new BlockPos(end); - if (entity != null && entity.getNavigation() instanceof IDynamicHeuristicNavigator) - { - heuristicModifier = ((IDynamicHeuristicNavigator) entity.getNavigation()).getAvgHeuristicModifier(); - } - - // Overestimate for long distances, +1 per 100 blocks - heuristicModifier += BlockPosUtil.distManhattan(start, end) / 100.0; extraNodes = 4; } @@ -80,7 +67,7 @@ protected Path search() @Override protected double computeHeuristic(final int x, final int y, final int z) { - return BlockPosUtil.distManhattan(destination, x, y, z) * heuristicModifier; + return BlockPosUtil.distManhattan(destination, x, y, z); } /** @@ -174,4 +161,19 @@ public BlockPos getDestination() { return destination; } + + /** + * Helper to compare if the given move to location job matches the input parameters + * + * @return true if the given job is the same + */ + public static boolean isJobFor(final AbstractPathJob job, final BlockPos desiredPosition) + { + if (job instanceof PathJobMoveToLocation pathJob) + { + return pathJob.getDestination().equals(desiredPosition); + } + + return false; + } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobRandomPos.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobRandomPos.java index b70c2b0fb7d..0612c224856 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobRandomPos.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/PathJobRandomPos.java @@ -5,7 +5,6 @@ import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.PathingOptions; import com.minecolonies.core.entity.pathfinding.SurfaceType; -import com.minecolonies.core.entity.pathfinding.navigation.IDynamicHeuristicNavigator; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Mob; @@ -38,11 +37,7 @@ public class PathJobRandomPos extends AbstractPathJob implements IDestinationPat * Box restriction area */ private AABB restrictionBox = null; - - /** - * Modifier to the heuristics - */ - private double heuristicModifier = 1.0; + private BlockPos restrictionBoxCenter = null; /** * Prepares the PathJob for the path finding system. @@ -65,11 +60,6 @@ public PathJobRandomPos( this.maxDistToDest = -1; this.destination = BlockPosUtil.getRandomPosAround(start, minDistFromStart); - - if (entity != null && entity.getNavigation() instanceof IDynamicHeuristicNavigator) - { - heuristicModifier = ((IDynamicHeuristicNavigator) entity.getNavigation()).getAvgHeuristicModifier(); - } } /** @@ -122,7 +112,7 @@ public PathJobRandomPos( Math.max(startRestriction.getX(), endRestriction.getX()), Math.max(startRestriction.getY(), endRestriction.getY()), Math.max(startRestriction.getZ(), endRestriction.getZ())); - + restrictionBoxCenter = BlockPos.containing(restrictionBox.getCenter()); this.minDistFromStart = minDistFromStart; this.maxDistToDest = -1; @@ -132,7 +122,12 @@ public PathJobRandomPos( @Override protected double computeHeuristic(final int x, final int y, final int z) { - return BlockPosUtil.distManhattan(destination, x, y, z) * heuristicModifier; + if (restrictionBox != null) + { + return (BlockPosUtil.distManhattan(destination, x, y, z) + BlockPosUtil.distManhattan(restrictionBoxCenter, x, y, z) / 2.0); + } + + return BlockPosUtil.distManhattan(destination, x, y, z); } @Override @@ -163,21 +158,24 @@ public void setPathingOptions(final PathingOptions pathingOptions) getPathingOptions().canDrop = false; } + @Override + public BlockPos getDestination() + { + return destination; + } + /** - * Checks if position and range match the given parameters + * Helper to compare if the given random pos job matches the input parameters * - * @param range max dist to dest range - * @param pos dest to look from - * @return + * @return true if the given job is the same */ - public boolean posAndRangeMatch(final int range, final BlockPos pos) + public static boolean isJobFor(final AbstractPathJob job, final BlockPos center, final int range) { - return destination != null && pos != null && range == maxDistToDest && destination.equals(pos); - } + if (job instanceof PathJobRandomPos pathJob) + { + return pathJob.destination != null && pathJob.destination.equals(center) && pathJob.maxDistToDest == range; + } - @Override - public BlockPos getDestination() - { - return destination; + return false; } } diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/proxy/EntityCitizenWalkToProxy.java b/src/main/java/com/minecolonies/core/entity/pathfinding/proxy/EntityCitizenWalkToProxy.java index b02676f410f..fbea2a62064 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/proxy/EntityCitizenWalkToProxy.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/proxy/EntityCitizenWalkToProxy.java @@ -11,16 +11,16 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingMiner; import com.minecolonies.core.colony.jobs.AbstractJobGuard; import com.minecolonies.core.colony.jobs.JobMiner; -import com.minecolonies.core.entity.ai.workers.util.MinerLevel; import com.minecolonies.core.entity.ai.workers.util.MineNode; -import com.minecolonies.core.util.WorkerUtil; -import net.minecraft.world.entity.Mob; -import net.minecraft.core.Direction; +import com.minecolonies.core.entity.ai.workers.util.MinerLevel; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Mob; import org.jetbrains.annotations.NotNull; import java.util.*; +// TODO: Rework public class EntityCitizenWalkToProxy extends AbstractWalkToProxy { /** @@ -269,11 +269,35 @@ private void calculateNodes(final MinerLevel level, final int levelDepth, final @Override public boolean isLivingAtSiteWithMove(final Mob entity, final int x, final int y, final int z, final int range) { - if (!WorkerUtil.isWorkerAtSiteWithMove((AbstractEntityCitizen) entity, x, y, z, range)) + if (!isWorkerAtSiteWithMove((AbstractEntityCitizen) entity, x, y, z, range)) { EntityUtils.tryMoveLivingToXYZ(entity, x, y, z); return false; } return true; } + + /** + * Checks if a worker is at his working site. If he isn't, sets it's path to the location. + * + * @param worker Worker to check + * @param x X-coordinate + * @param y Y-coordinate + * @param z Z-coordinate + * @param range Range to check in + * @return True if worker is at site, otherwise false. + */ + public static boolean isWorkerAtSiteWithMove(@NotNull final AbstractEntityCitizen worker, final int x, final int y, final int z, final int range) + { + if (!EntityUtils.isLivingAtSiteWithMove(worker, x, y, z, range)) + { + //If not moving the try setting the point where the entity should move to + if (worker.getNavigation().isDone()) + { + EntityUtils.tryMoveLivingToXYZ(worker, x, y, z); + } + return false; + } + return true; + } } diff --git a/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java b/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java index 3252372be0c..56663d36cf2 100644 --- a/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java @@ -7,7 +7,6 @@ import com.minecolonies.api.colony.requestsystem.location.ILocation; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.api.entity.citizen.citizenhandlers.*; -import com.minecolonies.api.entity.pathfinding.proxy.IWalkToProxy; import com.minecolonies.api.inventory.InventoryCitizen; import com.minecolonies.api.inventory.container.ContainerCitizenInventory; import com.minecolonies.api.util.*; @@ -22,9 +21,11 @@ import com.minecolonies.core.entity.ai.minimal.LookAtEntityInteractGoal; import com.minecolonies.core.entity.ai.visitor.EntityAIVisitor; import com.minecolonies.core.entity.citizen.EntityCitizen; -import com.minecolonies.core.entity.citizen.citizenhandlers.*; +import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenExperienceHandler; +import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenInventoryHandler; +import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenJobHandler; +import com.minecolonies.core.entity.citizen.citizenhandlers.CitizenSleepHandler; import com.minecolonies.core.entity.pathfinding.navigation.MovementHandler; -import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy; import com.minecolonies.core.network.messages.client.ItemParticleEffectMessage; import com.minecolonies.core.network.messages.server.colony.OpenInventoryMessage; import com.minecolonies.core.util.citizenutils.CitizenItemUtils; @@ -77,10 +78,6 @@ public class VisitorCitizen extends AbstractEntityCitizen * It's citizen Id. */ private int citizenId = 0; - /** - * The Walk to proxy (Shortest path through intermediate blocks). - */ - private IWalkToProxy proxy; /** * Reference to the data representation inside the colony. */ @@ -199,23 +196,6 @@ public boolean hurt(@NotNull final DamageSource damageSource, final float damage return false; } - /** - * Checks if a worker is at his working site. If he isn't, sets it's path to the location - * - * @param site the place where he should walk to - * @param range Range to check in - * @return True if worker is at site, otherwise false. - */ - @Override - public boolean isWorkerAtSiteWithMove(@NotNull final BlockPos site, final int range) - { - if (proxy == null) - { - proxy = new EntityCitizenWalkToProxy(this); - } - return proxy.walkToBlock(site, range, true); - } - @Nullable @Override public ICitizenData getCitizenData() @@ -282,12 +262,6 @@ public void playMoveAwaySound() } - @Override - public IWalkToProxy getProxy() - { - return proxy; - } - @Override public void decreaseSaturationForAction() { diff --git a/src/main/java/com/minecolonies/core/util/TeleportHelper.java b/src/main/java/com/minecolonies/core/util/TeleportHelper.java index f699a06d36c..ad19989a5f8 100755 --- a/src/main/java/com/minecolonies/core/util/TeleportHelper.java +++ b/src/main/java/com/minecolonies/core/util/TeleportHelper.java @@ -6,13 +6,13 @@ import com.minecolonies.api.util.BlockPosUtil; import com.minecolonies.api.util.EntityUtils; import com.minecolonies.api.util.MessageUtils; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.resources.ResourceKey; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.Level; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.TicketType; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import static com.minecolonies.api.util.constant.translation.CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND; @@ -51,6 +51,7 @@ public static boolean teleportCitizen(final AbstractEntityCitizen citizen, final citizen.getCitizenSleepHandler().onWakeUp(); } + citizen.getNavigation().stop(); citizen.stopRiding(); citizen.moveTo( spawnPoint.getX() + MIDDLE_BLOCK_OFFSET, @@ -58,16 +59,6 @@ public static boolean teleportCitizen(final AbstractEntityCitizen citizen, final spawnPoint.getZ() + MIDDLE_BLOCK_OFFSET, citizen.getRotationYaw(), citizen.getRotationPitch()); - if (citizen.getProxy() != null) - { - citizen.getProxy().reset(); - } - citizen.getNavigation().stop(); - if (citizen.getProxy() != null) - { - citizen.getProxy().reset(); - } - return true; } diff --git a/src/main/java/com/minecolonies/core/util/WorkerUtil.java b/src/main/java/com/minecolonies/core/util/WorkerUtil.java index b64f4d10529..585b0fb2235 100755 --- a/src/main/java/com/minecolonies/core/util/WorkerUtil.java +++ b/src/main/java/com/minecolonies/core/util/WorkerUtil.java @@ -7,9 +7,9 @@ import com.minecolonies.api.crafting.ItemStorage; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.api.equipment.ModEquipmentTypes; +import com.minecolonies.api.equipment.registry.EquipmentTypeEntry; import com.minecolonies.api.inventory.InventoryCitizen; import com.minecolonies.api.items.ModTags; -import com.minecolonies.api.equipment.registry.EquipmentTypeEntry; import com.minecolonies.api.util.EntityUtils; import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.api.util.Tuple; @@ -18,7 +18,6 @@ import com.minecolonies.core.colony.buildings.modules.SettingsModule; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingFlorist; import com.minecolonies.core.entity.ai.workers.util.MinerLevel; -import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.tileentities.TileEntityCompostedDirt; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; @@ -105,43 +104,6 @@ public static boolean isPathBlock(final Block block) return block.defaultBlockState().is(ModTags.pathingBlocks); } - /** - * {@link WorkerUtil#isWorkerAtSiteWithMove(AbstractEntityCitizen, int, int, int, int)}. - * - * @param worker Worker to check. - * @param site Chunk coordinates of site to check. - * @param range Range to check in. - * @return True when within range, otherwise false. - */ - public static boolean isWorkerAtSiteWithMove(@NotNull final EntityCitizen worker, @NotNull final BlockPos site, final int range) - { - return isWorkerAtSiteWithMove(worker, site.getX(), site.getY(), site.getZ(), range); - } - - /** - * Checks if a worker is at his working site. If he isn't, sets it's path to the location. - * - * @param worker Worker to check - * @param x X-coordinate - * @param y Y-coordinate - * @param z Z-coordinate - * @param range Range to check in - * @return True if worker is at site, otherwise false. - */ - public static boolean isWorkerAtSiteWithMove(@NotNull final AbstractEntityCitizen worker, final int x, final int y, final int z, final int range) - { - if (!EntityUtils.isLivingAtSiteWithMove(worker, x, y, z, range)) - { - //If not moving the try setting the point where the entity should move to - if (worker.getNavigation().isDone()) - { - EntityUtils.tryMoveLivingToXYZ(worker, x, y, z); - } - return false; - } - return true; - } - /** * Recalls the citizen, notifies player if not successful. *