Fixed lighting bug (maybe?), added weather attributes to level format, added additional example.

This commit is contained in:
Justin Aquadro 2011-05-14 21:53:39 +00:00
parent 32dd74415f
commit 434f7808fe
6 changed files with 258 additions and 23 deletions

View file

@ -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++) {

View file

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{15C04C0C-FD50-47E9-B62C-AA0A814189ED}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MoveSpawn</RootNamespace>
<AssemblyName>MoveSpawn</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Substrate">
<HintPath>..\..\bin\Release\Substrate.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -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 <world> <x> <y> <z>");
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();
}
}
}

View file

@ -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")]

View file

@ -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));
}
}
}
}

View file

@ -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);