Beispiel #1
0
        public bool CanPlace(NbtWorld World)
        {
            int averageHeight = 0;
            int maxHeight = 0;
            BlockManager bm = (BlockManager)World.GetBlockManager ();
            for (int x = 0; x < _fp.X; ++x) {
                for (int z = 0; z < _fp.Z; ++z) {
                    int h = bm.GetHeight (x + _x, z + _z);
                    averageHeight += h;
                    if (maxHeight < h)
                        maxHeight = h;
                }
            }
            averageHeight /= _fp.X * _fp.Z;
            if (averageHeight > 120)
                return false;

            for (int x = 0; x < _fp.X; ++x) {
                for (int z = 0; z < _fp.Z; ++z) {
                    if (Abs (bm.GetHeight (x + _x, z + _z) - averageHeight) > 3)
                        return false;
                }
            }
            //Build the house!
            BuildHouse (_x, _z, averageHeight, bm);
            return true;
        }
Beispiel #2
0
        public bool CanPlace(int X, int Z, NbtWorld World)
        {
            if (X - _radius < 0 || X + _radius >= _xMax || Z - _radius < 0 || Z + _radius >= _zMax)
                return false;
            BlockManager bm = (BlockManager)World.GetBlockManager ();
            bool tr = true;
            foreach (IBuilding b in _buildings) {
                tr = tr && b.CanPlace (World);
            }
            if (tr) {
                foreach (IBuilding b in _buildings) {
                    b.Build (World);
                }

                for (int x = 0; x < 2 * _radius; ++x) {
                    for (int z = 0; z < 2 * _radius; ++z) {
                        int xp = x + X - _radius;
                        int zp = z + Z - _radius;
                        bool isEdge = x == 0 || z == 0 || x == 2 * _radius - 1 || z == 2 * _radius - 1;
                        if (isEdge) {
                            bm.SetID (xp, bm.GetHeight (xp, zp) - 1, zp, BlockInfo.Wool.ID);
                            bm.SetData (xp, bm.GetHeight (xp, zp) - 1, zp, (int)WoolColor.PURPLE);
                        }
                    }
                }
            }
            return tr;
        }
