Fix MC-194811 - Removing structures causes chunk save errors.

This commit is contained in:
Alex O'Neill 2020-11-20 13:23:50 -05:00 committed by GitHub
parent fa46f3dd49
commit 56e538e8a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -17,6 +17,15 @@
chunkprimer.func_201637_h(blockpos);
}
}
@@ -167,7 +168,7 @@
Heightmap.func_222690_a(ichunk, enumset);
CompoundNBT compoundnbt4 = compoundnbt.func_74775_l("Structures");
ichunk.func_201612_a(func_235967_a_(p_222656_1_, compoundnbt4, p_222656_0_.func_72905_C()));
- ichunk.func_201606_b(func_227075_a_(p_222656_3_, compoundnbt4));
+ net.minecraftforge.common.ForgeHooks.fixNullStructureReferences(ichunk, func_227075_a_(p_222656_3_, compoundnbt4));
if (compoundnbt.func_74767_n("shouldSave")) {
ichunk.func_177427_f(true);
}
@@ -183,6 +184,7 @@
}

View File

@ -43,6 +43,8 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.advancements.Advancement;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@ -91,6 +93,8 @@ import net.minecraft.potion.PotionUtils;
import net.minecraft.stats.Stats;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.*;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.feature.structure.Structure;
import net.minecraft.world.spawner.AbstractSpawner;
import net.minecraft.tileentity.FurnaceTileEntity;
import net.minecraft.tileentity.TileEntity;
@ -1232,4 +1236,18 @@ public class ForgeHooks
modpacks.add("vanilla");
return modpacks;
}
/**
* Fixes MC-194811
* When a structure mod is removed, this map may contain null keys. This will make the world unable to save if this persists.
* If we remove a structure from the save data in this way, we then mark the chunk for saving
*/
public static void fixNullStructureReferences(IChunk chunk, Map<Structure<?>, LongSet> structureReferences)
{
if (structureReferences.remove(null) != null)
{
chunk.setModified(true);
}
chunk.setStructureReferences(structureReferences);
}
}