コード例 #1
0
    public static void ScatterNodes(Queue <Vector3i> nodes, bool generator)
    {
        while (nodes.Count > 0)
        {
            Vector3i pos = nodes.Dequeue();

            Block block = Map.GetBlock(pos.x, pos.y, pos.z);
            int   light = MapLight.GetSunlight(pos.x, pos.y, pos.z) - block.GetLightStep();

            if (light <= LightUtils.MinLight)
            {
                continue;
            }

            for (int i = 0; i < 6; i++)
            {
                Vector3i nextPos = pos + Vector3i.directions[i];

                if (Map.InBounds(nextPos.x, nextPos.y, nextPos.z))
                {
                    block = Map.GetBlock(nextPos.x, nextPos.y, nextPos.z);

                    if (block.IsTransparent() && SetMax((byte)light, nextPos.x, nextPos.y, nextPos.z))
                    {
                        nodes.Enqueue(nextPos);

                        if (!generator)
                        {
                            Map.FlagChunkForUpdate(nextPos.x, nextPos.y, nextPos.z);
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
    private static void RemoveNodes(Queue <Vector3i> nodes)
    {
        Queue <Vector3i> newNodes = new Queue <Vector3i>();

        while (nodes.Count > 0)
        {
            Vector3i pos = nodes.Dequeue();

            if (pos.y < 0 || pos.y >= Map.Height)
            {
                continue;
            }

            if (pos.y >= MapLight.GetRay(pos.x, pos.z))
            {
                newNodes.Enqueue(pos);
                continue;
            }

            byte light = (byte)(MapLight.GetSunlight(pos.x, pos.y, pos.z) - 1);
            MapLight.SetSunlight(pos.x, pos.y, pos.z, LightUtils.MinLight);

            if (light <= LightUtils.MinLight)
            {
                continue;
            }

            for (int i = 0; i < 6; i++)
            {
                Vector3i nextPos = pos + Vector3i.directions[i];

                if (Map.InBounds(nextPos.x, nextPos.z))
                {
                    Block block = Map.GetBlock(nextPos.x, nextPos.y, nextPos.z);

                    if (block.IsTransparent())
                    {
                        if (MapLight.GetSunlight(nextPos.x, nextPos.y, nextPos.z) <= light)
                        {
                            nodes.Enqueue(nextPos);
                            Map.FlagChunkForUpdate(nextPos.x, nextPos.y, nextPos.z);
                        }
                        else
                        {
                            newNodes.Enqueue(nextPos);
                        }
                    }
                }
            }
        }

        ScatterNodes(newNodes, false);
    }
コード例 #3
0
    private static bool SetMax(byte light, int x, int y, int z)
    {
        if (y >= MapLight.GetRay(x, z))
        {
            return(false);
        }

        byte oldLight = MapLight.GetSunlight(x, y, z);

        if (oldLight < light)
        {
            MapLight.SetSunlight(x, y, z, light);
            return(true);
        }

        return(false);
    }