Search in sources :

Example 1 with AIWorkerState

use of com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState in project minecolonies by ldtteam.

the class EntityAIWorkFarmer method workAtField.

/**
 * This (re)initializes a field. Checks the block above to see if it is a plant, if so, breaks it. Then tills.
 *
 * @return the next state to go into.
 */
private IAIState workAtField() {
    @Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
    final FarmerFieldModule module = buildingFarmer.getFirstModuleOccurance(FarmerFieldModule.class);
    if (checkForToolOrWeapon(ToolType.HOE) || module.getCurrentField() == null) {
        return PREPARING;
    }
    worker.getCitizenData().setVisibleStatus(FARMING_ICON);
    @Nullable final BlockPos field = module.getCurrentField();
    final TileEntity entity = world.getBlockEntity(field);
    if (entity instanceof ScarecrowTileEntity) {
        final ScarecrowTileEntity scarecrow = (ScarecrowTileEntity) entity;
        if (workingOffset != null) {
            if (scarecrow.getOwnerId() != worker.getCivilianID()) {
                module.freeField(module.getCurrentField());
                module.setCurrentField(null);
                return getState();
            }
            final BlockPos position = field.below().south(workingOffset.getZ()).east(workingOffset.getX());
            // Still moving to the block
            if (walkToBlock(position.above())) {
                return getState();
            }
            switch((AIWorkerState) getState()) {
                case FARMER_HOE:
                    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.hoeing"));
                    if (!hoeIfAble(position, scarecrow)) {
                        return getState();
                    }
                    break;
                case FARMER_PLANT:
                    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.planting"));
                    if (!tryToPlant(scarecrow, position)) {
                        return PREPARING;
                    }
                    break;
                case FARMER_HARVEST:
                    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.harvesting"));
                    if (!harvestIfAble(position)) {
                        return getState();
                    }
                    break;
                default:
                    return PREPARING;
            }
            prevPos = position;
            setDelay(getLevelDelay());
        }
        workingOffset = nextValidCell(scarecrow);
        if (workingOffset == null) {
            shouldDumpInventory = true;
            scarecrow.nextState();
            prevPos = null;
            return IDLE;
        }
    } else {
        return IDLE;
    }
    return getState();
}
Also used : ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) BuildingFarmer(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingFarmer) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AIWorkerState

use of com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method workAtField.

/**
 * This (re)initializes a field. Checks the block above to see if it is a plant, if so, breaks it. Then tills.
 *
 * @return the next state to go into.
 */
private IAIState workAtField() {
    @Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
    final FarmerFieldModule module = buildingFarmer.getFirstModuleOccurance(FarmerFieldModule.class);
    if (checkForToolOrWeapon(ToolType.HOE) || module.getCurrentField() == null) {
        return PREPARING;
    }
    worker.getCitizenData().setVisibleStatus(FARMING_ICON);
    @Nullable final BlockPos field = module.getCurrentField();
    final TileEntity entity = world.getBlockEntity(field);
    if (entity instanceof ScarecrowTileEntity) {
        final ScarecrowTileEntity scarecrow = (ScarecrowTileEntity) entity;
        if (workingOffset != null) {
            if (scarecrow.getOwnerId() != worker.getCivilianID()) {
                module.freeField(module.getCurrentField());
                module.setCurrentField(null);
                return getState();
            }
            final BlockPos position = field.below().south(workingOffset.getZ()).east(workingOffset.getX());
            // Still moving to the block
            if (walkToBlock(position.above())) {
                return getState();
            }
            switch((AIWorkerState) getState()) {
                case FARMER_HOE:
                    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.hoeing"));
                    if (!hoeIfAble(position, scarecrow)) {
                        return getState();
                    }
                    break;
                case FARMER_PLANT:
                    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.planting"));
                    if (!tryToPlant(scarecrow, position)) {
                        return PREPARING;
                    }
                    break;
                case FARMER_HARVEST:
                    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.harvesting"));
                    if (!harvestIfAble(position)) {
                        return getState();
                    }
                    break;
                default:
                    return PREPARING;
            }
            prevPos = position;
            setDelay(getLevelDelay());
        }
        workingOffset = nextValidCell(scarecrow);
        if (workingOffset == null) {
            shouldDumpInventory = true;
            scarecrow.nextState();
            prevPos = null;
            return IDLE;
        }
    } else {
        return IDLE;
    }
    return getState();
}
Also used : ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) BuildingFarmer(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingFarmer) FarmerFieldModule(com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractScarecrowTileEntity(com.minecolonies.api.tileentities.AbstractScarecrowTileEntity) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)2 AbstractScarecrowTileEntity (com.minecolonies.api.tileentities.AbstractScarecrowTileEntity)2 FarmerFieldModule (com.minecolonies.coremod.colony.buildings.modules.FarmerFieldModule)2 BuildingFarmer (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingFarmer)2 ScarecrowTileEntity (com.minecolonies.coremod.tileentities.ScarecrowTileEntity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 Nullable (org.jetbrains.annotations.Nullable)2