Search in sources :

Example 1 with BuildingEnchanter

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

the class EntityAIWorkEnchanter method decide.

/**
 * Decide method of the enchanter. Check if everything is alright to work and then decide between gathering and draining and actually enchanting.
 *
 * @return the next state to go to.
 */
protected IAIState decide() {
    worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
    if (walkToBuilding()) {
        return DECIDE;
    }
    final IAIState craftState = getNextCraftingState();
    if (craftState != getState() && !WorldUtil.isPastTime(world, 13000)) {
        return craftState;
    }
    if (getPrimarySkillLevel() < getOwnBuilding().getBuildingLevel() * MANA_REQ_PER_LEVEL) {
        final BuildingEnchanter enchanterBuilding = getOwnBuilding();
        final EnchanterStationsModule module = enchanterBuilding.getFirstModuleOccurance(EnchanterStationsModule.class);
        if (module.getBuildingsToGatherFrom().isEmpty()) {
            if (worker.getCitizenData() != null) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_WORKERS_TO_DRAIN_SET), ChatPriority.BLOCKING));
            }
            return IDLE;
        }
        final int booksInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), IS_BOOK);
        if (booksInInv <= 0) {
            final int numberOfBooksInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), IS_BOOK);
            if (numberOfBooksInBuilding > 0) {
                needsCurrently = new Tuple<>(IS_BOOK, 1);
                return GATHERING_REQUIRED_MATERIALS;
            }
            checkIfRequestForItemExistOrCreateAsynch(new ItemStack(Items.BOOK, 1));
            return IDLE;
        }
        final BlockPos posToDrainFrom = module.getRandomBuildingToDrainFrom();
        if (posToDrainFrom == null) {
            return IDLE;
        }
        job.setBuildingToDrainFrom(posToDrainFrom);
        return ENCHANTER_DRAIN;
    }
    final int ancientTomesInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), IS_ANCIENT_TOME);
    if (ancientTomesInInv <= 0) {
        final int amountOfAncientTomes = InventoryUtils.getCountFromBuilding(getOwnBuilding(), IS_ANCIENT_TOME);
        if (amountOfAncientTomes > 0) {
            needsCurrently = new Tuple<>(IS_ANCIENT_TOME, 1);
            return GATHERING_REQUIRED_MATERIALS;
        }
        checkIfRequestForItemExistOrCreateAsynch(new ItemStack(ModItems.ancientTome, 1), 1, 1, false);
        return IDLE;
    }
    return ENCHANT;
}
Also used : BuildingEnchanter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingEnchanter) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) EnchanterStationsModule(com.minecolonies.coremod.colony.buildings.modules.EnchanterStationsModule) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 2 with BuildingEnchanter

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

the class EntityAIWorkEnchanter method decide.

/**
 * Decide method of the enchanter. Check if everything is alright to work and then decide between gathering and draining and actually enchanting.
 *
 * @return the next state to go to.
 */
protected IAIState decide() {
    worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
    if (walkToBuilding()) {
        return DECIDE;
    }
    final IAIState craftState = getNextCraftingState();
    if (craftState != getState() && !WorldUtil.isPastTime(world, 13000)) {
        return craftState;
    }
    if (getPrimarySkillLevel() < building.getBuildingLevel() * MANA_REQ_PER_LEVEL) {
        final BuildingEnchanter enchanterBuilding = building;
        final EnchanterStationsModule module = enchanterBuilding.getFirstModuleOccurance(EnchanterStationsModule.class);
        if (module.getBuildingsToGatherFrom().isEmpty()) {
            if (worker.getCitizenData() != null) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_WORKERS_TO_DRAIN_SET), ChatPriority.BLOCKING));
            }
            return IDLE;
        }
        final int booksInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), IS_BOOK);
        if (booksInInv <= 0) {
            final int numberOfBooksInBuilding = InventoryUtils.hasBuildingEnoughElseCount(building, IS_BOOK, 1);
            if (numberOfBooksInBuilding > 0) {
                needsCurrently = new Tuple<>(IS_BOOK, 1);
                return GATHERING_REQUIRED_MATERIALS;
            }
            checkIfRequestForItemExistOrCreateAsync(new ItemStack(Items.BOOK, 1));
            return IDLE;
        }
        final BlockPos posToDrainFrom = module.getRandomBuildingToDrainFrom();
        if (posToDrainFrom == null) {
            return IDLE;
        }
        job.setBuildingToDrainFrom(posToDrainFrom);
        return ENCHANTER_DRAIN;
    }
    final int ancientTomesInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), IS_ANCIENT_TOME);
    if (ancientTomesInInv <= 0) {
        final int amountOfAncientTomes = InventoryUtils.hasBuildingEnoughElseCount(building, IS_ANCIENT_TOME, 1);
        if (amountOfAncientTomes > 0) {
            needsCurrently = new Tuple<>(IS_ANCIENT_TOME, 1);
            return GATHERING_REQUIRED_MATERIALS;
        }
        checkIfRequestForItemExistOrCreateAsync(new ItemStack(ModItems.ancientTome, 1), 1, 1, false);
        return IDLE;
    }
    return ENCHANT;
}
Also used : BuildingEnchanter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingEnchanter) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) EnchanterStationsModule(com.minecolonies.coremod.colony.buildings.modules.EnchanterStationsModule) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)2 EnchanterStationsModule (com.minecolonies.coremod.colony.buildings.modules.EnchanterStationsModule)2 BuildingEnchanter (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingEnchanter)2 StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2