Search in sources :

Example 1 with BlastState

use of icbm.classic.api.explosion.BlastState 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 BlastState

use of icbm.classic.api.explosion.BlastState in project ICBM-Classic by BuiltBrokenModding.

the class TestTileEMPTower method testFire_isReady_hasEnergy.

@Test
void testFire_isReady_hasEnergy() {
    // Create tower, create mock around tile so we can fake some methods
    final TileEMPTower tileEMPTower = spy(create());
    tileEMPTower.setPos(new BlockPos(20, 30, 40));
    tileEMPTower.setEnergy(Integer.MAX_VALUE);
    // Mock blast so we don't invoke world calls
    when(tileEMPTower.buildBlast()).thenReturn(new Blast() {

        @Override
        public BlastState runBlast() {
            return BlastState.TRIGGERED;
        }
    });
    // Should have fired
    Assertions.assertTrue(tileEMPTower.fire());
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Blast(icbm.classic.content.blast.Blast) IBlast(icbm.classic.api.explosion.IBlast) BlastState(icbm.classic.api.explosion.BlastState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with BlastState

use of icbm.classic.api.explosion.BlastState in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastTrigger method trigger.

/**
 * Triggers the explosive at the location
 *
 * @param sender        - user running the command
 * @param world         - position data
 * @param x             - position data
 * @param y             - position data
 * @param z             - position data
 * @param explosiveData - explosive to run
 * @param scale         - scale to apply, keep this small as its scale and not size (size defaults to 25 * scale of 2 = 50 size)
 */
private void trigger(ICommandSender sender, World world, double x, double y, double z, IExplosiveData explosiveData, float scale) {
    final BlastState result = ExplosiveHandler.createExplosion(null, world, x, y, z, explosiveData.getRegistryID(), scale, null);
    // Send translated message to user
    sender.sendMessage(new TextComponentTranslation(getTranslationKey(result), explosiveData.getRegistryName(), scale, world.provider.getDimension(), world.getWorldType().getName(), x, y, z));
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) BlastState(icbm.classic.api.explosion.BlastState)

Aggregations

BlastState (icbm.classic.api.explosion.BlastState)3 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 IBlast (icbm.classic.api.explosion.IBlast)1 IExplosiveData (icbm.classic.api.reg.IExplosiveData)1 Blast (icbm.classic.content.blast.Blast)1 SyntaxErrorException (net.minecraft.command.SyntaxErrorException)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1