[1.12] Change particles when creating an explosion

Discussion in 'Spigot Plugin Development' started by waterman1001, Jul 29, 2018.

  1. Hello!

    I am trying to let a player use a stick so that when it right clicks on the stick, there spawns an explosion on the location where it is looking at within a range of 10 blocks. (A sort of 'Wand' idea.)
    Currently I got this working.
    The only problem I have now is that I want to change the particles of the explosion from the standard 'EXPLOSION_NORMAL' to for example the 'PORTAL' particle effect.
    I can get the portal particles working but I cannot 'remove' the particles of the explosion.

    This is the code I am using:
    Code (Text):
    if ((e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) && (e.getItem().getType() == Material.STICK)){
                    Location viewpoint = e.getPlayer().getTargetBlock((Set<Material>) null, 10).getLocation();
                    double viewpointX = viewpoint.getX();
                    double viewpointY = viewpoint.getY();
                    double viewpointZ = viewpoint.getZ();
                    e.getPlayer().getWorld().createExplosion(viewpointX, viewpointY, viewpointZ, 4F, false, false);
                    e.getPlayer().getWorld().spawnParticle(Particle.PORTAL, viewpoint, 10);
    I hope there is someone who would like to help me with my code and who can help me out and knows if this is possible to do. If there is any other way to do this, I would like to hear it as well of course :)
    Thank you very much in advance!
    Let me know if something is unclear. :)
  2. Create a custom explosion, either blow the blocks up yourself or spawn an invisible creeper set to explode as soon as it spawns?
    • Like Like x 1
  3. Thanks for your reply!
    Well, a custom explosion could fix it indeed. How would I blow up the blocks myself?
    Do you maybe have a little example for me?
    And does an invisible creeper's explosion not have it's own particle effects as well?
    It could still be an option though.
  4. Bump :3
    Does someone have an idea or an example for me? :)
    #4 waterman1001, Jul 30, 2018
    Last edited: Jul 30, 2018
  5. Bump 2? :D
    I don't actually want to spam my own topic but I hope that, because I am posting this on another time then my previous posts, different people will read this and maybe want to help me. :p
  6. Creating your own explosion that exactly mimic's NMS explosions is going to be kind of challenging, in particular because you don't have direct access to Block hardness (explosion resistance). If you're up for some dirty NMS you could try copying the Explosion class and modifying it, but it's an obfuscated mess.

    If you're ok with a "dumbed down" sort of explosion, you could basically get all entities in a radius and damage them and get all blocks in a radius and randomly remove some, or just remove them all (hollow out a sphere).
  7. Since explosion is a type of particle effect, I imagine you can intercept the explosion particle and replace it with your own particles when necessary
    • Like Like x 1
  8. Aah Okay, Now I understand. Thank you for explaining that it would be a challenge (and also why it would be a challenge) to mimic a NMS explosion. Also, thank you very much for your response :)

    Well, That is something I thought as well, but I don't have an idea how I could intercept the explosion particle x3.
  9. That was a great suggestion- you'd want to use ProtocolLib for that. I've never done anything like that so I can't help much, but I imagine there are tutorials out there.
  10. Ah okay, thank you. :)