How can I spawn Exp orbs.

Discussion in 'Plugin Development' started by Eistee², Aug 11, 2012.

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

    Eistee²

    Hello ,
    My plugin give exp for block breaking and placeing and I want to spawn exp orbs when someon place a block.
    How can I do this?

    Eistee²
     
  2. Offline

    lol768

    Pretty sure it's just an entity.
    PHP:
    player.getWorld().spawn(player.getLocation(), XPOrb.class);
     
     
    Eistee² likes this.
  3. Offline

    Eistee²

    thanks , I will try this :)
     
  4. Offline

    lol768

    I was wrong:
    getWorld().spawn(e.getBlock().getLocation(), ExperienceOrb.class);
     
  5. Offline

    one4me

    I just decided to mess around and came up with this. It does work, but since there are already ways to spawn xp it was probably a waste of time making this.
    Code:
    @EventHandler
    public void onBlockPlaceEvent(BlockPlaceEvent e) {
      spawnOrb(e.getBlock().getLocation(), 5, 1);
    }
    @EventHandler
    public void onBlockBreakEvent(BlockBreakEvent e) {
      spawnOrb(e.getBlock().getLocation(), 5, 1);
    }
    public void spawnOrb(org.bukkit.Location l, int amount, int value) {
      double x = l.getX(), y = l.getY(), z = l.getZ();
      net.minecraft.server.World w = ((org.bukkit.craftbukkit.CraftWorld)l.getWorld()).getHandle();
      for(int i = 0; i < value; i++) {
        ((net.minecraft.server.World)w).addEntity(new net.minecraft.server.EntityExperienceOrb((net.minecraft.server.World) w, x, y, z, value));
      }
    }
    
     
    Eistee² likes this.
  6. Offline

    Eistee²


    ^^ No problem when you read my first post right you will see that I mean for "PlaceBlockEvent" :)

    And thanks for you help and here a bit smaller code for each one that maybe interested in this :)

    Code:
     for(int amount = 0 ; amount < exp;amount++)
    {
    ExperienceOrb orb = event.getPlayer().getWorld().spawn(expSpawn, ExperienceOrb.class);
    orb.setExperience(1);
     }
     
    one4me likes this.
Thread Status:
Not open for further replies.

Share This Page