diff --git a/Substrate/SubstrateCS/Examples/FlatMap/Program.cs b/Substrate/SubstrateCS/Examples/FlatMap/Program.cs index 750cb1e..70f816f 100644 --- a/Substrate/SubstrateCS/Examples/FlatMap/Program.cs +++ b/Substrate/SubstrateCS/Examples/FlatMap/Program.cs @@ -24,7 +24,10 @@ namespace FlatMap // We can set different world parameters world.Level.LevelName = "Flatlands"; - world.Level.SetDefaultPlayer(); + world.Level.SpawnX = 20; + world.Level.SpawnZ = 20; + world.Level.SpawnY = 70; + //world.Level.SetDefaultPlayer(); // We'll create chunks at chunk coordinates xmin,zmin to xmax,zmax for (int xi = xmin; xi < xmax; xi++) { diff --git a/Substrate/SubstrateCS/Examples/MoveSpawn/MoveSpawn.csproj b/Substrate/SubstrateCS/Examples/MoveSpawn/MoveSpawn.csproj new file mode 100644 index 0000000..df11fec --- /dev/null +++ b/Substrate/SubstrateCS/Examples/MoveSpawn/MoveSpawn.csproj @@ -0,0 +1,93 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {15C04C0C-FD50-47E9-B62C-AA0A814189ED} + Exe + Properties + MoveSpawn + MoveSpawn + v4.0 + 512 + + + + + 3.5 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\bin\Release\Substrate.dll + + + + + + + + + + False + Microsoft .NET Framework 4 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + + + \ No newline at end of file diff --git a/Substrate/SubstrateCS/Examples/MoveSpawn/Program.cs b/Substrate/SubstrateCS/Examples/MoveSpawn/Program.cs new file mode 100644 index 0000000..01a7e76 --- /dev/null +++ b/Substrate/SubstrateCS/Examples/MoveSpawn/Program.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Substrate; + +namespace MoveSpawn +{ + class Program + { + static void Main (string[] args) + { + if (args.Length != 4) { + Console.WriteLine("Usage: MoveSpawn "); + return; + } + + string dest = args[0]; + int x = Convert.ToInt32(args[1]); + int y = Convert.ToInt32(args[2]); + int z = Convert.ToInt32(args[3]); + + BetaWorld world = BetaWorld.Open(dest); + + world.Level.SpawnX = x; + world.Level.SpawnY = y; + world.Level.SpawnZ = z; + + world.Save(); + } + } +} diff --git a/Substrate/SubstrateCS/Examples/MoveSpawn/Properties/AssemblyInfo.cs b/Substrate/SubstrateCS/Examples/MoveSpawn/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c8f72ce --- /dev/null +++ b/Substrate/SubstrateCS/Examples/MoveSpawn/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MoveSpawn")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("MoveSpawn")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4925446f-56ff-454c-bca2-054e0294dd2e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Substrate/SubstrateCS/Source/BlockLight.cs b/Substrate/SubstrateCS/Source/BlockLight.cs index 02c51ae..6a431b6 100644 --- a/Substrate/SubstrateCS/Source/BlockLight.cs +++ b/Substrate/SubstrateCS/Source/BlockLight.cs @@ -56,12 +56,15 @@ namespace Substrate BlockKey primary = new BlockKey(lx, ly, lz); _update.Enqueue(primary); - QueueRelight(new BlockKey(lx - 1, ly, lz)); - QueueRelight(new BlockKey(lx + 1, ly, lz)); - QueueRelight(new BlockKey(lx, ly - 1, lz)); - QueueRelight(new BlockKey(lx, ly + 1, lz)); - QueueRelight(new BlockKey(lx, ly, lz - 1)); - QueueRelight(new BlockKey(lx, ly, lz + 1)); + BlockInfo info = _blockset.GetInfo(lx, ly, lz); + if (info.Luminance > BlockInfo.MIN_LUMINANCE || info.TransmitsLight) { + QueueRelight(new BlockKey(lx - 1, ly, lz)); + QueueRelight(new BlockKey(lx + 1, ly, lz)); + QueueRelight(new BlockKey(lx, ly - 1, lz)); + QueueRelight(new BlockKey(lx, ly + 1, lz)); + QueueRelight(new BlockKey(lx, ly, lz - 1)); + QueueRelight(new BlockKey(lx, ly, lz + 1)); + } UpdateBlockLight(); } @@ -294,19 +297,21 @@ namespace Substrate light = Math.Max(light, lld - 1); light = Math.Max(light, llu - 1); - //light = Math.Max(light - info.Opacity, 0); + light = Math.Max(light - info.Opacity, 0); if (light != lightval) { //Console.WriteLine("Block Light: ({0},{1},{2}) " + lightval + " -> " + light, k.x, k.y, k.z); cc.SetBlockLight(x, y, z, light); - QueueRelight(new BlockKey(k.x - 1, k.y, k.z)); - QueueRelight(new BlockKey(k.x + 1, k.y, k.z)); - QueueRelight(new BlockKey(k.x, k.y - 1, k.z)); - QueueRelight(new BlockKey(k.x, k.y + 1, k.z)); - QueueRelight(new BlockKey(k.x, k.y, k.z - 1)); - QueueRelight(new BlockKey(k.x, k.y, k.z + 1)); + if (info.TransmitsLight) { + QueueRelight(new BlockKey(k.x - 1, k.y, k.z)); + QueueRelight(new BlockKey(k.x + 1, k.y, k.z)); + QueueRelight(new BlockKey(k.x, k.y - 1, k.z)); + QueueRelight(new BlockKey(k.x, k.y + 1, k.z)); + QueueRelight(new BlockKey(k.x, k.y, k.z - 1)); + QueueRelight(new BlockKey(k.x, k.y, k.z + 1)); + } } } } @@ -351,19 +356,21 @@ namespace Substrate light = Math.Max(light, llu - 1); } - //light = Math.Max(light - info.Opacity, 0); + light = Math.Max(light - info.Opacity, 0); if (light != lightval) { //Console.WriteLine("Block SkyLight: ({0},{1},{2}) " + lightval + " -> " + light, k.x, k.y, k.z); cc.SetSkyLight(x, y, z, light); - - QueueRelight(new BlockKey(k.x - 1, k.y, k.z)); - QueueRelight(new BlockKey(k.x + 1, k.y, k.z)); - QueueRelight(new BlockKey(k.x, k.y - 1, k.z)); - QueueRelight(new BlockKey(k.x, k.y + 1, k.z)); - QueueRelight(new BlockKey(k.x, k.y, k.z - 1)); - QueueRelight(new BlockKey(k.x, k.y, k.z + 1)); + + if (info.TransmitsLight) { + QueueRelight(new BlockKey(k.x - 1, k.y, k.z)); + QueueRelight(new BlockKey(k.x + 1, k.y, k.z)); + QueueRelight(new BlockKey(k.x, k.y - 1, k.z)); + QueueRelight(new BlockKey(k.x, k.y + 1, k.z)); + QueueRelight(new BlockKey(k.x, k.y, k.z - 1)); + QueueRelight(new BlockKey(k.x, k.y, k.z + 1)); + } } } } diff --git a/Substrate/SubstrateCS/Source/Level.cs b/Substrate/SubstrateCS/Source/Level.cs index edac3ab..d987927 100644 --- a/Substrate/SubstrateCS/Source/Level.cs +++ b/Substrate/SubstrateCS/Source/Level.cs @@ -24,6 +24,10 @@ namespace Substrate new NBTScalerNode("RandomSeed", TagType.TAG_LONG), new NBTScalerNode("version", TagType.TAG_INT, NBTOptions.OPTIONAL), new NBTScalerNode("LevelName", TagType.TAG_STRING, NBTOptions.OPTIONAL), + new NBTScalerNode("raining", TagType.TAG_BYTE, NBTOptions.OPTIONAL), + new NBTScalerNode("thundering", TagType.TAG_BYTE, NBTOptions.OPTIONAL), + new NBTScalerNode("rainTime", TagType.TAG_INT, NBTOptions.OPTIONAL), + new NBTScalerNode("thunderTime", TagType.TAG_INT, NBTOptions.OPTIONAL), }, }; @@ -43,6 +47,11 @@ namespace Substrate private int? _version; private string _name; + private byte? _raining; + private byte? _thundering; + private int? _rainTime; + private int? _thunderTime; + public long Time { get { return _time; } @@ -110,6 +119,30 @@ namespace Substrate } } + public bool IsRaining + { + get { return (_raining ?? 0) == 1; } + set { _raining = value ? (byte)1 : (byte)0; } + } + + public bool IsThundering + { + get { return (_thundering ?? 0) == 1; } + set { _thundering = value ? (byte)1 : (byte)0; } + } + + public int RainTime + { + get { return _rainTime ?? 0; } + set { _rainTime = value; } + } + + public int ThunderTime + { + get { return _thunderTime ?? 0; } + set { _thunderTime = value; } + } + public Level (INBTWorld world) { _world = world; @@ -140,6 +173,11 @@ namespace Substrate _version = p._version; _name = p._name; + _raining = p._raining; + _thundering = p._thundering; + _rainTime = p._rainTime; + _thunderTime = p._thunderTime; + if (p._player != null) { _player = p._player.Copy(); } @@ -202,11 +240,23 @@ namespace Substrate if (ctree.ContainsKey("version")) { _version = ctree["version"].ToTagInt(); } - if (ctree.ContainsKey("LevelName")) { _name = ctree["LevelName"].ToTagString(); } + if (ctree.ContainsKey("raining")) { + _raining = ctree["raining"].ToTagByte(); + } + if (ctree.ContainsKey("thundering")) { + _thundering = ctree["thundering"].ToTagByte(); + } + if (ctree.ContainsKey("rainTime")) { + _rainTime = ctree["rainTime"].ToTagInt(); + } + if (ctree.ContainsKey("thunderTime")) { + _thunderTime = ctree["thunderTime"].ToTagInt(); + } + return this; } @@ -243,6 +293,19 @@ namespace Substrate data["LevelName"] = new TagString(_name); } + if (_raining != null) { + data["raining"] = new TagByte(_raining ?? 0); + } + if (_thundering != null) { + data["thundering"] = new TagByte(_thundering ?? 0); + } + if (_rainTime != null) { + data["rainTime"] = new TagInt(_rainTime ?? 0); + } + if (_thunderTime != null) { + data["thunderTime"] = new TagInt(_thunderTime ?? 0); + } + TagCompound tree = new TagCompound(); tree.Add("Data", data);