use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.
the class AbstractEntityAIRequestSmelter method fillUpFurnace.
/**
* Smelt the smeltable after the required items are in the inv.
*
* @return the next state to go to.
*/
private IAIState fillUpFurnace() {
final FurnaceUserModule module = getOwnBuilding().getFirstModuleOccurance(FurnaceUserModule.class);
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;
}
if (walkTo == null || world.getBlockState(walkTo).getBlock() != Blocks.FURNACE) {
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
final int burningCount = countOfBurningFurnaces();
final TileEntity entity = world.getBlockEntity(walkTo);
if (entity instanceof FurnaceTileEntity && currentRecipeStorage != null) {
final FurnaceTileEntity furnace = (FurnaceTileEntity) entity;
final int maxFurnaces = getMaxUsableFurnaces();
final Predicate<ItemStack> smeltable = stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(currentRecipeStorage.getCleanedInput().get(0).getItemStack(), stack);
final int smeltableInFurnaces = getExtendedCount(currentRecipeStorage.getCleanedInput().get(0).getItemStack());
final int resultInFurnaces = getExtendedCount(currentRecipeStorage.getPrimaryOutput());
final int resultInCitizenInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, currentRecipeStorage.getPrimaryOutput()));
final int targetCount = currentRequest.getRequest().getCount() - smeltableInFurnaces - resultInFurnaces - resultInCitizenInv;
if (targetCount <= 0) {
return START_WORKING;
}
final int amountOfSmeltableInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), smeltable);
final int amountOfSmeltableInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), smeltable);
if (worker.getItemInHand(Hand.MAIN_HAND).isEmpty()) {
worker.setItemInHand(Hand.MAIN_HAND, currentRecipeStorage.getCleanedInput().get(0).getItemStack().copy());
}
if (amountOfSmeltableInInv > 0) {
if (hasFuelInFurnaceAndNoSmeltable(furnace) || hasNeitherFuelNorSmeltAble(furnace)) {
int toTransfer = 0;
if (burningCount < maxFurnaces) {
final int availableFurnaces = maxFurnaces - burningCount;
if (targetCount > STACKSIZE * availableFurnaces) {
toTransfer = STACKSIZE;
} else {
// We need to split stacks and spread them across furnaces for best performance
// We will front-load the remainder
toTransfer = Math.min((targetCount / availableFurnaces) + (targetCount % availableFurnaces), STACKSIZE);
}
}
if (toTransfer > 0) {
if (walkToBlock(walkTo)) {
return getState();
}
worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo);
InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler(worker.getInventoryCitizen(), smeltable, toTransfer, new InvWrapper(furnace), SMELTABLE_SLOT);
}
}
} else if (amountOfSmeltableInBuilding >= targetCount - amountOfSmeltableInInv && currentRecipeStorage.getIntermediate() == Blocks.FURNACE) {
needsCurrently = new Tuple<>(smeltable, 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 FurnaceBlock)) {
module.removeFromFurnaces(walkTo);
}
walkTo = null;
setDelay(STANDARD_DELAY);
return START_WORKING;
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.
the class EntityAIWorkFlorist method decide.
/**
* Main decision method of florist to decide what to do.
*
* @return the next AI state to go to.
*/
private IAIState decide() {
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
if (getOwnBuilding().getPlantGround().isEmpty()) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_PLANT_GROUND_FLORIST), ChatPriority.BLOCKING));
return IDLE;
}
worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
final long distance = BlockPosUtil.getDistance2D(worker.blockPosition(), getOwnBuilding().getPosition());
if (distance > MAX_DISTANCE && walkToBuilding()) {
return DECIDE;
}
final int amountOfCompostInInv = InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), IS_COMPOST);
if (amountOfCompostInInv <= 0) {
final int amountOfCompostInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), IS_COMPOST);
if (amountOfCompostInBuilding > 0) {
needsCurrently = new Tuple<>(IS_COMPOST, STACKSIZE);
return GATHERING_REQUIRED_MATERIALS;
} else {
checkIfRequestForItemExistOrCreateAsynch(new ItemStack(ModItems.compost, COMPOST_REQUEST_QTY));
}
}
harvestPosition = areThereFlowersToGather();
if (harvestPosition != null) {
return FLORIST_HARVEST;
}
if (amountOfCompostInInv <= 0) {
if (!isThereCompostedLand(getOwnBuilding(), world)) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_COMPOST), ChatPriority.BLOCKING));
return START_WORKING;
}
return DECIDE;
} else {
compostPosition = getFirstNotCompostedLand();
return FLORIST_COMPOST;
}
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.
the class EntityAIWorkFlorist method compost.
/**
* Walk to the block to compost and apply compost to it.
*
* @return the next state to go to.
*/
private IAIState compost() {
if (compostPosition == null) {
return START_WORKING;
}
worker.getCitizenData().setVisibleStatus(GARDENING);
if (walkToBlock(compostPosition)) {
return getState();
}
final TileEntity entity = world.getBlockEntity(compostPosition);
if (entity instanceof TileEntityCompostedDirt) {
@Nullable final ItemStack stack = getOwnBuilding().getFlowerToGrow();
if (stack != null) {
if (worker.getRandom().nextInt(200 - getPrimarySkillLevel()) < 0 || InventoryUtils.shrinkItemCountInItemHandler(worker.getInventoryCitizen(), IS_COMPOST)) {
((TileEntityCompostedDirt) entity).compost(PERCENT_CHANGE_FOR_GROWTH - (getOwnBuilding().getBuildingLevel() * 0.01), getOwnBuilding().getFlowerToGrow());
}
} else {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(NO_FLOWERS_IN_CONFIG), ChatPriority.BLOCKING));
}
}
incrementActionsDone();
worker.decreaseSaturationForContinuousAction();
compostPosition = null;
return START_WORKING;
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.
the class CitizenSleepHandler method trySleep.
/**
* Attempts a sleep interaction with the citizen and the given bed.
*
* @param bedLocation The possible location to sleep.
*/
@Override
public boolean trySleep(final BlockPos bedLocation) {
final BlockState state = WorldUtil.isEntityBlockLoaded(citizen.level, bedLocation) ? citizen.level.getBlockState(bedLocation) : null;
final boolean isBed = state != null && state.getBlock().isBed(state, citizen.level, bedLocation, citizen);
if (!isBed) {
return false;
}
citizen.updatePose(Pose.SLEEPING);
citizen.getNavigation().stop();
citizen.setPos(((float) bedLocation.getX() + HALF_BLOCK), (float) bedLocation.getY() + 0.8F, ((float) bedLocation.getZ() + HALF_BLOCK));
citizen.setSleepingPos(bedLocation);
citizen.setDeltaMovement(Vector3d.ZERO);
citizen.hasImpulse = true;
// Remove item while citizen is asleep.
citizen.getCitizenItemHandler().removeHeldItem();
setIsAsleep(true);
citizen.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_SLEEPING), ChatPriority.HIDDEN));
if (citizen.getCitizenData() != null) {
citizen.getCitizenData().setBedPos(bedLocation);
}
citizen.getEntityData().set(DATA_BED_POS, bedLocation);
citizen.getCitizenData().getColony().getCitizenManager().onCitizenSleep();
return true;
}
use of com.minecolonies.coremod.colony.interactionhandling.StandardInteraction in project minecolonies by ldtteam.
the class EntityCitizen method determineDesiredActivity.
/**
* Determines the desired activity
*/
private boolean determineDesiredActivity() {
if (citizenJobHandler.getColonyJob() instanceof AbstractJobGuard) {
desiredActivity = DesiredActivity.WORK;
return false;
}
if (getCitizenColonyHandler().getColony().getRaiderManager().isRaided()) {
citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAID), ChatPriority.IMPORTANT));
setVisibleStatusIfNone(RAIDED);
desiredActivity = DesiredActivity.SLEEP;
return false;
}
// Sleeping
if (!WorldUtil.isPastTime(CompatibilityUtils.getWorldFromCitizen(this), NIGHT - 2000)) {
if (desiredActivity == DesiredActivity.SLEEP) {
setVisibleStatusIfNone(SLEEP);
return false;
}
if (citizenSleepHandler.shouldGoSleep()) {
citizenData.onGoSleep();
citizenData.decreaseSaturation(citizenColonyHandler.getPerBuildingFoodCost() * 2);
citizenData.markDirty();
citizenStatusHandler.setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.sleeping"));
desiredActivity = DesiredActivity.SLEEP;
return false;
}
}
// Mourning
if (citizenData.getCitizenMournHandler().isMourning() && citizenData.getCitizenMournHandler().shouldMourn()) {
if (!getCitizenColonyHandler().getColony().getRaiderManager().isRaided()) {
citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_MOURNING, citizenData.getCitizenMournHandler().getDeceasedCitizens().iterator().next()), new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_MOURNING), ChatPriority.IMPORTANT));
}
setVisibleStatusIfNone(MOURNING);
desiredActivity = DesiredActivity.MOURN;
return false;
}
if (citizenSleepHandler.isAsleep() && !citizenDiseaseHandler.isSick()) {
citizenSleepHandler.onWakeUp();
}
// Raining
if (CompatibilityUtils.getWorldFromCitizen(this).isRaining() && !shouldWorkWhileRaining() && !WorldUtil.isNetherType(level)) {
citizenStatusHandler.setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.waiting"), new TranslationTextComponent("com.minecolonies.coremod.status.rainStop"));
setVisibleStatusIfNone(BAD_WEATHER);
if (!citizenData.getColony().getRaiderManager().isRaided() && !citizenData.getCitizenMournHandler().isMourning()) {
citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAINING), ChatPriority.HIDDEN));
}
desiredActivity = DesiredActivity.SLEEP;
return false;
}
if (isBaby() && getCitizenJobHandler().getColonyJob() instanceof JobPupil && level.getDayTime() % 24000 > NOON) {
setVisibleStatusIfNone(HOUSE);
desiredActivity = DesiredActivity.IDLE;
return false;
}
if (getCitizenJobHandler().getColonyJob() != null) {
desiredActivity = DesiredActivity.WORK;
return false;
}
setVisibleStatusIfNone(HOUSE);
desiredActivity = DesiredActivity.IDLE;
return false;
}
Aggregations