Esempio n. 1
0
        protected virtual Chunk Func_48443_a(World par1World, int par2, int par3, NBTTagCompound par4NBTTagCompound)
        {
            if (!par4NBTTagCompound.HasKey("Level"))
            {
                Console.WriteLine((new StringBuilder()).Append("Chunk file at ").Append(par2).Append(",").Append(par3).Append(" is missing level data, skipping").ToString());
                return(null);
            }

            if (!par4NBTTagCompound.GetCompoundTag("Level").HasKey("Sections"))
            {
                Console.WriteLine((new StringBuilder()).Append("Chunk file at ").Append(par2).Append(",").Append(par3).Append(" is missing block data, skipping").ToString());
                return(null);
            }

            Chunk chunk = Func_48444_a(par1World, par4NBTTagCompound.GetCompoundTag("Level"));

            if (!chunk.IsAtLocation(par2, par3))
            {
                Console.WriteLine((new StringBuilder()).Append("Chunk file at ").Append(par2).Append(",").Append(par3).Append(" is in the wrong location; relocating. (Expected ").Append(par2).Append(", ").Append(par3).Append(", got ").Append(chunk.XPosition).Append(", ").Append(chunk.ZPosition).Append(")").ToString());
                par4NBTTagCompound.SetInteger("xPos", par2);
                par4NBTTagCompound.SetInteger("zPos", par3);
                chunk = Func_48444_a(par1World, par4NBTTagCompound.GetCompoundTag("Level"));
            }

            chunk.RemoveUnknownBlocks();
            return(chunk);
        }
Esempio n. 2
0
        /// <summary>
        /// @args: Takes two arguments - first the name of the directory containing the world and second the new name for
        /// that world. @desc: Renames the world by storing the new name in level.dat. It does *not* rename the directory
        /// containing the world data.
        /// </summary>
        public virtual void RenameWorld(string par1Str, string par2Str)
        {
            string file = IOPath.Combine(SavesDirectory, par1Str);

            if (!File.Exists(file))
            {
                return;
            }

            string file1 = IOPath.Combine(file, "level.dat");

            if (File.Exists(file1))
            {
                try
                {
                    NBTTagCompound nbttagcompound  = CompressedStreamTools.ReadCompressed(new FileStream(file1, FileMode.Open));
                    NBTTagCompound nbttagcompound1 = nbttagcompound.GetCompoundTag("Data");
                    nbttagcompound1.SetString("LevelName", par2Str);
                    CompressedStreamTools.WriteCompressed(nbttagcompound, new FileStream(file1, FileMode.Create));
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.ToString());
                    Console.Write(exception.StackTrace);
                }
            }
        }
