Stop entities from despawning

Discussion in 'Plugin Development' started by vildaberper, May 14, 2011.

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

    vildaberper

    By entities, I mean arrows, items etc.
    I want to stop them from despawning automaticly after 2 minutes or so.
    Can this be done? I really need this in ChairCraft. :)
     
  2. Offline

    DreadKyller

    I do not think so, because item disappearance is mostly minecraft itself, not bukkit
     
  3. Offline

    nisovin

    In net.minecraft.server.EntityItem, there is a "b" integer. It gets incremented every server tick, and when that variable hits 6000 the entity despawns. You can set it to, for example, Integer.MIN_VALUE to keep it from despawning for some 4 years or so. However, if the chunk the entity is in unloads, when it gets loaded back in that counter seems to reset to 0 again, so you'll have to watch for chunk loads and reset it back to MIN_VALUE.

    I've tested setting the b variable, that works fine. I haven't played with fixing the chunk loading issue though, so that'll be up to you.
     
  4. Offline

    vildaberper

    Thank you so much! :D

    Edit: Its private for Entities, can that be overridden or something?
    Id like to change it for arrows too.
     
  5. Offline

    fullwall

    Look up reflection to access the private field.
     
  6. Offline

    vildaberper

    Hmm, guess its not the right variable, looks like its always 1, no matter what.
    I even changed ticksLived, but that didnt change the time of despawn.
    I looked through every variable of the type int, but none of them was the real "ticksLived".
    This is hopeless. :(
     
  7. Offline

    nisovin

    It looks like arrows work different from item entities. It looks like it's possibly the private h variable, and the arrow despawns when that reaches 1200.
     
  8. Offline

    vildaberper

    Thanks, testing right now. :)

    Edit: Works, but if a player rides the arrow at the same time the arrow would despawn, he can walk around, still riding the arrow. The arrow itself is still at the same spot though.
    Looks pretty funny. xD But its not what Im looking for.
     
  9. Offline

    Kainzo

    Can we put this same concept to stop players from despawning on log out?
     
  10. Offline

    nisovin

    Sounds like that's probably client-side behavior, in which case there's nothing you can do.
     
  11. Offline

    narrowtux

    Just a note: The property "EntityItem.b" is now public :)
     
Thread Status:
Not open for further replies.

Share This Page