BiomePainter.RegionUtil.AddorRemoveBlocksSelection C# (CSharp) Method

AddorRemoveBlocksSelection() public static method

public static AddorRemoveBlocksSelection ( RegionFile region, Bitmap b, Color selectionColor, int blockIds, bool add ) : void
region Minecraft.RegionFile
b System.Drawing.Bitmap
selectionColor Color
blockIds int
add bool
return void
        public static void AddorRemoveBlocksSelection(RegionFile region, Bitmap b, Color selectionColor, int[] blockIds, bool add)
        {
            if (blockIds == null || blockIds.Length == 0)
                return;

            List<int> ids = new List<int>(blockIds);

            foreach (Chunk c in region.Chunks)
            {
                if (c.Root == null)
                    continue;
                Coord chunkOffset = new Coord(region.Coords);
                chunkOffset.RegiontoChunk();
                chunkOffset = new Coord(c.Coords.X - chunkOffset.X, c.Coords.Z - chunkOffset.Z);
                chunkOffset.ChunktoAbsolute();

                TAG_Compound[] sections = new TAG_Compound[16];
                int highest = -1;
                foreach (TAG t in (TAG[])c.Root["Level"]["Sections"])
                {
                    byte index = (byte)t["Y"];
                    if (index > highest)
                        highest = index;
                    sections[index] = (TAG_Compound)t;
                }

                //chunk exists but all blocks are air
                if (highest < 0)
                    return;

                highest = ((highest + 1) * 16) - 1;

                for (int z = 0; z < 16; z++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        int y;
                        if (c.ManualHeightmap[x + z * 16] >= 0)
                            y = c.ManualHeightmap[x + z * 16];
                        else
                        {
                            y = GetHeight(sections, x, z, highest);
                            c.ManualHeightmap[x + z * 16] = y;
                        }
                        if (y < 0)
                            continue;

                        if (ids.Contains(GetBlock(sections, x, y, z)))
                        {
                            b.SetPixel(OFFSETX + chunkOffset.X + x, OFFSETY + chunkOffset.Z + z, add ? selectionColor : Color.Transparent);
                        }
                    }
                }
            }
        }

Usage Example

Esempio n. 1
0
        private void btnAddorRemovebyBlocks_Click(object sender, EventArgs e)
        {
            if (world == null || region == null)
            {
                return;
            }
            int[] blockIds = null;
            bool  add      = sender == btnAddbyBlocks ? true : false;

            switch ((String)cmbBlockType.SelectedItem)
            {
            case "Cacti & Dead Bushes":
                blockIds = new int[] { 81, 32 };
                break;

            case "Dirt & Grass":
                blockIds = new int[] { 2, 3 };
                break;

            case "Flowers & Tall Grass":
                blockIds = new int[] { 31, 37, 38 };
                break;

            case "Gravel":
                blockIds = new int[] { 13 };
                break;

            case "Lily Pads & Vines":
                blockIds = new int[] { 111, 106 };
                break;

            case "Leaves & Logs":
                blockIds = new int[] { 17, 18 };
                break;

            case "Ice":
                blockIds = new int[] { 79 };
                break;

            case "Sand":
                blockIds = new int[] { 12 };
                break;

            case "Snow":
                blockIds = new int[] { 78, 80 };
                break;

            case "Stone":
                blockIds = new int[] { 1 };
                break;

            case "Water":
                blockIds = new int[] { 8, 9 };
                break;

            case "Input Block ID":
            {
                String msg   = String.Format("Type the ID number of the block type you want to {0}.{1}See http://www.minecraftwiki.net/wiki/Data_values for more info.", add ? "add to the selection" : "remove from the selection", Environment.NewLine);
                String input = "";
                while (true)
                {
                    input = InputBox.Show(msg, add ? "Add to Selection" : "Remove From Selection", input);
                    if (input.Length == 0)
                    {
                        break;
                    }

                    Match m = Regex.Match(input, @"^(\d+)$");
                    if (m.Groups.Count < 2)
                    {
                        msg = "Unable to parse block ID. Please try again or click cancel.";
                    }
                    else
                    {
                        int id;
                        if (!Int32.TryParse(m.Groups[1].Value, out id))
                        {
                            msg = "Unable to parse block ID. Please try again or click cancel.";
                        }
                        else
                        {
                            blockIds = new int[] { id };
                            break;
                        }
                    }
                }
            }
            break;
            }
            if (blockIds != null)
            {
                UpdateStatus(add ? "Adding to selection" : "Removing from selection");
                RegionUtil.AddorRemoveBlocksSelection(region, imgRegion.Layers[SELECTIONLAYER].Image, imgRegion.SelectionColor, blockIds, add);
                UpdateStatus("");
                imgRegion.Redraw();
                history.RecordSelectionState(imgRegion.Layers[SELECTIONLAYER].Image, add ? "Select by Block" : "Deselect by Block");
            }
        }