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;
}
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;
}
Aggregations