Solved Mobs "forgotten" in memory on chunk unload.

Discussion in 'Plugin Development' started by Connor2weirdness, Feb 6, 2016.

Thread Status:
Not open for further replies.
  1. Solved, use a list of UUIDs instead of entity objects, as entity objects change when reloaded in memory.
     
    Last edited: Feb 7, 2016
  2. Offline

    Xerox262

    @Connor2weirdness why is it static? Have you tried using the entity's UUID instead of the entity object? What does it show when you print the array list before you leave, then again after? How're you making the entity? If you're creating your own using NMS then you can just edit it so they never take damage.

    Yes, Entity#remove(); removes the entity.
     
  3. 1. I have no clue why I made it static.
    2. If I were to use the entity's UUID, how would I get an entity object from that? I have to loop through the entities and remove them onDisable().
    3. The array size stays the same when leaving and joining, but after that, I am then able to damage them.
    4. I am creating the entity by using world.spawnEntity().

    I am using NMS, but I need to fix this problem regardless, as I need to cancel interaction.
     
  4. Offline

    Konato_K

    @Connor2weirdness List#contains uses the equals method of the object to make sure of equality, and the CraftEntity code uses the entity ID for that, as far as I remember the entity ID chnges if the mob is unloaded and loaded again (similar to how players change their entity Id on rejoining the server or other stuff)

    Using the entity UUID might work properly
     
  5. Aha, sounds promising, thanks.

    As I said to @Xerox262, I am also using the ArrayList of entities to remove them onDisable(), and for other things.
    Can I convert an entity UUID back to an entity?
     
    Last edited: Feb 6, 2016
  6. Offline

    Konato_K

    @Connor2weirdness Mmmm the first thing I can think of is to iterate all entities and check if their UUID matches, there is probably a better way to do it though.
     
  7. Offline

    Xerox262

    If you're using NMS then why can't you just override the damageEntity method and make it do nothing, or override the isInvulnerable method and make it return true. Also if you're using SgtCaze, there's no reason you need to actually remove the entities on reload, from my experience they keep their data, they don't move after, they can't be damaged (So long as you're doing it in nms), etc.
     
  8. I can't use just NMS because I'm using the entity objects to kill them on config (reload) and onDisable(). Thanks.
     
  9. Offline

    Xerox262

    You said you were using NMS, that's why I suggested that, have you tried storing the UUID of the entity yet? You can get the entities back from the UUIDs by looping though all entities and checking if the arraylist contains their uuid.

    P.S. You can remove from NMS.
     
  10. I just tried using UUIDs and so far it seems to have worked. Thanks to you and @Konato_K.
    I'll report back if any issues arise.
     
    Konato_K likes this.
Thread Status:
Not open for further replies.

Share This Page