Beispiel #3
0
        /// <summary>
        /// Creates a copy of an existing <see cref="Level"/> object.
        /// </summary>
        /// <param name="p">The <see cref="Level"/> object to copy.</param>
        protected Level(Level p)
        {
            _world = p._world;

            _time       = p._time;
            _lastPlayed = p._lastPlayed;
            _spawnX     = p._spawnX;
            _spawnY     = p._spawnY;
            _spawnZ     = p._spawnZ;
            _sizeOnDisk = p._sizeOnDisk;
            _randomSeed = p._randomSeed;
            _version    = p._version;
            _name       = p._name;

            _raining     = p._raining;
            _thundering  = p._thundering;
            _rainTime    = p._rainTime;
            _thunderTime = p._thunderTime;

            _gameType    = p._gameType;
            _mapFeatures = p._mapFeatures;
            _hardcore    = p._hardcore;

            if (p._player != null)
            {
                _player = p._player.Copy();
            }

            if (p._source != null)
            {
                _source = p._source.Copy() as TagNodeCompound;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new <see cref="Level"/> object with reasonable defaults tied to the given world.
        /// </summary>
        /// <param name="world">The world that the <see cref="Level"/> should be tied to.</param>
        public Level(NbtWorld world)
        {
            _world = world;

            // Sane defaults
            _time       = 0;
            _lastPlayed = 0;
            _spawnX     = 0;
            _spawnY     = 64;
            _spawnZ     = 0;
            _sizeOnDisk = 0;
            _randomSeed = new Random().Next();
            //_version = 19132;
            _version   = 19133;
            _name      = "Untitled";
            _generator = "default";
            _hardcore  = 0;

            _generatorOptions = "";
            _generatorVersion = 1;
            _initialized      = 0;
            _allowCommands    = 0;
            _DayTime          = 0;
            _gameRules        = new GameRules();

            GameType       = GameType.SURVIVAL;
            UseMapFeatures = true;

            _source = new TagNodeCompound();
        }
Beispiel #5
0
        public RoadType GetRoadType(NbtWorld World)
        {
            //First, figure out which way the road is going.
            bool roadDir = Math.Abs ((End.Y - Start.Y) / (End.X - Start.X)) > 1.0;
            //Detect the min/max Y vals, as well as the average.

            return _rt;
        }
Beispiel #6
0
        public JsApi(string worldDirectory)
        {
            if (!Directory.Exists(worldDirectory))
                Directory.CreateDirectory(worldDirectory);

            this.world = AnvilWorld.Create(worldDirectory);
            this.blockManager = this.world.GetBlockManager();
        }
Beispiel #7
0
        /// <summary>
        /// Create an obsidian podium under the player's current location
        /// </summary>
        /// <param name="world">The world to be modified</param>
        /// <returns name="world">The world to be modified</returns>
        public static NbtWorld MakePodium(NbtWorld world)
        {
            BlockManager bm = (BlockManager)world.GetBlockManager();
            Player player = world.Level.Player;

            MakeArena(bm, player.Position, 2, 2);

            return world;
        }
Beispiel #8
0
        /// <summary>
        /// Save changes to a modified Minecraft world.
        /// </summary>
        /// <param name="world">The world to be saved. The world will be written back to the location it was opened from.</param>
        /// <returns name="world">The world to be saved</returns>
        public static NbtWorld SaveWorld(NbtWorld world)
        {
            RegionChunkManager rcm = (RegionChunkManager)world.GetChunkManager();
            rcm.RelightDirtyChunks();

            world.Save();

            return world;
        }
Beispiel #9
0
        public static Dictionary<String, Int32> GetPlayerPosition(NbtWorld world)
        {
            Vector3 pos = world.Level.Player.Position;

            return new Dictionary<String, Int32>
                {
                    {"X coordinate", (Int32)Math.Round(pos.X)},
                    {"Y coordinate", (Int32)Math.Round(pos.Y)},
                    {"Z coordinate", (Int32)Math.Round(pos.Z)}
                };
        }
Beispiel #10
0
 public ChunkRef GetChunk(NbtWorld World, int X, int Z)
 {
     ChunkRef tr;
     lock (World) {
         if (World.GetChunkManager ().ChunkExists (X, Z)) {
             World.GetChunkManager ().DeleteChunk (X, Z); //Delete the chunk if it exists.
         }
         tr = World.GetChunkManager ().CreateChunk (X, Z);
         Populate (tr);
         return tr;
     }
 }
Beispiel #11
0
 public void Build(NbtWorld World)
 {
     int averageHeight = 0;
     BlockManager bm = (BlockManager)World.GetBlockManager ();
     for (int x = 0; x < _fp.X; ++x) {
         for (int z = 0; z < _fp.Z; ++z) {
             averageHeight += bm.GetHeight (x + _x, z + _z);
         }
     }
     averageHeight /= _fp.X * _fp.Z;
     BuildHouse (_x, _z, averageHeight, bm);
 }
Beispiel #12
0
 public bool PlaceTown(NbtWorld world, Town t)
 {
     int x;
     int z;
     for (int i = 0; i < 5; ++i) {
         x = _mt.Next (_maxXSearchArea);
         z = _mt.Next (_maxZSearchArea);
         if (t.CanPlace (x, z, world))
             return true;
     }
     return false;
 }
Beispiel #13
0
        /// <summary>
        /// Creates a new <see cref="Level"/> object with reasonable defaults tied to the given world.
        /// </summary>
        /// <param name="world">The world that the <see cref="Level"/> should be tied to.</param>
        public Level(NbtWorld world)
        {
            _world = world;

            // Sane defaults
            _time       = 0;
            _lastPlayed = 0;
            _spawnX     = 0;
            _spawnY     = 64;
            _spawnZ     = 0;
            _sizeOnDisk = 0;
            _randomSeed = new Random().Next();
            _version    = 19132;
            _name       = "Untitled";
        }
Beispiel #14
0
 public void PopulateWorld(NbtWorld World, int Width, int Height)
 {
     Thread[] ts = new Thread [Width * Height];
     ChunkRef tr;
     for (int x = 0; x < Width; ++x) {
         for (int z = 0; z < Height; ++z) {
             Thread t = new Thread (Run);
             t.Name = "Chunk Generation Thread (" + x + ", " + z + ")";
             t.Start (new ChunkThreadParams (x, z, 1, 1, World));
             ts [x + z * Width] = t;
         }
     }
     for (int i = 0; i < ts.Length; ++i) {
         ts [i].Join ();
     }
 }
Beispiel #15
0
        public ChunkProcessor(NbtWorld world, List<BlockType> blockArgs)
        {
            _world = world;
            _blockIds = new Dictionary<int, Dictionary<int, BlockType>>();
            foreach (var blockArg in blockArgs)
            {
                if (_blockIds.ContainsKey(blockArg.Id))
                {
                    _blockIds[blockArg.Id][blockArg.Data] = blockArg;
                    continue;
                }
                _blockIds[blockArg.Id] = new Dictionary<int, BlockType>();
                _blockIds[blockArg.Id][blockArg.Data] = blockArg;
            }

            _blockArgs = blockArgs;
        }
Beispiel #16
0
        public void initializeMinecraftWorld()
        {
            currentWorld = AnvilWorld.Create(Settings.Default.outputPath);

            // We can set different world parameters
            currentWorld.Level.LevelName = Settings.Default.levelName;
            currentWorld.Level.Spawn = new SpawnPoint(0, 255, 0);
            if (Settings.Default.gameMode == 0)
            {
                currentWorld.Level.GameType = GameType.SURVIVAL;
            }
            else
            {
                currentWorld.Level.GameType = GameType.CREATIVE;
                currentWorld.Level.AllowCommands = true;
            }
        }
Beispiel #17
0
        /// <summary>
        /// Creates a new <see cref="Level"/> object with reasonable defaults tied to the given world.
        /// </summary>
        /// <param name="world">The world that the <see cref="Level"/> should be tied to.</param>
        public Level(NbtWorld world)
        {
            _world = world;

            // Sane defaults
            _time       = 0;
            _lastPlayed = 0;
            _spawnX     = 0;
            _spawnY     = 64;
            _spawnZ     = 0;
            _sizeOnDisk = 0;
            _randomSeed = new Random().Next();
            _version    = 19132;
            _name       = "Untitled";

            GameType       = GameType.SURVIVAL;
            UseMapFeatures = true;
        }
Beispiel #18
0
        /// <summary>
        /// Creates a copy of an existing <see cref="Level"/> object.
        /// </summary>
        /// <param name="p">The <see cref="Level"/> object to copy.</param>
        protected Level(Level p)
        {
            _world = p._world;

            _time       = p._time;
            _lastPlayed = p._lastPlayed;
            _spawnX     = p._spawnX;
            _spawnY     = p._spawnY;
            _spawnZ     = p._spawnZ;
            _sizeOnDisk = p._sizeOnDisk;
            _randomSeed = p._randomSeed;
            _version    = p._version;
            _name       = p._name;
            _generator  = p._generator;

            _raining     = p._raining;
            _thundering  = p._thundering;
            _rainTime    = p._rainTime;
            _thunderTime = p._thunderTime;

            _gameType    = p._gameType;
            _mapFeatures = p._mapFeatures;
            _hardcore    = p._hardcore;

            _generatorVersion = p._generatorVersion;
            _generatorOptions = p._generatorOptions;
            _initialized      = p._initialized;
            _allowCommands    = p._allowCommands;
            _DayTime          = p._DayTime;
            _gameRules        = p._gameRules.Copy();

            if (p._player != null)
            {
                _player = p._player.Copy();
            }

            if (p._source != null)
            {
                _source = p._source.Copy() as TagNodeCompound;
            }
        }
Beispiel #19
0
        /// <summary>
        /// Creates a copy of an existing <see cref="Level"/> object.
        /// </summary>
        /// <param name="p">The <see cref="Level"/> object to copy.</param>
        protected Level(Level p)
        {
            _world = p._world;

            _time       = p._time;
            _lastPlayed = p._lastPlayed;
            _spawnX     = p._spawnX;
            _spawnY     = p._spawnY;
            _spawnZ     = p._spawnZ;
            _sizeOnDisk = p._sizeOnDisk;
            _randomSeed = p._randomSeed;
            _version    = p._version;
            _name       = p._name;

            _raining     = p._raining;
            _thundering  = p._thundering;
            _rainTime    = p._rainTime;
            _thunderTime = p._thunderTime;

            if (p._player != null)
            {
                _player = p._player.Copy();
            }
        }
Beispiel #20
0
 public ChunkThreadParams(int X, int Z, int Width, int Height, NbtWorld World)
 {
     _x = X;
     _z = Z;
     _width = Width;
     _height = Height;
     _world = World;
 }
        private IEnumerable<ChunkRef> CreateWorld(NbtWorld world)
        {
            var cm = world.GetChunkManager();
            var radius = 10;
            int xmin = -radius;
            int xmax = radius;
            int zmin = -radius;
            int zmaz = radius;

            world.Level.AllowCommands = true;
            world.Level.LevelName = "MineDefined";
            world.Level.Spawn = new SpawnPoint(-5, -5, 9);

            world.Level.SetDefaultPlayer();
            world.Level.Player.GameType= PlayerGameType.Creative;
            world.Level.Player.Position = new Vector3() {
                X = -5,
                Y = 9,
                Z = -5
            };
            world.Level.Player.IsOnGround = false;
            var chunks = new List<ChunkRef>();

            // We'll create chunks at chunk coordinates xmin,zmin to xmax,zmax
            for (int xi = xmin; xi < xmax; xi++)
            {
                for (int zi = zmin; zi < zmaz; zi++)
                {
                    // This line will create a default empty chunk, and create a
                    // backing region file if necessary (which will immediately be
                    // written to disk)
                    ChunkRef chunk = cm.CreateChunk(xi, zi);
                    chunks.Add(chunk);

                    // This will suppress generating caves, ores, and all those
                    // other goodies.
                    chunk.IsTerrainPopulated = true;

                    // Auto light recalculation is horrifically bad for creating
                    // chunks from scratch, because we're placing thousands
                    // of blocks.  Turn it off.
                    chunk.Blocks.AutoLight = false;

                    // Set the blocks
                    FlatChunk(chunk, 8);

                    //Console.WriteLine("Built Chunk {0},{1}", chunk.X, chunk.Z);

                    // Save the chunk to disk so it doesn't hang around in RAM
                }
            }
            return chunks;
        }
Beispiel #22
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            if(folderBrowser.ShowDialog() == DialogResult.OK)
            {
                selectedWorldPath = folderBrowser.SelectedPath;
                aDisplayReady = false;

                string worldPath = selectedWorldPath;

                aSelectedChunks.Clear();
                zoomLabel.Text = "1";

                NbtWorld world = NbtWorld.Open(worldPath);
                string worldName = world.Level.LevelName;
                RegionChunkManager chunkMan = (RegionChunkManager)world.GetChunkManager(0);

                aWorld = world;
                aChunkMan = chunkMan;

                Bitmap map = GenerateMap(world, chunkMan);

                mapBox.Image = map;
                mapBox.Width = map.Width;
                mapBox.Height = map.Height;

                handleGraphics();

                /*string MapDirPath = System.IO.Directory.GetCurrentDirectory() + @"\MapData\";
                if (!Directory.Exists(MapDirPath))
                {
                    Directory.CreateDirectory(MapDirPath);
                }

                map.Save(MapDirPath + worldName + ".png");*/

                aDisplayReady = true;
            }
        }
Beispiel #23
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 & !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);
                        }
                    }
                }
            }*/
        }
