示例#1
0
    public static int3 GetBottomBlock(int3 coord, int4 chunkPos)
    {
        int3 newCoord      = new int3(coord.x, coord.y - 1, coord.z);
        int  newBlockIndex = Utils.to1D(newCoord);

        if (coord.y == 0)
        {
            int4 newChunkPos        = new int4(chunkPos.x, chunkPos.y - 1, chunkPos.z, chunkPos.w);
            int3 newChunkCoord      = new int3(coord.x, Chunk.Height - 1, coord.z);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        else
        {
            int3[] blocks = WorldSettings.Chunks[chunkPos].blocks;
            return(blocks[newBlockIndex]);
        }
    }
示例#2
0
    public static int3 GetBackBlock(int3 coord, int4 chunkPos)
    {
        int3 newCoord      = new int3(coord.x, coord.y, coord.z + 1);
        int  newBlockIndex = Utils.to1D(newCoord);

        if (coord.z == Chunk.Width - 1)
        {
            int4 newChunkPos        = new int4(chunkPos.x, chunkPos.y, chunkPos.z + 1, chunkPos.w);
            int3 newChunkCoord      = new int3(coord.x, coord.y, 0);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        else
        {
            int3[] blocks = WorldSettings.Chunks[chunkPos].blocks;
            return(blocks[newBlockIndex]);
        }
    }
示例#3
0
    int3 GetTopBlock(int3 coord, int4 chunkPos)
    {
        int3 newCoord      = new int3(coord.x, coord.y + 1, coord.z);
        int  newBlockIndex = Utils.to1D(newCoord);

        if (coord.y == Height - 1)
        {
            int4 newChunkPos        = new int4(chunkPos.x, chunkPos.y + 1, chunkPos.z, chunkPos.w);
            int3 newChunkCoord      = new int3(coord.x, 0, coord.z);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        else
        {
            return(blocks[newBlockIndex]);
        }
    }
示例#4
0
    int3 GetFrontBlock(int3 coord, int4 chunkPos)
    {
        int3 newCoord      = new int3(coord.x, coord.y, coord.z - 1);
        int  newBlockIndex = Utils.to1D(newCoord);

        if (coord.z == 0)
        {
            int4 newChunkPos        = new int4(chunkPos.x, chunkPos.y, chunkPos.z - 1, chunkPos.w);
            int3 newChunkCoord      = new int3(coord.x, coord.y, Width - 1);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        else
        {
            return(blocks[newBlockIndex]);
        }
    }
示例#5
0
    public static int3 GetBlock(int3 coord, int4 chunkPos, int3 offset)
    {
        if (offset.Equals(new int3(-1, 0, 1)))
        {
        }
        int3 newCoord      = new int3(coord.x + offset.x, coord.y + offset.y, coord.z + offset.z);
        int  newBlockIndex = Utils.to1D(newCoord);

        if (coord.z == 0 && offset.z == -1)
        {
            int4 newChunkPos        = new int4(chunkPos.x, chunkPos.y, chunkPos.z - 1, chunkPos.w);
            int3 newChunkCoord      = new int3(newCoord.x, newCoord.y, Chunk.Width - 1);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        if (coord.z == Chunk.Width - 1 && offset.z == 1)
        {
            int4 newChunkPos        = new int4(chunkPos.x, chunkPos.y, chunkPos.z + 1, chunkPos.w);
            int3 newChunkCoord      = new int3(newCoord.x, newCoord.y, 0);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        if (coord.x == 0 && offset.x == -1)
        {
            int4 newChunkPos        = new int4(chunkPos.x - 1, chunkPos.y, chunkPos.z, chunkPos.w);
            int3 newChunkCoord      = new int3(Chunk.Width - 1, newCoord.y, newCoord.z);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        if (coord.x == Chunk.Width - 1 && offset.x == 1)
        {
            int4 newChunkPos        = new int4(chunkPos.x + 1, chunkPos.y, chunkPos.z, chunkPos.w);
            int3 newChunkCoord      = new int3(0, newCoord.y, newCoord.z);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        if (coord.y == 0 && offset.y == -1)
        {
            int4 newChunkPos        = new int4(chunkPos.x, chunkPos.y - 1, chunkPos.z, chunkPos.w);
            int3 newChunkCoord      = new int3(newCoord.x, Chunk.Height - 1, newCoord.z);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        if (coord.y == Chunk.Height - 1 && offset.y == 1)
        {
            int4 newChunkPos        = new int4(chunkPos.x, chunkPos.y + 1, chunkPos.z, chunkPos.w);
            int3 newChunkCoord      = new int3(newCoord.x, 0, newCoord.z);
            int  newChunkBlockIndex = Utils.to1D(newChunkCoord);
            if (WorldSettings.Chunks.ContainsKey(newChunkPos))
            {
                return(WorldSettings.Chunks[newChunkPos].blocks[newChunkBlockIndex]);
            }
            else
            {
                return(WorldSettings.GetBlock(Utils.WorldBlockPosition(newChunkCoord, newChunkPos)));
            }
        }
        int3[] blocks = WorldSettings.Chunks[chunkPos].blocks;
        return(blocks[newBlockIndex]);
    }
示例#6
0
    public static int3 GetBlock(int3 worldBlockPosition)
    {
        int3 block = instance.GetBlock(worldBlockPosition.x, worldBlockPosition.y, worldBlockPosition.z);

        return(block);
    }