ForgePatch/patches/minecraft/net/minecraft/world/chunk/storage/AnvilChunkLoader.java.patch

168 lines
7.3 KiB
Diff

--- ../src-base/minecraft/net/minecraft/world/chunk/storage/AnvilChunkLoader.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/AnvilChunkLoader.java
@@ -49,9 +49,43 @@
this.field_186055_e = p_i46673_2_;
}
+ public boolean chunkExists(World world, int x, int z)
+ {
+ ChunkPos chunkcoordintpair = new ChunkPos(x, z);
+
+ if (this.field_75826_b.contains(chunkcoordintpair))
+ {
+ for(ChunkPos pendingChunkCoord : this.field_75828_a.keySet())
+ {
+ if (pendingChunkCoord.equals(chunkcoordintpair))
+ {
+ return true;
+ }
+ }
+ }
+
+ return RegionFileCache.func_76550_a(this.field_75825_d, x, z).chunkExists(x & 31, z & 31);
+ }
+
+
@Nullable
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
+ {
ChunkPos chunkpos = new ChunkPos(p_75815_2_, p_75815_3_);
NBTTagCompound nbttagcompound = (NBTTagCompound)this.field_75828_a.get(chunkpos);
@@ -67,7 +101,7 @@
nbttagcompound = this.field_186055_e.func_188257_a(FixTypes.CHUNK, 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);
}
public boolean func_191063_a(int p_191063_1_, int p_191063_2_)
@@ -80,6 +114,12 @@
@Nullable
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 {},{} is missing level data, skipping", new Object[] {Integer.valueOf(p_75822_2_), Integer.valueOf(p_75822_3_)});
@@ -103,10 +143,29 @@
field_151505_a.error("Chunk file at {},{} is in the wrong location; relocating. (Expected {}, {}, got {}, {})", new Object[] {Integer.valueOf(p_75822_2_), Integer.valueOf(p_75822_3_), Integer.valueOf(p_75822_2_), Integer.valueOf(p_75822_3_), Integer.valueOf(chunk.field_76635_g), Integer.valueOf(chunk.field_76647_h)});
nbttagcompound.func_74768_a("xPos", p_75822_2_);
nbttagcompound.func_74768_a("zPos", p_75822_3_);
+
+ // Have to move tile entities since we don't load them at this stage
+ NBTTagList _tileEntities = nbttagcompound.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_, nbttagcompound);
}
- 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;
}
}
}
@@ -121,7 +180,9 @@
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound.func_74782_a("Level", nbttagcompound1);
nbttagcompound.func_74768_a("DataVersion", 819);
+ net.minecraftforge.fml.common.FMLCommonHandler.instance().getDataFixer().writeVersionData(nbttagcompound);
this.func_75820_a(p_75816_2_, p_75816_1_, nbttagcompound1);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkDataEvent.Save(p_75816_2_, nbttagcompound));
this.func_75824_a(p_75816_2_.func_76632_l(), nbttagcompound);
}
catch (Exception exception)
@@ -307,8 +368,17 @@
if (entity.func_70039_c(nbttagcompound2))
{
+ try
+ {
p_75820_1_.func_177409_g(true);
nbttaglist1.func_74742_a(nbttagcompound2);
+ }
+ 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());
+ }
}
}
}
@@ -318,8 +388,17 @@
for (TileEntity tileentity : p_75820_1_.func_177434_r().values())
{
+ try
+ {
NBTTagCompound nbttagcompound3 = tileentity.func_189515_b(new NBTTagCompound());
nbttaglist2.func_74742_a(nbttagcompound3);
+ }
+ 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);
@@ -388,6 +467,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);
for (int j1 = 0; j1 < nbttaglist1.func_74745_c(); ++j1)
@@ -431,8 +516,6 @@
p_75823_1_.func_180497_b(new BlockPos(nbttagcompound3.func_74762_e("x"), nbttagcompound3.func_74762_e("y"), nbttagcompound3.func_74762_e("z")), block, nbttagcompound3.func_74762_e("t"), nbttagcompound3.func_74762_e("p"));
}
}
-
- return chunk;
}
@Nullable