From 6f78009c0ebd04a7641c1d1320513c4ef41156fb Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 13 Apr 2011 08:46:06 +0000 Subject: [PATCH] Chunk coordinates were being aliased during chunk generation, causing Minecraft to hang. Also fixed player object creation. --- Substrate/SubstrateCS/Examples/FlatMap/Program.cs | 13 +++++++++---- Substrate/SubstrateCS/Source/Chunk.cs | 12 +++++++++--- Substrate/SubstrateCS/Source/Entity.cs | 3 +++ Substrate/SubstrateCS/Source/Player.cs | 4 ++++ Substrate/SubstrateCS/Source/Region.cs | 5 ++++- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Substrate/SubstrateCS/Examples/FlatMap/Program.cs b/Substrate/SubstrateCS/Examples/FlatMap/Program.cs index e47978e..d91b066 100644 --- a/Substrate/SubstrateCS/Examples/FlatMap/Program.cs +++ b/Substrate/SubstrateCS/Examples/FlatMap/Program.cs @@ -13,10 +13,10 @@ namespace FlatMap static void Main (string[] args) { string dest = "F:\\Minecraft\\test"; - int xmin = -10; - int xmax = 10; - int zmin = -10; - int zmaz = 10; + int xmin = -20; + int xmax = 20; + int zmin = -20; + int zmaz = 20; // This will instantly create any necessary directory structure BetaWorld world = BetaWorld.Create(dest); @@ -24,6 +24,7 @@ namespace FlatMap // We can set different world parameters world.Level.LevelName = "Flatlands"; + world.Level.SetDefaultPlayer(); // We'll create chunks at chunk coordinates xmin,zmin to xmax,zmax for (int xi = xmin; xi < xmax; xi++) { @@ -33,6 +34,10 @@ namespace FlatMap // written to disk) ChunkRef chunk = cm.CreateChunk(xi, zi); + // This will suppress generating caves, ores, and all those + // other goodies. + chunk.IsTerrainPopulated = true; + // Auto light recalculation is horrifically bad for creating // chunks from scratch, because we're placing thousands // of blocks. Turn it off. diff --git a/Substrate/SubstrateCS/Source/Chunk.cs b/Substrate/SubstrateCS/Source/Chunk.cs index 6bfaa49..abd86f1 100644 --- a/Substrate/SubstrateCS/Source/Chunk.cs +++ b/Substrate/SubstrateCS/Source/Chunk.cs @@ -106,9 +106,9 @@ namespace Substrate level.Add("HeightMap", _heightMap); level.Add("Entities", _entities); level.Add("TileEntities", _tileEntities); - level.Add("LastUpdate", new TagLong()); - level.Add("xPos", new TagInt()); - level.Add("zPos", new TagInt()); + level.Add("LastUpdate", new TagLong(Timestamp())); + level.Add("xPos", new TagInt(_cx)); + level.Add("zPos", new TagInt(_cz)); level.Add("TerrainPopulated", new TagByte()); _tree = new NBT_Tree(); @@ -799,5 +799,11 @@ namespace Substrate return Math.Max(light, info.Luminance); } + + private int Timestamp () + { + DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0); + return (int)((DateTime.UtcNow - epoch).Ticks / (10000L * 1000L)); + } } } diff --git a/Substrate/SubstrateCS/Source/Entity.cs b/Substrate/SubstrateCS/Source/Entity.cs index e91f23f..b0359ab 100644 --- a/Substrate/SubstrateCS/Source/Entity.cs +++ b/Substrate/SubstrateCS/Source/Entity.cs @@ -97,6 +97,9 @@ namespace Substrate public UntypedEntity () { + _pos = new Vector3(); + _motion = new Vector3(); + _rotation = new Orientation(); } public UntypedEntity (UntypedEntity e) diff --git a/Substrate/SubstrateCS/Source/Player.cs b/Substrate/SubstrateCS/Source/Player.cs index ebb8e5d..752c4e0 100644 --- a/Substrate/SubstrateCS/Source/Player.cs +++ b/Substrate/SubstrateCS/Source/Player.cs @@ -85,6 +85,10 @@ namespace Substrate _dimension = 0; _sleeping = 0; _sleepTimer = 0; + + Air = 300; + //Health = 20; + Fire = -20; } public Player (Player p) diff --git a/Substrate/SubstrateCS/Source/Region.cs b/Substrate/SubstrateCS/Source/Region.cs index 8d2ae56..152cb49 100644 --- a/Substrate/SubstrateCS/Source/Region.cs +++ b/Substrate/SubstrateCS/Source/Region.cs @@ -264,7 +264,10 @@ namespace Substrate DeleteChunk(lcx, lcz); - Chunk c = new Chunk(lcx, lcz); + int cx = lcx + _rx * ChunkManager.REGION_XLEN; + int cz = lcz + _rz * ChunkManager.REGION_ZLEN; + + Chunk c = new Chunk(cx, cz); c.Save(GetChunkOutStream(lcx, lcz)); ChunkRef cr = new ChunkRef(this, cache, lcx, lcz);