Search in sources :

Example 1 with BuildingFarmer

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

the class EntityAIWorkFarmer method cycle.

/**
     * The main work cycle of the Famer.
     * This checks each block, harvests, tills, and plants.
     */
private AIState cycle() {
    @Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
    if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
        return AIState.PREPARING;
    }
    @Nullable final Field field = buildingFarmer.getCurrentField();
    if (workingOffset != null) {
        final BlockPos position = field.getLocation().down().south(workingOffset.getZ()).east(workingOffset.getX());
        // Still moving to the block
        if (walkToBlock(position.up())) {
            return AIState.FARMER_WORK;
        }
        // harvest the block if able to.
        if (harvestIfAble(position)) {
            setDelay(getLevelDelay());
        }
    }
    if (!handleOffsetHarvest(field)) {
        resetVariables();
        shouldDumpInventory = true;
        field.setNeedsWork(false);
        return AIState.IDLE;
    }
    return AIState.FARMER_WORK;
}
Also used : BlockHutField(com.minecolonies.coremod.blocks.BlockHutField) BlockPos(net.minecraft.util.math.BlockPos) BuildingFarmer(com.minecolonies.coremod.colony.buildings.BuildingFarmer) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with BuildingFarmer

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

the class EntityAIWorkFarmer method lookAtField.

/**
     * Farmer looks at field to see if it's harvestable.
     * Checks to see if there are any harvestable crops,
     * if so go to FARMER_WORK, if not, set needs work to false and go to IDLE.
     */
private AIState lookAtField() {
    @Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
    if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
        return AIState.PREPARING;
    }
    @Nullable final Field field = buildingFarmer.getCurrentField();
    setDelay(LOOK_WAIT);
    if (handleOffsetHarvest(field)) {
        return AIState.FARMER_WORK;
    } else {
        if (containsPlants(field)) {
            field.setNeedsWork(false);
            return AIState.PREPARING;
        } else {
            field.setInitialized(false);
            return AIState.PREPARING;
        }
    }
}
Also used : BlockHutField(com.minecolonies.coremod.blocks.BlockHutField) BuildingFarmer(com.minecolonies.coremod.colony.buildings.BuildingFarmer) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with BuildingFarmer

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

the class EntityAIWorkFarmer method prepareForFarming.

/**
     * Prepares the farmer for farming.
     * Also requests the tools and checks if the farmer has sufficient fields.
     *
     * @return the next AIState
     */
@NotNull
private AIState prepareForFarming() {
    @Nullable final BuildingFarmer building = getOwnBuilding();
    if (building == null || building.getBuildingLevel() < 1) {
        return AIState.PREPARING;
    }
    building.syncWithColony(world);
    if (building.getFarmerFields().size() < getOwnBuilding().getBuildingLevel() && !building.assignManually()) {
        searchAndAddFields();
    }
    if (building.hasNoFields()) {
        chatSpamFilter.talkWithoutSpam("entity.farmer.noFreeFields");
        return AIState.PREPARING;
    }
    //If the farmer has no currentField and there is no field which needs work, check fields.
    if (building.getCurrentField() == null && building.getFieldToWorkOn() == null) {
        building.resetFields();
        return AIState.IDLE;
    }
    @Nullable final Field currentField = building.getCurrentField();
    if (currentField.needsWork()) {
        if (currentField.isInitialized()) {
            walkToBlock(currentField.getLocation());
            return AIState.FARMER_OBSERVE;
        } else if (canGoPlanting(currentField, building) && !checkForHoe()) {
            return walkToBlock(currentField.getLocation()) ? AIState.PREPARING : AIState.FARMER_INITIALIZE;
        } else if (containsPlants(currentField) && !walkToBuilding() && !canGoPlanting(currentField, building)) {
            currentField.setInitialized(true);
            currentField.setNeedsWork(false);
        }
    } else {
        getOwnBuilding().setCurrentField(null);
    }
    return AIState.PREPARING;
}
Also used : BlockHutField(com.minecolonies.coremod.blocks.BlockHutField) BuildingFarmer(com.minecolonies.coremod.colony.buildings.BuildingFarmer) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with BuildingFarmer

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

the class EntityAIWorkFarmer method initialize.

/**
     * This (re)initializes a field.
     * Checks the block above to see if it is a plant, if so, breaks it. Then tills.
     */
private AIState initialize() {
    @Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
    if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
        return AIState.PREPARING;
    }
    @Nullable final Field field = buildingFarmer.getCurrentField();
    if (workingOffset != null) {
        final BlockPos position = field.getLocation().down().south(workingOffset.getZ()).east(workingOffset.getX());
        // Still moving to the block
        if (walkToBlock(position.up())) {
            return AIState.FARMER_INITIALIZE;
        }
        // Check to see if the block is a plant, and if it is, break it.
        final IBlockState blockState = world.getBlockState(position.up());
        if (blockState.getBlock() instanceof IGrowable && (!(blockState.getBlock() instanceof BlockCrops) || ((BlockCrops) blockState.getBlock()).getItem(world, position.up(), blockState) != field.getSeed())) {
            mineBlock(position.up());
            setDelay(getLevelDelay());
            return AIState.FARMER_INITIALIZE;
        }
        // hoe the block if able to.
        if (hoeIfAble(position, field)) {
            setDelay(getLevelDelay());
            return AIState.FARMER_INITIALIZE;
        }
        if (shouldPlant(position, field) && !plantCrop(field.getSeed(), position)) {
            resetVariables();
            return AIState.PREPARING;
        }
    }
    if (!handleOffset(field)) {
        resetVariables();
        shouldDumpInventory = true;
        field.setInitialized(true);
        field.setNeedsWork(false);
        return AIState.IDLE;
    }
    setDelay(getLevelDelay());
    return AIState.FARMER_INITIALIZE;
}
Also used : BlockHutField(com.minecolonies.coremod.blocks.BlockHutField) IBlockState(net.minecraft.block.state.IBlockState) BlockCrops(net.minecraft.block.BlockCrops) IGrowable(net.minecraft.block.IGrowable) BlockPos(net.minecraft.util.math.BlockPos) BuildingFarmer(com.minecolonies.coremod.colony.buildings.BuildingFarmer) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BlockHutField (com.minecolonies.coremod.blocks.BlockHutField)4 BuildingFarmer (com.minecolonies.coremod.colony.buildings.BuildingFarmer)4 Nullable (org.jetbrains.annotations.Nullable)4 BlockPos (net.minecraft.util.math.BlockPos)2 BlockCrops (net.minecraft.block.BlockCrops)1 IGrowable (net.minecraft.block.IGrowable)1 IBlockState (net.minecraft.block.state.IBlockState)1 NotNull (org.jetbrains.annotations.NotNull)1