Search in sources :

Example 11 with AbstractEntityCitizen

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);
    }
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 12 with AbstractEntityCitizen

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);
    }
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 13 with AbstractEntityCitizen

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);
    }
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 14 with AbstractEntityCitizen

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);
    }
}
Also used : net.minecraft.util(net.minecraft.util) IItemHandler(net.minecraftforge.items.IItemHandler) SittingEntity(com.minecolonies.coremod.entity.SittingEntity) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) com.minecolonies.coremod.entity.citizen.citizenhandlers(com.minecolonies.coremod.entity.citizen.citizenhandlers) Compatibility(com.minecolonies.api.compatibility.Compatibility) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) com.minecolonies.api.entity.citizen.citizenhandlers(com.minecolonies.api.entity.citizen.citizenhandlers) ThreatTable(com.minecolonies.api.entity.combat.threat.ThreatTable) Status(com.minecolonies.api.entity.ai.Status) CustomGoalSelector(com.minecolonies.api.entity.CustomGoalSelector) ResearchConstants(com.minecolonies.api.research.util.ResearchConstants) ContainerCitizenInventory(com.minecolonies.api.inventory.container.ContainerCitizenInventory) StringTextComponent(net.minecraft.util.text.StringTextComponent) ModItems(com.minecolonies.api.items.ModItems) Network(com.minecolonies.coremod.Network) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) DesiredActivity(com.minecolonies.api.entity.ai.DesiredActivity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EntityCitizenWalkToProxy(com.minecolonies.coremod.entity.pathfinding.EntityCitizenWalkToProxy) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) Team(net.minecraft.scoreboard.Team) com.minecolonies.coremod.entity.ai.minimal(com.minecolonies.coremod.entity.ai.minimal) SwimGoal(net.minecraft.entity.ai.goal.SwimGoal) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ITickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine) Capability(net.minecraftforge.common.capabilities.Capability) EntityAIInteractToggleAble(com.minecolonies.coremod.entity.ai.minimal.EntityAIInteractToggleAble) TeleportHelper(com.minecolonies.coremod.util.TeleportHelper) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EventType(com.minecolonies.api.sounds.EventType) LookAtWithoutMovingGoal(net.minecraft.entity.ai.goal.LookAtWithoutMovingGoal) Vector3d(net.minecraft.util.math.vector.Vector3d) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) MineColonies(com.minecolonies.coremod.MineColonies) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) LocalDate(java.time.LocalDate) IGuardBuilding(com.minecolonies.api.colony.buildings.IGuardBuilding) IState(com.minecolonies.api.entity.ai.statemachine.states.IState) com.minecolonies.coremod.colony.jobs(com.minecolonies.coremod.colony.jobs) ShieldItem(net.minecraft.item.ShieldItem) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) java.util(java.util) IPermissions(com.minecolonies.api.colony.permissions.IPermissions) OpenInventoryMessage(com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage) Container(net.minecraft.inventory.container.Container) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TickingTransition(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition) NameTagItem(net.minecraft.item.NameTagItem) Action(com.minecolonies.api.colony.permissions.Action) ITextComponent(net.minecraft.util.text.ITextComponent) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) LookAtGoal(net.minecraft.entity.ai.goal.LookAtGoal) EffectInstance(net.minecraft.potion.EffectInstance) Attributes(net.minecraft.entity.ai.attributes.Attributes) net.minecraft.entity(net.minecraft.entity) com.minecolonies.api.util(com.minecolonies.api.util) INCREMENT_AND_DECREMENT_OPERATORS_SHOULD_NOT_BE_USED_IN_A_METHOD_CALL_OR_MIXED_WITH_OTHER_OPERATORS_IN_AN_EXPRESSION(com.minecolonies.api.util.constant.Suppression.INCREMENT_AND_DECREMENT_OPERATORS_SHOULD_NOT_BE_USED_IN_A_METHOD_CALL_OR_MIXED_WITH_OTHER_OPERATORS_IN_AN_EXPRESSION) com.minecolonies.api.colony(com.minecolonies.api.colony) TickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateStateMachine) Effects(net.minecraft.potion.Effects) PlayerInventory(net.minecraft.entity.player.PlayerInventory) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) IWalkToProxy(com.minecolonies.api.entity.ai.pathfinding.IWalkToProxy) Month(java.time.Month) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) World(net.minecraft.world.World) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) BlockPos(net.minecraft.util.math.BlockPos) MovementHandler(com.minecolonies.coremod.entity.pathfinding.MovementHandler) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) Clock(java.time.Clock) CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent) ItemEntity(net.minecraft.entity.item.ItemEntity) IJob(com.minecolonies.api.colony.jobs.IJob) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ThreatTable(com.minecolonies.api.entity.combat.threat.ThreatTable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen)

Example 15 with AbstractEntityCitizen

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);
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) java.util(java.util) LootTable(net.minecraft.loot.LootTable) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Item(net.minecraft.item.Item) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) RecipeTypeEntry(com.minecolonies.api.crafting.registry.RecipeTypeEntry) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) ItemStack(net.minecraft.item.ItemStack) LootContext(net.minecraft.loot.LootContext) ImmutableList(com.google.common.collect.ImmutableList) Block(net.minecraft.block.Block) Hand(net.minecraft.util.Hand) LootParameterSet(net.minecraft.loot.LootParameterSet) Predicate(java.util.function.Predicate) ModItems(com.ldtteam.structurize.items.ModItems) LootParameters(net.minecraft.loot.LootParameters) IForgeRegistry(net.minecraftforge.registries.IForgeRegistry) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.block.Blocks) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ResourceLocation(net.minecraft.util.ResourceLocation) NotNull(org.jetbrains.annotations.NotNull) IItemHandler(net.minecraftforge.items.IItemHandler) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ItemStack(net.minecraft.item.ItemStack)

Aggregations

AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)73 BlockPos (net.minecraft.util.math.BlockPos)33 ICitizenData (com.minecolonies.api.colony.ICitizenData)32 PlayerEntity (net.minecraft.entity.player.PlayerEntity)22 ItemStack (net.minecraft.item.ItemStack)22 NotNull (org.jetbrains.annotations.NotNull)20 IColony (com.minecolonies.api.colony.IColony)17 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)14 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)14 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)12 Entity (net.minecraft.entity.Entity)12 java.util (java.util)10 Collectors (java.util.stream.Collectors)10 CompoundNBT (net.minecraft.nbt.CompoundNBT)10 IItemHandler (net.minecraftforge.items.IItemHandler)10 com.minecolonies.api.util (com.minecolonies.api.util)9 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)8 ArrayList (java.util.ArrayList)8 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)8 World (net.minecraft.world.World)8