Search in sources :

Example 1 with BuildingPlantation

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

the class EntityAIWorkPlanter method decide.

@Override
protected IAIState decide() {
    final IAIState nextState = super.decide();
    if (nextState != START_WORKING && nextState != IDLE) {
        return nextState;
    }
    final BuildingPlantation plantation = getOwnBuilding();
    final List<BlockPos> list = plantation.getPosForPhase();
    for (final BlockPos pos : list) {
        if (isAtLeastThreeHigh(pos)) {
            this.workPos = pos;
            return PLANTATION_FARM;
        }
    }
    final Item current = plantation.nextPlantPhase();
    final int plantInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemStack -> itemStack.sameItem(new ItemStack(current)));
    final int plantInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), itemStack -> itemStack.sameItem(new ItemStack(current)));
    if (plantInBuilding + plantInInv <= 0) {
        requestPlantable(current);
        return START_WORKING;
    }
    if (plantInInv == 0 && plantInBuilding > 0) {
        needsCurrently = new Tuple<>(itemStack -> itemStack.sameItem(new ItemStack(current)), Math.min(plantInBuilding, PLANT_TO_REQUEST));
        return GATHERING_REQUIRED_MATERIALS;
    }
    for (final BlockPos pos : list) {
        if (world.getBlockState(pos.above()).getBlock() instanceof AirBlock) {
            this.workPos = pos;
            return PLANTATION_PLANT;
        }
    }
    return START_WORKING;
}
Also used : BuildingPlantation(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation) JobPlanter(com.minecolonies.coremod.colony.jobs.JobPlanter) TICKS_20(com.minecolonies.api.util.constant.CitizenConstants.TICKS_20) BuildingPlantation(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation) Item(net.minecraft.item.Item) AirBlock(net.minecraft.block.AirBlock) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockPos(net.minecraft.util.math.BlockPos) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Tuple(com.minecolonies.api.util.Tuple) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockUtils(com.ldtteam.structurize.util.BlockUtils) InventoryUtils(com.minecolonies.api.util.InventoryUtils) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) ItemEntity(net.minecraft.entity.item.ItemEntity) NotNull(org.jetbrains.annotations.NotNull) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) Item(net.minecraft.item.Item) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 2 with BuildingPlantation

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

the class EntityAIWorkPlanter method decide.

@Override
protected IAIState decide() {
    final IAIState nextState = super.decide();
    if (nextState != START_WORKING && nextState != IDLE) {
        return nextState;
    }
    final BuildingPlantation plantation = getOwnBuilding();
    final List<BlockPos> list = plantation.getPosForPhase();
    for (final BlockPos pos : list) {
        if (isAtLeastThreeHigh(pos)) {
            this.workPos = pos;
            return PLANTATION_FARM;
        }
    }
    final Item current = plantation.nextPlantPhase();
    final int plantInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemStack -> itemStack.sameItem(new ItemStack(current)));
    final int plantInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), itemStack -> itemStack.sameItem(new ItemStack(current)));
    if (plantInBuilding + plantInInv <= 0) {
        requestPlantable(current);
        return START_WORKING;
    }
    if (plantInInv == 0 && plantInBuilding > 0) {
        needsCurrently = new Tuple<>(itemStack -> itemStack.sameItem(new ItemStack(current)), Math.min(plantInBuilding, PLANT_TO_REQUEST));
        return GATHERING_REQUIRED_MATERIALS;
    }
    for (final BlockPos pos : list) {
        if (world.getBlockState(pos.above()).getBlock() instanceof AirBlock) {
            this.workPos = pos;
            return PLANTATION_PLANT;
        }
    }
    return START_WORKING;
}
Also used : BuildingPlantation(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation) JobPlanter(com.minecolonies.coremod.colony.jobs.JobPlanter) TICKS_20(com.minecolonies.api.util.constant.CitizenConstants.TICKS_20) BuildingPlantation(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation) Item(net.minecraft.item.Item) AirBlock(net.minecraft.block.AirBlock) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockPos(net.minecraft.util.math.BlockPos) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Tuple(com.minecolonies.api.util.Tuple) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockUtils(com.ldtteam.structurize.util.BlockUtils) InventoryUtils(com.minecolonies.api.util.InventoryUtils) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) ItemEntity(net.minecraft.entity.item.ItemEntity) NotNull(org.jetbrains.annotations.NotNull) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) Item(net.minecraft.item.Item) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BlockUtils (com.ldtteam.structurize.util.BlockUtils)2 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)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 InventoryUtils (com.minecolonies.api.util.InventoryUtils)2 Tuple (com.minecolonies.api.util.Tuple)2 TICKS_20 (com.minecolonies.api.util.constant.CitizenConstants.TICKS_20)2 BuildingPlantation (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation)2 JobPlanter (com.minecolonies.coremod.colony.jobs.JobPlanter)2 AbstractEntityAICrafting (com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting)2 List (java.util.List)2 AirBlock (net.minecraft.block.AirBlock)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 BlockPos (net.minecraft.util.math.BlockPos)2 NotNull (org.jetbrains.annotations.NotNull)2