Haj, im having trouble with eggs :/ I want my eggs to not hatch. Code: egg = p.launchProjectile(Egg.class); PlayerEggThrowEvent event = new PlayerEggThrowEvent(p, e, false, (byte)o, EntiityType.CHICKEN); Infortunatel, it still hatches ;/ Could anyone explain to me how to properly do this?
brord Adding this event should work: Code:java @EventHandlerpublic void onEggThrow(PlayerEggThrowEvent event) { event.setHatching(false);} However, this blocks all eggs from hatching, if you want only the ones you've manually launched you have to add some if checks to the event.
brord or you could do Code:java @EventHandler public void onCreatureSpawn(CreatureSpawnEvent event){ if (event.getSpawnReason() == SpawnReason.EGG){ event.setCancelled(true); } }
I want to cancel jsut the eggs i shoot from a certain player. (he is holdign a gun) But i allready call the eggtrowevent, so who would i need to listen to it again, and set hatching to false? The false argument in the new PlayerEggThrowEvent allready sets nno hatching
You could do this Code: @EventHandler public void onCreatureSpawn(CreatureSpawnEvent event){ Player p = event.getPlayer(); if (p.getItemInHand().getType() == Material.GUN HERE){ if (event.getSpawnReason() == SpawnReason.EGG){ event.setCancelled(true); } }
Well the item in hand could change in the time from shooting and hatching the egg. He could even loose the gun in that time, so this wont work either :/ Thanks for the input though!
do a check if the egg material type matched with MonsterEgg. also fyi https://github.com/xize/xEssentials...ineinthebox/events/EntityEvent/egglogger.java Edit Afaik it should detect peacefull mobs aswell, also if you cancel the event you probably prevent mobs from spawnig.