Nether Star Projectile Not Working

Discussion in 'Plugin Development' started by BillyBobJoe168, Apr 22, 2014.

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

    BillyBobJoe168

    Hi, I am trying to make a ninja kit and what could be better than to be able to shoot nether stars? Well, I tried to use the same code that I used to shoot ice blocks for an ice kit I made but it doesn't work. It gives me an Event Exception on line 36 of the following code.
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e) {
    3. final Player p = e.getPlayer();
    4. Vector vec = p.getLocation().getDirection();
    5. if ((e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) && p.getItemInHand() != null) {
    6. if (p.getItemInHand().getType() == Material.NETHER_STAR) {
    7. FallingBlock fb = p.getWorld().spawnFallingBlock(p.getEyeLocation(), Material.NETHER_STAR, (byte) 0x0);//line 36
    8. fb.setVelocity(vec.multiply(5.0D));
    9. }

    yes, the brackets are wrong, there is other code after this that works fine and I didn't want to take up space by pasting the other code. Anyone have a solution to this? Maybe you can't make Nether stars falling blocks because it isn't even a block?
     
  2. Offline

    Garris0n

    Well, you know what would be useful is the Event Exception and an indicator of which line is 36.
     
  3. Offline

    BillyBobJoe168

    LOL my first time posting I did have that but then I edited my code and forgot to put that info back inXD My bad line 36 is line 7 on the code posted above. I will edit thisXD
     
  4. Offline

    turqmelon

    A nether star isn't a block, so it can't be spawned as a falling block.

    BillyBobJoe168

    (At least as far as I've tested...)
     
    Garris0n likes this.
  5. Offline

    BillyBobJoe168

    hmm I will experiment with dropping the item instead of making it a falling block. turqmelon

    Alright, I came up with the following code that works pretty well.
    Code:java
    1. Vector vec = p.getLocation().getDirection();
    2.  
    3. Item drops = p.getWorld().dropItem(p.getLocation(), p.getItemInHand());
    4. drops.setVelocity(vec.multiply(30.0D).normalize());

    Now, there are 2 problems with this. If the player is holding more than one nether star, let's say 10 of them, then the player will shoot 10 nether stars (bad idea...). Also, I would like them to be removed when they hit the ground. How would I check when the nether star hits the ground? Thanks:)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  6. Offline

    Captain Dory

    Use a repeating task tick- check if drops.isOnGround() (Might be something else) and if so, remove the item.
     
  7. Offline

    BillyBobJoe168

    lol there was an isOnGround() method? woopsXD. I beleive that will solve my problem but I will have to test it tomorrow since I'm on my phone. Do you have a way to make it only shoot one nether star instead of however many you have in your hand? I just did /i netherstar and found out I was shooting stacks of netherstarsXD. I do not want that happening.
     
  8. Offline

    Captain Dory

    Do you mean like a cooldown?
     
  9. Offline

    BillyBobJoe168

    no not a cooldown. I know how to make cooldowns. When I went to my server to test the plugin, I did /i netherstar and when I right clicked, I started shooting STACKS of netherstars. I want it to shoot only one nether star regardless of how many you have in your hand. Would you like me to post a video?
     
  10. Offline

    Gater12

    BillyBobJoe168
    Because you drop the whole dang thing in the code. (p.getItemInHand() returns an ItemStack thus if the player has 64 nether stars... It would return the ItemStack with the Material.NETHER_ STAR and a quantity of 64)
     
  11. Offline

    BillyBobJoe168

    so should I just create my own Item Stack with only 1 nether star and make the player drop that instead?
     
  12. Offline

    Gater12

Thread Status:
Not open for further replies.

Share This Page