Search in sources :

Example 1 with PathResult

use of com.minecolonies.api.entity.pathfinding.PathResult in project minecolonies by Minecolonies.

the class EntityAIWorkLumberjack method findTree.

/**
 * Search for a tree.
 *
 * @return LUMBERJACK_GATHERING if job was canceled.
 */
private IAIState findTree() {
    final BuildingLumberjack building = getOwnBuilding();
    worker.getCitizenData().setVisibleStatus(SEARCH);
    if (pathResult != null && pathResult.isComputing()) {
        return getState();
    }
    if (pathResult == null) {
        if (building.shouldRestrict()) {
            final BlockPos startPos = building.getStartRestriction();
            final BlockPos endPos = building.getEndRestriction();
            pathResult = worker.getNavigation().moveToTree(startPos, endPos, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), worker.getCitizenColonyHandler().getColony());
        } else {
            pathResult = worker.getNavigation().moveToTree(SEARCH_RANGE + searchIncrement, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), worker.getCitizenColonyHandler().getColony());
        }
        return getState();
    }
    if (pathResult.isDone()) {
        return setNewTree(building);
    }
    // None of the above yielded a result, report no trees found.
    return LUMBERJACK_NO_TREES_FOUND;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) Path(net.minecraft.pathfinding.Path) Item(net.minecraft.item.Item) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ModTags.fungi(com.minecolonies.api.items.ModTags.fungi) Compatibility(com.minecolonies.api.compatibility.Compatibility) Direction(net.minecraft.util.Direction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) net.minecraft.block(net.minecraft.block) BlockTags(net.minecraft.tags.BlockTags) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) SoundCategory(net.minecraft.util.SoundCategory) Constants(com.minecolonies.api.util.constant.Constants) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) JobLumberjack(com.minecolonies.coremod.colony.jobs.JobLumberjack) MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) BuildingLumberjack(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack) PathPoint(net.minecraft.pathfinding.PathPoint) ITag(net.minecraft.tags.ITag) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) IPlantable(net.minecraftforge.common.IPlantable) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) TreePathResult(com.minecolonies.api.entity.pathfinding.TreePathResult) Material(net.minecraft.block.material.Material) BlockItem(net.minecraft.item.BlockItem) MineColonies(com.minecolonies.coremod.MineColonies) WorkerUtil(com.minecolonies.coremod.util.WorkerUtil) ResourceLocation(net.minecraft.util.ResourceLocation) AbstractPathJob(com.minecolonies.coremod.entity.pathfinding.pathjobs.AbstractPathJob) ToolType(com.minecolonies.api.util.constant.ToolType) NotNull(org.jetbrains.annotations.NotNull) PathJobMoveToWithPassable(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveToWithPassable) BlockPos(net.minecraft.util.math.BlockPos) BuildingLumberjack(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack)

Example 2 with PathResult

use of com.minecolonies.api.entity.pathfinding.PathResult in project minecolonies by Minecolonies.

the class DruidCombatAI method moveInAttackPosition.

@Override
protected PathResult moveInAttackPosition(final LivingEntity target) {
    if (BlockPosUtil.getDistanceSquared(target.blockPosition(), user.blockPosition()) <= 4.0) {
        final PathJobMoveAwayFromLocation job = new PathJobMoveAwayFromLocation(user.level, AbstractPathJob.prepareStart(target), target.blockPosition(), 12, (int) user.getAttribute(Attributes.FOLLOW_RANGE).getValue(), user);
        final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
        job.setPathingOptions(combatPathingOptions);
        return pathResult;
    } else if (BlockPosUtil.getDistance2D(target.blockPosition(), user.blockPosition()) >= 20) {
        final PathJobMoveToLocation job = new PathJobMoveToLocation(user.level, AbstractPathJob.prepareStart(user), target.blockPosition(), 200, user);
        final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
        job.setPathingOptions(combatPathingOptions);
        return pathResult;
    }
    final PathJobCanSee job = new PathJobCanSee(user, target, user.level, ((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getGuardPos(), 40);
    final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
    job.setPathingOptions(combatPathingOptions);
    return pathResult;
}
Also used : MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) PathJobMoveAwayFromLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) PathJobMoveToLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveToLocation) PathJobCanSee(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobCanSee)

