Custom Projectiles

Discussion in 'Spigot Plugin Development' started by Skyler, Mar 22, 2015.

  1. I was on the Lichcraft server (us.lichcraft.com) and noticed the Grenade Launcher. Since then, I have been trying to duplicate it, so I could use the knowledge I got from doing so, in future projects. Using a snowball, I have found I can produce the same result, minus the fact you can see the projectile, and it doesn't bounce. I figured there were two ways to solve this.
    1. Create a new projectile (I figured it would be similar to creating a Custom Entity), and alter the code, to make the desired effect.
    2. Create a mathematical algorithm that can do the desired effect.

    I figured that the second one was at use on this server, but creating a new projectile would make it much more efficient.

    So, basically I need help choosing the more efficient path, and how to get the desired effect.

    Thanks in advance! :)
     
  2. When asking for help then it is easier for us if you begin with describing the effect you want to achieve as not that many people are going to join the server just to watch how the grenade launcher work to then respond to your post.

    Though I guess what you try to achieve is having a snowball that bounce and then maybe after x time or x bounces it explodes?

    If you want it to bounce you could try
    Code (Text):
    Projectile pro = player.launchProjectile(Snowball.class);
    pro.setBounce(true);
    I haven't tested this and seen what effect it gives, but my guessing is that it makes it bounce :p

    If that does not work then as you said spawning a new snowball on ProjectileHitEvent would be another approach though this might look a bit weird for the client as if you have just a tiny amount of lag then you would see it as hitting the ground and get destroyed then a new snowball reappears maybe a second later and so on.

    What you also could try is to instead of using a snowball to rather use a dropped item displaying a snowball. They would look exactly the same but the item does not disappear when it hits ground/walls. You would then have to probably check the item every tick to see if it has hit a block, as it does not throw a ProjectileHitEvent, checking the velocity and looking for solid blocks would probably be easiest.

    You most probably don't need to create a custom entity in the sense of playing with NSM if that is what you meant, as most of this could be done just by the bukkit api with events and such.
     

  3. Yes. That would all work, but I don't want the projectile to be seen, and I don't think .setBounce(true) will really have that effect.

    And I know I don't NEED to make a custom projectile, but it would made it so efficient.
     
  4. Did you TRY the setBounce(true) ?
     
  5. I have already suggested a few different approaches to this problem, have you tried ALL of them? If so what happened, why doesn't it work, what is your current state? What do you got so far?
     
  6. As Lichcraft Dev I can say that Grenade Launcher I can say that it's actually very simple, no entities and minimal math :p
    Pretty old thread, but just wanted to say this :D
     
  7. Its good to see your telling us that there are no entities (im not sure how the grenade launcher works) but how exactly would that be possible i mean im thinking that the thing moves... which ultimatley leads me to... its an entity, please explain not exactly how you did it but how it can be possible that you can make such an effect without entities
     
  8. Haha. Yeah. I did finally figure it out. I did trying what everyone else was says (.setBounce(true)) but that just didn't work.

    None the less, I did make my own version of the Grenade Launcher. In fact, I think I made a better one. In my version, it takes account of walls and ceilings, rather than just the floor.