From e215ccd7d5cc180088933bfc7573efff2dd318e7 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Fri, 29 Apr 2011 06:23:18 +0000 Subject: [PATCH] Some more lighting fixes (transparent, blocking blocks like half-steps and stairs will no longer be partially dark) --- Substrate/SubstrateCS/Source/BlockInfo.cs | 33 +++++++++- Substrate/SubstrateCS/Source/ChunkRef.cs | 77 +++++++++++++---------- 2 files changed, 76 insertions(+), 34 deletions(-) diff --git a/Substrate/SubstrateCS/Source/BlockInfo.cs b/Substrate/SubstrateCS/Source/BlockInfo.cs index 0ede762..0fa8a9e 100644 --- a/Substrate/SubstrateCS/Source/BlockInfo.cs +++ b/Substrate/SubstrateCS/Source/BlockInfo.cs @@ -166,6 +166,7 @@ namespace Substrate private string _name = ""; private int _opacity = MAX_OPACITY; private int _luminance = MIN_LUMINANCE; + private bool _transmitLight = false; private DataLimits _dataLimits; @@ -175,7 +176,7 @@ namespace Substrate public static ItemCache LuminanceTable; - public static ItemCache SchemaTable; + //public static ItemCache SchemaTable; public int ID { @@ -197,6 +198,11 @@ namespace Substrate get { return _luminance; } } + public bool TransmitsLight + { + get { return _transmitLight; } + } + public BlockInfo (int id) { _id = id; @@ -214,6 +220,14 @@ namespace Substrate { _opacity = MIN_OPACITY + opacity; _opacityTable[_id] = _opacity; + + if (opacity == MAX_OPACITY) { + _transmitLight = false; + } + else { + _transmitLight = true; + } + return this; } @@ -224,6 +238,12 @@ namespace Substrate return this; } + public BlockInfo SetLightTransmission (bool transmit) + { + _transmitLight = transmit; + return this; + } + public BlockInfo SetDataLimits (int low, int high, int bitmask) { _dataLimits = new DataLimits(low, high, bitmask); @@ -374,7 +394,7 @@ namespace Substrate GoldBlock = new BlockInfo(41, "Gold Block"); IronBlock = new BlockInfo(42, "Iron Block"); DoubleSlab = new BlockInfo(43, "Double Slab"); - Slab = new BlockInfo(44, "Slab"); + Slab = new BlockInfo(44, "Slab").SetOpacity(0); BrickBlock = new BlockInfo(45, "Brick Block"); TNT = new BlockInfo(46, "TNT"); Bookshelf = new BlockInfo(47, "Bookshelf"); @@ -432,6 +452,15 @@ namespace Substrate } } + // Override default light transmission rules + + Lava.SetLightTransmission(false); + StationaryLava.SetLightTransmission(false); + Slab.SetLightTransmission(false); + WoodStairs.SetLightTransmission(false); + Farmland.SetLightTransmission(false); + CobbleStairs.SetLightTransmission(false); + // Set Tile Entity Data Dispenser.SetTileEntity("Trap"); diff --git a/Substrate/SubstrateCS/Source/ChunkRef.cs b/Substrate/SubstrateCS/Source/ChunkRef.cs index e1ed906..a82c06b 100644 --- a/Substrate/SubstrateCS/Source/ChunkRef.cs +++ b/Substrate/SubstrateCS/Source/ChunkRef.cs @@ -543,7 +543,7 @@ namespace Substrate SetBlockLight(lx, ly, lz, priLum); } - if (primaryLight > primary.Luminance - 1) { + if (primaryLight > primary.Luminance - 1 || !primary.TransmitsLight) { return; } @@ -575,12 +575,14 @@ namespace Substrate if (dimStr > light) { cc.SetBlockLight(x, y, z, dimStr); - spread.Enqueue(new LightRecord(rec.x - 1, rec.y, rec.z, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x + 1, rec.y, rec.z, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z - 1, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z + 1, dimStr - 1)); + if (info.TransmitsLight) { + spread.Enqueue(new LightRecord(rec.x - 1, rec.y, rec.z, dimStr - 1)); + spread.Enqueue(new LightRecord(rec.x + 1, rec.y, rec.z, dimStr - 1)); + spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, dimStr - 1)); + spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, dimStr - 1)); + spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z - 1, dimStr - 1)); + spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z + 1, dimStr - 1)); + } } } } @@ -595,7 +597,7 @@ namespace Substrate SetBlockSkyLight(lx, ly, lz, priLum); } - if (primaryLight > BlockInfo.MAX_LUMINANCE - 1) { + if (primaryLight > BlockInfo.MAX_LUMINANCE - 1 || !primary.TransmitsLight) { return; } @@ -650,34 +652,36 @@ namespace Substrate if (dimStr > light) { cc.SetBlockSkyLight(x, y, z, dimStr); - spread.Enqueue(new LightRecord(rec.x - 1, rec.y, rec.z, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x + 1, rec.y, rec.z, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z - 1, dimStr - 1)); - spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z + 1, dimStr - 1)); - - if (heightMap[xi, zi] > rec.y - 1) { - spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, dimStr - 1)); - } - else { - spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, dimStr)); - } - - if (heightMap[xi - 1, zi] > rec.y) { + if (info.TransmitsLight) { spread.Enqueue(new LightRecord(rec.x - 1, rec.y, rec.z, dimStr - 1)); - } - if (heightMap[xi + 1, zi] > rec.y) { spread.Enqueue(new LightRecord(rec.x + 1, rec.y, rec.z, dimStr - 1)); - } - if (heightMap[xi, zi] > rec.y + 1) { + spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, dimStr - 1)); spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, dimStr - 1)); - } - if (heightMap[xi, zi] > rec.y) { spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z - 1, dimStr - 1)); - } - if (heightMap[xi, zi + 1] > rec.y) { spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z + 1, dimStr - 1)); + + if (heightMap[xi, zi] > rec.y - 1) { + spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, dimStr - 1)); + } + else { + spread.Enqueue(new LightRecord(rec.x, rec.y - 1, rec.z, dimStr)); + } + + if (heightMap[xi - 1, zi] > rec.y) { + spread.Enqueue(new LightRecord(rec.x - 1, rec.y, rec.z, dimStr - 1)); + } + if (heightMap[xi + 1, zi] > rec.y) { + spread.Enqueue(new LightRecord(rec.x + 1, rec.y, rec.z, dimStr - 1)); + } + if (heightMap[xi, zi] > rec.y + 1) { + spread.Enqueue(new LightRecord(rec.x, rec.y + 1, rec.z, dimStr - 1)); + } + if (heightMap[xi, zi] > rec.y) { + spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z - 1, dimStr - 1)); + } + if (heightMap[xi, zi + 1] > rec.y) { + spread.Enqueue(new LightRecord(rec.x, rec.y, rec.z + 1, dimStr - 1)); + } } } } @@ -790,7 +794,7 @@ 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); @@ -884,6 +888,10 @@ namespace Substrate z = (z + ZDim * 2) % ZDim; BlockInfo info = src.GetBlockInfo(x, y, z); + if (!info.TransmitsLight) { + return info.Luminance; + } + int light = src.GetBlockLight(x, y, z); return Math.Max(light, info.Luminance); @@ -903,6 +911,11 @@ namespace Substrate x = (x + XDim * 2) % XDim; z = (z + ZDim * 2) % ZDim; + BlockInfo info = src.GetBlockInfo(x, y, z); + if (!info.TransmitsLight) { + return BlockInfo.MIN_LUMINANCE; + } + int light = src.GetBlockSkyLight(x, y, z); return light;