While playing on my skyblock world today, I built a grass platform and a while later, a cow spawned. When I went to craft a boat to prevent the cow from despawning, it disappeared. My friend, however, says that it is impossible for animals to despawn. Can they?
I can't find any information on the mc wiki on this either ;-;
They cannot despawn in the sense that the game will regularly schedule their deletion the way hostile mobs are removed. However, certain glitches can let animals escape from otherwise-inescapeable situations (like being in a boat or contained in a fenced pen). The basic way the latter happens is that the game initializes each entity separately and for a very short amount of time they're free to move independently (so the cow in the boat could just walk off). The entity usually ends up in an illegal position and the game then tries to fix things by pushing the mob into the next block.
Sometimes an entity will not be saved with the chunk, or there's something wrong with the data that effectively deletes it (sort of like rubberbanding, except it's just gone instead of put somewhere else).
Most of the time the mob is just damaged to a point that death occurs, but since you don't really notice (you're either doing something else nearby or you're off on adventure) the item gets left on the ground long enough to despawn with you none the wiser. It could've been a lightning strike, it could have been an attack meant for something else (ie, a drowned or a zombie was chasing a villager and happened to be next to the cow when it attacked, hitting the cow instead of the villager), it could even be something as simple as being too close to solid blocks and the cow just turned around (thereby putting more than 50% of its body in a solid block).
With other players, there's also the possibility of mischief (they hid the cow from you) or some kind of action (they put the cow back into the pen, they were fighting mobs at night and accidentally killed the cow, they took the cow because they needed it).
It is quite awful and shameful that Mojang simply can't seem to fix this bug (and many, many others), which is caused by floating point precision errors, particularly when entities are unloaded and reloaded, which involves calculating their center position from their bounding box and vice-versa (if the entire bounding box were saved these errors wouldn't happen) - the community has provided multiple fixes to Mojang's own bug tracker, and there are probably mods that fix it (other than my own, but this is useless to you since it is part of a custom version based on 1.6.4), one of which is quite trivial (add a small margin to collision calculations so entities stop a short distance away from the actual blocks; as long as the margin is enough precision errors will be swamped out so there is no need to save the entire bounding box):
Conversions between entity coordinates and entity hitboxes are vulnerable to rounding artifacts. The bug occurs due for the following reasons: An entity can be moved by translating its hitbox. When that happens, coordinates have to be recomputed, which can result in a rounding artifact. When an entity is saved to disk, the hitbox is not saved. It has to be recalculated upon reload, which can result in rounding artifacts. Those rounding artifacts may result in a miniscule shift in position and/or size of the hitbox. This can cause the new hitbox to overlap blocks in the world, which the entity can then pass into.
We have decided to recommend one of Xcom’s solutions, which is to impose a very tiny margin (on the order of 1e-12) between entity hitboxes and solid objects. When reloaded from disk, rounding artifacts computing the hitbox will err away from walls.
This is the actual fix that I used, copied from the comments following the one linked to above; I made the margin much larger just to be safe (it is still only a millionth of a block in the x and z directions; the next comment in the link above says the error is between one in 10 trillion to one in a quadrillion, which is still enough to make entities clip into blocks):
public class AxisAlignedBB
{
// Adds a margin to AABB collision checks to fix MC-2025 (Y is probably not needed but a
// small margin was included just in case)
private static final double MARGIN_XZ = 0.000001D;
private static final double MARGIN_Y = 0.000000001D;
// Also applied to Y and Z
public double calculateXOffset(AxisAlignedBB par1AxisAlignedBB, double par2)
{
if (par1AxisAlignedBB.maxY > this.minY && par1AxisAlignedBB.minY < this.maxY && par1AxisAlignedBB.maxZ > this.minZ && par1AxisAlignedBB.minZ < this.maxZ)
{
if (par2 > 0.0D && par1AxisAlignedBB.maxX <= this.minX)
{
double var4 = this.minX - par1AxisAlignedBB.maxX;
return (var4 < par2 ? var4 - MARGIN_XZ : par2);
}
else if (par2 < 0.0D && par1AxisAlignedBB.minX >= this.maxX)
{
double var4 = this.maxX - par1AxisAlignedBB.minX;
return (var4 > par2 ? var4 + MARGIN_XZ : par2);
}
}
return par2;
}
Note that my y-position is not an integer (in vanilla you don't have the 000...1 after the decimal) since I'm actually floating above the ground due to the collision code not allowing me to go any further down (I'm still on the ground as far as other code is concerned, you can actually go as high as 0.1 or so before the game thinks you are floating):
2021-02-06 20:16:58 [SERVER] [INFO] TheMasterCaver[/127.0.0.1:0] logged in with entity id 1 at (198.5, 4.000000001, 67.5)
A related issue is baby mobs suffocating when they grow up next to a block due to their hitbox clipping into it; the fix is a bit more complicated but has still been implemented by the modding community (TMCW includes this code as well, plus I make animals temporarily immune to suffocation damage when they grow up as otherwise they still take one hit of damage):
Otherwise, entities can't move in "lazy chunks" (the outermost 2 chunks around the loaded chunk area) so this should never be a factor - the game doesn't tick them at all so they can't even die and even hostile mobs can't despawn, even if you switched to Peaceful, so no such thing as "entities" wandering into unloaded chunks" can ever possibly occur (this includes the time an entity can freely wander when more than 32 blocks from a player since their entire AI is nonfunctional in lazy chunks). I've never heard of entities simply not being saved, which again shouldn't occur since there is no way for them to move into a chunk as it is getting unloaded (then again, current versions do have major issues with the chunk saving process). There are also bugs that cause entities to be invisible (not sent to the client, this means that hostile mobs can still attack the player but they can't be seen; this bug report claims it was fixed but comments indicate that it still happens).
While playing on my skyblock world today, I built a grass platform and a while later, a cow spawned. When I went to craft a boat to prevent the cow from despawning, it disappeared. My friend, however, says that it is impossible for animals to despawn. Can they?
I can't find any information on the mc wiki on this either ;-;
They cannot despawn in the sense that the game will regularly schedule their deletion the way hostile mobs are removed. However, certain glitches can let animals escape from otherwise-inescapeable situations (like being in a boat or contained in a fenced pen). The basic way the latter happens is that the game initializes each entity separately and for a very short amount of time they're free to move independently (so the cow in the boat could just walk off). The entity usually ends up in an illegal position and the game then tries to fix things by pushing the mob into the next block.
Sometimes an entity will not be saved with the chunk, or there's something wrong with the data that effectively deletes it (sort of like rubberbanding, except it's just gone instead of put somewhere else).
Most of the time the mob is just damaged to a point that death occurs, but since you don't really notice (you're either doing something else nearby or you're off on adventure) the item gets left on the ground long enough to despawn with you none the wiser. It could've been a lightning strike, it could have been an attack meant for something else (ie, a drowned or a zombie was chasing a villager and happened to be next to the cow when it attacked, hitting the cow instead of the villager), it could even be something as simple as being too close to solid blocks and the cow just turned around (thereby putting more than 50% of its body in a solid block).
With other players, there's also the possibility of mischief (they hid the cow from you) or some kind of action (they put the cow back into the pen, they were fighting mobs at night and accidentally killed the cow, they took the cow because they needed it).
It is quite awful and shameful that Mojang simply can't seem to fix this bug (and many, many others), which is caused by floating point precision errors, particularly when entities are unloaded and reloaded, which involves calculating their center position from their bounding box and vice-versa (if the entire bounding box were saved these errors wouldn't happen) - the community has provided multiple fixes to Mojang's own bug tracker, and there are probably mods that fix it (other than my own, but this is useless to you since it is part of a custom version based on 1.6.4), one of which is quite trivial (add a small margin to collision calculations so entities stop a short distance away from the actual blocks; as long as the margin is enough precision errors will be swamped out so there is no need to save the entire bounding box):
This is the actual fix that I used, copied from the comments following the one linked to above; I made the margin much larger just to be safe (it is still only a millionth of a block in the x and z directions; the next comment in the link above says the error is between one in 10 trillion to one in a quadrillion, which is still enough to make entities clip into blocks):
Note that my y-position is not an integer (in vanilla you don't have the 000...1 after the decimal) since I'm actually floating above the ground due to the collision code not allowing me to go any further down (I'm still on the ground as far as other code is concerned, you can actually go as high as 0.1 or so before the game thinks you are floating):
A related issue is baby mobs suffocating when they grow up next to a block due to their hitbox clipping into it; the fix is a bit more complicated but has still been implemented by the modding community (TMCW includes this code as well, plus I make animals temporarily immune to suffocation damage when they grow up as otherwise they still take one hit of damage):
https://bugs.mojang.com/secure/attachment/148216/MC-9568 Proposal.txt
Otherwise, entities can't move in "lazy chunks" (the outermost 2 chunks around the loaded chunk area) so this should never be a factor - the game doesn't tick them at all so they can't even die and even hostile mobs can't despawn, even if you switched to Peaceful, so no such thing as "entities" wandering into unloaded chunks" can ever possibly occur (this includes the time an entity can freely wander when more than 32 blocks from a player since their entire AI is nonfunctional in lazy chunks). I've never heard of entities simply not being saved, which again shouldn't occur since there is no way for them to move into a chunk as it is getting unloaded (then again, current versions do have major issues with the chunk saving process). There are also bugs that cause entities to be invisible (not sent to the client, this means that hostile mobs can still attack the player but they can't be seen; this bug report claims it was fixed but comments indicate that it still happens).
TheMasterCaver's First World - possibly the most caved-out world in Minecraft history - includes world download.
TheMasterCaver's World - my own version of Minecraft largely based on my views of how the game should have evolved since 1.6.4.
Why do I still play in 1.6.4?