Пример #1
0
        public override bool ApplyToolBuild(WorldEdit worldEdit, Block block, BlockPos pos, ushort oldBlockId, BlockFacing onBlockFace, Vec3f hitPos, bool didOffset)
        {
            if (heights == null)
            {
                return(false);
            }

            worldEdit.Good("Ok, placing blocks, this may take a while");

            int      width  = heights.GetLength(0);
            int      length = heights.GetLength(1);
            BlockPos tmpPos = new BlockPos();

            IBlockAccessor blockAccessorBulk = worldEdit.sapi.World.BulkBlockAccessor;

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < length; z++)
                {
                    int height = heights[x, z];

                    tmpPos.Set(pos.X + x - width / 2, pos.Y, pos.Z + z - length / 2);

                    for (int y = 0; y < height; y++)
                    {
                        blockAccessorBulk.SetBlock(block.BlockId, tmpPos);
                        tmpPos.Up();
                    }
                }
            }

            blockAccessorBulk.Commit();

            return(false);
        }
Пример #2
0
        public void TryLoadHeightMap(WorldEdit worldEdit, string filename)
        {
            string folderPath = worldEdit.sapi.GetOrCreateDataPath("Heightmaps");
            string filePath   = Path.Combine(folderPath, filename);

            if (!File.Exists(filePath))
            {
                worldEdit.Bad("No such file found.");
                return;
            }

            Bitmap bmp = null;

            try
            {
                bmp = new Bitmap(filePath);
            } catch (Exception e)
            {
                worldEdit.Bad("Unable to load {0}: {1}", filePath, e);
                return;
            }

            heights = new int[bmp.Width, bmp.Height];

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    heights[x, y] = bmp.GetPixel(x, y).R;
                }
            }

            worldEdit.Good("Ok, loaded {0}x{1} image", bmp.Width, bmp.Height);

            bmp.Dispose();
        }