Beispiel #24
0
        public Bitmap GenerateMap(NbtWorld world, RegionChunkManager chunkMan)
        {
            int[,] colors = { { 0, 255, 0, 255 }, { 1, 128, 128, 128 }, { 2, 64, 192, 64 }, { 3, 128, 48, 0 }, { 4, 64, 64, 64 }, { 5, 255, 128, 64 }, { 6, 0, 192, 0 }, { 7, 32, 32, 32 }, { 8, 16, 16, 128 }, { 9, 16, 16, 128 }, { 10, 255, 0, 0 }, { 11, 255, 0, 0 }, { 12, 255, 255, 192 }, { 13, 156, 128, 128 }, { 14, 192, 192, 128 }, { 15, 192, 128, 96 }, { 16, 48, 48, 32 }, { 17, 192, 96, 48 }, { 18, 0, 128, 0 }, { 19, 255, 255, 0 }, { 20, 224, 224, 224 }, { 21, 128, 128, 192 }, { 22, 64, 64, 255 }, { 23, 64, 64, 64 }, { 24, 128, 128, 96 }, { 25, 192, 96, 48 }, { 26, 255, 128, 128 }, { 27, 224, 128, 128 }, { 28, 224, 128, 128 }, { 29, 128, 192, 48 }, { 30, 224, 224, 224 }, { 31, 96, 32, 0 }, { 32, 128, 64, 32 }, { 33, 255, 192, 96 }, { 34, 255, 192, 96 }, { 35, 224, 224, 224 }, { 36, 0, 0, 0 }, { 37, 255, 255, 0 }, { 38, 255, 48, 48 }, { 39, 192, 128, 96 }, { 40, 255, 192, 96 }, { 41, 255, 255, 64 }, { 42, 192, 192, 192 }, { 43, 140, 140, 140 }, { 44, 150, 150, 150 }, { 45, 192, 64, 64 }, { 46, 128, 0, 0 }, { 47, 255, 128, 64 }, { 48, 64, 128, 64 }, { 49, 16, 16, 24 }, { 50, 255, 255, 0 }, { 51, 255, 224, 0 }, { 52, 96, 128, 192 }, { 53, 255, 192, 96 }, { 54, 224, 128, 64 }, { 55, 128, 0, 0 }, { 56, 128, 138, 92 }, { 57, 128, 192, 255 }, { 58, 192, 96, 48 }, { 59, 192, 255, 0 }, { 60, 192, 96, 0 }, { 61, 96, 96, 96 }, { 62, 96, 96, 96 }, { 63, 255, 128, 64 }, { 64, 255, 128, 64 }, { 65, 255, 128, 64 }, { 66, 224, 224, 192 }, { 67, 78, 78, 78 }, { 68, 255, 128, 64 }, { 69, 128, 96, 64 }, { 70, 133, 133, 133 }, { 71, 192, 192, 192 }, { 72, 255, 192, 128 }, { 73, 224, 128, 128 }, { 74, 224, 128, 128 }, { 75, 255, 64, 64 }, { 76, 255, 64, 64 }, { 77, 255, 64, 64 }, { 78, 255, 255, 255 }, { 79, 0, 192, 224 }, { 80, 255, 255, 255 }, { 81, 0, 192, 0 }, { 82, 170, 160, 170 }, { 83, 96, 255, 32 }, { 84, 192, 96, 48 }, { 85, 255, 128, 64 }, { 86, 255, 128, 0 }, { 87, 128, 24, 48 }, { 88, 128, 96, 64 }, { 89, 255, 224, 96 }, { 90, 128, 0, 255 }, { 91, 255, 128, 0 }, { 92, 255, 192, 192 }, { 93, 255, 96, 96 }, { 94, 255, 96, 96 }, { 95, 0, 0, 0 }, { 96, 255, 128, 64 } };

            int[] minXZ = { 0, 0 };
            int[] maxXZ = { 0, 0 };

            foreach (ChunkRef chunk in chunkMan)
            {
                minXZ[0] = Math.Min(chunk.X * 16, minXZ[0]);
                minXZ[1] = Math.Min(chunk.Z * 16, minXZ[1]);

                maxXZ[0] = Math.Max(16 + chunk.X * 16, maxXZ[0]);
                maxXZ[1] = Math.Max(16 + chunk.Z * 16, maxXZ[1]);
            }

            aMinXZ = minXZ;

            int[] worldSize = { maxXZ[0] - minXZ[0], maxXZ[1] - minXZ[1] };

            Bitmap map = new Bitmap(worldSize[0], worldSize[1]);

            int y;
            int block;
            int[] pixelpos = { 0, 0 };
            Color color;

            long chunkCount = chunkMan.Count();
            long chunkCurrent = 0;

            foreach (ChunkRef chunk in chunkMan)
            {
                for (int x = 0; x < 16; x++)
                {
                    for (int z = 0; z < 16; z++)
                    {
                        y = chunk.Blocks.GetHeight(x, z);

                        if (y > 0 && y < 256)
                        {
                            block = chunk.Blocks.GetID(x, y - 1, z);

                            int blockColor = block;

                            if (blockColor < colors.GetUpperBound(0) + 1)
                            {
                                color = color = Color.FromArgb(colors[blockColor, 1], colors[blockColor, 2], colors[blockColor, 3]);
                            }
                            else
                            {
                                color = color = Color.FromArgb(255, 0, 255);
                            }

                            if (x == 0 || z == 0)
                            {
                                color = Color.FromArgb(color.R / 2, color.G / 2, color.B / 2);
                            }
                        }
                        else
                        {
                            color = Color.Black;
                        }

                        pixelpos[0] = Math.Abs(minXZ[0]) + (chunk.X * 16) + x;
                        pixelpos[1] = Math.Abs(minXZ[1]) + (chunk.Z * 16) + z;

                        map.SetPixel(pixelpos[0], pixelpos[1], color);
                    }
                }
                chunkCurrent++;
                pbProgress.Value = (int)(100.0 * ((double)chunkCurrent / (double)chunkCount));
                pbProgress.PerformStep();
            }
            pbProgress.Value = 0;
            pbProgress.PerformStep();

            return map;
        }
