creating an explosion

Discussion in 'Plugin Development' started by WEEEEEE, Jul 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    WEEEEEE

    how can i create explosion without damage to nearby entites, i want only visual effect and sound.
    i dont want to set "size" of explosion at 0F, so thats why i dont want use bukkit method world.createExplosion
    tried this but it does damage too.
    ((CraftWorld)event.getPlayer().getWorld()).getHandle().createExplosion(null, b.getX(), b.getY(), b.getZ(), 4F, false, false);
    now im trying to use nms, but i dont know if it will even work and how can i convert Player to EntityPlayer?
    net.minecraft.server.World a = ((CraftWorld)event.getPlayer().getWorld()).getHandle();
    net.minecraft.server.Explosion ex = new Explosion(a, --,b.getX(),getY(),b.getZ(),4F);
    ex.a(true)/ex.a(false)?
     
  2. Offline

    Wolfram1

    You can try creating an explosion and canceling the damage event on TNT explosion.
    Code:java
    1. @EventHandler
    2. public void onEntityDamage(EntityDamageEvent e){
    3. if(e.getEntity() instanceof Entity && e.getCause().equals(DamageCause.BLOCK_EXPLOSION)){
    4. e.setCancelled(true);
    5. }
    6. }
     
  3. Offline

    andf54

    You might be able to send the explosion packet to the client. Look under Resources forum.
     
  4. Offline

    xTrollxDudex

    andf54 Wolfram1 WEEEEEE
    Seriously? In the plugin tutorial it has a create explosion thing.
    Code:java
    1. player.getWorld().createExplosion(<location>, <power>);
     
  5. Offline

    andf54

    He said he wants the effect, not the damage. Setting power to 0 was not an option.
     
  6. Offline

    WEEEEEE

    yep its possible cancell it like this, but due to other stuff in plugin i cant block it like this.
     
  7. Offline

    xTrollxDudex

    andf54
    It doesn't have an effect does it?
     
  8. Offline

    Alxlre

    Why not? Can you show us that other stuff in the plugin which makes you unable to block it like that?
     
  9. Offline

    WEEEEEE

  10. Offline

    xTrollxDudex

    andf54 WEEEEEE
    Code:java
    1. ((CraftServer) server).getHandle().playerConnection.sendPacket(new Packet60Explosion(b.getX(), b.getY(), b.getZ(), 4, 0, ((byte) 0, (byte) 0, (byte) 0), (float) 0, (float) 0, (float) 0));

    I'm a total noob at packets my first time... Hopefully it works tho!
     
  11. Offline

    WEEEEEE

    ^please, stop trolling in this topic.
     
  12. Offline

    andf54

    My guess that's its the direction the player is propelled to. It's logical, if you think about it. Normal create explosion calculates player velocity itself. But since you are sending the packet, you need to fill that in manually.

    http://mc.kev009.com/Protocol#Explosion_.280x3C.29
     
  13. Offline

    xTrollxDudex

    WEEEEEE
    Am I trolling?

    I know you have done it through packages but this one worked for me...
    This is what i used to create a grenade that damged players and showed the effect but this stopped blocks being damaged!
    Code:
    public Main plugin;
        public Grenade(Main plugin){
            this.plugin = plugin;
        }
        ArrayList<Item> cantPickup = new ArrayList<Item>();
        public static boolean blockdamage = false;
        @EventHandler
        public void slimeGrenade(PlayerInteractEvent event) {
            final Player player = event.getPlayer();
            World world = player.getWorld();
                if (player.getItemInHand().getType() == Material.SLIME_BALL) {
                    if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                        final Item grenade = world.dropItem(player.getEyeLocation(), new ItemStack(Material.SLIME_BALL));
                        grenade.setVelocity(player.getEyeLocation().getDirection());
                        ItemStack slimeball = new ItemStack(Material.SLIME_BALL, 1);
                        player.getInventory().remove(slimeball);
                        cantPickup.add(grenade);
                        plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
     
                            @Override
                            public void run() {
                                Grenade.blockdamage = true;
                                grenade.getWorld().createExplosion(grenade.getLocation(), 3F);
                                Grenade.blockdamage = false;
                                grenade.remove();
                                cantPickup.remove(grenade);
                            }
                        }, 40L);
                    }
                }
            }
       
        @EventHandler
        public void onEntityExplode(EntityExplodeEvent event)
        {
        if(blockdamage && event.getEntity() == null)event.blockList().clear();
        }
       
        @EventHandler
        public void onItemPickup(PlayerPickupItemEvent event){
            Item item = event.getItem();
            if(cantPickup.contains(item)){
                event.setCancelled(true);
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 26, 2021
  14. Offline

    WEEEEEE

    andf54 thanks for help, problem was solved.
     
Thread Status:
Not open for further replies.

Share This Page