mojira.dev
MC-265933

Stray conversion timer resets upon reloading the skeleton

When a skeleton in powder snow begins to shake, the StrayConversionTime starts to count down, and this behavior is correct.
However, if you unload the skeleton and load it back in (eg by re-entering the world), the skeleton no longer is converting, and the StrayConversionTime is set back to -1.

Steps to Reproduce:

  1. Spawn a skeleton in powdered snow

  2. Wait ~8 seconds

  3. Check the skeleton's conversion timer
    → Note value

    /data get entity @e[type=minecraft:skeleton,limit=1,sort=nearest] StrayConversionTime
  4. Leave, and re-enter the world

  5. Repeat step 3
    → Note value

Expected & Observed Results:

❌ - The first check for the skeleton's `StrayConversionTime` will be in the hundreds starting from 300 and counting down, when the player leaves the world and rejoins, the value will be reset to `-1` indicating that the timer was not properly saved to NBT.
✔ - The skeleton would properly have it's conversion timer saved to NBT data, allowing the player to leave and rejoin the world.

Notes:

  1. Code analysis can be found in the pinned comment of this issue.

  2. It appears there's another timer that's not written to NBT: the time spent in the powder snow. Because it is not written, the skeleton believes it hasn't been in powder snow for at least 3 seconds, and stops the conversion.
    Zombies have their respective timer written to NBT as InWaterTime.

  3. This issue has been updated by @unknown on 3/13/2024 to include more information, but retains all information from the original issue description.

Linked issues

Comments 2

Can confirm. Additionally, here is code analysis snowcasing the fix for this:

As described the data needs to be properly written and read in 'addAdditionalSaveData()' and 'readAdditionalSaveData'

Class: net.minecraft.world.entity.monster\Skeleton.java
public void addAdditionalSaveData(CompoundTag compoundTag) {
      super.addAdditionalSaveData(compoundTag);
FIX
      compoundTag.putInt("InPowderSnowTime", this.isFreezing() ? this.inPowderSnowTime : -1);
FIX END
      compoundTag.putInt(CONVERSION_TAG, this.isFreezeConverting() ? this.conversionTime : -1);
   }
public void readAdditionalSaveData(CompoundTag compoundTag) {
      super.readAdditionalSaveData(compoundTag);
FIX
      this.inPowderSnowTime = compoundTag.getInt("InPowderSnowTime");
FIX END
      if (compoundTag.contains(CONVERSION_TAG, 99) && compoundTag.getInt(CONVERSION_TAG) > -1) {
         this.startFreezeConversion(compoundTag.getInt(CONVERSION_TAG));
      }
   }

Considering I have written code analysis about this issue and understand it, I would like to request ownership. Current owner will not be updating it going forward anyways.

user-f2760

[Mod] Jingy

(Unassigned)

Community Consensus

Gameplay

Low

Mob behaviour, Save Data

conversion, nbt, save-data, skeleton, stray

1.20.2, 23w42a, 23w43b, 1.20.4, 24w10a, 1.21

Retrieved