Search in sources :

Example 51 with AbstractEntityCitizen

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

the class CommandCitizenTeleport method onExecute.

/**
 * What happens when the command is executed after preConditions are successful.
 *
 * @param context the context of the command execution
 */
@Override
public int onExecute(final CommandContext<CommandSource> context) {
    final Entity sender = context.getSource().getEntity();
    // Colony
    final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
    final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
    if (colony == null) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND, colonyID), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_FOUND), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_LOADED), true);
        return 0;
    }
    final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
    final ILocationArgument targetLocation = Vec3Argument.getCoordinates(context, POS_ARG);
    final BlockPos targetPos = targetLocation.getBlockPos(context.getSource());
    if (context.getSource().getLevel() == entityCitizen.level) {
        entityCitizen.moveTo(targetPos.getX(), targetPos.getY(), targetPos.getZ(), entityCitizen.getViewYRot(1F), entityCitizen.getViewXRot(1F));
        entityCitizen.getNavigation().stop();
    }
    return 1;
}
Also used : Entity(net.minecraft.entity.Entity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IColony(com.minecolonies.api.colony.IColony) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenData(com.minecolonies.api.colony.ICitizenData) ILocationArgument(net.minecraft.command.arguments.ILocationArgument) BlockPos(net.minecraft.util.math.BlockPos)

Example 52 with AbstractEntityCitizen

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

the class RecallCitizenHutMessage method onExecute.

@Override
protected void onExecute(@NotNull final NetworkEvent.Context ctxIn, final boolean isLogicalServer, @NotNull final IColony colony, @NotNull final IBuilding building) {
    final BlockPos location = building.getPosition();
    final World world = colony.getWorld();
    for (final ICitizenData citizenData : building.getAllAssignedCitizen()) {
        Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
        if (!optionalEntityCitizen.isPresent()) {
            Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
            citizenData.setNextRespawnPosition(EntityUtils.getSpawnPoint(world, location));
            citizenData.updateEntityIfNecessary();
            optionalEntityCitizen = citizenData.getEntity();
        }
        if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), world, location)) {
            final PlayerEntity player = ctxIn.getSender();
            if (player == null) {
                return;
            }
            MessageUtils.format(WARNING_CITIZEN_RECALL_FAILED).sendTo(player);
        }
    }
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 53 with AbstractEntityCitizen

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

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

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

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

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

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