Beispiel #25
0
 public BlockStamp(NbtWorld world)
 {
     _world = world;
 }
        public void ApplyChunk (NbtWorld world, ChunkRef chunk)
        {
            if (opt.OPT_V) {
                Console.WriteLine("Generating {0} size {1} deposits of {2} between {3} and {4}",
                    opt.OPT_ROUNDS, opt.OPT_SIZE, opt.OPT_ID, opt.OPT_MIN, opt.OPT_MAX);
            }

            IGenerator generator;
            if (opt.OPT_DATA == null) {
                generator = new NativeGenOre((int)opt.OPT_ID, (int)opt.OPT_SIZE);
                ((NativeGenOre)generator).MathFix = opt.OPT_MATHFIX;
            }
            else {
                generator = new NativeGenOre((int)opt.OPT_ID, (int)opt.OPT_DATA, (int)opt.OPT_SIZE);
                ((NativeGenOre)generator).MathFix = opt.OPT_MATHFIX;
            }

            IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
            IBlockManager bm = new GenOreBlockManager(cm, opt);

            for (int i = 0; i < opt.OPT_ROUNDS; i++) {
                if (opt.OPT_VV) {
                    Console.WriteLine("Generating round {0}...", i);
                }

                int x = chunk.X * chunk.Blocks.XDim + rand.Next(chunk.Blocks.XDim);
                int y = (int)opt.OPT_MIN + rand.Next((int)opt.OPT_MAX - (int)opt.OPT_MIN);
                int z = chunk.Z * chunk.Blocks.ZDim + rand.Next(chunk.Blocks.ZDim);

                generator.Generate(bm, rand, x, y, z);
            }
        }
Beispiel #27
0
 public WorldStamp(NbtWorld world)
 {
     _world = world;
     _blockManager = _world.GetBlockManager();
 }
Beispiel #28
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);
                        }
                    }
                }
            }*/
        }