Index() public method

Converts given coordinates to a block array index.
public Index ( Vector3I coords ) : int
coords Vector3I Coordinate vector (X,Y,Z).
return int
Ejemplo n.º 1
0
 private static void SealLiquids(Map map, byte sealantType)
 {
     for (int x = 1; x < map.Width - 1; x++)
     {
         for (int z = 1; z < map.Height; z++)
         {
             for (int y = 1; y < map.Length - 1; y++)
             {
                 int index = map.Index(x, y, z);
                 if ((map.Blocks[index] == 10 || map.Blocks[index] == 11 || map.Blocks[index] == 8 || map.Blocks[index] == 9) &&
                     (map.GetBlock(x - 1, y, z) == Block.Air || map.GetBlock(x + 1, y, z) == Block.Air ||
                      map.GetBlock(x, y - 1, z) == Block.Air || map.GetBlock(x, y + 1, z) == Block.Air ||
                      map.GetBlock(x, y, z - 1) == Block.Air))
                 {
                     map.Blocks[index] = sealantType;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 static void SealLiquids(Map map, byte sealantType)
 {
     for (int x = 1; x < map.WidthX - 1; x++)
     {
         for (int h = 1; h < map.Height; h++)
         {
             for (int y = 1; y < map.WidthY - 1; y++)
             {
                 int index = map.Index(x, y, h);
                 if ((map.Blocks[index] == 10 || map.Blocks[index] == 11 || map.Blocks[index] == 8 || map.Blocks[index] == 9) &&
                     (map.GetBlock(x - 1, y, h) == Block.Air || map.GetBlock(x + 1, y, h) == Block.Air ||
                      map.GetBlock(x, y - 1, h) == Block.Air || map.GetBlock(x, y + 1, h) == Block.Air ||
                      map.GetBlock(x, y, h - 1) == Block.Air))
                 {
                     map.Blocks[index] = sealantType;
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public BlockDBEntry[] Lookup([NotNull] PlayerInfo info, [NotNull] BoundingBox area, TimeSpan span)
        {
            if (!IsEnabled || !IsEnabledGlobally)
            {
                throw new InvalidOperationException("Trying to lookup on disabled BlockDB.");
            }
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (area == null)
            {
                throw new ArgumentNullException("area");
            }
            long ticks = DateTime.UtcNow.Subtract(span).ToUnixTime();
            Dictionary <int, BlockDBEntry> results = new Dictionary <int, BlockDBEntry>();
            Map map = World.LoadMap();

            if (isPreloaded)
            {
                lock ( SyncRoot )
                {
                    fixed(BlockDBEntry *entries = cacheStore)
                    {
                        for (int i = CacheSize - 1; i >= 0; i--)
                        {
                            if (entries[i].Timestamp < ticks)
                            {
                                break;
                            }
                            if (entries[i].PlayerID == info.ID && area.Contains(entries[i].X, entries[i].Y, entries[i].Z))
                            {
                                int index = map.Index(entries[i].X, entries[i].Y, entries[i].Z);
                                results[index] = entries[i];
                            }
                        }
                    }
                }
            }
            else
            {
                Flush();
                byte[] bytes      = Load();
                int    entryCount = bytes.Length / BlockDBEntry.Size;
                fixed(byte *parr = bytes)
                {
                    BlockDBEntry *entries = (BlockDBEntry *)parr;

                    for (int i = entryCount - 1; i >= 0; i--)
                    {
                        if (entries[i].Timestamp < ticks)
                        {
                            break;
                        }
                        if (entries[i].PlayerID == info.ID && area.Contains(entries[i].X, entries[i].Y, entries[i].Z))
                        {
                            int index = map.Index(entries[i].X, entries[i].Y, entries[i].Z);
                            results[index] = entries[i];
                        }
                    }
                }
            }
            return(results.Values.ToArray());
        }
Ejemplo n.º 4
0
        public BlockDBEntry[] Lookup([NotNull] PlayerInfo info, int max)
        {
            if (!IsEnabled || !IsEnabledGlobally)
            {
                throw new InvalidOperationException("Trying to lookup on disabled BlockDB.");
            }
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            Dictionary <int, BlockDBEntry> results = new Dictionary <int, BlockDBEntry>();
            int count = 0;

            Map map = World.LoadMap();

            if (isPreloaded)
            {
                lock ( SyncRoot )
                {
                    fixed(BlockDBEntry *entries = cacheStore)
                    {
                        for (int i = CacheSize - 1; i >= 0; i--)
                        {
                            if (entries[i].PlayerID == info.ID)
                            {
                                int index = map.Index(entries[i].X, entries[i].Y, entries[i].Z);
                                results[index] = entries[i];
                                count++;
                                if (count >= max)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Flush();
                byte[] bytes      = Load();
                int    entryCount = bytes.Length / BlockDBEntry.Size;
                fixed(byte *parr = bytes)
                {
                    BlockDBEntry *entries = (BlockDBEntry *)parr;

                    for (int i = entryCount - 1; i >= 0; i--)
                    {
                        if (entries[i].PlayerID == info.ID)
                        {
                            int index = map.Index(entries[i].X, entries[i].Y, entries[i].Z);
                            results[index] = entries[i];
                            count++;
                            if (count >= max)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(results.Values.ToArray());
        }
Ejemplo n.º 5
0
 static void SealLiquids(Map map, byte sealantType)
 {
     for (int x = 1; x < map.Width - 1; x++)
     {
         for (int z = 1; z < map.Height; z++)
         {
             for (int y = 1; y < map.Length - 1; y++)
             {
                 int index = map.Index(x, y, z);
                 if ((map.Blocks[index] == 10 || map.Blocks[index] == 11 || map.Blocks[index] == 8 || map.Blocks[index] == 9) &&
                     (map.GetBlock(x - 1, y, z) == Block.Air || map.GetBlock(x + 1, y, z) == Block.Air ||
                     map.GetBlock(x, y - 1, z) == Block.Air || map.GetBlock(x, y + 1, z) == Block.Air ||
                     map.GetBlock(x, y, z - 1) == Block.Air))
                 {
                     map.Blocks[index] = sealantType;
                 }
             }
         }
     }
 }