Esempio n. 3
0
        public WorldInfo(NBTTagCompound par1NBTTagCompound)
        {
            TerrainType = WorldType.DEFAULT;
            Hardcore    = false;
            RandomSeed  = par1NBTTagCompound.GetLong("RandomSeed");

            if (par1NBTTagCompound.HasKey("generatorName"))
            {
                string s = par1NBTTagCompound.GetString("generatorName");
                TerrainType = WorldType.ParseWorldType(s);

                if (TerrainType == null)
                {
                    TerrainType = WorldType.DEFAULT;
                }
                else if (TerrainType.Func_48626_e())
                {
                    int i = 0;

                    if (par1NBTTagCompound.HasKey("generatorVersion"))
                    {
                        i = par1NBTTagCompound.GetInteger("generatorVersion");
                    }

                    TerrainType = TerrainType.Func_48629_a(i);
                }
            }

            GameType = par1NBTTagCompound.GetInteger("GameType");

            if (par1NBTTagCompound.HasKey("MapFeatures"))
            {
                MapFeaturesEnabled = par1NBTTagCompound.Getbool("MapFeatures");
            }
            else
            {
                MapFeaturesEnabled = true;
            }

            SpawnX         = par1NBTTagCompound.GetInteger("SpawnX");
            SpawnY         = par1NBTTagCompound.GetInteger("SpawnY");
            SpawnZ         = par1NBTTagCompound.GetInteger("SpawnZ");
            WorldTime      = par1NBTTagCompound.GetLong("Time");
            LastTimePlayed = par1NBTTagCompound.GetLong("LastPlayed");
            SizeOnDisk     = par1NBTTagCompound.GetLong("SizeOnDisk");
            LevelName      = par1NBTTagCompound.GetString("LevelName");
            SaveVersion    = par1NBTTagCompound.GetInteger("version");
            RainTime       = par1NBTTagCompound.GetInteger("rainTime");
            Raining        = par1NBTTagCompound.Getbool("raining");
            ThunderTime    = par1NBTTagCompound.GetInteger("thunderTime");
            Thundering     = par1NBTTagCompound.Getbool("thundering");
            Hardcore       = par1NBTTagCompound.Getbool("hardcore");

            if (par1NBTTagCompound.HasKey("Player"))
            {
                PlayerTag = par1NBTTagCompound.GetCompoundTag("Player");
                Dimension = PlayerTag.GetInteger("Dimension");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Read the stack fields from a NBT object.
        /// </summary>
        public void ReadFromNBT(NBTTagCompound par1NBTTagCompound)
        {
            ItemID     = par1NBTTagCompound.GetShort("id");
            StackSize  = par1NBTTagCompound.GetByte("Count");
            ItemDamage = par1NBTTagCompound.GetShort("Damage");

            if (par1NBTTagCompound.HasKey("tag"))
            {
                StackTagCompound = par1NBTTagCompound.GetCompoundTag("tag");
            }
        }
        /// <summary>
        /// (abstract) Protected helper method to read subclass entity data from NBT.
        /// </summary>
        public override void ReadEntityFromNBT(NBTTagCompound par1NBTTagCompound)
        {
            Health = par1NBTTagCompound.GetShort("Health") & 0xff;
            Age    = par1NBTTagCompound.GetShort("Age");
            NBTTagCompound nbttagcompound = par1NBTTagCompound.GetCompoundTag("Item");

            ItemStack = ItemStack.LoadItemStackFromNBT(nbttagcompound);

            if (ItemStack == null)
            {
                SetDead();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// gets the world info
        /// </summary>
        public virtual WorldInfo GetWorldInfo(string par1Str)
        {
            string file = IOPath.Combine(SavesDirectory, par1Str);

            if (!Directory.Exists(file))
            {
                return(null);
            }

            string file1 = IOPath.Combine(file, "level.dat");

            if (File.Exists(file1))
            {
                try
                {
                    MemoryStream stream = new MemoryStream();
                    using (var fs = new FileStream(file1, FileMode.Open))
                    {
                        fs.CopyTo(stream);
                    }
                    stream.Seek(0, SeekOrigin.Begin);

                    NBTTagCompound nbttagcompound  = CompressedStreamTools.ReadCompressed(stream);
                    NBTTagCompound nbttagcompound2 = nbttagcompound.GetCompoundTag("Data");
                    return(new WorldInfo(nbttagcompound2));
                }
                catch (Exception exception)
                {
                    Utilities.LogException(exception);
                }
            }

            file1 = IOPath.Combine(file, "level.dat_old");

            if (File.Exists(file1))
            {
                try
                {
                    NBTTagCompound nbttagcompound1 = CompressedStreamTools.ReadCompressed(new FileStream(file1, FileMode.Open));
                    NBTTagCompound nbttagcompound3 = nbttagcompound1.GetCompoundTag("Data");
                    return(new WorldInfo(nbttagcompound3));
                }
                catch (Exception exception1)
                {
                    Utilities.LogException(exception1);
                }
            }

            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Loads an existing MapDataBase corresponding to the given String id from disk, instantiating the given Class, or
        /// returns null if none such file exists. args: Class to instantiate, String dataid
        /// </summary>
        public virtual WorldSavedData LoadData(Type par1Class, string par2Str)
        {
            WorldSavedData worldsaveddata = LoadedDataMap[par2Str];

            if (worldsaveddata != null)
            {
                return(worldsaveddata);
            }

            if (SaveHandler != null)
            {
                try
                {
                    string file = SaveHandler.GetMapFileFromName(par2Str);

                    if (file != null && File.Exists(file))
                    {
                        try
                        {
                            worldsaveddata = (WorldSavedData)Activator.CreateInstance(par1Class, new object[] { par2Str });
                        }
                        catch (Exception exception1)
                        {
                            throw new Exception(new StringBuilder().Append("Failed to instantiate ").Append(par1Class.ToString()).ToString(), exception1);
                        }

                        FileStream     fileinputstream = new FileStream(file, FileMode.Open);
                        NBTTagCompound nbttagcompound  = CompressedStreamTools.ReadCompressed(fileinputstream);
                        fileinputstream.Close();
                        worldsaveddata.ReadFromNBT(nbttagcompound.GetCompoundTag("data"));
                    }
                }
                catch (Exception exception)
                {
                    Utilities.LogException(exception);
                }
            }

            if (worldsaveddata != null)
            {
                LoadedDataMap[par2Str] = worldsaveddata;
                LoadedDataList.Add(worldsaveddata);
            }

            return(worldsaveddata);
        }
        /// <summary>
        /// Loads and returns the world info
        /// </summary>
        public virtual WorldInfo LoadWorldInfo()
        {
            string file = IOPath.Combine(SaveDirectory, "level.dat");

            if (File.Exists(file))
            {
                try
                {
                    NBTTagCompound nbttagcompound  = CompressedStreamTools.ReadCompressed(new FileStream(file, FileMode.Open));
                    NBTTagCompound nbttagcompound2 = nbttagcompound.GetCompoundTag("Data");
                    return(new WorldInfo(nbttagcompound2));
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.ToString());
                    Console.Write(exception.StackTrace);
                }
            }

            file = IOPath.Combine(SaveDirectory, "level.dat_old");

            if (File.Exists(file))
            {
                try
                {
                    NBTTagCompound nbttagcompound1 = CompressedStreamTools.ReadCompressed(new FileStream(file, FileMode.Open));
                    NBTTagCompound nbttagcompound3 = nbttagcompound1.GetCompoundTag("Data");
                    return(new WorldInfo(nbttagcompound3));
                }
                catch (Exception exception1)
                {
                    Console.WriteLine(exception1.ToString());
                    Console.Write(exception1.StackTrace);
                }
            }

            return(null);
        }
Esempio n. 9
0
        private void Func_48430_a(string par1File, string par2File, WorldChunkManager par3WorldChunkManager, int par4, int par5, IProgressUpdate par6IProgressUpdate)
        {
            try
            {
                FileInfo   file        = new FileInfo(par2File);
                string     s           = file.Name;
                RegionFile regionfile  = new RegionFile(par2File);
                RegionFile regionfile1 = new RegionFile(IOPath.Combine(par1File, (new StringBuilder()).Append(s.Substring(0, s.Length - ".mcr".Length)).Append(".mca").ToString()));

                for (int i = 0; i < 32; i++)
                {
                    for (int j = 0; j < 32; j++)
                    {
                        if (!regionfile.IsChunkSaved(i, j) || regionfile1.IsChunkSaved(i, j))
                        {
                            continue;
                        }

                        Stream datainputstream = regionfile.GetChunkFileStream(i, j);

                        if (datainputstream == null)
                        {
                            Console.WriteLine("Failed to fetch input stream");
                        }
                        else
                        {
                            NBTTagCompound nbttagcompound = CompressedStreamTools.Read(new BinaryReader(datainputstream));
                            datainputstream.Close();

                            NBTTagCompound nbttagcompound1 = nbttagcompound.GetCompoundTag("Level");

                            AnvilConverterData anvilconverterdata = ChunkLoader.Load(nbttagcompound1);
                            NBTTagCompound     nbttagcompound2    = new NBTTagCompound();
                            NBTTagCompound     nbttagcompound3    = new NBTTagCompound();
                            nbttagcompound2.SetTag("Level", nbttagcompound3);

                            ChunkLoader.ConvertToAnvilFormat(anvilconverterdata, nbttagcompound3, par3WorldChunkManager);

                            Stream dataoutputstream = regionfile1.GetChunkDataOutputStream(i, j);
                            CompressedStreamTools.Write(nbttagcompound2, new BinaryWriter(dataoutputstream));
                            dataoutputstream.Close();
                        }
                    }

                    int k = (int)Math.Round((100D * (double)(par4 * 1024)) / (double)(par5 * 1024));
                    int l = (int)Math.Round((100D * (double)((i + 1) * 32 + par4 * 1024)) / (double)(par5 * 1024));

                    if (l > k)
                    {
                        par6IProgressUpdate.SetLoadingProgress(l);
                    }
                }

                regionfile.Close();
                regionfile1.Close();
            }
            catch (IOException ioexception)
            {
                Utilities.LogException(ioexception);
            }
        }