Beispiel #1
0
        private bool Test(BlockCoordinates coordinates, MaskEntry mask)
        {
            if (Level == null)
            {
                return(true);
            }

            if (mask.AboveOnly)
            {
                coordinates += BlockCoordinates.Down;
            }
            else if (mask.BelowOnly)
            {
                coordinates += BlockCoordinates.Up;
            }

            Block block = Level.GetBlock(coordinates);

            var matches = mask.BlockList.Exists(entry => entry.Id == block.Id && (entry.IgnoreMetadata || block.Metadata == entry.Metadata));

            if (mask.Inverted)
            {
                return(!matches);
            }

            return(matches);
        }
        public void Add(MaskEntry entry)
        {
            if (!entry.IsValid)
            {
                return;
            }

            _masks.Add(entry);
        }
Beispiel #3
0
        public Mask(Level level, List <Block> blocks, bool ignoreMetadata)
        {
            Level = level;

            MaskEntry entry = new MaskEntry();

            foreach (var block in blocks)
            {
                entry.BlockList.Add(new BlockDataEntry()
                {
                    Id = block.Id, Metadata = block.Metadata, IgnoreMetadata = ignoreMetadata
                });
            }

            _masks = new[] { entry };
        }
 public bool Contains(MaskEntry entry)
 {
     return(_masks.Contains(entry));
 }
 public bool Remove(MaskEntry entry)
 {
     return(_masks.Remove(entry));
 }
Beispiel #6
0
        public virtual void Deserialize(Player player, string input)
        {
            Level = player.Level;

            // x1:0,air,log:12
            // x<blockId>:<blockData>,<blockId>:<blockData>, .. <blockId>:<blockData>

            // TODO: !, #existing, #region, <, >,

            if (input.StartsWith("x"))
            {
                input = input.Remove(0, 1);                                    // remove starting x
            }
            OriginalMask = input;

            string[] inputs = input.Split(' ');

            _masks = new MaskEntry[inputs.Length];
            for (int i = 0; i < inputs.Length; i++)
            {
                MaskEntry entry = new MaskEntry();
                _masks[i] = entry;

                string currentPattern = inputs[i];

                if (currentPattern.StartsWith(">"))                 // Only place above certain blocks
                {
                    entry.AboveOnly = true;
                    currentPattern  = currentPattern.Remove(0, 1);       // remove starting x
                }
                else if (currentPattern.StartsWith("<"))                 // Only place below certain blocks
                {
                    entry.BelowOnly = true;
                    currentPattern  = currentPattern.Remove(0, 1);       // remove starting x
                }
                else if (currentPattern.StartsWith("!"))                 // Only place if NOT certain blocks
                {
                    entry.Inverted = true;
                    currentPattern = currentPattern.Remove(0, 1);                     // remove starting x
                }

                var patterns = currentPattern.Split(',');

                foreach (var pattern in patterns)
                {
                    var blockInfos = pattern.Split(':');

                    var dataEntry = new BlockDataEntry();

                    byte id;

                    string binfo = blockInfos[0];
                    if (!byte.TryParse(binfo, out id))
                    {
                        id = BlockFactory.GetBlockIdByName(binfo);
                    }

                    dataEntry.Id = id;

                    if (blockInfos.Length == 2)
                    {
                        byte metadata;

                        byte.TryParse(blockInfos[1], out metadata);
                        dataEntry.Metadata       = metadata;
                        dataEntry.IgnoreMetadata = false;
                    }

                    entry.BlockList.Add(dataEntry);
                }
            }
        }