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 2020-05-03 17:27:06 -03:00 committed by GitHub
parent 4fce4eb10b
commit 1fa88ebd56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 1 deletions

View File

@ -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) {

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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());
}
}
}

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