Exemple #1
0
        // TODO: average color is calculated per face, mods can override colors (dictionary)
        protected override Color GetVertexColor(IChunk chunk, LocalBlockPosition blockPosition, LocalBlockPosition airPosition)
        {
            var block = chunk.Blocks.GetBlock(blockPosition);
            var color = Palette(block.ID, block.Data);
            var lum   = base.GetVertexColor(chunk, blockPosition, airPosition);

            return(color * lum);
        }
Exemple #2
0
        protected virtual Color GetVertexColor([NotNull] IChunk chunk, LocalBlockPosition blockPosition, LocalBlockPosition airPosition)
        {
            var bl = chunk.Blocks.GetBlockLight(airPosition);
            var sl = chunk.Blocks.GetSkyLight(airPosition);
            // range 32-255
            var lum = (byte)(Math.Max(bl, sl) * 14 + 32);

            return(new Color(lum, lum, lum, (byte)255));
        }
Exemple #3
0
 public static int GetBlockLight(this AlphaBlockCollection blocks, LocalBlockPosition position)
 {
     return(blocks.GetBlockLight(position.X, position.Y, position.Z));
 }
Exemple #4
0
 public static TileEntity GetTileEntity(this AlphaBlockCollection blocks, LocalBlockPosition position)
 {
     return(blocks.GetTileEntity(position.X, position.Y, position.Z));
 }
Exemple #5
0
 public static BlockInfo GetInfo(this AlphaBlockCollection blocks, LocalBlockPosition position)
 {
     return(blocks.GetInfo(position.X, position.Y, position.Z));
 }
Exemple #6
0
 public static AlphaBlockRef GetBlockRef(this AlphaBlockCollection blocks, LocalBlockPosition position)
 {
     return(blocks.GetBlockRef(position.X, position.Y, position.Z));
 }
Exemple #7
0
 public static int GetTileTickValue(this AlphaBlockCollection blocks, LocalBlockPosition position)
 {
     return(blocks.GetTileTickValue(position.X, position.Y, position.Z));
 }
Exemple #8
0
        // TODO: Return bare minimum required to do collision, user gets the rest.
        public IEnumerator <IChunkTraceData> GetEnumerator()
        {
            // fields
            var rayPos          = _tracer.Position;
            var currentChunkPos = (ChunkPosition) new BlockPosition((int)rayPos.X, (int)rayPos.Y, (int)rayPos.Z);
            var enumerator      = _tracer.GetEnumerator();

            enumerator.MoveNext();

            // TODO: IChunkTraceData is a problem when traversing ungenerated chunks. (wont know size of a chunk or when it enters a new one.)
            var size        = new ChunkSize(16, 256, 16);
            var positions   = new List <LocalBlockPosition>(20);
            var alphaBlocks = new List <AlphaBlock>(20);
            var chunkNull   = false;

            // this was supposed to be simple and beautiful, but the fact that you cant yield in a lambda made it pretty nasty.
            var tracerReachedLimit = false;

            while (!tracerReachedLimit)
            {
                _world.GetChunk(new ChunkPositionDimension(currentChunkPos, _dimension), AccessMode.Read, chunk =>
                {
                    while (true)
                    {
                        // check to see if we've moved on to the next chunk. if so, return without reading its data.
                        var exactPos = (ChunkPosition)enumerator.Current;
                        if (currentChunkPos != exactPos)
                        {
                            // yield return our current ChunkTraceData, loads the next chunk
                            break;
                        }

                        // gather data
                        if (chunk != null)
                        {
                            // get block data
                            var blocks   = chunk.Blocks;
                            var localPos = new LocalBlockPosition(chunk, enumerator.Current);
                            positions.Add(localPos);
                            // if it is out of range, it's air
                            alphaBlocks.Add((localPos.Y >= 256 || localPos.Y < 0) ? new AlphaBlock(0) : blocks.GetBlock(localPos));
                        }
                        else
                        {
                            chunkNull = true;
                        }

                        if (enumerator.MoveNext())
                        {
                            continue;
                        }

                        // enumerator cant MoveNext, break and return the last of our data
                        tracerReachedLimit = true;
                        break;
                    }
                });

                // yield return our current ChunkTraceData

                yield return(new ChunkTraceData(currentChunkPos, size, chunkNull ? null : positions, chunkNull ? null : alphaBlocks));

                // create new collections for reading the next chunk data
                positions   = new List <LocalBlockPosition>(20);
                alphaBlocks = new List <AlphaBlock>(20);
                chunkNull   = false;

                // move currentChunkPos to the next chunk
                currentChunkPos = enumerator.Current;
            }
        }