GetBlockFilter() public method

public GetBlockFilter ( ) : IBlockFilter
return IBlockFilter
Ejemplo n.º 1
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);
             *          }
             *      }
             *  }
             * }*/
        }
Ejemplo n.º 2
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);
             *          }
             *      }
             *  }
             * }*/
        }