Incorrect Entity Location After Chunk Unload

Discussion in 'Plugin Development' started by teathiev, Aug 11, 2019.

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

    teathiev

    I have a very odd problem where a saved entity has the incorrect location once it's chunk is unloaded. Perhaps I don't understand how entities work, but my understanding is that a bukkit Entity object persists alongside its in-game entity.

    I am storing my registered Entity objects via a HashMap "petEntityMap", the key is a data class "Pet".

    I'm using Kotlin (sorry) but my snippet to get the location is:
    Code:
    sender.sendMessage(AppStateManager.petEntityMap[pet]?.location?.toVector().toString())
    "AppStateManager" is just a singleton object, "pet" is a Pet object.

    Steps to reproduce the problem:

    1. Get location of entity at Location 1 (X = -354)

    upload_2019-8-11_15-4-43.png

    2. Move entity to Location 2 and get location (X = -348)

    upload_2019-8-11_15-5-45.png

    3. Warp away or do something similar to unload its chunk

    4. Warp/travel back and move back to Location 1

    upload_2019-8-11_15-7-17.png


    Note that Step 4's X coordinate (what should be Location 1) is X = -348 which if that of Location 2 in Step 2


    Can anyone shed light on this issue? Neither the entity nor its location is null, otherwise, I wouldn't get coordinates in Step 4. Are bukkit Entity objects decoupled from game entities on chunk unload and just assigned a new one on chunk load?
    I can't find an explanation of how this works (rather why it doesn't work) anywhere so any help would be appreciated.
     
    Last edited: Aug 11, 2019
Thread Status:
Not open for further replies.

Share This Page