Search in sources :

Example 31 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

the class VisitorManager method registerCivilian.

@Override
public void registerCivilian(final AbstractCivilianEntity visitor) {
    if (visitor.getCivilianID() == 0 || visitorMap.get(visitor.getCivilianID()) == null) {
        visitor.remove();
        return;
    }
    final ICitizenData data = visitorMap.get(visitor.getCivilianID());
    final Optional<AbstractEntityCitizen> existingCitizen = data.getEntity();
    if (!existingCitizen.isPresent()) {
        data.setEntity(visitor);
        visitor.setCivilianData(data);
        return;
    }
    if (existingCitizen.get() == visitor) {
        return;
    }
    if (visitor.isAlive()) {
        existingCitizen.get().remove();
        data.setEntity(visitor);
        visitor.setCivilianData(data);
        return;
    }
    visitor.remove();
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 32 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

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 33 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

the class JobKnight method ignoresDamage.

@Override
public boolean ignoresDamage(@NotNull final DamageSource damageSource) {
    if (damageSource.isExplosion() && this.getColony().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) > 0 && InventoryUtils.findFirstSlotInItemHandlerWith(this.getCitizen().getInventory(), Items.SHIELD) != -1) {
        if (!this.getCitizen().getEntity().isPresent()) {
            return true;
        }
        final AbstractEntityCitizen worker = this.getCitizen().getEntity().get();
        worker.getCitizenItemHandler().setHeldItem(Hand.OFF_HAND, InventoryUtils.findFirstSlotInItemHandlerWith(this.getCitizen().getInventory(), Items.SHIELD));
        worker.startUsingItem(Hand.OFF_HAND);
        // Apply the colony Flag to the shield
        ItemStack shieldStack = worker.getInventoryCitizen().getHeldItem(Hand.OFF_HAND);
        CompoundNBT nbt = shieldStack.getOrCreateTagElement("BlockEntityTag");
        nbt.put(TAG_BANNER_PATTERNS, worker.getCitizenColonyHandler().getColony().getColonyFlag());
        worker.decreaseSaturationForContinuousAction();
        return true;
    }
    return super.ignoresDamage(damageSource);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ItemStack(net.minecraft.item.ItemStack)

Example 34 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

the class JobKnight method onLevelUp.

@Override
public void onLevelUp() {
    // Bonus Health for knights(gets reset upon Firing)
    if (getCitizen().getEntity().isPresent()) {
        final AbstractEntityCitizen citizen = getCitizen().getEntity().get();
        // +1 Heart every 2 level
        final AttributeModifier healthModLevel = new AttributeModifier(GUARD_HEALTH_MOD_LEVEL_NAME, getCitizen().getCitizenSkillHandler().getLevel(Skill.Stamina) + KNIGHT_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 35 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

the class JobLumberjack 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() == this.getJobRegistryEntry()).getSecondarySkill()) / 2.0) * 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)

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