Skip to content

Commit

Permalink
Fix a possible crash upon loading old disease data (#10495)
Browse files Browse the repository at this point in the history
Fix a possible crash upon loading old disease data
  • Loading branch information
Thodor12 authored Dec 1, 2024
1 parent 3f76f96 commit bb4ba6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ public final class CitizenConstants
*/
public static final String TAG_DISEASE = "disease";

/**
* Disease iod tag.
*/
public static final String TAG_DISEASE_ID = "disease_id";

/**
* Disease immunity tag,
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.minecolonies.core.datalistener.DiseasesListener;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -172,7 +173,7 @@ public void write(final CompoundTag compound)
CompoundTag diseaseTag = new CompoundTag();
if (disease != null)
{
diseaseTag.putString(TAG_DISEASE, disease.id().toString());
diseaseTag.putString(TAG_DISEASE_ID, disease.id().toString());
}
diseaseTag.putInt(TAG_IMMUNITY, immunityTicks);
compound.put(TAG_DISEASE, diseaseTag);
Expand All @@ -181,10 +182,15 @@ public void write(final CompoundTag compound)
@Override
public void read(final CompoundTag compound)
{
if (!compound.contains(TAG_DISEASE, Tag.TAG_COMPOUND))
{
return;
}

CompoundTag diseaseTag = compound.getCompound(TAG_DISEASE);
if (diseaseTag.contains(TAG_DISEASE))
if (diseaseTag.contains(TAG_DISEASE_ID))
{
this.disease = DiseasesListener.getDisease(new ResourceLocation(diseaseTag.getString(TAG_DISEASE)));
this.disease = DiseasesListener.getDisease(new ResourceLocation(diseaseTag.getString(TAG_DISEASE_ID)));
}
this.immunityTicks = diseaseTag.getInt(TAG_IMMUNITY);
}
Expand Down

0 comments on commit bb4ba6e

Please sign in to comment.