Fixed ChunkDataEvent.Save being fired with a null world if chunk isn't fully generated when unloaded. (#6628)

This commit is contained in:
Corey Frenette authored and GitHub committed 2020-05-03 13:27:06 -07:00
1 parent 4fce4eb10b
commit 1fa88ebd56
5 files changed
+46 -1

No files matched your search

@@ -36,7 +36,7 @@
this.field_219255_i.func_217381_Z().func_230035_c_("chunkSave");
CompoundNBT compoundnbt1 = ChunkSerializer.func_222645_a(this.field_219255_i, p_219229_1_);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkDataEvent.Save(p_219229_1_, compoundnbt1));
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkDataEvent.Save(p_219229_1_, p_219229_1_.getWorldForge() != null ? p_219229_1_.getWorldForge() : this.field_219255_i, compoundnbt1));
this.func_219100_a(chunkpos, compoundnbt1);
return true;
} catch (Exception exception) {
@@ -20,6 +20,7 @@
package net.minecraftforge.event.world;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
@@ -47,6 +48,12 @@ public class ChunkDataEvent extends ChunkEvent
this.data = data;
}
public ChunkDataEvent(IChunk chunk, IWorld world, CompoundNBT data)
{
super(chunk, world);
this.data = data;
}
public CompoundNBT getData()
{
return data;
@@ -92,9 +99,15 @@ public class ChunkDataEvent extends ChunkEvent
**/
public static class Save extends ChunkDataEvent
{
@Deprecated // remove in 1.16
public Save(IChunk chunk, CompoundNBT data)
{
super(chunk, data);
}
public Save(IChunk chunk, IWorld world, CompoundNBT data)
{
super(chunk, world, data);
}
}
}
@@ -19,6 +19,7 @@
package net.minecraftforge.event.world;
import net.minecraft.world.IWorld;
import net.minecraft.world.chunk.IChunk;
import net.minecraftforge.common.MinecraftForge;
@@ -41,6 +42,12 @@ public class ChunkEvent extends WorldEvent
this.chunk = chunk;
}
public ChunkEvent(IChunk chunk, IWorld world)
{
super(world);
this.chunk = chunk;
}
public IChunk getChunk()
{
return chunk;
@@ -0,0 +1,23 @@
package net.minecraftforge.debug.world;
import net.minecraftforge.event.world.ChunkDataEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Mod(ChunkDataEventSaveNullWorldTest.MODID)
@Mod.EventBusSubscriber
public class ChunkDataEventSaveNullWorldTest {
static final String MODID = "chunk_data_event_save_null_world_test";
private static final Logger LOGGER = LogManager.getLogger(MODID);
@SubscribeEvent
public static void onChunkSave(final ChunkDataEvent.Save event)
{
if(event.getWorld() == null)
{
LOGGER.info("Chunk at {} had null world", event.getChunk().getPos());
}
}
}
+2
View File
@@ -63,6 +63,8 @@ loaderVersion="[28,)"
modId="global_loot_test"
[[mods]]
modId="custom_plant_type_test"
[[mods]]
modId="chunk_data_event_save_null_world_test"
[[dependencies.global_loot_test]]
modId="forge"
mandatory=true