use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class EntityAIWorkPupil method decide.
/**
* Decide between recess and studying.
*
* @return next state to go to.
*/
private IAIState decide() {
if (worker.getRandom().nextInt(STUDY_TO_RECESS_RATIO) < 1) {
recessPos = building.getPosition();
return RECESS;
}
final BuildingSchool school = building;
final BlockPos pos = school.getRandomPlaceToSit();
if (pos == null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(PUPIL_NO_CARPET), ChatPriority.BLOCKING));
return DECIDE;
}
studyPos = pos;
return STUDY;
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class EntityAIWorkSifter method sift.
/**
* The sifting process.
*
* @return the next AiState to go to.
*/
protected IAIState sift() {
final BuildingSifter sifterBuilding = building;
// Go idle if we can't do any more today
if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity()) {
return IDLE;
}
if (walkToBuilding()) {
return getState();
}
if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
return INVENTORY_FULL;
}
if (currentRecipeStorage == null) {
final ICraftingBuildingModule module = building.getFirstModuleOccurance(BuildingSifter.CraftingModule.class);
currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
}
if (currentRecipeStorage == null) {
if (InventoryUtils.hasBuildingEnoughElseCount(sifterBuilding, i -> ModTags.meshes.contains(i.getItem()), 1) == 0) {
if (InventoryUtils.getItemCountInProvider(worker, i -> ModTags.meshes.contains(i.getItem())) > 0) {
// We don't want the mesh in our inventory, we 'craft' out of the building
incrementActionsDone();
return INVENTORY_FULL;
}
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(SIFTER_NO_MESH), ChatPriority.IMPORTANT));
setDelay(NO_MESH_DELAY);
}
}
if (!ItemStackUtils.isEmpty(worker.getMainHandItem())) {
worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
}
if (!ItemStackUtils.isEmpty(worker.getOffhandItem())) {
worker.setItemInHand(Hand.OFF_HAND, ItemStack.EMPTY);
}
progress = 0;
return START_WORKING;
}
final ItemStack meshItem = currentRecipeStorage.getCraftingTools().get(0);
final ItemStack inputItem = currentRecipeStorage.getCleanedInput().stream().map(ItemStorage::getItemStack).filter(item -> !ItemStackUtils.compareItemStacksIgnoreStackSize(item, meshItem, false, true)).findFirst().orElse(ItemStack.EMPTY);
if (meshItem.isEmpty() || inputItem.isEmpty()) {
currentRecipeStorage = null;
return getState();
}
if (!inputItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getMainHandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getMainHandItem(), inputItem))) {
worker.setItemInHand(Hand.MAIN_HAND, inputItem);
}
if (!meshItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getOffhandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getOffhandItem(), meshItem, false, true))) {
worker.setItemInHand(Hand.OFF_HAND, meshItem);
}
WorkerUtil.faceBlock(building.getPosition(), worker);
progress++;
if (progress > MAX_LEVEL - (getEffectiveSkillLevel(getSecondarySkillLevel()) / 2)) {
progress = 0;
sifterBuilding.setCurrentDailyQuantity(sifterBuilding.getCurrentDailyQuantity() + 1);
if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity() || worker.getRandom().nextInt(ONE_HUNDRED_PERCENT) < CHANCE_TO_DUMP_INV) {
incrementActionsDoneAndDecSaturation();
}
if (!currentRecipeStorage.fullfillRecipe(getLootContext(), sifterBuilding.getHandlers())) {
currentRecipeStorage = null;
return getState();
}
worker.decreaseSaturationForContinuousAction();
worker.getCitizenExperienceHandler().addExperience(0.2);
}
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(meshItem, sifterBuilding.getID()), worker);
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(inputItem, sifterBuilding.getID().below()), worker);
worker.swing(Hand.MAIN_HAND);
SoundUtils.playSoundAtCitizen(world, building.getID(), SoundEvents.LEASH_KNOT_BREAK);
return getState();
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class AbstractEntityAIUsesFurnace method fillUpFurnace.
/**
* Smelt the smeltable after the required items are in the inv.
*
* @return the next state to go to.
*/
private IAIState fillUpFurnace() {
if (building.getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), ChatPriority.BLOCKING));
}
return START_WORKING;
}
if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.FURNACE) {
walkTo = null;
return START_WORKING;
}
if (walkToBlock(walkTo)) {
return getState();
}
final TileEntity entity = world.getBlockEntity(walkTo);
if (entity instanceof FurnaceTileEntity) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
if (InventoryUtils.hasItemInItemHandler((worker.getInventoryCitizen()), this::isSmeltable) && (hasFuelInFurnaceAndNoSmeltable(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler((worker.getInventoryCitizen()), this::isSmeltable, STACKSIZE, new InvWrapper(furnace), SMELTABLE_SLOT);
}
final ItemListModule module = building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST));
if (InventoryUtils.hasItemInItemHandler((worker.getInventoryCitizen()), stack -> module.isItemInList(new ItemStorage(stack))) && (hasSmeltableInFurnaceAndNoFuel(furnace) || hasNeitherFuelNorSmeltAble(furnace))) {
InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoInItemHandler((worker.getInventoryCitizen()), stack -> module.isItemInList(new ItemStorage(stack)), STACKSIZE, new InvWrapper(furnace), FUEL_SLOT);
}
}
walkTo = null;
return START_WORKING;
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method checkIfExecute.
/**
* Check if the deliveryman code should be executed. More concretely if he has a warehouse to work at.
*
* @return false if should continue as planned.
*/
private boolean checkIfExecute() {
final IWareHouse wareHouse = getAndCheckWareHouse();
if (wareHouse != null) {
worker.getCitizenData().setWorking(true);
if (wareHouse.getTileEntity() == null) {
return false;
}
{
return true;
}
}
worker.getCitizenData().setWorking(false);
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NOWAREHOUSE), ChatPriority.BLOCKING));
}
return false;
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.
the class EntityAIStructureMiner method checkMineShaft.
@NotNull
private IAIState checkMineShaft() {
final BuildingMiner buildingMiner = getOwnBuilding();
// Check if we reached the bottom of the shaft
if (getLastLadder(buildingMiner.getLadderLocation(), world) < SHAFT_BASE_DEPTH) {
AdvancementUtils.TriggerAdvancementPlayersForColony(job.getColony(), AdvancementTriggers.DEEP_MINE::trigger);
}
// Check if we reached the mineshaft depth limit
if (getLastLadder(buildingMiner.getLadderLocation(), world) < buildingMiner.getDepthLimit()) {
// If the miner hut has been placed too deep.
if (buildingMiner.getFirstModuleOccurance(MinerLevelManagementModule.class).getNumberOfLevels() == 0) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NEEDS_BETTER_HUT), ChatPriority.BLOCKING));
return IDLE;
}
worker.getCitizenData().setVisibleStatus(MINING);
return MINER_MINING_NODE;
}
worker.getCitizenData().setVisibleStatus(MINING);
return MINER_MINING_SHAFT;
}
Aggregations