From 56e538e8a9f1b8e6ff847b9d2385484c48849b8d Mon Sep 17 00:00:00 2001 From: Alex O'Neill <35673674+alcatrazEscapee@users.noreply.github.com> Date: Fri, 20 Nov 2020 13:23:50 -0500 Subject: [PATCH] Fix MC-194811 - Removing structures causes chunk save errors. --- .../chunk/storage/ChunkSerializer.java.patch | 9 +++++++++ .../net/minecraftforge/common/ForgeHooks.java | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/patches/minecraft/net/minecraft/world/chunk/storage/ChunkSerializer.java.patch b/patches/minecraft/net/minecraft/world/chunk/storage/ChunkSerializer.java.patch index 119f6b851..475ad1cba 100644 --- a/patches/minecraft/net/minecraft/world/chunk/storage/ChunkSerializer.java.patch +++ b/patches/minecraft/net/minecraft/world/chunk/storage/ChunkSerializer.java.patch @@ -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 @@ } diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index e934f49df..3eadf2a94 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -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, LongSet> structureReferences) + { + if (structureReferences.remove(null) != null) + { + chunk.setModified(true); + } + chunk.setStructureReferences(structureReferences); + } }