Issue: teleporting a mob to an unloaded chunk will result in the mob not getting saved if player doesn't go to said unloaded chunk.
Steps to reproduce:
/summon sheep ~ ~ ~ {Color:1}
/tp @e[type=sheep] ~ ~ ~+1000
save and quit the world
/tp ~ ~ ~+1000 entity orange sheep doesn't exist
Steps to produce entity not rendering:
repeat above but, stop before quitting the world
/tp ~ ~ ~+1000 entity doesn't show up but, you can hear the sheep
quit world go back in and orange sheep is there
Solution:
I don't have a set one since it looks like the world is setting the entity dead or isn't being added to the chunk. In my custom tp command test I forced a chunk to load and it didn't fix this issue. My solution would be to stop the entity from being dead when teleporting, make sure it's added to the chunk so on save it doesn't disappear .
Related issues
Comments


yeah I think the entity is dead or something since In my custom mod command it does the same thing. I don't think entities should die when teleporting seems unintended especially since it doesn't save the entity.
Could also be that the entity isn't being added to the chunk.

They aren't dying. Entities are saved to a chunk specifically when the chunk unloads. Using /teleport
to teleport an entity (apart from a player) into an unloaded chunk does not load that chunk. Since the chunk isn't loaded when the world is closed, there's no chunk to initiate entity saving, thus the entity would only exist in-memory which is then wiped on world close.

let me debug this more I am going to test in debug with my custom command and see if I can get an exact fix for this.
use /tp I cannot verify the bug happens with the other "teleport" command

Upon closer examination, this would be MC-108469 (which covers both loaded lazy chunks where entities aren't ticked and unloaded chunks).

ok this isn't optimized but, I have a fix for you. Adding this line of code will force the entity to be added to the chunk and load it. It doesn't check if the chunk isn't loaded I tried writing that if statement and it didn't exicute.
entity.world.getChunkProvider().provideChunk((int)entity.posX >> 4, (int)entity.posZ >> 4).addEntity(entity);
Ok well still use this fix don't be a rude and not use the free code I gave. just give that to one of the devs and tell them it needs an if statement for if the chunk isn't loaded

@unknown: your ticket is resovled specifically as a "duplicate" (which you can see directly below the text "resolved"), because there already exists a report (which itself already contains a code analysis and potential fix).

right but, I am saying to give my code to the devs since it fixed it on my command. so ignoring the code I gave you to help you help someone is rude. If you read my fix works better for /tp if you read my fix on the other bug I said the more proper fix would be to add it to the chunk on teleport change if the chunk detected isn't the same.
I was just specifying my code fix is here. their code fixes either break something or do nothing for the issue which I described above. Except for some which I already commented on. If you look at the methods move on collided that isn't moving in general only occurs when an entity collides most likely not a proper fix.
No I don't expect you to learn code but, as for tp you can send that to the mojang devs and they be like o crap not a proper fix it needs to be done at a base level I understand why these issues are happening now. Or they would be like thanks that's a proper fix but, we need to fix this for other things on entities not being added to chunks just needs an if statement
Confirmed for 1.13 snapshots too.