Not allowing xp orb pickup?

Discussion in 'Plugin Development' started by thok13, Nov 26, 2013.

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

    thok13

    I'm trying to make a plugin with "fairies", which are xp orbs riding invisible chickens. Is there a way to prevent players from picking up the xp orb? I managed to make it so the xp orb does not float towards them by canceling PlayerPickupItemEvent, but if the player gets too close to the xp they can still pick it up. I also tried not making the orbs ride the chickens and scheduling a runnable to teleport the orb to the chicken.
     
  2. Offline

    DreTaX

    Copy the code pls
     
  3. Offline

    thok13

    Which part?
     
  4. Offline

    DreTaX

    The event part
     
  5. Offline

    DarkBladee12

    thok13 Exp orbs are not items! You can't disable the orb pickup via events, you'd have to make a custom exp orb class which extends EntityExperienceOrb and override/modify the method b_.
     
  6. Offline

    thok13

    I know they are not items, but I heard from somebody else that orb pickup triggers the PlayerPickupItemEvent. I guess that person was wrong.

    I tried this, however at first I can't see them. When I get close to them, I can see them, but they start moving towards me and then snap back to where they were. my code:
    Code:java
    1. public class fairyorb extends EntityExperienceOrb
    2. {
    3.  
    4. public fairyorb(World world) {
    5. super(world);
    6. // TODO Auto-generated constructor stub
    7. }
    8. @Override
    9. public void b_(EntityHuman e)
    10. {
    11. return;
    12. }
    13. @Override
    14. public void l_()
    15. {
    16. return;
    17. }
    18.  
    19. }
    20.  


    *bump*

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

    DarkBladee12

    thok13 The problem is that you're overriding the l_ method, which is responsible for the movement of the exp orb... Just override b_ and nothing else. Btw your class names should start with an uppercase letter.
     
  8. Offline

    thok13

    Okay I will try that. As for the class names, is that a requirement or just a suggestion?

    Here's the b_ method:
    Code:java
    1. @Override
    2. public void b_(EntityHuman en)
    3. {
    4. motX = 0;
    5. motY = 0;
    6. motZ = 0;
    7. return;
    8. }

    I still can't see it when I spawn it, and it starts moving towards me when I get close to it.

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

    DarkBladee12

    thok13 I'll try that out and see if it works for me. And class names that don't start with an uppercase letter are discouraged.

    thok13 Okay, I got it to work, but only if the orb is a passenger of an entity. Otherwise it'll still follow the player around and be invisible until the player approaches. (seems like a bug of minecraft, even the experience orbs that come out of an Bottle o' Enchanting are invisible at first) This is the code I'm using:

    Code:java
    1. import java.lang.reflect.Method;
    2.  
    3. import net.minecraft.server.v1_6_R3.EntityExperienceOrb;
    4. import net.minecraft.server.v1_6_R3.EntityHuman;
    5. import net.minecraft.server.v1_6_R3.World;
    6.  
    7. import org.bukkit.Location;
    8. import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
    9. import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    10.  
    11. public class FairyOrb extends EntityExperienceOrb {
    12. public FairyOrb(World world) {
    13. super(world);
    14. }
    15.  
    16. @Override
    17. public void b_(EntityHuman entityhuman) {}
    18.  
    19. public static FairyOrb spawn(Location loc) {
    20. World w = ((CraftWorld) loc.getWorld()).getHandle();
    21. FairyOrb f = new FairyOrb(w);
    22. f.setPosition(loc.getX(), loc.getY(), loc.getZ());
    23. w.addEntity(f, SpawnReason.CUSTOM);
    24. return f;
    25. }
    26.  
    27. public static void registerEntity() {
    28. try {
    29. Method a = net.minecraft.server.v1_6_R3.EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class);
    30. a.setAccessible(true);
    31. a.invoke(a, FairyOrb.class, "ExperienceOrb", 301);
    32. } catch (Exception e) {
    33. e.printStackTrace();
    34. }
    35. }
    36. }


    Code:java
    1. Chicken c = (Chicken) LOCATION.getWorld().spawn(LOCATION, Chicken.class);
    2. c.setPassenger(FairyOrb.spawn(LOCATION).getBukkitEntity());


    So you just need to apply the invisible potion effect to the chicken now and move it around ;)

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

    thok13

    Thankyou so much! Happy thanksgiving!
     
Thread Status:
Not open for further replies.

Share This Page