Search in sources :

Example 1 with SyntaxErrorException

use of net.minecraft.command.SyntaxErrorException in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastSpread method doCommand.

private void doCommand(@Nonnull ICommandSender sender, @Nonnull String[] args) throws CommandException {
    final int count = CommandBase.parseInt(args[0], 1);
    final int distance = CommandBase.parseInt(args[1], 1);
    // Get explosive data from user
    final IExplosiveData explosiveData = CommandBlastTrigger.getExplosive(args[2]);
    // Get world position
    final World world = CommandUtils.getWorld(sender, args[3], sender.getEntityWorld());
    final double xInput = CommandUtils.getNumber(sender, args[4], sender.getPosition().getX() + 0.5);
    final double yInput = CommandUtils.getNumber(sender, args[5], sender.getPosition().getY() + 0.5);
    final double zInput = CommandUtils.getNumber(sender, args[6], sender.getPosition().getZ() + 0.5);
    // Get scale from user
    // TODO turn into helper method
    final float scale = Float.parseFloat(args[7]);
    if (scale <= 0) {
        throw new SyntaxErrorException(CommandBlastTrigger.TRANSLATION_ERROR_SCALE_ZERO);
    }
    final int expectedSpawnCount = (int) Math.floor(Math.pow((count * 2) + 1, 2));
    sender.sendMessage(new TextComponentTranslation(TRANSLATION_SPREAD_START, explosiveData.getRegistryName(), scale, world.provider.getDimension(), world.getWorldType().getName(), xInput, yInput, zInput, count, distance, expectedSpawnCount));
    // Generate blasts in a grid
    for (int xi = -count; xi <= count; xi++) {
        for (int zi = -count; zi <= count; zi++) {
            // calc position
            final double x = xInput + xi * distance;
            final double z = zInput + zi * distance;
            // Trigger blast
            final BlastState result = ExplosiveHandler.createExplosion(null, world, x, yInput, z, explosiveData.getRegistryID(), scale, null);
            if (result != BlastState.TRIGGERED && result != BlastState.THREADING) {
                // Send translated message to user
                sender.sendMessage(new TextComponentTranslation(CommandBlastTrigger.getTranslationKey(result), explosiveData.getRegistryName(), scale, world.provider.getDimension(), world.getWorldType().getName(), x, yInput, z));
            }
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) SyntaxErrorException(net.minecraft.command.SyntaxErrorException) World(net.minecraft.world.World) IExplosiveData(icbm.classic.api.reg.IExplosiveData) BlastState(icbm.classic.api.explosion.BlastState)

Example 2 with SyntaxErrorException

use of net.minecraft.command.SyntaxErrorException in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastTrigger method shortVersion.

private void shortVersion(ICommandSender sender, IExplosiveData explosiveData, String[] args) throws SyntaxErrorException {
    final float scale = Float.parseFloat(args[1]);
    if (scale <= 0) {
        throw new SyntaxErrorException(TRANSLATION_ERROR_SCALE_ZERO);
    }
    // Get position data
    final World world = sender.getEntityWorld();
    final double x = sender.getPositionVector().x;
    final double y = sender.getPositionVector().y;
    final double z = sender.getPositionVector().z;
    // Trigger blast
    trigger(sender, world, x, y, z, explosiveData, scale);
}
Also used : SyntaxErrorException(net.minecraft.command.SyntaxErrorException) World(net.minecraft.world.World)

Example 3 with SyntaxErrorException

use of net.minecraft.command.SyntaxErrorException in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastTrigger method longVersion.

private void longVersion(ICommandSender sender, IExplosiveData explosiveData, String[] args) throws SyntaxErrorException {
    final float scale = Float.parseFloat(args[5]);
    if (scale <= 0) {
        throw new SyntaxErrorException(TRANSLATION_ERROR_SCALE_ZERO);
    }
    // Get position data
    final World world = CommandUtils.getWorld(sender, args[1], sender.getEntityWorld());
    final double x = CommandUtils.getNumber(sender, args[2], sender.getPositionVector().x);
    final double y = CommandUtils.getNumber(sender, args[3], sender.getPositionVector().y);
    final double z = CommandUtils.getNumber(sender, args[4], sender.getPositionVector().z);
    // Trigger blast
    trigger(sender, world, x, y, z, explosiveData, scale);
}
Also used : SyntaxErrorException(net.minecraft.command.SyntaxErrorException) World(net.minecraft.world.World)

Aggregations

SyntaxErrorException (net.minecraft.command.SyntaxErrorException)3 World (net.minecraft.world.World)3 BlastState (icbm.classic.api.explosion.BlastState)1 IExplosiveData (icbm.classic.api.reg.IExplosiveData)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1