Search in sources :

Example 1 with FallingBlock

use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.

the class DropSpell method drop.

protected void drop(Block block, MaterialSet dropTypes, Collection<ItemStack> drops, int maxRecursion, int rDepth) {
    registerForUndo(block);
    if (dropCount < 0 || drops.size() < dropCount) {
        drops.addAll(block.getDrops());
    } else if (falling) {
        Location blockLocation = block.getLocation();
        FallingBlock falling = block.getWorld().spawnFallingBlock(blockLocation, block.getType(), block.getData());
        falling.setDropItem(false);
    }
    block.setType(Material.AIR);
    if (rDepth < maxRecursion) {
        tryDrop(block.getRelative(BlockFace.NORTH), dropTypes, drops, maxRecursion, rDepth + 1);
        tryDrop(block.getRelative(BlockFace.WEST), dropTypes, drops, maxRecursion, rDepth + 1);
        tryDrop(block.getRelative(BlockFace.SOUTH), dropTypes, drops, maxRecursion, rDepth + 1);
        tryDrop(block.getRelative(BlockFace.EAST), dropTypes, drops, maxRecursion, rDepth + 1);
        tryDrop(block.getRelative(BlockFace.UP), dropTypes, drops, maxRecursion, rDepth + 1);
        tryDrop(block.getRelative(BlockFace.DOWN), dropTypes, drops, maxRecursion, rDepth + 1);
        if (diagonals) {
            tryDrop(block.getRelative(BlockFace.NORTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(block.getRelative(BlockFace.NORTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(block.getRelative(BlockFace.SOUTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(block.getRelative(BlockFace.SOUTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
            Block up = block.getRelative(BlockFace.UP);
            tryDrop(up.getRelative(BlockFace.NORTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(up.getRelative(BlockFace.NORTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(up.getRelative(BlockFace.SOUTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(up.getRelative(BlockFace.SOUTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(up.getRelative(BlockFace.NORTH), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(up.getRelative(BlockFace.WEST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(up.getRelative(BlockFace.SOUTH), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(up.getRelative(BlockFace.EAST), dropTypes, drops, maxRecursion, rDepth + 1);
            Block down = block.getRelative(BlockFace.DOWN);
            tryDrop(down.getRelative(BlockFace.NORTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(down.getRelative(BlockFace.NORTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(down.getRelative(BlockFace.SOUTH_EAST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(down.getRelative(BlockFace.SOUTH_WEST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(down.getRelative(BlockFace.NORTH), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(down.getRelative(BlockFace.WEST), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(down.getRelative(BlockFace.SOUTH), dropTypes, drops, maxRecursion, rDepth + 1);
            tryDrop(down.getRelative(BlockFace.EAST), dropTypes, drops, maxRecursion, rDepth + 1);
        }
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) Location(org.bukkit.Location)

Example 2 with FallingBlock

use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.

the class DropAction method perform.

@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
    Block block = context.getTargetBlock();
    if (!context.hasBreakPermission(block)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (!context.isDestructible(block)) {
        return SpellResult.NO_TARGET;
    }
    // Don't allow dropping temporary blocks
    UndoList blockUndoList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(block.getLocation());
    if (blockUndoList != null && blockUndoList.isScheduled()) {
        return SpellResult.NO_TARGET;
    }
    if (dropCount < 0 || drops.size() < dropCount) {
        drops.addAll(block.getDrops());
    } else if (falling) {
        Location blockLocation = block.getLocation();
        FallingBlock falling = block.getWorld().spawnFallingBlock(blockLocation, block.getType(), block.getData());
        falling.setDropItem(false);
    }
    block.setType(Material.AIR);
    return SpellResult.CAST;
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) Location(org.bukkit.Location)

Example 3 with FallingBlock

use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.

the class TossSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Location location = getLocation();
    if (!hasBuildPermission(location.getBlock())) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    location.setY(location.getY() - 1);
    MaterialBrush buildWith = getBrush();
    buildWith.setTarget(location);
    Material material = buildWith.getMaterial();
    byte data = buildWith.getBlockData();
    int tossCount = 1;
    tossCount = parameters.getInt("count", tossCount);
    tossCount = (int) (mage.getRadiusMultiplier() * tossCount);
    float speed = 0.6f;
    speed = (float) parameters.getDouble("speed", speed);
    Vector direction = getDirection();
    direction.normalize().multiply(speed);
    Vector up = new Vector(0, 1, 0);
    Vector perp = new Vector();
    perp.copy(direction);
    perp.crossProduct(up);
    for (int i = 0; i < tossCount; i++) {
        FallingBlock block = null;
        location = getEyeLocation();
        location.setX(location.getX() + perp.getX() * (Math.random() * tossCount / 4 - tossCount / 8));
        location.setY(location.getY());
        location.setZ(location.getZ() + perp.getZ() * (Math.random() * tossCount / 4 - tossCount / 8));
        block = getWorld().spawnFallingBlock(location, material, data);
        if (block == null) {
            registerForUndo();
            return SpellResult.FAIL;
        }
        registerForUndo(block);
        block.setDropItem(false);
        SafetyUtils.setVelocity(block, direction);
    }
    registerForUndo();
    return SpellResult.CAST;
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) Material(org.bukkit.Material) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 4 with FallingBlock

use of org.bukkit.entity.FallingBlock in project Ublisk by Derkades.

the class PlayerInteract method spellTest.

@EventHandler(priority = EventPriority.MONITOR)
public void spellTest(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.BLAZE_ROD) {
            final Block block = event.getClickedBlock();
            if (block.getType() == Material.COBBLESTONE) {
                @SuppressWarnings("deprecation") FallingBlock fall = block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
                Vector velocity = fall.getVelocity();
                velocity.setY(velocity.getY() + 1.0);
                fall.setVelocity(velocity);
                block.setType(Material.AIR);
                Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {

                    public void run() {
                        Location loc = block.getLocation();
                        loc.setY(loc.getY() + 1);
                        ThrownPotion potion = (ThrownPotion) Var.WORLD.spawnEntity(loc, EntityType.SPLASH_POTION);
                        PotionEffect effect = new PotionEffect(PotionEffectType.HARM, 1, 2);
                        potion.getEffects().add(effect);
                    }
                }, 2 * 20);
            }
        }
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) PotionEffect(org.bukkit.potion.PotionEffect) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) URunnable(xyz.derkades.ublisk.utils.URunnable) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) ThrownPotion(org.bukkit.entity.ThrownPotion) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 5 with FallingBlock

use of org.bukkit.entity.FallingBlock in project EliteMobs by MagmaGuy.

the class EliteExplosionEvent method visualExplosionEffect.

public void visualExplosionEffect(ElitePower elitePower) {
    VisualExplosionEffectType visualExplosionEffectType;
    if (elitePower == null)
        visualExplosionEffectType = VisualExplosionEffectType.NORMAL;
    else if (elitePower.getFileName().equals(new EnderDragonEmpoweredLightning().getFileName()))
        visualExplosionEffectType = VisualExplosionEffectType.ASCEND;
    else if (elitePower instanceof EnderDragonTornado) {
        visualExplosionEffectType = VisualExplosionEffectType.HIGH_POWER;
    } else
        visualExplosionEffectType = VisualExplosionEffectType.NORMAL;
    for (BlockState blockState : blockStates) {
        FallingBlock fallingBlock = blockState.getBlock().getWorld().spawnFallingBlock(blockState.getLocation().add(new Vector(0, 0.2, 0)), blockState.getBlockData());
        fallingBlock.setDropItem(false);
        fallingBlock.setHurtEntities(true);
        switch(visualExplosionEffectType) {
            case ASCEND:
                fallingBlock.setVelocity(fallingBlock.getLocation().clone().subtract(explosionSourceLocation).toVector().normalize().setY(1).normalize().multiply(ThreadLocalRandom.current().nextDouble()));
                fallingBlock.setGravity(false);
                fallingBlock.setGlowing(true);
                break;
            case HIGH_POWER:
                fallingBlock.setVelocity(fallingBlock.getLocation().clone().subtract(explosionSourceLocation).toVector().normalize().setY(2).multiply(0.9));
                break;
            case NORMAL:
            default:
                fallingBlock.setVelocity(fallingBlock.getLocation().clone().subtract(explosionSourceLocation).toVector().normalize().setY(1).multiply(0.5));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                if (fallingBlock.isValid())
                    fallingBlock.remove();
            }
        }.runTaskLater(MetadataHandler.PLUGIN, 20 * 4);
        CrashFix.persistentTracker(fallingBlock);
        fallingBlocks.add(fallingBlock);
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) EnderDragonTornado(com.magmaguy.elitemobs.powers.majorpowers.enderdragon.EnderDragonTornado) BlockState(org.bukkit.block.BlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EnderDragonEmpoweredLightning(com.magmaguy.elitemobs.powers.majorpowers.enderdragon.EnderDragonEmpoweredLightning) Vector(org.bukkit.util.Vector)

Aggregations

FallingBlock (org.bukkit.entity.FallingBlock)11 Location (org.bukkit.Location)7 Material (org.bukkit.Material)6 Block (org.bukkit.block.Block)6 Vector (org.bukkit.util.Vector)6 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)4 ItemStack (org.bukkit.inventory.ItemStack)4 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)3 EventHandler (org.bukkit.event.EventHandler)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 Entity (org.bukkit.entity.Entity)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 SourceLocation (com.elmakers.mine.bukkit.magic.SourceLocation)1 EnderDragonEmpoweredLightning (com.magmaguy.elitemobs.powers.majorpowers.enderdragon.EnderDragonEmpoweredLightning)1 EnderDragonTornado (com.magmaguy.elitemobs.powers.majorpowers.enderdragon.EnderDragonTornado)1 BlockCache (fr.neatmonster.nocheatplus.utilities.map.BlockCache)1 WrapBlockCache (fr.neatmonster.nocheatplus.utilities.map.WrapBlockCache)1 IWorldData (fr.neatmonster.nocheatplus.worlds.IWorldData)1 World (org.bukkit.World)1 BlockState (org.bukkit.block.BlockState)1