Anyone willing to do a little background research on World.spawnCreature?

Discussion in 'Plugin Development' started by DrBoweNur, Aug 28, 2011.

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

    DrBowe

    Okay, I'm looking for two things here:

    1) A link to reference all of the CraftBukkit code, so I can look this stuff up on my own from now Google is my friend.

    -and-

    2) I need clarification on what this method is actually doing inside CraftBukkit, and if there would be any way to submit a request to have it changed slightly. It's painfully obvious that server's are capable of knowing when it has a full capacity for mobs.

    However, World.spawnCreature (to my knowledge) currently does not pass any of its new mobs to the server's total mob count.

    As a result, any attempt to 'modify' a CreatureSpawnEvent is currently difficult to do without a very hacky workaround.

    To elaborate further, if I cancel the CreatureSpawnEvent, then spawn a different creature at the location of the old event, it will not count as a 'mob' on the server. Due to this, the server will continuously fire the CreatureSpawnEvent, because--to its knowledge--there are no mobs on the server. This then causes the world to fill up, overload, and crash.

    Currently, I'm having to implement my own 'cap' on the mobs in the world. This 'works', but it is not an ideal way of doing it, and can lead to issues with smaller servers overloading (and larger servers not getting enough mobs) based on what I set the maximum amount to. I could include it as a configuration option, but again, this is not the ideal way of going about it.

    Any help on this would be appreciated.

    EDIT:
    I believe this has something to do with it, but I'm having trouble locating where mob counts may/may not be kept track of.

    https://github.com/Bukkit/CraftBukk...net/minecraft/server/SpawnerCreature.java#L26
     
  2. Offline

    Shamebot

    Only spawn a new mob if the SpawnReason != Custom
     
  3. Offline

    DrBowe

    That was my first attempt. However, the problem isn't that it's looping.
    When I cancel the spawn event (or remove the original entity, or manually kill the original entity), then the world will continue to fire off this event until it adds a mob to what I presume to be some sort of mob count. I already check to see if the SpawnReason == SpawnReason.NATURAL before proceeding to do anything.

    @Shamebot
    After looking through the source, it appears that what I'm going to want to use is
    net.minecraft.server.World's addEntity(Entity entity, SpawnReason spawnReason)
    -or-
    CraftWorld's addEntity

    However, I've never worked with CraftBukkit source directly before, so I'm having some issues with casting.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  4. Offline

    Shamebot

    Code:java
    1. net.minecraft.server.World nmsWorld = ((CraftWorld)bukkitWorld).getHandle();
     
  5. Offline

    DrBowe

    @Shamebot
    Thanks, I'll try to work with this and see if I have any more issues

    @Shamebot
    Well, I managed to get it to call addEntity(), but it seems that it has the same effect as spawnCreature() (in the sense that it doesn't add the spawned creature to the server's count of mobs)

    Obviously there's a value to track the amount of mobs in the net.minecraft.server code, otherwise all servers would crash on start up. I suppose I'll go search around some more to see what I can come up with.

    Alright, I think I've located where it might be handled. But I can't seem to find where the count might be kept track of (if at all)
    https://github.com/Bukkit/CraftBukk...net/minecraft/server/SpawnerCreature.java#L26

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
Thread Status:
Not open for further replies.

Share This Page