How to make an item throwable

Discussion in 'Plugin Development' started by DatCookiez, Mar 28, 2013.

  1. Offline

    DatCookiez

    Hey guys!
    I am wanting to know how to make an item throwable (like a magma cream *with eggs throw*, when you right click it)
     
  2. I will make it, but I won't test it. It will be something I use a lot in my kitpvp plugin while I'm testing.. Just gimme a few minutes.
     
  3. Offline

    DatCookiez

  4. Code:java
    1. public void onThrow(PlayerInteractEvent e){
    2. Player player = e.getPlayer();
    3. PlayerInventory pi = player.getInventory();
    4. ItemStack a = new ItemStack(Material.MAGMA_CREAM, 1);
    5. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
    6. if(pi.getItemInHand().getType() == Material.MAGMA_CREAM){
    7. if(pi.contains(a, 1)){
    8. player.getWorld().spawn(player.getLocation().add(0,1.62,0), Egg.class);
    9. player.launchProjectile(Egg.class);
    10. pi.remove(a);
    11. } else player.sendMessage("You ain't got no MagmaCream!");
    12. }
    13. }
    14. }
     
  5. Offline

    DatCookiez

    Why does it pop an egg out too?
     
  6. realiez Don't forget to tag me if your trying to reply to me.. But you said, didn't you?
     
  7. Offline

    DatCookiez

    kreashenz I got it :p Do you know how to block explosion damage to blocks and damage to players, but still have a knockback of the explosion with this?:

    Code:java
    1. @EventHandler
    2. public void onLeverSwitch(PlayerEggThrowEvent event)
    3. {
    4.  
    5. event.getEgg().getWorld().createExplosion(event.getEgg().getLocation(), 6);
    6. }
     
  8. Code:java
    1.  
    2. @EventHandler
    3. public void onLeverSwitch(PlayerEggThrowEvent event){
    4. Location loc = event.getEgg().getLocation();
    5. event.getEgg().getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 6F, false false);
    6. }

    realiez Try this, I'm pretty sure that'd work.
     
  9. Offline

    DatCookiez

    kreashenz Would this do damage to people still? Because I want it to do no damage but still give them the knockback effect
     
  10. realiez Oh, I'm not entirely sure on that, but that blocks block damage and fire.
     
  11. Offline

    DatCookiez

Share This Page