--- a/net/minecraft/world/chunk/storage/ChunkSerializer.java
+++ b/net/minecraft/world/chunk/storage/ChunkSerializer.java
@@ -132,6 +132,7 @@
          ichunk = new Chunk(p_222656_0_.func_201672_e(), p_222656_3_, biomecontainer, upgradedata, iticklist, iticklist1, k1, achunksection, (p_222648_1_) -> {
             func_222650_a(compoundnbt, p_222648_1_);
          });
+         if (compoundnbt.func_74764_b("ForgeCaps")) ((Chunk)ichunk).readCapsFromNBT(compoundnbt.func_74775_l("ForgeCaps"));
       } else {
          ChunkPrimer chunkprimer = new ChunkPrimer(p_222656_3_, upgradedata, achunksection, chunkprimerticklist, chunkprimerticklist1);
          chunkprimer.func_225548_a_(biomecontainer);
@@ -144,7 +145,7 @@
 
          if (!flag && chunkprimer.func_201589_g().func_209003_a(ChunkStatus.field_222614_j)) {
             for(BlockPos blockpos : BlockPos.func_191531_b(p_222656_3_.func_180334_c(), 0, p_222656_3_.func_180333_d(), p_222656_3_.func_180332_e(), 255, p_222656_3_.func_180330_f())) {
-               if (ichunk.func_180495_p(blockpos).func_185906_d() != 0) {
+               if (ichunk.func_180495_p(blockpos).getLightValue(ichunk, blockpos) != 0) {
                   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 @@
       }
 
       if (chunkstatus$type == ChunkStatus.Type.LEVELCHUNK) {
+         net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkDataEvent.Load(ichunk, p_222656_4_, chunkstatus$type));
          return new ChunkPrimerWrapper((Chunk)ichunk);
       } else {
          ChunkPrimer chunkprimer1 = (ChunkPrimer)ichunk;
@@ -216,6 +218,8 @@
             chunkprimer1.func_205767_a(generationstage$carving, BitSet.valueOf(compoundnbt5.func_74770_j(s1)));
          }
 
+         net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkDataEvent.Load(ichunk, p_222656_4_, chunkstatus$type));
+
          return chunkprimer1;
       }
    }
@@ -295,12 +299,22 @@
          for(int k = 0; k < chunk.func_177429_s().length; ++k) {
             for(Entity entity : chunk.func_177429_s()[k]) {
                CompoundNBT compoundnbt3 = new CompoundNBT();
+               try {
                if (entity.func_70039_c(compoundnbt3)) {
                   chunk.func_177409_g(true);
                   listnbt2.add(compoundnbt3);
                }
+               } catch (Exception e) {
+                  LogManager.getLogger().error("An Entity type {} has thrown an exception trying to write state. It will not persist. Report this to the mod author", entity.func_200600_R(), e);
+               }
             }
          }
+         try {
+             final CompoundNBT capTag = chunk.writeCapsToNBT();
+             if (capTag != null) compoundnbt1.func_218657_a("ForgeCaps", capTag);
+         } catch (Exception exception) {
+             LogManager.getLogger().error("A capability provider has thrown an exception trying to write state. It will not persist. Report this to the mod author", exception);
+         }
       } else {
          ChunkPrimer chunkprimer = (ChunkPrimer)p_222645_1_;
          listnbt2.addAll(chunkprimer.func_201652_l());
