Search in sources :

Example 66 with AbstractEntityCitizen

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

the class CommandCitizenInfo 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(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
        return 0;
    }
    context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.desc", citizenData.getId(), citizenData.getName()), true);
    final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
    final BlockPos citizenPosition = entityCitizen.blockPosition();
    context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.pos", citizenPosition.getX(), citizenPosition.getY(), citizenPosition.getZ()), true);
    final BlockPos homePosition = entityCitizen.getRestrictCenter();
    context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.homepos", homePosition.getX(), homePosition.getY(), homePosition.getZ()), true);
    if (entityCitizen.getCitizenColonyHandler().getWorkBuilding() == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.workposnull"), true);
    } else {
        final BlockPos workingPosition = entityCitizen.getCitizenColonyHandler().getWorkBuilding().getPosition();
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.workpos", workingPosition.getX(), workingPosition.getY(), workingPosition.getZ()), true);
    }
    context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.health", entityCitizen.getHealth(), entityCitizen.getMaxHealth()), true);
    Object[] skills = new Object[] { citizenData.getCitizenSkillHandler().getSkills().get(Skill.Athletics).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Dexterity).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Strength).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Agility).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Stamina).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Mana).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Adaptability).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Focus).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Creativity).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Knowledge).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Intelligence).getA() };
    context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.skills", skills), true);
    if (entityCitizen.getCitizenJobHandler().getColonyJob() == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.jobnull"), true);
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.noactivity"), true);
    } else if (entityCitizen.getCitizenColonyHandler().getWorkBuilding() != null && entityCitizen.getCitizenColonyHandler().getWorkBuilding().hasModule(WorkerBuildingModule.class)) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.job", entityCitizen.getCitizenColonyHandler().getWorkBuilding().getFirstModuleOccurance(WorkerBuildingModule.class).getJobEntry().getTranslationKey()), true);
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.activity", entityCitizen.getDesiredActivity(), entityCitizen.getCitizenJobHandler().getColonyJob().getNameTagDescription(), entityCitizen.goalSelector.getRunningGoals().findFirst().get().getGoal().toString()), true);
    }
    return 1;
}
Also used : Entity(net.minecraft.entity.Entity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos)

Example 67 with AbstractEntityCitizen

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

the class CommandCitizenKill 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) {
    // Colony
    final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
    final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, context.getSource().getLevel().dimension());
    if (colony == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
        return 0;
    }
    if (!context.getSource().hasPermission(OP_PERM_LEVEL) && !MineColonies.getConfig().getServer().canPlayerUseKillCitizensCommand.get()) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.notenabledinconfig"), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
        return 0;
    }
    context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.desc", citizenData.getId(), citizenData.getName()), true);
    final BlockPos position = optionalEntityCitizen.get().blockPosition();
    context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.pos", position.getX(), position.getY(), position.getZ()), true);
    context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizenkill.success", position.getX(), position.getY(), position.getZ()), true);
    optionalEntityCitizen.get().die(CONSOLE_DAMAGE_SOURCE);
    return 1;
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos)

Example 68 with AbstractEntityCitizen

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

the class CommandCitizenTrack 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();
    if (!(sender instanceof PlayerEntity)) {
        return 1;
    }
    // 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(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
        return 0;
    }
    final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
    if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entityCitizen.getUUID())) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.disable"), true);
        AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
        Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
    } else {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.enable"), true);
        AbstractPathJob.trackingMap.put((PlayerEntity) sender, entityCitizen.getUUID());
    }
    return 1;
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SyncPathMessage(com.minecolonies.coremod.network.messages.client.SyncPathMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) HashSet(java.util.HashSet)

Example 69 with AbstractEntityCitizen

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

the class CommandCitizenTriggerWalkTo 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(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), 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) {
        if (entityCitizen instanceof EntityCitizen && entityCitizen.getCitizenJobHandler().getColonyJob() != null) {
            final AbstractEntityAIBasic basic = ((AbstractEntityAIBasic) entityCitizen.getCitizenJobHandler().getColonyJob().getWorkerAI());
            basic.setWalkTo(targetPos);
            basic.registerTarget(new AIOneTimeEventTarget(AIWorkerState.WALK_TO));
        } else {
            entityCitizen.getNavigation().moveTo(targetPos.getX(), targetPos.getY(), targetPos.getZ(), 1f);
        }
    }
    return 1;
}
Also used : Entity(net.minecraft.entity.Entity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) AIOneTimeEventTarget(com.minecolonies.api.entity.ai.statemachine.AIOneTimeEventTarget) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) ILocationArgument(net.minecraft.command.arguments.ILocationArgument) BlockPos(net.minecraft.util.math.BlockPos) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) AbstractEntityAIBasic(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIBasic)

Example 70 with AbstractEntityCitizen

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

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;
            }
            LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerhuts.recallFail");
        }
    }
}
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)

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