use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class AbstractEntityAIRequestSmelter method craft.
@Override
protected IAIState craft() {
final FurnaceUserModule module = building.getFirstModuleOccurance(FurnaceUserModule.class);
final List<ItemStack> possibleFuels = getAllowedFuel();
if (possibleFuels.isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FUEL), ChatPriority.BLOCKING));
}
return getState();
}
if (currentRecipeStorage != null) {
possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
// There is always only one input.
possibleFuels.removeIf(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getCleanedInput().get(0).getItemStack()));
}
if (walkToBuilding()) {
setDelay(STANDARD_DELAY);
return getState();
}
if (currentRecipeStorage != null && currentRequest == null) {
currentRequest = job.getCurrentTask();
}
if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() != Blocks.FURNACE) {
return super.craft();
}
if (module.getFurnaces().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
}
setDelay(STANDARD_DELAY);
return START_WORKING;
}
final BlockPos furnacePosWithUsedFuel = getPositionOfOvenToRetrieveFuelFrom();
if (furnacePosWithUsedFuel != null) {
walkTo = furnacePosWithUsedFuel;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_USED_FUEL_FROM_FURNACE;
}
final BlockPos posOfOven = getPositionOfOvenToRetrieveFrom();
if (posOfOven != null) {
walkTo = posOfOven;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_END_PRODUCT_FROM_FURNACE;
}
// Safety net, should get caught removing things from the furnace.
if (currentRequest != null && job.getMaxCraftingCount() > 0 && job.getCraftCounter() >= job.getMaxCraftingCount()) {
job.finishRequest(true);
currentRecipeStorage = null;
currentRequest = null;
resetValues();
return INVENTORY_FULL;
}
if (currentRequest != null && (currentRequest.getState() == RequestState.CANCELLED || currentRequest.getState() == RequestState.FAILED)) {
incrementActionsDone(getActionRewardForCraftingSuccess());
currentRecipeStorage = null;
currentRequest = null;
resetValues();
return START_WORKING;
}
return checkIfAbleToSmelt();
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class AbstractEntityAIUsesFurnace method startWorking.
/**
* Central method of the furnace user, he decides about what to do next from here. First check if any of the workers has important tasks to handle first. If not check if there
* is an oven with an item which has to be retrieved. If not check if fuel and smeltable are available and request if necessary and get into inventory. Then check if able to
* smelt already.
*
* @return the next state to go to.
*/
public IAIState startWorking() {
if (walkToBuilding()) {
return getState();
}
final FurnaceUserModule furnaceModule = building.getFirstModuleOccurance(FurnaceUserModule.class);
final ItemListModule itemListModule = building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
if (itemListModule.getList().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FUEL), ChatPriority.BLOCKING));
}
return getState();
}
if (furnaceModule.getFurnaces().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
}
return getState();
}
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
final IAIState nextState = checkForImportantJobs();
if (nextState != START_WORKING) {
return nextState;
}
final BlockPos posOfUsedFuelOven = getPositionOfOvenToRetrieveFuelFrom();
if (posOfUsedFuelOven != null) {
walkTo = posOfUsedFuelOven;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_USED_FUEL_FROM_FURNACE;
}
final BlockPos posOfOven = getPositionOfOvenToRetrieveFrom();
if (posOfOven != null) {
walkTo = posOfOven;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_END_PRODUCT_FROM_FURNACE;
}
final int amountOfSmeltableInBuilding = InventoryUtils.getCountFromBuilding(building, this::isSmeltable);
final int amountOfSmeltableInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), this::isSmeltable);
final int amountOfFuelInBuilding = InventoryUtils.getCountFromBuilding(building, itemListModule.getList());
final int amountOfFuelInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), stack -> itemListModule.isItemInList(new ItemStorage(stack)));
if (amountOfSmeltableInBuilding + amountOfSmeltableInInv <= 0 && !reachedMaxToKeep()) {
requestSmeltable();
}
if (amountOfFuelInBuilding + amountOfFuelInInv <= 0 && !building.hasWorkerOpenRequestsFiltered(worker.getCitizenData().getId(), req -> req.getShortDisplayString().getSiblings().contains(new TranslationTextComponent(RequestSystemTranslationConstants.REQUESTS_TYPE_BURNABLE)))) {
worker.getCitizenData().createRequestAsync(new StackList(getAllowedFuel(), RequestSystemTranslationConstants.REQUESTS_TYPE_BURNABLE, STACKSIZE * furnaceModule.getFurnaces().size(), 1));
}
if (amountOfSmeltableInBuilding > 0 && amountOfSmeltableInInv == 0) {
needsCurrently = new Tuple<>(this::isSmeltable, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
} else if (amountOfFuelInBuilding > 0 && amountOfFuelInInv == 0) {
needsCurrently = new Tuple<>(stack -> itemListModule.isItemInList(new ItemStorage(stack)), STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
}
return checkIfAbleToSmelt(amountOfFuelInBuilding + amountOfFuelInInv, amountOfSmeltableInBuilding + amountOfSmeltableInInv);
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class EntityAIWorkAlchemist method fillUpBrewingStand.
/**
* Brew the ingredient after the required items are in the inv.
*
* @return the next state to go to.
*/
private IAIState fillUpBrewingStand() {
if (building.getAllBrewingStandPositions().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
}
setDelay(STANDARD_DELAY);
return START_WORKING;
}
if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.BREWING_STAND) {
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
final int burningCount = countOfBubblingBrewingStands();
final TileEntity entity = world.getBlockEntity(walkTo);
if (entity instanceof BrewingStandTileEntity && currentRecipeStorage != null) {
final BrewingStandTileEntity brewingStand = (BrewingStandTileEntity) entity;
final int maxBrewingStands = getMaxUsableBrewingStands();
final int resultInBrewingStand = getExtendedCount(currentRecipeStorage.getPrimaryOutput());
final int resultInCitizenInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
if (isEmpty(((BrewingStandTileEntity) entity).getItem(0)) || isEmpty(((BrewingStandTileEntity) entity).getItem(1)) || isEmpty(((BrewingStandTileEntity) entity).getItem(2))) {
final ItemStack potionStack = currentRecipeStorage.getCleanedInput().get(1).getItemStack();
final Predicate<ItemStack> potion = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(potionStack, stack);
final int potionInBrewingStand = getExtendedCount(potionStack);
final int targetCount = currentRequest.getRequest().getCount() * currentRecipeStorage.getPrimaryOutput().getCount() - potionInBrewingStand - resultInBrewingStand - resultInCitizenInv;
if (targetCount <= 0) {
return START_WORKING;
}
final int amountOfPotionInBuilding = InventoryUtils.getCountFromBuilding(building, potion);
final int amountOfPotionInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), potion);
if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
worker.setItemInHand(Hand.MAIN_HAND, potionStack.copy());
}
if (amountOfPotionInInv > 0) {
if (hasFuelAndNoBrewable(brewingStand) || hasNeitherFuelNorBrewable(brewingStand)) {
for (int slot = 0; slot < 3; slot++) {
if (!isEmpty(((BrewingStandTileEntity) entity).getItem(slot))) {
continue;
}
int toTransfer = 0;
if (burningCount < maxBrewingStands) {
toTransfer = 1;
}
if (toTransfer > 0) {
if (walkToBlock(walkTo)) {
return getState();
}
worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), potion, toTransfer, new InvWrapper(brewingStand), slot);
}
}
}
} else if (amountOfPotionInBuilding >= targetCount - amountOfPotionInInv && currentRecipeStorage.getIntermediate() == Blocks.BREWING_STAND) {
needsCurrently = new Tuple<>(potion, targetCount);
return GATHERING_REQUIRED_MATERIALS;
} else {
// This is a safety net for the AI getting way out of sync with it's tracking. It shouldn't happen.
job.finishRequest(false);
resetValues();
walkTo = null;
return IDLE;
}
} else if (isEmpty(((BrewingStandTileEntity) entity).getItem(INGREDIENT_SLOT))) {
final ItemStack ingredientStack = currentRecipeStorage.getCleanedInput().get(0).getItemStack();
final Predicate<ItemStack> ingredient = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(ingredientStack, stack);
final int ingredientInBrewingStand = getExtendedCount(ingredientStack);
final int targetCount = currentRequest.getRequest().getCount() * currentRecipeStorage.getPrimaryOutput().getCount() - ingredientInBrewingStand * 3 - resultInBrewingStand - resultInCitizenInv;
if (targetCount <= 0) {
return START_WORKING;
}
final int amountOfIngredientInBuilding = InventoryUtils.getCountFromBuilding(building, ingredient);
final int amountOfIngredientInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), ingredient);
if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
worker.setItemInHand(Hand.MAIN_HAND, ingredientStack.copy());
}
if (amountOfIngredientInInv > 0) {
if (hasFuelAndNoBrewable(brewingStand) || hasNeitherFuelNorBrewable(brewingStand)) {
int toTransfer = 0;
if (burningCount < maxBrewingStands) {
toTransfer = 1;
}
if (toTransfer > 0) {
if (walkToBlock(walkTo)) {
return getState();
}
worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), ingredient, toTransfer, new InvWrapper(brewingStand), INGREDIENT_SLOT);
}
}
} else if (amountOfIngredientInBuilding >= targetCount - amountOfIngredientInInv && currentRecipeStorage.getIntermediate() == Blocks.BREWING_STAND) {
needsCurrently = new Tuple<>(ingredient, targetCount);
return GATHERING_REQUIRED_MATERIALS;
} else {
// This is a safety net for the AI getting way out of sync with it's tracking. It shouldn't happen.
job.finishRequest(false);
resetValues();
walkTo = null;
return IDLE;
}
}
} else if (!(world.getBlockState(walkTo).getBlock() instanceof BrewingStandBlock)) {
building.removeBrewingStand(walkTo);
}
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class EntityAIWorkAlchemist method craft.
@Override
protected IAIState craft() {
if (walkToBuilding()) {
setDelay(STANDARD_DELAY);
return getState();
}
if (currentRecipeStorage != null && currentRequest == null) {
currentRequest = job.getCurrentTask();
}
if (currentRecipeStorage != null && currentRecipeStorage.getIntermediate() != Blocks.BREWING_STAND) {
return super.craft();
}
if (building.getAllBrewingStandPositions().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
}
setDelay(STANDARD_DELAY);
return START_WORKING;
}
final BlockPos posOfOven = getPositionOfBrewingStandToRetrieveFrom();
if (posOfOven != null) {
walkTo = posOfOven;
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.retrieving"));
return RETRIEVING_END_PRODUCT_FROM_BREWINGSTAMD;
}
// Safety net, should get caught removing things from the brewingStand.
if (currentRequest != null && job.getMaxCraftingCount() > 0 && job.getCraftCounter() >= job.getMaxCraftingCount()) {
job.finishRequest(true);
currentRecipeStorage = null;
currentRequest = null;
resetValues();
return INVENTORY_FULL;
}
if (currentRequest != null && (currentRequest.getState() == RequestState.CANCELLED || currentRequest.getState() == RequestState.FAILED)) {
incrementActionsDone(getActionRewardForCraftingSuccess());
currentRecipeStorage = null;
currentRequest = null;
resetValues();
return START_WORKING;
}
return checkIfAbleToSmelt();
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class EntityAIWorkBeekeeper method decideWhatToDo.
/**
* Decides what job the beekeeper should switch to, breeding or harvesting.
*
* @return The next {@link IAIState} the beekeeper should switch to, after executing this method.
*/
private IAIState decideWhatToDo() {
setDelay(DECIDING_DELAY + (99 / getSecondarySkillLevel() - 1));
final Set<BlockPos> hives = building.getHives();
if (hives.isEmpty()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_HIVES), ChatPriority.BLOCKING));
setDelay(NO_HIVES_DELAY);
return DECIDE;
}
ItemListModule flowersModule = building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST));
if (flowersModule.getList().isEmpty()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), ChatPriority.BLOCKING));
setDelay(NO_FLOWERS_DELAY);
return DECIDE;
}
for (BlockPos pos : hives) {
if (!(world.getBlockState(pos).getBlock() instanceof BeehiveBlock)) {
building.removeHive(pos);
}
}
final Optional<BlockPos> hive = building.getHives().stream().filter(pos -> BeehiveTileEntity.getHoneyLevel(world.getBlockState(pos)) >= 5).findFirst();
if (hive.isPresent()) {
return BEEKEEPER_HARVEST;
}
final List<BeeEntity> bees = searchForAnimals(world, building);
final JobBeekeeper job = worker.getCitizenJobHandler().getColonyJob(JobBeekeeper.class);
if (bees.isEmpty()) {
if (getBeesInHives() <= 0) {
job.tickNoBees();
if (job.checkForBeeInteraction()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_BEES), ChatPriority.BLOCKING));
}
} else {
job.resetCounter();
}
setDelay(NO_ANIMALS_DELAY);
return DECIDE;
} else {
job.resetCounter();
}
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_DECIDING));
if (isReadyForBreeding()) {
return HERDER_BREED;
}
return START_WORKING;
}
Aggregations