193 lines
8.0 KiB
Diff
193 lines
8.0 KiB
Diff
--- ../src-base/minecraft/net/minecraft/world/chunk/storage/AnvilChunkLoader.java
|
|
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/AnvilChunkLoader.java
|
|
@@ -26,6 +26,8 @@
|
|
import net.minecraft.world.chunk.NibbleArray;
|
|
import net.minecraft.world.storage.IThreadedFileIO;
|
|
import net.minecraft.world.storage.ThreadedFileIOBase;
|
|
+import net.minecraftforge.common.MinecraftForge;
|
|
+import net.minecraftforge.event.world.ChunkDataEvent;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
@@ -43,8 +45,45 @@
|
|
this.field_75825_d = p_i2003_1_;
|
|
}
|
|
|
|
+ public boolean chunkExists(World world, int x, int z)
|
|
+ {
|
|
+ ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(x, z);
|
|
+
|
|
+ synchronized (this.field_75827_c)
|
|
+ {
|
|
+ if (this.field_75826_b.contains(chunkcoordintpair))
|
|
+ {
|
|
+ Iterator iter = this.field_75828_a.iterator();
|
|
+ while (iter.hasNext())
|
|
+ {
|
|
+ PendingChunk pendingChunk = (PendingChunk)iter.next();
|
|
+ if (pendingChunk.field_76548_a.equals(chunkcoordintpair))
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return RegionFileCache.func_76550_a(this.field_75825_d, x, z).chunkExists(x & 31, z & 31);
|
|
+ }
|
|
public Chunk func_75815_a(World p_75815_1_, int p_75815_2_, int p_75815_3_) throws IOException
|
|
{
|
|
+ Object[] data = this.loadChunk__Async(p_75815_1_, p_75815_2_, p_75815_3_);
|
|
+
|
|
+ if (data != null)
|
|
+ {
|
|
+ Chunk chunk = (Chunk) data[0];
|
|
+ NBTTagCompound nbttagcompound = (NBTTagCompound) data[1];
|
|
+ this.loadEntities(p_75815_1_, nbttagcompound.func_74775_l("Level"), chunk);
|
|
+ return chunk;
|
|
+ }
|
|
+
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ public Object[] loadChunk__Async(World p_75815_1_, int p_75815_2_, int p_75815_3_) throws IOException
|
|
+ {
|
|
NBTTagCompound nbttagcompound = null;
|
|
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(p_75815_2_, p_75815_3_);
|
|
Object object = this.field_75827_c;
|
|
@@ -53,11 +92,13 @@
|
|
{
|
|
if (this.field_75826_b.contains(chunkcoordintpair))
|
|
{
|
|
- for (int k = 0; k < this.field_75828_a.size(); ++k)
|
|
+ Iterator iter = this.field_75828_a.iterator();
|
|
+ while (iter.hasNext())
|
|
{
|
|
- if (((AnvilChunkLoader.PendingChunk)this.field_75828_a.get(k)).field_76548_a.equals(chunkcoordintpair))
|
|
+ PendingChunk pendingChunk = (PendingChunk)iter.next();
|
|
+ if (pendingChunk.field_76548_a.equals(chunkcoordintpair))
|
|
{
|
|
- nbttagcompound = ((AnvilChunkLoader.PendingChunk)this.field_75828_a.get(k)).field_76547_b;
|
|
+ nbttagcompound = pendingChunk.field_76547_b;
|
|
break;
|
|
}
|
|
}
|
|
@@ -76,11 +117,17 @@
|
|
nbttagcompound = CompressedStreamTools.func_74794_a(datainputstream);
|
|
}
|
|
|
|
- return this.func_75822_a(p_75815_1_, p_75815_2_, p_75815_3_, nbttagcompound);
|
|
+ return this.checkedReadChunkFromNBT__Async(p_75815_1_, p_75815_2_, p_75815_3_, nbttagcompound);
|
|
}
|
|
|
|
protected Chunk func_75822_a(World p_75822_1_, int p_75822_2_, int p_75822_3_, NBTTagCompound p_75822_4_)
|
|
{
|
|
+ Object[] data = this.checkedReadChunkFromNBT__Async(p_75822_1_, p_75822_2_, p_75822_3_, p_75822_4_);
|
|
+ return data != null ? (Chunk)data[0] : null;
|
|
+ }
|
|
+
|
|
+ protected Object[] checkedReadChunkFromNBT__Async(World p_75822_1_, int p_75822_2_, int p_75822_3_, NBTTagCompound p_75822_4_)
|
|
+ {
|
|
if (!p_75822_4_.func_150297_b("Level", 10))
|
|
{
|
|
field_151505_a.error("Chunk file at " + p_75822_2_ + "," + p_75822_3_ + " is missing level data, skipping");
|
|
@@ -100,10 +147,27 @@
|
|
field_151505_a.error("Chunk file at " + p_75822_2_ + "," + p_75822_3_ + " is in the wrong location; relocating. (Expected " + p_75822_2_ + ", " + p_75822_3_ + ", got " + chunk.field_76635_g + ", " + chunk.field_76647_h + ")");
|
|
p_75822_4_.func_74768_a("xPos", p_75822_2_);
|
|
p_75822_4_.func_74768_a("zPos", p_75822_3_);
|
|
+
|
|
+ // Have to move tile entities since we don't load them at this stage
|
|
+ NBTTagList _tileEntities = p_75822_4_.func_74775_l("Level").func_150295_c("TileEntities", 10);
|
|
+
|
|
+ if (_tileEntities != null)
|
|
+ {
|
|
+ for (int te = 0; te < _tileEntities.func_74745_c(); te++)
|
|
+ {
|
|
+ NBTTagCompound _nbt = (NBTTagCompound) _tileEntities.func_150305_b(te);
|
|
+ _nbt.func_74768_a("x", p_75822_2_ * 16 + (_nbt.func_74762_e("x") - chunk.field_76635_g * 16));
|
|
+ _nbt.func_74768_a("z", p_75822_3_ * 16 + (_nbt.func_74762_e("z") - chunk.field_76647_h * 16));
|
|
+ }
|
|
+ }
|
|
chunk = this.func_75823_a(p_75822_1_, p_75822_4_.func_74775_l("Level"));
|
|
}
|
|
-
|
|
- return chunk;
|
|
+ Object[] data = new Object[2];
|
|
+ data[0] = chunk;
|
|
+ data[1] = p_75822_4_;
|
|
+ // event is fired in ChunkIOProvider.callStage2 since it must be fired after TE's load.
|
|
+ // MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Load(chunk, par4NBTTagCompound));
|
|
+ return data;
|
|
}
|
|
}
|
|
|
|
@@ -117,6 +181,7 @@
|
|
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
|
nbttagcompound.func_74782_a("Level", nbttagcompound1);
|
|
this.func_75820_a(p_75816_2_, p_75816_1_, nbttagcompound1);
|
|
+ MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Save(p_75816_2_, nbttagcompound));
|
|
this.func_75824_a(p_75816_2_.func_76632_l(), nbttagcompound);
|
|
}
|
|
catch (Exception exception)
|
|
@@ -287,11 +352,20 @@
|
|
Entity entity = (Entity)iterator.next();
|
|
nbttagcompound1 = new NBTTagCompound();
|
|
|
|
+ try
|
|
+ {
|
|
if (entity.func_70039_c(nbttagcompound1))
|
|
{
|
|
p_75820_1_.func_177409_g(true);
|
|
nbttaglist1.func_74742_a(nbttagcompound1);
|
|
}
|
|
+ }
|
|
+ catch (Exception e)
|
|
+ {
|
|
+ net.minecraftforge.fml.common.FMLLog.log(org.apache.logging.log4j.Level.ERROR, e,
|
|
+ "An Entity type %s has thrown an exception trying to write state. It will not persist. Report this to the mod author",
|
|
+ entity.getClass().getName());
|
|
+ }
|
|
}
|
|
}
|
|
|
|
@@ -303,8 +377,17 @@
|
|
{
|
|
TileEntity tileentity = (TileEntity)iterator.next();
|
|
nbttagcompound1 = new NBTTagCompound();
|
|
+ try
|
|
+ {
|
|
tileentity.func_145841_b(nbttagcompound1);
|
|
nbttaglist2.func_74742_a(nbttagcompound1);
|
|
+ }
|
|
+ catch (Exception e)
|
|
+ {
|
|
+ net.minecraftforge.fml.common.FMLLog.log(org.apache.logging.log4j.Level.ERROR, e,
|
|
+ "A TileEntity type %s has throw an exception trying to write state. It will not persist. Report this to the mod author",
|
|
+ tileentity.getClass().getName());
|
|
+ }
|
|
}
|
|
|
|
p_75820_3_.func_74782_a("TileEntities", nbttaglist2);
|
|
@@ -386,6 +469,12 @@
|
|
chunk.func_76616_a(p_75823_2_.func_74770_j("Biomes"));
|
|
}
|
|
|
|
+ // End this method here and split off entity loading to another method
|
|
+ return chunk;
|
|
+ }
|
|
+
|
|
+ public void loadEntities(World p_75823_1_, NBTTagCompound p_75823_2_, Chunk chunk)
|
|
+ {
|
|
NBTTagList nbttaglist1 = p_75823_2_.func_150295_c("Entities", 10);
|
|
|
|
if (nbttaglist1 != null)
|
|
@@ -457,8 +546,6 @@
|
|
}
|
|
}
|
|
}
|
|
-
|
|
- return chunk;
|
|
}
|
|
|
|
static class PendingChunk
|