Search in sources :

Example 1 with BuildingLumberjack

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack 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 BuildingLumberjack

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack in project minecolonies by Minecolonies.

the class EntityAIWorkLumberjack method chopTree.

/**
 * Work on the tree. First find your way to the tree trunk. Then chop away and wait for saplings to drop then place a sapling if shouldReplant is true
 *
 * @return LUMBERJACK_GATHERING if tree is done
 */
private IAIState chopTree() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.chopping"));
    if (job.getTree().hasLogs() || (job.getTree().hasLeaves() && job.getTree().isNetherTree()) || checkedInHut) {
        if (!walkToTree(job.getTree().getStumpLocations().get(0))) {
            if (checkIfStuck()) {
                tryUnstuck();
            }
            return getState();
        }
    }
    if (!job.getTree().hasLogs() && (!job.getTree().isNetherTree() || !(job.getTree().hasLeaves()))) {
        if (hasNotDelayed(WAIT_BEFORE_SAPLING)) {
            return getState();
        }
        final BuildingLumberjack building = getOwnBuilding();
        if (building.shouldReplant()) {
            plantSapling();
        } else {
            job.setTree(null);
            checkedInHut = false;
        }
        worker.getCitizenExperienceHandler().addExperience(XP_PER_TREE);
        incrementActionsDoneAndDecSaturation();
        workFrom = null;
        setDelay(TICKS_SECOND * GATHERING_DELAY);
        return LUMBERJACK_GATHERING;
    }
    if (isOnSapling()) {
        @Nullable final BlockPos spawnPoint = Utils.scanForBlockNearPoint(world, workFrom, 1, 1, 1, 3, Blocks.AIR, Blocks.CAVE_AIR, Blocks.SNOW, Blocks.TALL_GRASS);
        WorkerUtil.setSpawnPoint(spawnPoint, worker);
    }
    if (job.getTree().hasLogs()) {
        // take first log from queue
        final BlockPos log = job.getTree().peekNextLog();
        if (job.getTree().isDynamicTree()) {
            // Dynamic Trees handles drops/tool dmg upon tree break, so those are set to false here
            if (!mineBlock(log, workFrom, false, false, Compatibility.getDynamicTreeBreakAction(world, log, worker.getItemInHand(Hand.MAIN_HAND), worker.blockPosition()))) {
                return getState();
            }
            // Successfully mined Dynamic tree, count as 6 actions done(1+5)
            for (int i = 0; i < 6; i++) {
                this.incrementActionsDone();
            }
            // Wait 5 sec for falling trees(dyn tree feature)/drops
            setDelay(100);
        } else {
            if (!mineBlock(log, workFrom)) {
                return getState();
            }
        }
        job.getTree().pollNextLog();
        worker.decreaseSaturationForContinuousAction();
    } else if (job.getTree().hasLeaves() && job.getTree().isNetherTree()) {
        final BlockPos leaf = job.getTree().peekNextLeaf();
        if (!mineBlock(leaf, workFrom)) {
            return getState();
        }
        job.getTree().pollNextLeaf();
    }
    return getState();
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) BuildingLumberjack(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack) Nullable(org.jetbrains.annotations.Nullable) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 3 with BuildingLumberjack

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack in project minecolonies by ldtteam.

the class EntityAIWorkLumberjack method chopTree.

/**
 * Work on the tree. First find your way to the tree trunk. Then chop away and wait for saplings to drop then place a sapling if shouldReplant is true
 *
 * @return LUMBERJACK_GATHERING if tree is done
 */
