Пример #1
0
        public FilterContainer(
            IBlockFilter blockFilter             = null,
            ITransactionFilter transactionFilter = null,
            ITransactionReceiptFilter transactionReceiptFilter       = null,
            ITransactionAndReceiptFilter transactionAndReceiptFilter = null,
            ITransactionLogFilter transactionLogFilter = null)
        {
            if (blockFilter != null)
            {
                BlockFilters = new List <IBlockFilter>(1)
                {
                    blockFilter
                };;
            }

            if (transactionFilter != null)
            {
                TransactionFilters = new List <ITransactionFilter>(1)
                {
                    transactionFilter
                };
            }

            if (transactionReceiptFilter != null)
            {
                TransactionReceiptFilters = new List <ITransactionReceiptFilter>(1)
                {
                    transactionReceiptFilter
                };
            }

            if (transactionAndReceiptFilter != null)
            {
                TransactionAndReceiptFilters = new List <ITransactionAndReceiptFilter>(1)
                {
                    transactionAndReceiptFilter
                };
            }

            if (transactionLogFilter != null)
            {
                TransactionLogFilters = new List <ITransactionLogFilter>(1)
                {
                    transactionLogFilter
                };
            }
        }
Пример #2
0
        public void ApplyChunk(NbtWorld world, ChunkRef chunk)
        {
            IBlockFilter opt_b = opt.GetBlockFilter();

            int xBase = chunk.X * chunk.Blocks.XDim;
            int zBase = chunk.Z * chunk.Blocks.ZDim;

            // Determine X range
            int xmin = 0;
            int xmax = 15;

            if (opt_b.XAboveEq != null)
            {
                xmin = (int)opt_b.XAboveEq - xBase;
            }
            if (opt_b.XBelowEq != null)
            {
                xmax = (int)opt_b.XBelowEq - xBase;
            }

            xmin = (xmin < 0) ? 0 : xmin;
            xmax = (xmax > 15) ? 15 : xmax;

            if (xmin > 15 || xmax < 0 || xmin > xmax)
            {
                return;
            }

            // Determine Y range
            int ymin = 0;
            int ymax = 127;

            if (opt_b.YAboveEq != null)
            {
                ymin = (int)opt_b.YAboveEq;
            }
            if (opt_b.YBelowEq != null)
            {
                ymax = (int)opt_b.YBelowEq;
            }

            if (ymin > ymax)
            {
                return;
            }

            // Determine X range
            int zmin = 0;
            int zmax = 15;

            if (opt_b.ZAboveEq != null)
            {
                zmin = (int)opt_b.ZAboveEq - zBase;
            }
            if (opt_b.ZBelowEq != null)
            {
                zmax = (int)opt_b.ZBelowEq - zBase;
            }

            zmin = (zmin < 0) ? 0 : zmin;
            zmax = (zmax > 15) ? 15 : zmax;

            if (zmin > 15 || zmax < 0 || zmin > zmax)
            {
                return;
            }

            int xdim = chunk.Blocks.XDim;
            int ydim = chunk.Blocks.YDim;
            int zdim = chunk.Blocks.ZDim;

            // Bin blocks
            for (int y = ymin; y <= ymax; y++)
            {
                for (int x = xmin; x <= xmax; x++)
                {
                    for (int z = zmin; z <= zmax; z++)
                    {
                        int id = chunk.Blocks.GetID(x, y, z);
                        _sort[id].Add(new BlockKey(x, y, z));
                    }
                }
            }

            // Process bins
            for (int i = 0; i < 256; i++)
            {
                if (_sort[i].Count == 0)
                {
                    continue;
                }

                if (opt_b.IncludedBlockCount > 0 & !opt_b.IncludedBlocksContains(i))
                {
                    continue;
                }

                if (opt_b.ExcludedBlockCount > 0 & opt_b.ExcludedBlocksContains(i))
                {
                    continue;
                }

                foreach (BlockKey key in _sort[i])
                {
                    chunk.Blocks.SetID(key.x, key.y, key.z, (int)opt.OPT_AFTER);

                    if (opt.OPT_VV)
                    {
                        int gx = chunk.X * xdim + key.x;
                        int gz = chunk.Z * zdim + key.z;
                        Console.WriteLine("Replaced block {0} at {1},{2},{3}", i, gx, key.y, gz);
                    }

                    if (opt.OPT_DATA != null)
                    {
                        chunk.Blocks.SetData(key.x, key.y, key.z, (int)opt.OPT_DATA);
                    }
                }
            }

            // Reset bins
            for (int i = 0; i < 256; i++)
            {
                _sort[i].Clear();
            }

            // Process Chunk

            /*for (int y = ymin; y <= ymax; y++) {
             *  for (int x = xmin; x <= xmax; x++) {
             *      for (int z = zmin; z <= zmax; z++) {
             *          // Probability test
             *          if (opt_b.ProbMatch != null) {
             *              double c = rand.NextDouble();
             *              if (c > opt_b.ProbMatch) {
             *                  continue;
             *              }
             *          }
             *
             *          int lx = x % xdim;
             *          int ly = y % ydim;
             *          int lz = z % zdim;
             *
             *          // Get the old block
             *          int oldBlock = chunk.Blocks.GetID(lx , ly, lz);
             *
             *          // Skip block if it doesn't match the inclusion list
             *          if (opt_b.IncludedBlockCount > 0) {
             *              bool match = false;
             *              foreach (int ib in opt_b.IncludedBlocks) {
             *                  if (oldBlock == ib) {
             *                      match = true;
             *                      break;
             *                  }
             *              }
             *
             *              if (!match) {
             *                  continue;
             *              }
             *          }
             *
             *          // Skip block if it does match the exclusion list
             *          if (opt_b.ExcludedBlockCount > 0) {
             *              bool match = false;
             *              foreach (int xb in opt_b.ExcludedBlocks) {
             *                  if (oldBlock == xb) {
             *                      match = true;
             *                      break;
             *                  }
             *              }
             *
             *              if (match) {
             *                  continue;
             *              }
             *          }
             *
             *          // Replace the block
             *          chunk.Blocks.SetID(lx, ly, lz, (int)opt.OPT_AFTER);
             *
             *          if (opt.OPT_VV) {
             *              int gx = chunk.X * xdim + lx;
             *              int gz = chunk.Z * zdim + lz;
             *              Console.WriteLine("Replaced block at {0},{1},{2}", gx, ly, gz);
             *          }
             *
             *          if (opt.OPT_DATA != null) {
             *              chunk.Blocks.SetData(lx, ly, lz, (int)opt.OPT_DATA);
             *          }
             *      }
             *  }
             * }*/
        }