Example 3 with PathResult

use of com.minecolonies.api.entity.pathfinding.PathResult in project minecolonies by ldtteam.

the class EntityAIWorkLumberjack method findTree.

/**
 * Search for a tree.
 *
 * @return LUMBERJACK_GATHERING if job was canceled.
 */
private IAIState findTree() {
    final BuildingLumberjack building = getOwnBuilding();
    worker.getCitizenData().setVisibleStatus(SEARCH);
    if (pathResult != null && pathResult.isComputing()) {
        return getState();
    }
    if (pathResult == null) {
        if (building.shouldRestrict()) {
            final BlockPos startPos = building.getStartRestriction();
            final BlockPos endPos = building.getEndRestriction();
            pathResult = worker.getNavigation().moveToTree(startPos, endPos, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), worker.getCitizenColonyHandler().getColony());
        } else {
            pathResult = worker.getNavigation().moveToTree(SEARCH_RANGE + searchIncrement, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), worker.getCitizenColonyHandler().getColony());
        }
        return getState();
    }
    if (pathResult.isDone()) {
        return setNewTree(building);
    }
    // None of the above yielded a result, report no trees found.
    return LUMBERJACK_NO_TREES_FOUND;
}
Also used : ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) Path(net.minecraft.pathfinding.Path) Item(net.minecraft.item.Item) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ModTags.fungi(com.minecolonies.api.items.ModTags.fungi) Compatibility(com.minecolonies.api.compatibility.Compatibility) Direction(net.minecraft.util.Direction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) net.minecraft.block(net.minecraft.block) BlockTags(net.minecraft.tags.BlockTags) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) SoundCategory(net.minecraft.util.SoundCategory) Constants(com.minecolonies.api.util.constant.Constants) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) JobLumberjack(com.minecolonies.coremod.colony.jobs.JobLumberjack) MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) BuildingLumberjack(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack) PathPoint(net.minecraft.pathfinding.PathPoint) ITag(net.minecraft.tags.ITag) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) IPlantable(net.minecraftforge.common.IPlantable) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) TreePathResult(com.minecolonies.api.entity.pathfinding.TreePathResult) Material(net.minecraft.block.material.Material) BlockItem(net.minecraft.item.BlockItem) MineColonies(com.minecolonies.coremod.MineColonies) WorkerUtil(com.minecolonies.coremod.util.WorkerUtil) ResourceLocation(net.minecraft.util.ResourceLocation) AbstractPathJob(com.minecolonies.coremod.entity.pathfinding.pathjobs.AbstractPathJob) ToolType(com.minecolonies.api.util.constant.ToolType) NotNull(org.jetbrains.annotations.NotNull) PathJobMoveToWithPassable(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveToWithPassable) BlockPos(net.minecraft.util.math.BlockPos) BuildingLumberjack(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack)

Example 4 with PathResult

use of com.minecolonies.api.entity.pathfinding.PathResult in project minecolonies by ldtteam.

the class RangerCombatAI method moveInAttackPosition.

