Chicken egg laying problems.

Discussion in 'Plugin Development' started by tremor, Dec 17, 2012.

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

    tremor

    I have a problem on my server with players making chicken farms that spawn out thousands of eggs.. our food market is destroyed because pumpkin pie's basically are free. So I set about not removing the chance of eggs being laid, but slowing it down a lot. I was unable to locate anything in the JD about chicken egg laying directly, so I resorted to listening to item spawn event and checking if the item was a chicken egg. I put a chance in of whether or not the event would spawn an egg.. it works. However I still get the 'sound' of an egg being laid, when the egg laying event is cancelled.

    Any suggestions? Why is there no API for the chicken egg laying event, or am I just not finding it?
     
  2. Offline

    tommycake50

    to stop the sound you need to destroy the packets of egg laying being sent.
     
  3. Offline

    tremor

    Seems like an awful lot of work to decrease the egg laying rate and a long, roundabout and inefficient manner. There really should be a way to tell the chicken under what circumstances (beyond the default) it is allowed to drop eggs. I'd even like to possibly tie it to biome, or Y: coordinate ranges. Listening to every spawn event to see if it's a chicken egg (then checking to see if it's been laid and not thrown or dropped from a player), and now, packet stuff which, unless someone pretty much walks me through it, I wouldn't even know where to being.
     
  4. Offline

    tommycake50

    well its the only way i can think of apart from looping through all the chickens in the world and setting them to a modified version of the chicken class.
     
  5. Offline

    fireblast709

    God why not just use the ItemSpawnEvent and a Random? Use the random to get a number, and define the chance yourself. If it does not fit the chance, disable the event
     
  6. Offline

    tommycake50

    thats what he was doing but he said there was still a sound :/
     
  7. Offline

    tremor

    This is exactly what I did. However;
    1. There is still an egg pop sound. (sound CHICKEN_EGG_POP)
    2. It seems incredibly inefficient to me to listen to every ItemSpawnEvent for this.
    What I'm trying to say it would be far superior approach to tell the chicken in this case, to fire this event less often. I've found no way to do that.. so i'll take whatever advice I need in order to also stop the sound for now. It just feels like a real what comes first, chicken or egg scenario here.

    Oh and the other problem with checking the ItemSpawnEvent and adding a random is.. testing whether the event came from the chicken, a player... or another plugin. This all has a huge amount of overhead when you're looking at potentially thousands of events per second on a large server.
     
  8. Offline

    tommycake50

    *cough*stopping laying sound packets*cough*
     
  9. Offline

    fireblast709

    2 things:
    1. its not that hard for the server
    2. override the EntityChicken class
    tommycake50 ... no comment on how bad the idea
     
  10. Offline

    tommycake50

    oh yeah i just realised why that idea is bad xD.
     
  11. Offline

    tremor

    *cough* 1.4.5-R0.3 *stopping repeating solution I won't accept without even explaining how to do it in an acceptable way *cough*

    fireblast709: I would override the Chicken Class - http://jd.bukkit.org/doxygen/d3/dfa/interfaceorg_1_1bukkit_1_1entity_1_1Chicken.html - But I don't see anything in Bukkit that references the Egg spawning event, I don't think it exists. The only possibility I can think of is to use age.. and not allow the chicken to get to whatever age it begins to drop eggs at. However I have no reference point for that either.
     
  12. Offline

    fireblast709

    I ment the EntityChicken, the minecraft one (people usually refer to the code as NMS code, net.minecraft.server code, which uses Craftbukkit)
     
  13. Offline

    tremor

    I only code to Bukkit. I'm not that avid a plugin developer to open that can of worms.
     
  14. Offline

    fireblast709

    Then your best bet is the ItemSpawnEvent
     
  15. Offline

    tremor

    I was afraid of that. Trying to think of creative ways to stop the egg pop sound.. and also, maybe identify the chicken that laid the egg, I was thinking after laying an egg, killing the chicken might be fun.
     
  16. Offline

    fireblast709

    :p. Well can't help you more by just using Bukkit D:
     
Thread Status:
Not open for further replies.

Share This Page