Skip to content

Commit

Permalink
Fixed crash / failed to save chunk error when changing dimensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
alcatrazEscapee committed Feb 20, 2019
1 parent a42641b commit 774bb35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
Expand Up @@ -24,6 +24,7 @@
import net.dries007.tfc.api.types.Ore;
import net.dries007.tfc.api.types.Rock;
import net.dries007.tfc.api.types.Tree;
import net.dries007.tfc.util.NBTBuilder;
import net.dries007.tfc.util.OreSpawnData;
import net.dries007.tfc.world.classic.DataLayer;

Expand Down Expand Up @@ -215,7 +216,10 @@ public static void read(DataLayer[] layers, byte[] bytes)
@Override
public NBTBase writeNBT(Capability<ChunkDataTFC> capability, ChunkDataTFC instance, EnumFacing side)
{
if (instance == null) return null;
if (instance == null || !instance.isInitialized())
{
return new NBTBuilder().setBoolean("valid", false).build();
}
NBTTagCompound root = new NBTTagCompound();

root.setTag("rockLayer1", new NBTTagIntArray(instance.rockLayer1));
Expand Down Expand Up @@ -244,28 +248,30 @@ public NBTBase writeNBT(Capability<ChunkDataTFC> capability, ChunkDataTFC instan
@Override
public void readNBT(Capability<ChunkDataTFC> capability, ChunkDataTFC instance, EnumFacing side, NBTBase nbt)
{
NBTTagCompound root = ((NBTTagCompound) nbt);

System.arraycopy(root.getIntArray("rockLayer1"), 0, instance.rockLayer1, 0, 256);
System.arraycopy(root.getIntArray("rockLayer2"), 0, instance.rockLayer2, 0, 256);
System.arraycopy(root.getIntArray("rockLayer3"), 0, instance.rockLayer3, 0, 256);
System.arraycopy(root.getIntArray("seaLevelOffset"), 0, instance.seaLevelOffset, 0, 256);
NBTTagCompound root = (NBTTagCompound) nbt;
if (nbt != null && root.getBoolean("valid"))
{
System.arraycopy(root.getIntArray("rockLayer1"), 0, instance.rockLayer1, 0, 256);
System.arraycopy(root.getIntArray("rockLayer2"), 0, instance.rockLayer2, 0, 256);
System.arraycopy(root.getIntArray("rockLayer3"), 0, instance.rockLayer3, 0, 256);
System.arraycopy(root.getIntArray("seaLevelOffset"), 0, instance.seaLevelOffset, 0, 256);

read(instance.stabilityLayer, root.getByteArray("stabilityLayer"));
read(instance.drainageLayer, root.getByteArray("drainageLayer"));
read(instance.stabilityLayer, root.getByteArray("stabilityLayer"));
read(instance.drainageLayer, root.getByteArray("drainageLayer"));

instance.fishPopulation = root.getInteger("fishPopulation");
instance.fishPopulation = root.getInteger("fishPopulation");

instance.rainfall = root.getFloat("rainfall");
instance.baseTemp = root.getFloat("baseTemp");
instance.avgTemp = root.getFloat("avgTemp");
instance.floraDensity = root.getFloat("floraDensity");
instance.floraDiversity = root.getFloat("floraDiversity");
instance.rainfall = root.getFloat("rainfall");
instance.baseTemp = root.getFloat("baseTemp");
instance.avgTemp = root.getFloat("avgTemp");
instance.floraDensity = root.getFloat("floraDensity");
instance.floraDiversity = root.getFloat("floraDiversity");

instance.oresSpawned.clear();
root.getTagList("oresSpawned", Constants.NBT.TAG_COMPOUND).forEach(x -> instance.oresSpawned.add(new ChunkDataOreSpawned(((NBTTagCompound) x))));
instance.oresSpawned.clear();
root.getTagList("oresSpawned", Constants.NBT.TAG_COMPOUND).forEach(x -> instance.oresSpawned.add(new ChunkDataOreSpawned(((NBTTagCompound) x))));

instance.initialized = true;
instance.initialized = true;
}
}
}
}
2 changes: 1 addition & 1 deletion tfc.json
Expand Up @@ -5,6 +5,6 @@
"1.12.2-recommended": "0.1.0"
},
"1.12.2": {
"0.1.0": "Commit message of the century: Fixed a number of issues and added a whole bunch of little things:\n - Better shift-click integration for various GUIs\n - Forgeable item heat tooltips (workable, weldable, danger)\n - Anvil tooltips, GUI cleanup, rendering, and bugfixes\n - Migrated knapping packet to PacketGuiButton\n - Firepit bellows integration\n - Fixes involving incorrectly specified metal tiers / missing tiers.\n - IFireable cleanup involving tiers\nAnd lots of javadoc comments everywhere"
"0.1.0": "Merge pull request #25 from alcatrazEscapee/forge-stuff\nMetalworking Stuff"
}
}

0 comments on commit 774bb35

Please sign in to comment.