How to stop egg hatching without PlayerEggThrowEvent

Discussion in 'Plugin Development' started by blablubbabc, Dec 20, 2012.

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

    blablubbabc

    Hey,
    I am trying to stop the egg hatching from eggs not thrown by players but spawned via loc.getWorld().spawn(loc, Egg.class) where "loc" is a location.

    I don't want to let the egg be thrown by a player and then teleported to the position where i want it to be anymore to stop it from hatching. This is how I do it currently.
     
  2. Offline

    EnvisionRed

    Listen for an ItemSpawnEvent, if the item is an egg, remove it?
     
  3. Offline

    blablubbabc

    I dont want to remove the eggs. I want to stop them from hatching.
    I made a quick try to rmove them on ProjectileHitEvent, which didn't work either..
     
  4. Offline

    Woobie

    blablubbabc
    Code:
    PlayerEggThrowEvent -> event.setHatching(false);
    or
    Code:
        @EventHandler
        public void onCreatureSpawn(CreatureSpawnEvent event)
        {
            if (event.getSpawnReason() == SpawnReason.EGG)
            {
                event.setCancelled(true);
            }
        }
     
    zzienzz likes this.
  5. Offline

    fireblast709

    Note that the last will stop all chicken eggs from hatching :3
     
    zzienzz likes this.
  6. Offline

    Woobie

    Oh whoops, I didnt even read what he wants.. :D I just read the title.
     
  7. Offline

    blablubbabc

    Unfortunly I can't get the Egg inside the CreatureSpawnEvent, to compare it with the eggs i wanted to disable hatching for..
     
  8. Offline

    ZeusAllMighty11

    Don't items have a UUID? Or is that only mobs?



    I guess if you really had to, you could manually do the event and onRightClick cancel it, project the egg with correct velocity and vectors, and ensure that the egg only disappears after it hits, so that it doesn't hatch a chicken?

    Not sure how the chickens hatch to be honest.
     
  9. Offline

    blablubbabc

    yes they have. but as for example the creature spawn event doesn't give me the egg a chicken spawned from, i can't compare my saved UUID/egg with the egg from the creature spawning..

    eggs also hatch chickens when they are not thrown but spawned, thats the problem. I already tried to remove the egg on projectileHitEvent, which didn't stop it from hatching..
     
  10. Offline

    blablubbabc

  11. Offline

    fireblast709

    Cancel the CreatureSpawnEvent when its reason is an egg and spawn one yourself in ProjectileHitEvent? This way you can register the UUID in the ProjectileLauncEvent/PlayerThrowEggEvent
     
  12. Offline

    blablubbabc

    but if I create a new egg in the cre4ature spawn event, it will not have the same UUID i remebered from the egg spawning...
     
  13. Offline

    fireblast709

    You don't create a new egg. You check if the SpawnReason was SpawnReason.EGG, and if so cancel it. Then you check in the ProjectileHitEvent if the egg was in a ArrayList<UUID>, and if so spawn a chicken. You create the ArrayList<UUID> yourself, and add UUIDs to it in the PlayerEggThrowEvent or ProjectileLaunchEvent
     
  14. Offline

    blablubbabc

    ahh, I get what you mean..
    This way I would have to "simulate" the chicken spawning of minecraft on my onw :/ ..
     
  15. Offline

    fireblast709

  16. Offline

    Hoolean

    How about getting ProjectileHitEvent, then if getShooter() instanceof Player then allow it, else not? (only problem would be with dispensors :()
     
  17. Offline

    fireblast709

    Exactly how I was suggesting it :3.
     
  18. Offline

    Hoolean

    Weren't you saying using UUIDs and Lists?
     
  19. Offline

    fireblast709

    Mmh you got a point there...
     
  20. Offline

    blablubbabc

    How would I "allow" or "deny" it inside the projectilehit event ? hmm, I will test to cancle the hit event, maybe this helps..
     
  21. Offline

    Hoolean

    Cancelling the hit event should work swell :D
     
  22. Offline

    blablubbabc

    just tried it: I wasn't able to cancle the ProjectileHit event, as its not cancleable :(
     
  23. Offline

    Hoolean

    event.getEntity().remove()

    Just a guess, may not work :p
     
  24. Offline

    blablubbabc

    Nope, didn't work.. :(
     
  25. Offline

    fireblast709

    If you want to allow or deny it, use the method discussed before. Cancel the CreatureSpawnEvent if the reason is SpawnReason.EGG, and decide in the ProjectileHitEvent (if the projectile instanceof Egg) if you want to spawn a chicken or not
     
  26. Offline

    blablubbabc

    yeah ..so if its a normal thrown egg i would have to simulate the minecraft spawning.. like aready said.. so.. its randomly 1 of 8 isn't it ?

    So I would replace the minecraft egg spawning on each server with my own, amateur spawning, if the server is running my plugin .. :(
     
  27. Offline

    fireblast709

    yep, that is basically the only option if you want to stop spawning chickens from chicken eggs. Note that they can still spawn naturally ;3
     
  28. Offline

    blablubbabc

    I guess I will then just use the old method, letting a player throw the egg, stop the hatching inside the eggthrowevent and then teleport it to the right location and do stuff with it there...

    I don't like to take stuff out of default minecraft :/

    Hopefully this will be possible in a cleaner way in the future then ..:/
     
Thread Status:
Not open for further replies.

Share This Page