private IAIState chopTree() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.chopping"));
    if (job.getTree().hasLogs() || (job.getTree().hasLeaves() && job.getTree().isNetherTree()) || checkedInHut) {
        if (!walkToTree(job.getTree().getStumpLocations().get(0))) {
            if (checkIfStuck()) {
                tryUnstuck();
            }
            return getState();
        }
    }
    if (!job.getTree().hasLogs() && (!job.getTree().isNetherTree() || !(job.getTree().hasLeaves()))) {
        if (hasNotDelayed(WAIT_BEFORE_SAPLING)) {
            return getState();
        }
        final BuildingLumberjack building = getOwnBuilding();
        if (building.shouldReplant()) {
            plantSapling();
        } else {
            job.setTree(null);
            checkedInHut = false;
        }
        worker.getCitizenExperienceHandler().addExperience(XP_PER_TREE);
        incrementActionsDoneAndDecSaturation();
        workFrom = null;
        setDelay(TICKS_SECOND * GATHERING_DELAY);
        return LUMBERJACK_GATHERING;
    }
    if (isOnSapling()) {
        @Nullable final BlockPos spawnPoint = Utils.scanForBlockNearPoint(world, workFrom, 1, 1, 1, 3, Blocks.AIR, Blocks.CAVE_AIR, Blocks.SNOW, Blocks.TALL_GRASS);
        WorkerUtil.setSpawnPoint(spawnPoint, worker);
    }
    if (job.getTree().hasLogs()) {
        // take first log from queue
        final BlockPos log = job.getTree().peekNextLog();
        if (job.getTree().isDynamicTree()) {
            // Dynamic Trees handles drops/tool dmg upon tree break, so those are set to false here
            if (!mineBlock(log, workFrom, false, false, Compatibility.getDynamicTreeBreakAction(world, log, worker.getItemInHand(Hand.MAIN_HAND), worker.blockPosition()))) {
                return getState();
            }
            // Successfully mined Dynamic tree, count as 6 actions done(1+5)
            for (int i = 0; i < 6; i++) {
                this.incrementActionsDone();
            }
            // Wait 5 sec for falling trees(dyn tree feature)/drops
            setDelay(100);
        } else {
            if (!mineBlock(log, workFrom)) {
                return getState();
            }
        }
        job.getTree().pollNextLog();
        worker.decreaseSaturationForContinuousAction();
    } else if (job.getTree().hasLeaves() && job.getTree().isNetherTree()) {
        final BlockPos leaf = job.getTree().peekNextLeaf();
        if (!mineBlock(leaf, workFrom)) {
            return getState();
        }
        job.getTree().pollNextLeaf();
    }
    return getState();
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) BuildingLumberjack(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack) Nullable(org.jetbrains.annotations.Nullable) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 4 with BuildingLumberjack

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack 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 5 with BuildingLumberjack

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack in project minecolonies by Minecolonies.

the class ItemScepterLumberjack method storeRestrictedArea.

private void storeRestrictedArea(final PlayerEntity player, final CompoundNBT compound, final World worldIn) {
    final BlockPos startRestriction = BlockPosUtil.read(compound, NBT_START_POS);
    final BlockPos endRestriction = BlockPosUtil.read(compound, NBT_END_POS);
    // Check restricted area isn't too large
    final int minX = Math.min(startRestriction.getX(), endRestriction.getX());
    final int minZ = Math.min(startRestriction.getZ(), endRestriction.getZ());
    final int maxX = Math.max(startRestriction.getX(), endRestriction.getX());
    final int maxZ = Math.max(startRestriction.getZ(), endRestriction.getZ());
    final int distX = maxX - minX;
    final int distZ = maxZ - minZ;
    final int area = distX * distZ;
    final int maxArea = (int) Math.floor(2 * Math.pow(EntityAIWorkLumberjack.SEARCH_RANGE, 2));
    if (area > maxArea) {
        LanguageHandler.sendPlayerMessage(player, "item.minecolonies.scepterlumberjack.restrictiontoobig", area, maxArea);
        return;
    }
    LanguageHandler.sendPlayerMessage(player, "item.minecolonies.scepterlumberjack.restrictionset", minX, maxX, minZ, maxZ, area, maxArea);
    final IColony colony = IColonyManager.getInstance().getColonyByWorld(compound.getInt(TAG_ID), worldIn);
    final BlockPos hutPos = BlockPosUtil.read(compound, TAG_POS);
    final BuildingLumberjack hut = colony.getBuildingManager().getBuilding(hutPos, BuildingLumberjack.class);
    if (hut == null) {
        return;
    }
    hut.setRestrictedArea(startRestriction, endRestriction);
}
Also used : IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) BuildingLumberjack(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack)

Aggregations

BuildingLumberjack (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack)6 BlockPos (net.minecraft.util.math.BlockPos)6 PathPoint (net.minecraft.pathfinding.PathPoint)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 Nullable (org.jetbrains.annotations.Nullable)4 IColony (com.minecolonies.api.colony.IColony)2 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 PathResult (com.minecolonies.api.entity.pathfinding.PathResult)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