use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* BlockEvent.BreakEvent handler.
*
* @param event BlockEvent.BreakEvent
*/
@SubscribeEvent
public void on(final BlockEvent.BreakEvent event) {
final IWorld world = event.getWorld();
if (!MineColonies.getConfig().getServer().enableColonyProtection.get() || world.isClientSide()) {
return;
}
if (event.getState().getBlock() instanceof AbstractBlockHut) {
@Nullable final IBuilding building = IColonyManager.getInstance().getBuilding(event.getPlayer().level, event.getPos());
if (building == null) {
return;
}
if (event.getState().getBlock() == ModBlocks.blockHutTownHall && !((BlockHutTownHall) event.getState().getBlock()).getValidBreak() && !event.getPlayer().isCreative()) {
cancelEvent(event, event.getPlayer(), colony, Action.BREAK_HUTS, event.getPos());
return;
}
if (!building.getColony().getPermissions().hasPermission(event.getPlayer(), Action.BREAK_HUTS)) {
if (checkEventCancelation(Action.BREAK_HUTS, event.getPlayer(), event.getPlayer().getCommandSenderWorld(), event, event.getPos())) {
return;
}
}
building.destroy();
if (MineColonies.getConfig().getServer().pvp_mode.get() && event.getState().getBlock() == ModBlocks.blockHutTownHall) {
IColonyManager.getInstance().deleteColonyByWorld(building.getColony().getID(), false, event.getPlayer().level);
}
} else if (event.getState().getBlock() instanceof BlockDecorationController) {
colony.getBuildingManager().removeLeisureSite(event.getPos());
} else {
checkEventCancelation(Action.BREAK_BLOCKS, event.getPlayer(), event.getPlayer().getCommandSenderWorld(), event, event.getPos());
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class BackUpHelper method loadColonyBackup.
/**
* Load the colony backup by colony, also works for backups of deleted colonies.
*
* @param colonyId of the colony.
* @param dimension the colony dimension.
* @param loadDeleted whether to load deleted colonies aswell.
* @param claimChunks if chunks shall be claimed on loading.
*/
public static void loadColonyBackup(final int colonyId, final RegistryKey<World> dimension, boolean loadDeleted, boolean claimChunks) {
@NotNull final File saveDir = new File(ServerLifecycleHooks.getCurrentServer().getWorldPath(FolderName.ROOT).toFile(), FILENAME_MINECOLONIES_PATH);
@NotNull final File backupFile = new File(saveDir, getFolderForDimension(dimension.location()) + String.format(FILENAME_COLONY, colonyId));
CompoundNBT compound = loadNBTFromPath(backupFile);
if (compound == null) {
if (loadDeleted) {
compound = loadNBTFromPath(new File(saveDir, String.format(getFolderForDimension(dimension.location()) + String.format(FILENAME_COLONY_DELETED, colonyId))));
}
if (compound == null) {
Log.getLogger().warn("Can't find NBT of colony: " + colonyId + " at location: " + backupFile);
return;
}
}
IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyId, dimension);
if (colony != null) {
colony.read(compound);
} else {
Log.getLogger().warn("Colony:" + colonyId + " is missing, loading backup!");
final World colonyWorld = ServerLifecycleHooks.getCurrentServer().getLevel(dimension);
final Colony loadedColony = Colony.loadColony(compound, colonyWorld);
if (loadedColony == null || colonyWorld == null) {
Log.getLogger().warn("Colony:" + colonyId + " loadBackup failed!");
return;
}
colonyWorld.getCapability(COLONY_MANAGER_CAP, null).ifPresent(cap -> cap.addColony(loadedColony));
if (claimChunks) {
final Chunk chunk = ((Chunk) colonyWorld.getChunk(loadedColony.getCenter()));
final int id = chunk.getCapability(CLOSE_COLONY_CAP, null).map(IColonyTagCapability::getOwningColony).orElse(0);
if (id != colonyId) {
ChunkDataHelper.claimColonyChunks(colonyWorld, true, loadedColony.getID(), loadedColony.getCenter());
for (final IBuilding building : loadedColony.getBuildingManager().getBuildings().values()) {
ChunkDataHelper.claimBuildingChunks(loadedColony, true, building.getPosition(), building.getClaimRadius(building.getBuildingLevel()));
}
}
}
}
Log.getLogger().warn("Successfully restored colony:" + colonyId);
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class InteractionValidatorInitializer method init.
/**
* Init method called on startup.
*/
public static void init() {
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FUEL), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).getList().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(RAW_FOOD), citizen -> InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), ISCOOKABLE) != -1 && InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), stack -> CAN_EAT.test(stack) && (citizen.getWorkBuilding() == null || citizen.getWorkBuilding().canEat(stack))) == -1);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BETTER_FOOD), citizen -> citizen.getSaturation() == 0 && !citizen.isChild() && citizen.needsBetterFood());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BETTER_FOOD_CHILDREN), citizen -> citizen.getSaturation() == 0 && citizen.isChild() && citizen.needsBetterFood());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_RESTAURANT), citizen -> citizen.getColony() != null && citizen.getSaturation() <= LOW_SATURATION && citizen.getEntity().isPresent() && citizen.getColony().getBuildingManager().getBestBuilding(citizen.getEntity().get(), BuildingCook.class) == null && InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(citizen.getInventory(), ISFOOD) == -1);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_HOSPITAL), citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && citizen.getEntity().get().getCitizenDiseaseHandler().isSick() && citizen.getColony().getBuildingManager().getBestBuilding(citizen.getEntity().get(), BuildingHospital.class) == null);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WAITING_FOR_CURE), citizen -> citizen.getColony() != null && citizen.getEntity().isPresent() && !citizen.getEntity().get().getCitizenDiseaseHandler().getDisease().isEmpty());
InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), (citizen, pos) -> {
if (citizen.getJob() instanceof JobDeliveryman) {
final IColony colony = citizen.getColony();
if (colony != null) {
final IBuilding building = colony.getBuildingManager().getBuilding(pos);
if (building != null) {
final IItemHandler inv = building.getCapability(ITEM_HANDLER_CAPABILITY, null).resolve().orElse(null);
if (inv != null) {
return InventoryUtils.openSlotCount(inv) > 0;
}
}
}
}
return false;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NOWAREHOUSE), cit -> {
if (cit.getJob() instanceof JobDeliveryman && cit.getWorkBuilding() != null) {
return ((JobDeliveryman) cit.getJob()).findWareHouse() == null;
}
return false;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_FREE_FIELDS), citizen -> citizen.getWorkBuilding() instanceof BuildingFarmer && ((BuildingFarmer) citizen.getWorkBuilding()).getFirstModuleOccurance(FarmerFieldModule.class).hasNoFields());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(INVALID_MINESHAFT), citizen -> citizen.getWorkBuilding() instanceof BuildingMiner && citizen.getJob() instanceof JobMiner && (((BuildingMiner) citizen.getWorkBuilding()).getCobbleLocation() == null || ((BuildingMiner) citizen.getWorkBuilding()).getLadderLocation() == null));
InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(NO_SEED_SET), (citizen, pos) -> {
if (citizen.getJob() instanceof JobFarmer) {
final IColony colony = citizen.getColony();
if (colony != null) {
final World world = colony.getWorld();
if (world != null) {
final TileEntity tileEntity = world.getBlockEntity(pos);
if (tileEntity instanceof ScarecrowTileEntity) {
return ((ScarecrowTileEntity) tileEntity).getSeed() == null;
}
}
}
}
return false;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_INVENTORYFULLCHEST), citizen -> citizen.getWorkBuilding() != null && InventoryUtils.isProviderFull(citizen.getWorkBuilding()));
InteractionValidatorRegistry.registerPosBasedPredicate(new TranslationTextComponent(REQUEST_SYSTEM_BUILDING_LEVEL_TOO_LOW), (citizen, pos) -> {
final IBuilding workBuilding = citizen.getWorkBuilding();
if (workBuilding != null) {
final IColony colony = citizen.getColony();
if (colony != null) {
final World world = colony.getWorld();
if (world != null) {
return workBuilding.getMaxToolLevel() < WorkerUtil.getCorrectHarvestLevelForBlock(world.getBlockState(pos));
}
}
}
return false;
});
InteractionValidatorRegistry.registerTokenBasedPredicate(new TranslationTextComponent(REQUEST_RESOLVER_NORMAL), (citizen, token) -> {
final IColony colony = citizen.getColony();
if (colony != null) {
return RequestUtils.requestChainNeedsPlayer(token, citizen.getColony().getRequestManager());
}
return false;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_ORE), citizen -> {
if (citizen.getWorkBuilding() instanceof BuildingSmeltery) {
final List<ItemStorage> oreList = ((BuildingSmeltery) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(ORE_LIST)).getList();
for (final ItemStorage storage : IColonyManager.getInstance().getCompatibilityManager().getSmeltableOres()) {
if (!oreList.contains(storage)) {
return true;
}
}
}
return false;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(PATIENT_FULL_INVENTORY), citizen -> citizen.getEntity().isPresent() && citizen.getEntity().get().getCitizenDiseaseHandler().isSick() && InventoryUtils.isItemHandlerFull(citizen.getEntity().get().getInventoryCitizen()));
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(PUPIL_NO_CARPET), citizen -> citizen.getEntity().isPresent() && citizen.isChild() && citizen.getWorkBuilding() instanceof BuildingSchool && ((BuildingSchool) citizen.getWorkBuilding()).getRandomPlaceToSit() == null);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WATER_TOO_FAR), citizen -> citizen.getJob() instanceof JobFisherman && ((JobFisherman) citizen.getJob()).getPonds().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FUEL), citizen -> citizen.getWorkBuilding() != null && citizen.getWorkBuilding().hasModule(FurnaceUserModule.class) && citizen.getWorkBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FUEL_LIST)).getList().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(FURNACE_USER_NO_FOOD), citizen -> {
if (!(citizen.getWorkBuilding() instanceof BuildingCook)) {
return false;
}
final ImmutableList<ItemStorage> exclusionList = ((BuildingCook) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(FOOD_EXCLUSION_LIST)).getList();
for (final ItemStorage storage : IColonyManager.getInstance().getCompatibilityManager().getEdibles(citizen.getWorkBuilding().getBuildingLevel() - 1)) {
if (!exclusionList.contains(storage)) {
return false;
}
}
return true;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(SIFTER_NO_MESH), citizen -> {
if (!(citizen.getWorkBuilding() instanceof BuildingSifter)) {
return false;
}
return InventoryUtils.getItemCountInProvider(citizen.getWorkBuilding(), item -> ModTags.meshes.contains(item.getItem())) <= 0 && InventoryUtils.getItemCountInItemHandler(citizen.getInventory(), item -> ModTags.meshes.contains(item.getItem())) <= 0;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(BAKER_HAS_NO_FURNACES_MESSAGE), citizen -> citizen.getWorkBuilding() instanceof BuildingBaker && citizen.getWorkBuilding().getFirstModuleOccurance(FurnaceUserModule.class).getFurnaces().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_HIVES), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && ((BuildingBeekeeper) citizen.getWorkBuilding()).getHives().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_BEES), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && citizen.getJob(JobBeekeeper.class).checkForBeeInteraction());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_WORKERS_TO_DRAIN_SET), citizen -> citizen.getWorkBuilding() instanceof BuildingEnchanter && ((BuildingEnchanter) citizen.getWorkBuilding()).getFirstModuleOccurance(EnchanterStationsModule.class).getBuildingsToGatherFrom().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_PLANT_GROUND_FLORIST), citizen -> citizen.getWorkBuilding() instanceof BuildingFlorist && ((BuildingFlorist) citizen.getWorkBuilding()).getPlantGround().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_FLOWERS_IN_CONFIG), citizen -> citizen.getWorkBuilding() instanceof BuildingFlorist && ItemStackUtils.isEmpty(((BuildingFlorist) citizen.getWorkBuilding()).getFlowerToGrow()));
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO_COMPOST), citizen -> {
final IBuilding buildingFlorist = citizen.getWorkBuilding();
if (buildingFlorist instanceof BuildingFlorist && buildingFlorist.getColony().getWorld() != null) {
return InventoryUtils.getItemCountInItemHandler(citizen.getInventory(), IS_COMPOST) == 0 && !isThereCompostedLand((BuildingFlorist) buildingFlorist, buildingFlorist.getColony().getWorld());
}
return false;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NEEDS_BETTER_HUT), citizen -> {
final AbstractBuilding buildingMiner = (AbstractBuilding) citizen.getWorkBuilding();
if (buildingMiner instanceof BuildingMiner && citizen.getColony() != null && citizen.getColony().getWorld() != null && citizen.getJob() instanceof JobMiner) {
return getLastLadder(((BuildingMiner) buildingMiner).getLadderLocation(), citizen.getColony().getWorld()) < ((BuildingMiner) buildingMiner).getDepthLimit() && ((BuildingMiner) buildingMiner).getFirstModuleOccurance(MinerLevelManagementModule.class).getNumberOfLevels() == 0;
}
return false;
});
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(WORKER_AI_EXCEPTION), citizen -> citizen.getJob() != null && ((AbstractEntityAIBasic<?, ?>) citizen.getJob().getWorkerAI()).getExceptionTimer() > 1);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + HOMELESSNESS), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() > DEMANDS_DAYS_WITHOUT_HOUSE && citizen.getHomeBuilding() == null);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + HOMELESSNESS), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() > COMPLAIN_DAYS_WITHOUT_HOUSE && (citizen.getCitizenHappinessHandler()).getModifier(HOMELESSNESS).getDays() <= DEMANDS_DAYS_WITHOUT_HOUSE && citizen.getHomeBuilding() == null);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + UNEMPLOYMENT), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() > DEMANDS_DAYS_WITHOUT_JOB && citizen.getJob() == null);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + UNEMPLOYMENT), citizen -> (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() > COMPLAIN_DAYS_WITHOUT_JOB && (citizen.getCitizenHappinessHandler()).getModifier(UNEMPLOYMENT).getDays() <= DEMANDS_DAYS_WITHOUT_JOB && citizen.getJob() == null);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(DEMANDS + IDLEATJOB), citizen -> citizen.getJob() != null && (citizen.getCitizenHappinessHandler()).getModifier(IDLEATJOB).getDays() > citizen.getJob().getIdleSeverity(true));
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + IDLEATJOB), citizen -> citizen.getJob() != null && citizen.getCitizenHappinessHandler().getModifier(IDLEATJOB).getDays() > citizen.getJob().getIdleSeverity(false) && citizen.getCitizenHappinessHandler().getModifier(IDLEATJOB).getDays() <= citizen.getJob().getIdleSeverity(true));
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(NO + SLEPTTONIGHT), citizen -> !(citizen.getJob() instanceof AbstractJobGuard) && citizen.getCitizenHappinessHandler().getModifier(SLEPTTONIGHT).getDays() <= 0);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_BEEKEEPER_NOFLOWERS), citizen -> citizen.getWorkBuilding() instanceof BuildingBeekeeper && ((BuildingBeekeeper) citizen.getWorkBuilding()).getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST)).getList().isEmpty());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAINING), citizen -> citizen.getEntity().isPresent() && citizen.getEntity().get().getCommandSenderWorld().isRaining() && !citizen.getColony().getRaiderManager().isRaided() && !citizen.getCitizenMournHandler().isMourning());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_RAID), citizen -> citizen.getEntity().isPresent() && citizen.getColony().getRaiderManager().isRaided());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_SLEEPING), citizen -> citizen.getEntity().isPresent() && citizen.isAsleep());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_CITIZEN_MOURNING), citizen -> citizen.getEntity().isPresent() && citizen.getCitizenMournHandler().isMourning() && !citizen.getColony().getRaiderManager().isRaided());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(CITIZEN_NOT_GUARD_NEAR_WORK), citizen -> citizen.getWorkBuilding() != null && !citizen.getWorkBuilding().isGuardBuildingNear());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(CITIZEN_NOT_GUARD_NEAR_HOME), citizen -> citizen.getHomeBuilding() != null && !citizen.getHomeBuilding().isGuardBuildingNear());
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(QUARRY_MINER_NO_QUARRY), citizen -> citizen.getJob() instanceof JobQuarrier && ((JobQuarrier) citizen.getJob()).findQuarry() == null);
InteractionValidatorRegistry.registerStandardPredicate(new TranslationTextComponent(QUARRY_MINER_FINISHED_QUARRY), citizen -> citizen.getJob() instanceof JobQuarrier && ((JobQuarrier) citizen.getJob()).findQuarry() != null && ((JobQuarrier) citizen.getJob()).findQuarry().getFirstModuleOccurance(QuarryModule.class).isFinished());
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method dumpOneMoreSlot.
/**
* Dumps one inventory slot into the building chest.
*
* @return true if is has to dump more.
*/
@SuppressWarnings("PMD.PrematureDeclaration")
private boolean dumpOneMoreSlot() {
if (walkToBlock(getBuildingToDump().getPosition())) {
return true;
}
@Nullable final IBuilding buildingWorker = building;
ItemStack stackToDump = worker.getInventoryCitizen().getStackInSlot(slotAt);
final int totalSize = worker.getInventoryCitizen().getSlots();
while (stackToDump.isEmpty()) {
if (slotAt >= totalSize) {
return false;
}
slotAt++;
stackToDump = worker.getInventoryCitizen().getStackInSlot(slotAt);
}
boolean dumpAnyway = false;
if (slotAt + MIN_OPEN_SLOTS * 2 >= totalSize) {
final long openSlots = InventoryUtils.openSlotCount(worker.getInventoryCitizen());
if (openSlots < MIN_OPEN_SLOTS * 2) {
if (stackToDump.getCount() < CHANCE_TO_DUMP_50) {
dumpAnyway = worker.getRandom().nextBoolean();
} else {
dumpAnyway = worker.getRandom().nextInt(stackToDump.getCount()) < CHANCE_TO_DUMP;
}
}
}
if (buildingWorker != null && !ItemStackUtils.isEmpty(stackToDump)) {
final int amount = dumpAnyway ? stackToDump.getCount() : buildingWorker.buildingRequiresCertainAmountOfItem(stackToDump, alreadyKept, true, job.getJobRegistryEntry());
if (amount > 0) {
final ItemStack activeStack = getInventory().extractItem(slotAt, amount, false);
InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(activeStack, getBuildingToDump().getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null));
hasDumpedItems = true;
}
}
slotAt++;
return slotAt < totalSize;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method dumpInventory.
/**
* Walk to building and dump inventory. If inventory is dumped, continue execution so that the state can be resolved.
*
* @return INVENTORY_FULL | IDLE
*/
@NotNull
private IAIState dumpInventory() {
final IBuilding building = getBuildingToDump();
if (building == null) {
// Uh oh, that shouldn't happen. Restart AI.
return afterDump();
}
if (!worker.isWorkerAtSiteWithMove(building.getPosition(), DEFAULT_RANGE_FOR_DELAY)) {
setDelay(WALK_DELAY);
return INVENTORY_FULL;
}
if (InventoryUtils.isProviderFull(building)) {
final ICitizenData citizenData = worker.getCitizenData();
if (citizenData != null) {
citizenData.triggerInteraction(new StandardInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_ENTITY_WORKER_INVENTORYFULLCHEST), ChatPriority.IMPORTANT));
}
// Note that this will not create a pickup request when another request is already in progress.
if (building.getPickUpPriority() > 0) {
building.createPickupRequest(getMaxBuildingPriority(true));
hasDumpedItems = false;
}
alreadyKept.clear();
slotAt = 0;
this.clearActionsDone();
return afterDump();
} else if (dumpOneMoreSlot()) {
return INVENTORY_FULL;
}
alreadyKept.clear();
slotAt = 0;
this.clearActionsDone();
if (isAfterDumpPickupAllowed() && building.getPickUpPriority() > 0 && hasDumpedItems) {
// Worker is not currently crafting, pickup is allowed.
// Note that this will not create a pickup request when another request is already in progress.
building.createPickupRequest(scaledPriority(building.getPickUpPriority()));
hasDumpedItems = false;
}
return afterDump();
}
Aggregations