Пример #3
0
        public void ApplyChunk(NbtWorld world, ChunkRef chunk)
        {
            IBlockFilter opt_b = opt.GetBlockFilter();

            //chunk.Blocks.AutoLight = false;
            //chunk.Blocks.AutoTileTick = false;

            int xBase = chunk.X * chunk.Blocks.XDim;
            int zBase = chunk.Z * chunk.Blocks.ZDim;

            // Determine X range
            int xmin = 0;
            int xmax = 15;

            if (opt_b.XAboveEq != null)
            {
                xmin = (int)opt_b.XAboveEq - xBase;
            }
            if (opt_b.XBelowEq != null)
            {
                xmax = (int)opt_b.XBelowEq - xBase;
            }

            xmin = (xmin < 0) ? 0 : xmin;
            xmax = (xmax > 15) ? 15 : xmax;

            if (xmin > 15 || xmax < 0 || xmin > xmax)
            {
                return;
            }

            // Determine Y range
            int ymin = 0;
            int ymax = 127;

            if (opt_b.YAboveEq != null)
            {
                ymin = (int)opt_b.YAboveEq;
            }
            if (opt_b.YBelowEq != null)
            {
                ymax = (int)opt_b.YBelowEq;
            }

            if (ymin > ymax)
            {
                return;
            }

            // Determine X range
            int zmin = 0;
            int zmax = 15;

            if (opt_b.ZAboveEq != null)
            {
                zmin = (int)opt_b.ZAboveEq - zBase;
            }
            if (opt_b.ZBelowEq != null)
            {
                zmax = (int)opt_b.ZBelowEq - zBase;
            }

            zmin = (zmin < 0) ? 0 : zmin;
            zmax = (zmax > 15) ? 15 : zmax;

            if (zmin > 15 || zmax < 0 || zmin > zmax)
            {
                return;
            }

            int xdim = chunk.Blocks.XDim;
            int ydim = chunk.Blocks.YDim;
            int zdim = chunk.Blocks.ZDim;

            // Bin blocks
            for (int y = ymin; y <= ymax; y++)
            {
                for (int x = xmin; x <= xmax; x++)
                {
                    for (int z = zmin; z <= zmax; z++)
                    {
                        int id = chunk.Blocks.GetID(x, y, z);
                        if (!_sort.ContainsKey(id))
                        {
                            _sort[id] = new List <BlockKey>();
                        }

                        _sort[id].Add(new BlockKey(x, y, z));
                    }
                }
            }

            // Process bins
            //for (int i = 0; i < maxBin; i++) {
            foreach (var kv in _sort)
            {
                if (kv.Value.Count == 0)
                {
                    continue;
                }

                if (opt_b.IncludedBlockCount > 0)
                {
                    if (!opt_b.IncludedBlocksContains(kv.Key))
                    {
                        bool found = false;
                        foreach (var range in opt_b.IncludedBlockRanges)
                        {
                            if (kv.Key >= range.Key && kv.Key <= range.Value)
                            {
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            continue;
                        }
                    }
                }

                if (opt_b.ExcludedBlockCount > 0)
                {
                    if (opt_b.ExcludedBlocksContains(kv.Key))
                    {
                        continue;
                    }
                    foreach (var range in opt_b.ExcludedBlockRanges)
                    {
                        if (kv.Key >= range.Key && kv.Key <= range.Value)
                        {
                            continue;
                        }
                    }
                }

                if (opt_b.IncludedBlockCount > 0 & !opt_b.IncludedBlocksContains(kv.Key))
                {
                    continue;
                }

                if (opt_b.ExcludedBlockCount > 0 & opt_b.ExcludedBlocksContains(kv.Key))
                {
                    continue;
                }

                foreach (BlockKey key in kv.Value)
                {
                    // Probability test
                    if (opt_b.ProbMatch != null)
                    {
                        double c = rand.NextDouble();
                        if (c > opt_b.ProbMatch)
                        {
                            continue;
                        }
                    }

                    if (opt_b.BlocksAboveCount > 0 && key.y < ydim - 1)
                    {
                        int neighborId = chunk.Blocks.GetID(key.x, key.y + 1, key.z);
                        if (!opt_b.BlocksAboveContains(neighborId))
                        {
                            continue;
                        }
                    }

                    if (opt_b.BlocksBelowCount > 0 && key.y > 0)
                    {
                        int neighborId = chunk.Blocks.GetID(key.x, key.y - 1, key.z);
                        if (!opt_b.BlocksBelowContains(neighborId))
                        {
                            continue;
                        }
                    }

                    if (opt_b.BlocksSideCount > 0)
                    {
                        bool          validNeighbor = false;
                        AlphaBlockRef block1        = GetNeighborBlock(chunk, key.x - 1, key.y, key.z);
                        if (block1.IsValid && opt_b.BlocksSideContains(block1.ID) && !validNeighbor)
                        {
                            validNeighbor = true;
                        }
                        AlphaBlockRef block2 = GetNeighborBlock(chunk, key.x + 1, key.y, key.z);
                        if (block2.IsValid && opt_b.BlocksSideContains(block2.ID) && !validNeighbor)
                        {
                            validNeighbor = true;
                        }
                        AlphaBlockRef block3 = GetNeighborBlock(chunk, key.x, key.y, key.z - 1);
                        if (block3.IsValid && opt_b.BlocksSideContains(block3.ID) && !validNeighbor)
                        {
                            validNeighbor = true;
                        }
                        AlphaBlockRef block4 = GetNeighborBlock(chunk, key.x, key.y, key.z + 1);
                        if (block4.IsValid && opt_b.BlocksSideContains(block4.ID) && !validNeighbor)
                        {
                            validNeighbor = true;
                        }
                        if (!validNeighbor)
                        {
                            continue;
                        }
                    }

                    if (opt_b.BlocksNAboveCount > 0 && key.y < ydim - 1)
                    {
                        int neighborId = chunk.Blocks.GetID(key.x, key.y + 1, key.z);
                        if (opt_b.BlocksNAboveContains(neighborId))
                        {
                            continue;
                        }
                    }

                    if (opt_b.BlocksNBelowCount > 0 && key.y > 0)
                    {
                        int neighborId = chunk.Blocks.GetID(key.x, key.y - 1, key.z);
                        if (opt_b.BlocksNBelowContains(neighborId))
                        {
                            continue;
                        }
                    }

                    if (opt_b.BlocksNSideCount > 0)
                    {
                        AlphaBlockRef block1 = GetNeighborBlock(chunk, key.x - 1, key.y, key.z);
                        if (block1.IsValid && opt_b.BlocksNSideContains(block1.ID))
                        {
                            continue;
                        }
                        AlphaBlockRef block2 = GetNeighborBlock(chunk, key.x + 1, key.y, key.z);
                        if (block2.IsValid && opt_b.BlocksNSideContains(block2.ID))
                        {
                            continue;
                        }
                        AlphaBlockRef block3 = GetNeighborBlock(chunk, key.x, key.y, key.z - 1);
                        if (block3.IsValid && opt_b.BlocksNSideContains(block3.ID))
                        {
                            continue;
                        }
                        AlphaBlockRef block4 = GetNeighborBlock(chunk, key.x, key.y, key.z + 1);
                        if (block4.IsValid && opt_b.BlocksNSideContains(block4.ID))
                        {
                            continue;
                        }
                    }

                    if (opt_b.IncludedDataCount > 0 || opt_b.ExcludedDataCount > 0)
                    {
                        int data = chunk.Blocks.GetData(key.x, key.y, key.z);
                        if (opt_b.IncludedDataCount > 0 && !opt_b.IncludedDataContains(data))
                        {
                            continue;
                        }

                        if (opt_b.ExcludedDataCount > 0 && opt_b.ExcludedDataContains(data))
                        {
                            continue;
                        }
                    }

                    chunk.Blocks.SetID(key.x, key.y, key.z, (int)opt.OPT_AFTER);

                    if (opt.OPT_VV)
                    {
                        int gx = chunk.X * xdim + key.x;
                        int gz = chunk.Z * zdim + key.z;
                        Console.WriteLine("Replaced block {0} at {1},{2},{3}", kv.Key, gx, key.y, gz);
                    }

                    if (opt.OPT_DATA != null)
                    {
                        chunk.Blocks.SetData(key.x, key.y, key.z, (int)opt.OPT_DATA);
                    }
                }
            }

            // Reset bins
            _sort.Clear();

            // Process Chunk

            /*for (int y = ymin; y <= ymax; y++) {
             *  for (int x = xmin; x <= xmax; x++) {
             *      for (int z = zmin; z <= zmax; z++) {
             *          // Probability test
             *          if (opt_b.ProbMatch != null) {
             *              double c = rand.NextDouble();
             *              if (c > opt_b.ProbMatch) {
             *                  continue;
             *              }
             *          }
             *
             *          int lx = x % xdim;
             *          int ly = y % ydim;
             *          int lz = z % zdim;
             *
             *          // Get the old block
             *          int oldBlock = chunk.Blocks.GetID(lx , ly, lz);
             *
             *          // Skip block if it doesn't match the inclusion list
             *          if (opt_b.IncludedBlockCount > 0) {
             *              bool match = false;
             *              foreach (int ib in opt_b.IncludedBlocks) {
             *                  if (oldBlock == ib) {
             *                      match = true;
             *                      break;
             *                  }
             *              }
             *
             *              if (!match) {
             *                  continue;
             *              }
             *          }
             *
             *          // Skip block if it does match the exclusion list
             *          if (opt_b.ExcludedBlockCount > 0) {
             *              bool match = false;
             *              foreach (int xb in opt_b.ExcludedBlocks) {
             *                  if (oldBlock == xb) {
             *                      match = true;
             *                      break;
             *                  }
             *              }
             *
             *              if (match) {
             *                  continue;
             *              }
             *          }
             *
             *          // Replace the block
             *          chunk.Blocks.SetID(lx, ly, lz, (int)opt.OPT_AFTER);
             *
             *          if (opt.OPT_VV) {
             *              int gx = chunk.X * xdim + lx;
             *              int gz = chunk.Z * zdim + lz;
             *              Console.WriteLine("Replaced block at {0},{1},{2}", gx, ly, gz);
             *          }
             *
             *          if (opt.OPT_DATA != null) {
             *              chunk.Blocks.SetData(lx, ly, lz, (int)opt.OPT_DATA);
             *          }
             *      }
             *  }
             * }*/
        }
 public CompositeBlockFilter(IBlockFilter innerFilter, Func <Foreground.Id, ForegroundBlock?, bool> foregroundPredicate, Func <Background.Id, BackgroundBlock?, bool> backgroundPredicate)
 {
     this._innerFilter         = innerFilter;
     this._foregroundPredicate = foregroundPredicate;
     this._backgroundPredicate = backgroundPredicate;
 }
Пример #5
0
 public DictionaryBlockLayer(IDictionaryLayerGenerator <TId, TBlock, TItem> generator, IBlockFilter <TId, TBlock> filter)
 {
     this._generator = generator;
     this._filter    = filter;
 }
Пример #6
0
 public FilterContainer(IBlockFilter blockFilter)
     : this(blockFilter, null)
 {
 }
Пример #7
0
 public static ReadOnlyWorldDictionary ToReadOnlyWorldDictionary(this IWorldAreaEnumerable <ForegroundBlock, BackgroundBlock> worldArea, IBlockFilter filter)
 {
     return(new ReadOnlyWorldDictionary(worldArea, filter));
 }
Пример #8
0
        public BlocksAreaDictionary(IBlockAreaEnumerable blockArea, BotBitsClient client, IBlockFilter filter)
        {
            this._client    = client;
            this._blockArea = blockArea;

            var fgGen = new ForegroundDictionaryLayerGenerator <BlocksItem>((p, b) => this._blockArea.At(p.X, p.Y));
            var bgGen = new BackgroundDictionaryLayerGenerator <BlocksItem>((p, b) => this._blockArea.At(p.X, p.Y));

            this.InternalForeground = new DictionaryBlockLayer <Foreground.Id, ForegroundBlock, BlocksItem, PointSet>(fgGen, filter);
            this.InternalBackground = new DictionaryBlockLayer <Background.Id, BackgroundBlock, BlocksItem, PointSet>(bgGen, filter);

            this.Reindex();

            EventLoader.Of(this._client).Load(this);
        }
Пример #9
0
        private bool CheckBlockFilter(int x, int y, int z, int blockId)
        {
            IBlockFilter opt_b = opt.GetBlockFilter();

            if (!opt_b.InvertXYZ)
            {
                if (opt_b.XAboveEq != null && x < opt_b.XAboveEq)
                {
                    return(false);
                }
                if (opt_b.XBelowEq != null && x > opt_b.XBelowEq)
                {
                    return(false);
                }
                if (opt_b.YAboveEq != null && y < opt_b.YAboveEq)
                {
                    return(false);
                }
                if (opt_b.YBelowEq != null && y > opt_b.YBelowEq)
                {
                    return(false);
                }
                if (opt_b.ZAboveEq != null && z < opt_b.ZAboveEq)
                {
                    return(false);
                }
                if (opt_b.ZBelowEq != null && z > opt_b.ZBelowEq)
                {
                    return(false);
                }
            }
            else
            {
                if (opt_b.XAboveEq != null && opt_b.XBelowEq != null &&
                    opt_b.YAboveEq != null && opt_b.YBelowEq != null &&
                    opt_b.ZAboveEq != null && opt_b.ZBelowEq != null &&
                    x > opt_b.XAboveEq && x < opt_b.XBelowEq &&
                    y > opt_b.YAboveEq && y < opt_b.YBelowEq &&
                    z > opt_b.ZAboveEq && z < opt_b.ZBelowEq)
                {
                    return(false);
                }
            }

            if (opt_b.IncludedBlockCount > 0)
            {
                if (!opt_b.IncludedBlocksContains(blockId))
                {
                    bool found = false;
                    foreach (var range in opt_b.IncludedBlockRanges)
                    {
                        if (blockId >= range.Key && blockId <= range.Value)
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        return(false);
                    }
                }
            }

            if (opt_b.ExcludedBlockCount > 0)
            {
                if (opt_b.ExcludedBlocksContains(blockId))
                {
                    return(false);
                }
                foreach (var range in opt_b.ExcludedBlockRanges)
                {
                    if (blockId >= range.Key && blockId <= range.Value)
                    {
                        return(false);
                    }
                }
            }

            if (opt_b.BlocksAboveCount > 0 && y < chunkYDim - 1)
            {
                int neighborId = cache.Blocks.GetID(x & chunkXMask, (y + 1) & chunkYMask, z & chunkZMask);
                if (!opt_b.BlocksAboveContains(neighborId))
                {
                    return(false);
                }
            }

            if (opt_b.BlocksBelowCount > 0 && y > 0)
            {
                int neighborId = cache.Blocks.GetID(x & chunkXMask, (y - 1) & chunkYMask, z & chunkZMask);
                if (!opt_b.BlocksBelowContains(neighborId))
                {
                    return(false);
                }
            }

            if (opt_b.BlocksSideCount > 0)
            {
                while (true)
                {
                    AlphaBlockRef block1 = GetBlockRefUnchecked(x - 1, y, z);
                    if (block1.IsValid && opt_b.BlocksSideContains(block1.ID))
                    {
                        break;
                    }
                    AlphaBlockRef block2 = GetBlockRefUnchecked(x + 1, y, z);
                    if (block2.IsValid && opt_b.BlocksSideContains(block2.ID))
                    {
                        break;
                    }
                    AlphaBlockRef block3 = GetBlockRefUnchecked(x, y, z - 1);
                    if (block3.IsValid && opt_b.BlocksSideContains(block3.ID))
                    {
                        break;
                    }
                    AlphaBlockRef block4 = GetBlockRefUnchecked(x, y, z + 1);
                    if (block4.IsValid && opt_b.BlocksSideContains(block4.ID))
                    {
                        break;
                    }
                    return(false);
                }
            }

            if (opt_b.BlocksNAboveCount > 0 && y < chunkYDim - 1)
            {
                int neighborId = cache.Blocks.GetID(x & chunkXMask, (y + 1) & chunkYMask, z & chunkZMask);
                if (opt_b.BlocksNAboveContains(neighborId))
                {
                    return(false);
                }
            }

            if (opt_b.BlocksNBelowCount > 0 && y > 0)
            {
                int neighborId = cache.Blocks.GetID(x & chunkXMask, (y - 1) & chunkYMask, z & chunkZMask);
                if (opt_b.BlocksNBelowContains(neighborId))
                {
                    return(false);
                }
            }

            if (opt_b.BlocksNSideCount > 0)
            {
                while (true)
                {
                    AlphaBlockRef block1 = GetBlockRefUnchecked(x - 1, y, z);
                    if (block1.IsValid && opt_b.BlocksNSideContains(block1.ID))
                    {
                        return(false);
                    }
                    AlphaBlockRef block2 = GetBlockRefUnchecked(x + 1, y, z);
                    if (block2.IsValid && opt_b.BlocksNSideContains(block2.ID))
                    {
                        return(false);
                    }
                    AlphaBlockRef block3 = GetBlockRefUnchecked(x, y, z - 1);
                    if (block3.IsValid && opt_b.BlocksNSideContains(block3.ID))
                    {
                        return(false);
                    }
                    AlphaBlockRef block4 = GetBlockRefUnchecked(x, y, z + 1);
                    if (block4.IsValid && opt_b.BlocksNSideContains(block4.ID))
                    {
                        return(false);
                    }
                    break;
                }
            }

            if (opt_b.ProbMatch != null)
            {
                double c = rand.NextDouble();
                if (c > opt_b.ProbMatch)
                {
                    return(false);
                }
            }

            if (opt_b.IncludedDataCount > 0 || opt_b.ExcludedDataCount > 0)
            {
                int data = cache.Blocks.GetData(x & chunkXMask, y & chunkYMask, z & chunkZMask);
                if (opt_b.IncludedDataCount > 0 && !opt_b.IncludedDataContains(data))
                {
                    return(false);
                }

                if (opt_b.ExcludedDataCount > 0 && opt_b.ExcludedDataContains(data))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #10
0
        public ReadOnlyWorldDictionary(IReadOnlyWorldAreaEnumerable <ForegroundBlock, BackgroundBlock> worldArea, IBlockFilter filter)
        {
            if (worldArea.Area.Width > ushort.MaxValue || worldArea.Area.Height > ushort.MaxValue)
            {
                throw new NotSupportedException($"WorldDictionary only supports worlds that are {ushort.MaxValue} wide or tall at maximum.");
            }
            var fgGen = new ForegroundDictionaryLayerGenerator <ReadOnlyWorldDictionaryItem>((p, b) => new ReadOnlyWorldDictionaryItem(b, p.X, p.Y));
            var bgGen = new BackgroundDictionaryLayerGenerator <ReadOnlyWorldDictionaryItem>((p, b) => new ReadOnlyWorldDictionaryItem(b, p.X, p.Y));

            this.InternalForeground = new DictionaryBlockLayer <Foreground.Id, ForegroundBlock, ReadOnlyWorldDictionaryItem, ReadOnlyPointSet>(fgGen, filter);
            this.InternalBackground = new DictionaryBlockLayer <Background.Id, BackgroundBlock, ReadOnlyWorldDictionaryItem, ReadOnlyPointSet>(bgGen, filter);

            this.Width  = worldArea.Area.Width;
            this.Height = worldArea.Area.Height;

            for (var y = 0; y < this.Height; y++)
            {
                for (var x = 0; x < this.Width; x++)
                {
                    this.InternalForeground.Add(worldArea.At(x, y).Foreground, new Point(x, y));
                    this.InternalBackground.Add(worldArea.At(x, y).Background, new Point(x, y));
                }
            }
        }
Пример #11
0
 public ReadOnlyWorldDictionary(IWorldAreaEnumerable <ForegroundBlock, BackgroundBlock> worldArea, IBlockFilter filter)
     : this(worldArea.ToReadOnlyWorldAreaEnumerable(), filter)
 {
 }