Search in sources :

Example 1 with ILocationArgument

use of net.minecraft.command.arguments.ILocationArgument in project minecolonies by Minecolonies.

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 2 with ILocationArgument

use of net.minecraft.command.arguments.ILocationArgument in project minecolonies by ldtteam.

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(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) {
        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) ICitizenData(com.minecolonies.api.colony.ICitizenData) ILocationArgument(net.minecraft.command.arguments.ILocationArgument) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with ILocationArgument

use of net.minecraft.command.arguments.ILocationArgument 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(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) {
        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) ICitizenData(com.minecolonies.api.colony.ICitizenData) ILocationArgument(net.minecraft.command.arguments.ILocationArgument) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with ILocationArgument

use of net.minecraft.command.arguments.ILocationArgument 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)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)4 IColony (com.minecolonies.api.colony.IColony)4 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)4 ILocationArgument (net.minecraft.command.arguments.ILocationArgument)4 Entity (net.minecraft.entity.Entity)4 BlockPos (net.minecraft.util.math.BlockPos)4 AIOneTimeEventTarget (com.minecolonies.api.entity.ai.statemachine.AIOneTimeEventTarget)2 AbstractEntityAIBasic (com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIBasic)2 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)2