use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
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 ldtteam.
the class JobDruid method onLevelUp.
@Override
public void onLevelUp() {
// Bonus Health for druids(gets reset upon Firing)
if (getCitizen().getEntity().isPresent()) {
final AbstractEntityCitizen citizen = getCitizen().getEntity().get();
// +1 Heart every 4 level
final AttributeModifier healthModLevel = new AttributeModifier(GUARD_HEALTH_MOD_LEVEL_NAME, getCitizen().getCitizenSkillHandler().getLevel(Skill.Mana) / 2.0 + DRUID_HP_BONUS, AttributeModifier.Operation.ADDITION);
AttributeModifierUtils.addHealthModifier(citizen, healthModLevel);
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class JobHealer 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 ldtteam.
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);
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class RecipeStorage method fullfillRecipeAndCopy.
/**
* Check for space, remove items, and insert crafted items, returning a copy of the crafted items.
*
* @param context loot context
* @param handlers the handlers to use
* @return copy of the crafted items if successful, null on failure
*/
@Override
public List<ItemStack> fullfillRecipeAndCopy(final LootContext context, final List<IItemHandler> handlers) {
if (!checkForFreeSpace(handlers) || !canFullFillRecipe(1, Collections.emptyMap(), handlers.toArray(new IItemHandler[0]))) {
return null;
}
final AbstractEntityCitizen citizen = (AbstractEntityCitizen) context.getParamOrNull(LootParameters.THIS_ENTITY);
for (final ItemStorage storage : getCleanedInput()) {
final ItemStack stack = storage.getItemStack();
int amountNeeded = storage.getAmount();
if (amountNeeded == 0) {
break;
}
for (final IItemHandler handler : handlers) {
int slotOfStack = InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(handler, itemStack -> !ItemStackUtils.isEmpty(itemStack) && ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack, false, !storage.ignoreNBT()));
while (slotOfStack != -1 && amountNeeded > 0) {
if (citizen != null && ItemStackUtils.compareItemStackListIgnoreStackSize(tools, stack, false, !storage.ignoreNBT()) && ItemStackUtils.getDurability(handler.getStackInSlot(slotOfStack)) > 0) {
ItemStack toDamage = handler.extractItem(slotOfStack, 1, false);
if (!ItemStackUtils.isEmpty(toDamage)) {
// The 4 parameter inner call from forge is for adding a callback to alter the damage caused,
// but unlike its description does not actually damage the item(despite the same function name). So used to just calculate the damage.
toDamage.hurtAndBreak(toDamage.getItem().damageItem(stack, 1, citizen, item -> item.broadcastBreakEvent(Hand.MAIN_HAND)), citizen, item -> item.broadcastBreakEvent(Hand.MAIN_HAND));
}
if (!ItemStackUtils.isEmpty(toDamage)) {
handler.insertItem(slotOfStack, toDamage, false);
}
amountNeeded -= stack.getCount();
} else {
final int count = ItemStackUtils.getSize(handler.getStackInSlot(slotOfStack));
final ItemStack extractedStack = handler.extractItem(slotOfStack, amountNeeded, false).copy();
// Deletes some items, but hey.
if (ItemStackUtils.isEmpty(extractedStack)) {
handler.insertItem(slotOfStack, extractedStack, false);
return null;
}
amountNeeded -= count;
if (amountNeeded > 0) {
slotOfStack = InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(handler, itemStack -> !ItemStackUtils.isEmpty(itemStack) && ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack, false, !storage.ignoreNBT()));
}
}
}
// stop looping handlers if we have what we need
if (amountNeeded <= 0) {
break;
}
}
if (amountNeeded > 0) {
return null;
}
}
return insertCraftedItems(handlers, getPrimaryOutput(), context);
}
Aggregations