@Override
protected PathResult moveInAttackPosition(final LivingEntity target) {
    if (BlockPosUtil.getDistanceSquared(target.blockPosition(), user.blockPosition()) <= 4.0) {
        final PathJobMoveAwayFromLocation job = new PathJobMoveAwayFromLocation(user.level, AbstractPathJob.prepareStart(target), target.blockPosition(), (int) 7.0, (int) user.getAttribute(Attributes.FOLLOW_RANGE).getValue(), user);
        final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
        job.setPathingOptions(combatPathingOptions);
        return pathResult;
    } else if (BlockPosUtil.getDistance2D(target.blockPosition(), user.blockPosition()) >= 20) {
        final PathJobMoveToLocation job = new PathJobMoveToLocation(user.level, AbstractPathJob.prepareStart(user), target.blockPosition(), 200, user);
        final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
        job.setPathingOptions(combatPathingOptions);
        return pathResult;
    }
    final PathJobCanSee job = new PathJobCanSee(user, target, user.level, ((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getGuardPos(), 40);
    final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
    job.setPathingOptions(combatPathingOptions);
    return pathResult;
}
Also used : MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) PathJobMoveAwayFromLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) PathJobMoveToLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveToLocation) PathJobCanSee(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobCanSee)

Example 5 with PathResult

use of com.minecolonies.api.entity.pathfinding.PathResult in project minecolonies by Minecolonies.

the class RangerCombatAI method moveInAttackPosition.

@Override
protected PathResult moveInAttackPosition(final LivingEntity target) {
    if (BlockPosUtil.getDistanceSquared(target.blockPosition(), user.blockPosition()) <= 4.0) {
        final PathJobMoveAwayFromLocation job = new PathJobMoveAwayFromLocation(user.level, AbstractPathJob.prepareStart(target), target.blockPosition(), (int) 7.0, (int) user.getAttribute(Attributes.FOLLOW_RANGE).getValue(), user);
        final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
        job.setPathingOptions(combatPathingOptions);
        return pathResult;
    } else if (BlockPosUtil.getDistance2D(target.blockPosition(), user.blockPosition()) >= 20) {
        final PathJobMoveToLocation job = new PathJobMoveToLocation(user.level, AbstractPathJob.prepareStart(user), target.blockPosition(), 200, user);
        final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
        job.setPathingOptions(combatPathingOptions);
        return pathResult;
    }
    final PathJobCanSee job = new PathJobCanSee(user, target, user.level, ((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getGuardPos(), 40);
    final PathResult pathResult = ((MinecoloniesAdvancedPathNavigate) user.getNavigation()).setPathJob(job, null, getCombatMovementSpeed(), true);
    job.setPathingOptions(combatPathingOptions);
    return pathResult;
}
Also used : MinecoloniesAdvancedPathNavigate(com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate) PathJobMoveAwayFromLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) PathJobMoveToLocation(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveToLocation) PathJobCanSee(com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobCanSee)

Aggregations

PathResult (com.minecolonies.api.entity.pathfinding.PathResult)6 MinecoloniesAdvancedPathNavigate (com.minecolonies.coremod.entity.pathfinding.MinecoloniesAdvancedPathNavigate)6 PathJobCanSee (com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobCanSee)4 PathJobMoveAwayFromLocation (com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveAwayFromLocation)4 PathJobMoveToLocation (com.minecolonies.coremod.entity.pathfinding.pathjobs.PathJobMoveToLocation)4 Compatibility (com.minecolonies.api.compatibility.Compatibility)2 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)2 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)2 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)2 VisibleCitizenStatus (com.minecolonies.api.entity.citizen.VisibleCitizenStatus)2 TreePathResult (com.minecolonies.api.entity.pathfinding.TreePathResult)2 ModTags.fungi (com.minecolonies.api.items.ModTags.fungi)2 com.minecolonies.api.util (com.minecolonies.api.util)2 Constants (com.minecolonies.api.util.constant.Constants)2 TICKS_SECOND (com.minecolonies.api.util.constant.Constants.TICKS_SECOND)2 ToolType (com.minecolonies.api.util.constant.ToolType)2 MineColonies (com.minecolonies.coremod.MineColonies)2 ItemListModule (com.minecolonies.coremod.colony.buildings.modules.ItemListModule)2 BuildingLumberjack (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack)2 JobLumberjack (com.minecolonies.coremod.colony.jobs.JobLumberjack)2