// Find,

        /// <summary>
        /// Find object on screen
        /// </summary>
        /// <param name="findshader">The shader to use for the find</param>
        /// <param name="glstate">Render state</param>
        /// <param name="pos">Position on screen of find point</param>
        /// <param name="size">Screen size</param>
        /// <returns>Returns null, or
        /// item1 = return the list of blocks
        /// item2 = the found block
        /// item3 = the index within that found block
        /// item4 = the total index into the data (summed up)
        /// item5 = the z of the find
        ///</returns>

        public Tuple <List <GLObjectsWithLabels.BlockRef>, int, int, int, float> FindBlock(GLShaderPipeline findshader, GLRenderState glstate, Point pos, Size size)
        {
            var ret = Find(findshader, glstate, pos, size);       // return set, group, index, z

            if (ret != null)
            {
                GLObjectsWithLabels s = set[ret.Item1];                                                     // this is set

                var fb = BlockList.Find(x => x.Find(y => y.owl == s && y.blockindex == ret.Item2) != null); // find (set,blockindex) in block list

                if (fb != null)
                {
                    int c = 0;
                    foreach (var br in fb)      // until we get to owl/blockindex, count previous block counts so we get a cumulative total
                    {
                        if (br.owl == s && br.blockindex == ret.Item2)
                        {
                            break;
                        }
                        c += br.count;
                    }

                    return(new Tuple <List <GLObjectsWithLabels.BlockRef>, int, int, int, float>(fb, ret.Item2, ret.Item3, c + ret.Item3, ret.Item4));       // return block list, and real index into it
                }
            }

            return(null);
        }
Esempio n. 2
0
 /*********************************************/
 /// <summary>
 /// 元件索引函数
 /// </summary>
 /// <param name="id">方块ID</param>
 /// <returns></returns>
 public T GetUnit <T>(int id, int level) where T : class
 {
     if (typeof(T) == typeof(Block))
     {
         return(BlockList.Find((block) => block.Id == id && block.BlockLevel == level) as T);
     }
     if (typeof(T) == typeof(ShipComponent))
     {
         return(ShipComponentList.Find((shipComponent) => shipComponent.Id == id && shipComponent.ShipCompoionentLevel == level) as T);
     }
     return(null);
 }
Esempio n. 3
0
 public Options(Texture2D blockSprite, Texture2D resetSprite, Texture2D backSprite, int screenWidth, int screenHeight, SpriteFont spriteFont, BlockList blocks)
 {
     block = blockSprite;
     reset = resetSprite;
     back = backSprite;
     this.screenWidth = screenWidth;
     this.screenHeight = screenHeight;
     this.blocks = blocks;
     block1 = blocks.Find(1);
     block2 = blocks.Find(2);
     block3 = blocks.Find(3);
     block4 = blocks.Find(4);
     block5 = blocks.Find(5);
     block6 = blocks.Find(6);
     block7 = blocks.Find(7);
     font = spriteFont;
     backRect = new Rectangle(screenWidth / 2 - backSprite.Width / 2, screenHeight - backSprite.Height - 100, backSprite.Width, backSprite.Height);
 }
Esempio n. 4
0
        static void LoadBlocksAnvilFormat(ChunkData chunk, CompoundContainer nbtCompound, Version?version)
        {
            var sectionsList = nbtCompound.GetAsList("Sections");

            foreach (var o in sectionsList.cont)
            {
                var section = new ChunkSection(null);

                var compound = (CompoundContainer)o;
                if (!compound.Contains("Y") || !compound.Contains("Palette"))
                {
                    continue;
                }
                sbyte secY;
                unchecked
                {
                    secY = Convert.ToSByte(compound.Get("Y"));
                }
                section.palette.Clear();
                foreach (var cont in compound.GetAsList("Palette").cont)
                {
                    CompoundContainer block = (CompoundContainer)cont;
                    var proto = BlockList.Find((string)block.Get("Name"));
                    var bs    = new BlockState(proto);
                    if (block.Contains("Properties"))
                    {
                        bs.properties = block.GetAsCompound("Properties");
                    }
                    section.palette.Add(bs);
                }

                //1.15 uses the full range of bits where 1.16 doesn't use the last bits if they can't contain a block index
                int    indexLength = Math.Max(4, (int)Math.Log(section.palette.Count - 1, 2.0) + 1);
                long[] longs       = (long[])compound.Get("BlockStates");
                string bits        = "";
                for (int i = 0; i < longs.Length; i++)
                {
                    string newBits = "";
                    byte[] bytes   = BitConverter.GetBytes(longs[i]);
                    for (int j = 0; j < 8; j++)
                    {
                        newBits += Converter.ByteToBinary(bytes[j], true);
                    }
                    if (version == null || version.Value < Version.Release_1(16, 0))
                    {
                        bits += newBits;
                    }
                    else
                    {
                        bits += newBits.Substring(0, (int)Math.Floor(newBits.Length / (double)indexLength) * indexLength);
                    }
                }
                //TODO: needs testing
                for (int y = 0; y < 16; y++)
                {
                    for (int z = 0; z < 16; z++)
                    {
                        for (int x = 0; x < 16; x++)
                        {
                            section.blocks[x, y, z] = Converter.BitsToValue(bits, y * 256 + z * 16 + x, indexLength);
                        }
                    }
                }
                chunk.sections.Add(secY, section);
            }
        }