use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class JobDeliveryman method onLevelUp.
@Override
public void onLevelUp() {
if (getCitizen().getEntity().isPresent()) {
final AbstractEntityCitizen worker = getCitizen().getEntity().get();
final AttributeModifier speedModifier = new AttributeModifier(SKILL_BONUS_ADD, getCitizen().getCitizenSkillHandler().getLevel(getCitizen().getWorkBuilding().getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == getJobRegistryEntry()).getPrimarySkill()) * BONUS_SPEED_PER_LEVEL, AttributeModifier.Operation.ADDITION);
AttributeModifierUtils.addModifier(worker, speedModifier, Attributes.MOVEMENT_SPEED);
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class EntityAIWorkCook method checkForImportantJobs.
/**
* Checks if the cook has anything important to do before going to the default furnace user jobs. First calculate the building range if not cached yet. Then check for citizens
* around the building. If no citizen around switch to default jobs. If citizens around check if food in inventory, if not, switch to gather job. If food in inventory switch to
* serve job.
*
* @return the next IAIState to transfer to.
*/
@Override
protected IAIState checkForImportantJobs() {
// Clear the cache of current pending work
this.reservedItemCache.clear();
citizenToServe.clear();
final List<AbstractEntityCitizen> citizenList = WorldUtil.getEntitiesWithinBuilding(world, AbstractEntityCitizen.class, building, null).stream().filter(cit -> !(cit.getCitizenJobHandler().getColonyJob() instanceof JobCook) && cit.shouldBeFed() && !InventoryUtils.hasItemInItemHandler(cit.getItemHandlerCitizen(), stack -> CAN_EAT.test(stack) && canEat(stack, cit))).sorted(Comparator.comparingInt(a -> (a.getCitizenJobHandler().getColonyJob() == null ? 1 : 0))).collect(Collectors.toList());
final List<PlayerEntity> playerList = WorldUtil.getEntitiesWithinBuilding(world, PlayerEntity.class, building, player -> player != null && player.getFoodData().getFoodLevel() < LEVEL_TO_FEED_PLAYER && building.getColony().getPermissions().hasPermission(player, Action.MANAGE_HUTS));
playerToServe.addAll(playerList);
boolean hasFoodInBuilding = false;
for (final AbstractEntityCitizen citizen : citizenList) {
final Predicate<ItemStack> foodPredicate = stack -> ItemStackUtils.CAN_EAT.test(stack) && !isItemStackForAssistant(stack) && canEat(stack, citizen);
if (InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), foodPredicate)) {
citizenToServe.add(citizen);
} else {
if (InventoryUtils.hasItemInProvider(building, foodPredicate)) {
hasFoodInBuilding = true;
needsCurrently = new Tuple<>(foodPredicate, STACKSIZE);
}
}
}
if (!citizenToServe.isEmpty()) {
return COOK_SERVE_FOOD_TO_CITIZEN;
}
if (hasFoodInBuilding) {
return GATHERING_REQUIRED_MATERIALS;
}
return START_WORKING;
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class RenderBipedCitizen method render.
@Override
public void render(@NotNull final AbstractEntityCitizen citizen, final float limbSwing, final float partialTicks, @NotNull final MatrixStack matrixStack, @NotNull final IRenderTypeBuffer renderTypeBuffer, final int light) {
setupMainModelFrom(citizen);
final CitizenModel<AbstractEntityCitizen> citizenModel = model;
final ItemStack mainHandStack = citizen.getMainHandItem();
final ItemStack offHandStack = citizen.getOffhandItem();
final BipedModel.ArmPose armPoseMainHand = getArmPoseFrom(citizen, mainHandStack);
final BipedModel.ArmPose armPoseOffHand = getArmPoseFrom(citizen, offHandStack);
updateArmPose(citizen, citizenModel, armPoseMainHand, armPoseOffHand);
if (isItGhostTime) {
RenderSystem.enableBlend();
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 0.3F);
super.render(citizen, limbSwing, partialTicks, matrixStack, renderTypeBuffer, light);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1F);
RenderSystem.disableBlend();
} else {
super.render(citizen, limbSwing, partialTicks, matrixStack, renderTypeBuffer, light);
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class EntityAIWorkEnchanter method gatherAndDrain.
/**
* Gather experience from a worker. Go to the hut of the worker. Wait for the worker. Drain, and then return to work building.
*
* @return next state to go to.
*/
private IAIState gatherAndDrain() {
if (job.getPosToDrainFrom() == null) {
return IDLE;
}
if (walkToBlock(job.getPosToDrainFrom())) {
return getState();
}
final AbstractBuilding buildingWorker = building.getColony().getBuildingManager().getBuilding(job.getPosToDrainFrom(), AbstractBuilding.class);
if (buildingWorker == null) {
resetDraining();
building.getFirstModuleOccurance(EnchanterStationsModule.class).removeWorker(job.getPosToDrainFrom());
return IDLE;
}
if (citizenToGatherFrom == null) {
final List<AbstractEntityCitizen> workers = new ArrayList<>();
for (final Optional<AbstractEntityCitizen> citizen : getModuleForJob().getAssignedEntities()) {
citizen.ifPresent(workers::add);
}
final AbstractEntityCitizen citizen;
if (workers.size() > 1) {
citizen = workers.get(worker.getRandom().nextInt(workers.size()));
} else {
if (workers.isEmpty()) {
resetDraining();
return DECIDE;
}
citizen = workers.get(0);
}
citizenToGatherFrom = citizen.getCitizenData();
progressTicks = 0;
return getState();
}
if (!citizenToGatherFrom.getEntity().isPresent()) {
citizenToGatherFrom = null;
return getState();
}
if (progressTicks == 0) {
// If worker is too far away wait.
if (BlockPosUtil.getDistance2D(citizenToGatherFrom.getEntity().get().blockPosition(), worker.blockPosition()) > MIN_DISTANCE_TO_DRAIN) {
if (!job.incrementWaitingTicks()) {
resetDraining();
return DECIDE;
}
return getState();
}
}
progressTicks++;
if (progressTicks < MAX_PROGRESS_TICKS) {
final Vector3d start = worker.position().add(0, 2, 0);
final Vector3d goal = citizenToGatherFrom.getEntity().get().position().add(0, 2, 0);
Network.getNetwork().sendToTrackingEntity(new StreamParticleEffectMessage(start, goal, ParticleTypes.ENCHANT, progressTicks % MAX_PROGRESS_TICKS, MAX_PROGRESS_TICKS), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(start, ParticleTypes.HAPPY_VILLAGER, progressTicks), worker);
WorkerUtil.faceBlock(new BlockPos(goal), worker);
if (worker.getRandom().nextBoolean()) {
worker.swing(Hand.MAIN_HAND);
} else {
worker.swing(Hand.OFF_HAND);
}
return getState();
}
final int bookSlot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), Items.BOOK);
if (bookSlot != -1) {
final int size = citizenToGatherFrom.getInventory().getSlots();
final int attempts = (int) (getSecondarySkillLevel() / 5.0);
for (int i = 0; i < attempts; i++) {
int randomSlot = worker.getRandom().nextInt(size);
final ItemStack stack = citizenToGatherFrom.getInventory().getStackInSlot(randomSlot);
if (!stack.isEmpty() && stack.isEnchantable()) {
EnchantmentHelper.enchantItem(worker.getRandom(), stack, getSecondarySkillLevel() > 50 ? 2 : 1, false);
break;
}
}
worker.getInventoryCitizen().extractItem(bookSlot, 1, false);
worker.getCitizenData().getCitizenSkillHandler().incrementLevel(Skill.Mana, 1);
worker.getCitizenExperienceHandler().addExperience(XP_PER_DRAIN);
worker.getCitizenData().markDirty();
}
resetDraining();
return IDLE;
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class EntityCitizen method callForHelp.
@Override
public void callForHelp(final Entity attacker, final int guardHelpRange) {
if (!(attacker instanceof LivingEntity) || !MineColonies.getConfig().getServer().citizenCallForHelp.get() || callForHelpCooldown != 0) {
return;
}
// Don't call for help when a guard gets woken up
if (citizenJobHandler.getColonyJob() instanceof AbstractJobGuard && citizenJobHandler.getColonyJob(AbstractJobGuard.class).isAsleep()) {
return;
}
callForHelpCooldown = CALL_HELP_CD;
List<AbstractEntityCitizen> possibleGuards = new ArrayList<>();
for (final ICitizenData entry : getCitizenColonyHandler().getColony().getCitizenManager().getCitizens()) {
if (entry.getEntity().isPresent()) {
// Checking for guard nearby
if (entry.getJob() instanceof AbstractJobGuard && entry.getId() != citizenData.getId() && BlockPosUtil.getDistanceSquared(entry.getEntity().get().blockPosition(), blockPosition()) < guardHelpRange && entry.getJob().getWorkerAI() != null) {
final ThreatTable table = ((EntityCitizen) entry.getEntity().get()).getThreatTable();
table.addThreat((LivingEntity) attacker, 0);
if (((AbstractEntityAIGuard<?, ?>) entry.getJob().getWorkerAI()).canHelp()) {
possibleGuards.add(entry.getEntity().get());
}
}
}
}
Collections.sort(possibleGuards, Comparator.comparingInt(guard -> (int) blockPosition().distSqr(guard.blockPosition())));
for (int i = 0; i < possibleGuards.size() && i <= CALL_TO_HELP_AMOUNT; i++) {
((AbstractEntityAIGuard<?, ?>) possibleGuards.get(i).getCitizenData().getJob().getWorkerAI()).startHelpCitizen((LivingEntity) attacker);
}
}
Aggregations