Пример #1
0
    public static void SpillLight(World world, BlockPos pos, byte light, List <BlockPos> chunksToUpdate, Chunk chunk = null)
    {
        bool stayWithinChunk = true;

        if (chunk == null)
        {
            chunk           = world.GetChunk(pos);
            stayWithinChunk = false;
        }

        BlockPos localPos = pos.Subtract(chunk.pos);

        if (!Chunk.InRange(localPos))
        {
            return;
        }

        Block block = chunk.GetBlock(localPos);

        if (!block.controller.IsTransparent())
        {
            return;
        }

        if (block.data1 >= light)
        {
            return;
        }

        if (!chunksToUpdate.Contains(chunk.pos))
        {
            chunksToUpdate.Add(chunk.pos);
        }

        block.data1 = light;
        chunk.SetBlock(localPos, block, false);

        if (block.data1 > lightReduceBy)
        {
            block.data1 -= lightReduceBy;

            CallSpillLight(world, chunk, pos.Add(1, 0, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 1, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 0, 1), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(-1, 0, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, -1, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 0, -1), block.data1, chunksToUpdate, stayWithinChunk);
        }
        return;
    }
Пример #2
0
    static void CallSpillLight(World world, Chunk chunk, BlockPos pos, byte light, List <BlockPos> chunksToUpdate, bool stayWithinChunk)
    {
        BlockPos localPos = pos.Subtract(chunk.pos);

        if (Chunk.InRange(localPos))
        {
            SpillLight(world, pos, light, chunksToUpdate, chunk);
        }
        else
        {
            if (!stayWithinChunk)
            {
                SpillLight(world, pos, light, chunksToUpdate);
            }
        }
    }
Пример #3
0
 static void CallSpillLight(World world, Chunk chunk, BlockPos pos, byte light, List<BlockPos> chunksToUpdate, bool stayWithinChunk)
 {
     BlockPos localPos = pos.Subtract(chunk.pos);
     if (Chunk.InRange(localPos))
     {
         SpillLight(world, pos, light, chunksToUpdate, chunk);
     }
     else
     {
         if(!stayWithinChunk)
             SpillLight(world, pos, light, chunksToUpdate);
     }
 }
Пример #4
0
    public static void SpillLight(World world, BlockPos pos, byte light, List<BlockPos> chunksToUpdate, Chunk chunk = null)
    {
        bool stayWithinChunk = true;
        if (chunk == null)
        {
            chunk = world.GetChunk(pos);
            stayWithinChunk = false;
        }

        BlockPos localPos = pos.Subtract(chunk.pos);

        if (!Chunk.InRange(localPos))
            return;

        Block block = chunk.GetBlock(localPos);

        if (!block.controller.IsTransparent())
            return;

        if (block.data1 >= light)
            return;

        if (!chunksToUpdate.Contains(chunk.pos))
            chunksToUpdate.Add(chunk.pos);

        block.data1 = light;
        chunk.SetBlock(localPos, block, false);

        if (block.data1 > lightReduceBy)
        {
            block.data1 -= lightReduceBy;

            CallSpillLight(world, chunk, pos.Add(1, 0, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 1, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 0, 1), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(-1, 0, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, -1, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 0, -1), block.data1, chunksToUpdate, stayWithinChunk);
        }
        return;
    }