示例#1
0
        public static ItemStack LoadItemStackFromNBT(NBTTagCompound par0NBTTagCompound)
        {
            ItemStack itemstack = new ItemStack();

            itemstack.ReadFromNBT(par0NBTTagCompound);
            return(itemstack.GetItem() == null ? null : itemstack);
        }
示例#2
0
 /// <summary>
 /// Writes food stats to an NBT object.
 /// </summary>
 public virtual void WriteNBT(NBTTagCompound par1NBTTagCompound)
 {
     par1NBTTagCompound.SetInteger("foodLevel", FoodLevel);
     par1NBTTagCompound.SetInteger("foodTickTimer", FoodTimer);
     par1NBTTagCompound.SetFloat("foodSaturationLevel", FoodSaturationLevel);
     par1NBTTagCompound.SetFloat("foodExhaustionLevel", FoodExhaustionLevel);
 }
示例#3
0
        /// <summary>
        /// (abstract) Protected helper method to read subclass entity data from NBT.
        /// </summary>
        public override void ReadEntityFromNBT(NBTTagCompound par1NBTTagCompound)
        {
            MinecartType = par1NBTTagCompound.GetInteger("Type");

            if (MinecartType == 2)
            {
                PushX = (float)par1NBTTagCompound.GetDouble("PushX");
                PushZ = (float)par1NBTTagCompound.GetDouble("PushZ");
                Fuel  = par1NBTTagCompound.GetShort("Fuel");
            }
            else if (MinecartType == 1)
            {
                NBTTagList nbttaglist = par1NBTTagCompound.GetTagList("Items");
                CargoItems = new ItemStack[GetSizeInventory()];

                for (int i = 0; i < nbttaglist.TagCount(); i++)
                {
                    NBTTagCompound nbttagcompound = (NBTTagCompound)nbttaglist.TagAt(i);
                    int            j = nbttagcompound.GetByte("Slot") & 0xff;

                    if (j >= 0 && j < CargoItems.Length)
                    {
                        CargoItems[j] = ItemStack.LoadItemStackFromNBT(nbttagcompound);
                    }
                }
            }
        }
        /// <summary>
        /// Creates a new entity and loads its data from the specified NBT.
        /// </summary>
        public static TileEntity CreateAndLoadEntity(NBTTagCompound par0NBTTagCompound)
        {
            TileEntity tileentity = null;

            try
            {
                Type class1 = NameToClassMap[par0NBTTagCompound.GetString("id")];

                if (class1 != null)
                {
                    tileentity = (TileEntity)Activator.CreateInstance(class1);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
            }

            if (tileentity != null)
            {
                tileentity.ReadFromNBT(par0NBTTagCompound);
            }
            else
            {
                Console.WriteLine((new StringBuilder()).Append("Skipping TileEntity with id ").Append(par0NBTTagCompound.GetString("id")).ToString());
            }

            return(tileentity);
        }
示例#5
0
        /// <summary>
        /// Saves the given MapDataBase to disk.
        /// </summary>
        private void SaveData(WorldSavedData par1WorldSavedData)
        {
            if (SaveHandler == null)
            {
                return;
            }

            try
            {
                string file = SaveHandler.GetMapFileFromName(par1WorldSavedData.MapName);

                if (file != null)
                {
                    NBTTagCompound nbttagcompound = new NBTTagCompound();
                    par1WorldSavedData.WriteToNBT(nbttagcompound);
                    NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                    nbttagcompound1.SetCompoundTag("data", nbttagcompound);
                    FileStream fileoutputstream = new FileStream(file, FileMode.Create);
                    CompressedStreamTools.WriteCompressed(nbttagcompound1, fileoutputstream);
                    fileoutputstream.Close();
                }
            }
            catch (Exception exception)
            {
                Utilities.LogException(exception);
            }
        }
示例#6
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);
                }
            }
        }
        /// <summary>
        /// (abstract) Protected helper method to read subclass entity data from NBT.
        /// </summary>
        public override void ReadEntityFromNBT(NBTTagCompound par1NBTTagCompound)
        {
            Direction = par1NBTTagCompound.GetByte("Dir");
            XPosition = par1NBTTagCompound.GetInteger("TileX");
            YPosition = par1NBTTagCompound.GetInteger("TileY");
            ZPosition = par1NBTTagCompound.GetInteger("TileZ");
            string s = par1NBTTagCompound.GetString("Motive");

            Art[] aenumart = Art.ArtArray;
            int   i        = aenumart.Length;

            for (int j = 0; j < i; j++)
            {
                Art enumart = aenumart[j];

                if (enumart.Title.Equals(s))
                {
                    Art = enumart;
                }
            }

            if (Art == null)
            {
                Art = Art.Kebab;
            }

            Func_412_b(Direction);
        }
示例#8
0
        /// <summary>
        /// (abstract) Protected helper method to write subclass entity data to NBT.
        /// </summary>
        public override void WriteEntityToNBT(NBTTagCompound par1NBTTagCompound)
        {
            par1NBTTagCompound.SetInteger("Type", MinecartType);

            if (MinecartType == 2)
            {
                par1NBTTagCompound.SetDouble("PushX", PushX);
                par1NBTTagCompound.SetDouble("PushZ", PushZ);
                par1NBTTagCompound.SetShort("Fuel", (short)Fuel);
            }
            else if (MinecartType == 1)
            {
                NBTTagList nbttaglist = new NBTTagList();

                for (int i = 0; i < CargoItems.Length; i++)
                {
                    if (CargoItems[i] != null)
                    {
                        NBTTagCompound nbttagcompound = new NBTTagCompound();
                        nbttagcompound.SetByte("Slot", (byte)i);
                        CargoItems[i].WriteToNBT(nbttagcompound);
                        nbttaglist.AppendTag(nbttagcompound);
                    }
                }

                par1NBTTagCompound.SetTag("Items", nbttaglist);
            }
        }
        /// <summary>
        /// create a new instance of an entity from NBT store
        /// </summary>
        public static Entity CreateEntityFromNBT(NBTTagCompound par0NBTTagCompound, World par1World)
        {
            Entity entity = null;

            try
            {
                Type class1 = StringToClassMapping[par0NBTTagCompound.GetString("id")];

                if (class1 != null)
                {
                    entity = (Entity)Activator.CreateInstance(class1, new object[] { par1World });
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
            }

            if (entity != null)
            {
                entity.ReadFromNBT(par0NBTTagCompound);
            }
            else
            {
                Console.WriteLine((new StringBuilder()).Append("Skipping Entity with id ").Append(par0NBTTagCompound.GetString("id")).ToString());
            }

            return(entity);
        }
示例#10
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);
        }
示例#11
0
        private void UpdateTagCompound(NBTTagCompound par1NBTTagCompound, NBTTagCompound par2NBTTagCompound)
        {
            par1NBTTagCompound.SetLong("RandomSeed", RandomSeed);
            par1NBTTagCompound.SetString("generatorName", TerrainType.Func_48628_a());
            par1NBTTagCompound.SetInteger("generatorVersion", TerrainType.GetGeneratorVersion());
            par1NBTTagCompound.SetInteger("GameType", GameType);
            par1NBTTagCompound.Setbool("MapFeatures", MapFeaturesEnabled);
            par1NBTTagCompound.SetInteger("SpawnX", SpawnX);
            par1NBTTagCompound.SetInteger("SpawnY", SpawnY);
            par1NBTTagCompound.SetInteger("SpawnZ", SpawnZ);
            par1NBTTagCompound.SetLong("Time", WorldTime);
            par1NBTTagCompound.SetLong("SizeOnDisk", SizeOnDisk);
            par1NBTTagCompound.SetLong("LastPlayed", JavaHelper.CurrentTimeMillis());
            par1NBTTagCompound.SetString("LevelName", LevelName);
            par1NBTTagCompound.SetInteger("version", SaveVersion);
            par1NBTTagCompound.SetInteger("rainTime", RainTime);
            par1NBTTagCompound.Setbool("raining", Raining);
            par1NBTTagCompound.SetInteger("thunderTime", ThunderTime);
            par1NBTTagCompound.Setbool("thundering", Thundering);
            par1NBTTagCompound.Setbool("hardcore", Hardcore);

            if (par2NBTTagCompound != null)
            {
                par1NBTTagCompound.SetCompoundTag("Player", par2NBTTagCompound);
            }
        }
        public static void SafeWrite(NBTTagCompound par0NBTTagCompound, string par1File)
        {
            string file = System.IO.Path.Combine((new StringBuilder()).Append(System.IO.Path.GetFullPath(par1File)).Append("_tmp").ToString());

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            Write(par0NBTTagCompound, file);

            if (File.Exists(par1File))
            {
                File.Delete(par1File);
            }

            if (File.Exists(par1File))
            {
                throw new IOException((new StringBuilder()).Append("Failed to delete ").Append(par1File).ToString());
            }
            else
            {
                File.Move(file, par1File);
                return;
            }
        }
示例#13
0
        /// <summary>
        /// Gets the NBTTagCompound for the worldInfo
        /// </summary>
        public virtual NBTTagCompound GetNBTTagCompound()
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();

            UpdateTagCompound(nbttagcompound, PlayerTag);
            return(nbttagcompound);
        }
示例#14
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");
            }
        }
示例#15
0
 /// <summary>
 /// (abstract) Protected helper method to read subclass entity data from NBT.
 /// </summary>
 public override void ReadEntityFromNBT(NBTTagCompound par1NBTTagCompound)
 {
     XTile    = par1NBTTagCompound.GetShort("xTile");
     YTile    = par1NBTTagCompound.GetShort("yTile");
     ZTile    = par1NBTTagCompound.GetShort("zTile");
     InTile   = par1NBTTagCompound.GetByte("inTile") & 0xff;
     InGround = par1NBTTagCompound.GetByte("inGround") == 1;
 }
示例#16
0
 /// <summary>
 /// (abstract) Protected helper method to write subclass entity data to NBT.
 /// </summary>
 public override void WriteEntityToNBT(NBTTagCompound par1NBTTagCompound)
 {
     par1NBTTagCompound.SetShort("xTile", (short)XTile);
     par1NBTTagCompound.SetShort("yTile", (short)YTile);
     par1NBTTagCompound.SetShort("zTile", (short)ZTile);
     par1NBTTagCompound.SetByte("inTile", (byte)InTile);
     par1NBTTagCompound.SetByte("inGround", (byte)(InGround ? 1 : 0));
 }
 /// <summary>
 /// (abstract) Protected helper method to write subclass entity data to NBT.
 /// </summary>
 public override void WriteEntityToNBT(NBTTagCompound par1NBTTagCompound)
 {
     par1NBTTagCompound.SetByte("Dir", (byte)Direction);
     par1NBTTagCompound.SetString("Motive", Art.Title);
     par1NBTTagCompound.SetInteger("TileX", XPosition);
     par1NBTTagCompound.SetInteger("TileY", YPosition);
     par1NBTTagCompound.SetInteger("TileZ", ZPosition);
 }
 /// <summary>
 /// Writes a tile entity to NBT.
 /// </summary>
 public override void WriteToNBT(NBTTagCompound par1NBTTagCompound)
 {
     base.WriteToNBT(par1NBTTagCompound);
     par1NBTTagCompound.SetString("Text1", SignText[0]);
     par1NBTTagCompound.SetString("Text2", SignText[1]);
     par1NBTTagCompound.SetString("Text3", SignText[2]);
     par1NBTTagCompound.SetString("Text4", SignText[3]);
 }
 /// <summary>
 /// Reads a tile entity from NBT.
 /// </summary>
 public override void ReadFromNBT(NBTTagCompound par1NBTTagCompound)
 {
     base.ReadFromNBT(par1NBTTagCompound);
     StoredBlockID     = par1NBTTagCompound.GetInteger("blockId");
     StoredMetadata    = par1NBTTagCompound.GetInteger("blockData");
     StoredOrientation = par1NBTTagCompound.GetInteger("facing");
     LastProgress      = Progress = par1NBTTagCompound.GetFloat("progress");
     Extending         = par1NBTTagCompound.Getbool("extending");
 }
 /// <summary>
 /// Writes a tile entity to NBT.
 /// </summary>
 public override void WriteToNBT(NBTTagCompound par1NBTTagCompound)
 {
     base.WriteToNBT(par1NBTTagCompound);
     par1NBTTagCompound.SetInteger("blockId", StoredBlockID);
     par1NBTTagCompound.SetInteger("blockData", StoredMetadata);
     par1NBTTagCompound.SetInteger("facing", StoredOrientation);
     par1NBTTagCompound.SetFloat("progress", LastProgress);
     par1NBTTagCompound.Setbool("extending", Extending);
 }
        /// <summary>
        /// (abstract) Protected helper method to write subclass entity data to NBT.
        /// </summary>
        public override void WriteEntityToNBT(NBTTagCompound par1NBTTagCompound)
        {
            base.WriteEntityToNBT(par1NBTTagCompound);

            if (DataWatcher.GetWatchableObjectByte(17) == 1)
            {
                par1NBTTagCompound.Setbool("powered", true);
            }
        }
示例#22
0
 /// <summary>
 /// Reads food stats from an NBT object.
 /// </summary>
 public virtual void ReadNBT(NBTTagCompound par1NBTTagCompound)
 {
     if (par1NBTTagCompound.HasKey("foodLevel"))
     {
         FoodLevel           = par1NBTTagCompound.GetInteger("foodLevel");
         FoodTimer           = par1NBTTagCompound.GetInteger("foodTickTimer");
         FoodSaturationLevel = par1NBTTagCompound.GetFloat("foodSaturationLevel");
         FoodExhaustionLevel = par1NBTTagCompound.GetFloat("foodExhaustionLevel");
     }
 }
示例#23
0
 /// <summary>
 /// write data to NBTTagCompound from this MapDataBase, similar to Entities and TileEntities
 /// </summary>
 public override void WriteToNBT(NBTTagCompound par1NBTTagCompound)
 {
     par1NBTTagCompound.SetByte("dimension", Dimension);
     par1NBTTagCompound.SetInteger("xCenter", XCenter);
     par1NBTTagCompound.SetInteger("zCenter", ZCenter);
     par1NBTTagCompound.SetByte("scale", Scale);
     par1NBTTagCompound.SetShort("width", (short)128);
     par1NBTTagCompound.SetShort("height", (short)128);
     par1NBTTagCompound.SetByteArray("colors", Colors);
 }
示例#24
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");
            }
        }
示例#25
0
 /// <summary>
 /// (abstract) Protected helper method to write subclass entity data to NBT.
 /// </summary>
 public override void WriteEntityToNBT(NBTTagCompound par1NBTTagCompound)
 {
     par1NBTTagCompound.SetShort("xTile", (short)XTile);
     par1NBTTagCompound.SetShort("yTile", (short)YTile);
     par1NBTTagCompound.SetShort("zTile", (short)ZTile);
     par1NBTTagCompound.SetByte("inTile", (byte)InTile);
     par1NBTTagCompound.SetByte("inData", (byte)InData);
     par1NBTTagCompound.SetByte("shake", (byte)ArrowShake);
     par1NBTTagCompound.SetByte("inGround", (byte)(InGround ? 1 : 0));
     par1NBTTagCompound.Setbool("player", DoesArrowBelongToPlayer);
     par1NBTTagCompound.SetDouble("damage", Damage);
 }
示例#26
0
        /// <summary>
        /// Creates a clone of the tag.
        /// </summary>
        public override NBTBase Copy()
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound(GetName());
            string         s;

            for (IEnumerator <string> iterator = TagMap.Keys.GetEnumerator(); iterator.MoveNext(); nbttagcompound.SetTag(s, ((NBTBase)TagMap[s]).Copy()))
            {
                s = (string)iterator.Current;
            }

            return(nbttagcompound);
        }
示例#27
0
 public override bool Equals(object par1Obj)
 {
     if (base.Equals(par1Obj))
     {
         NBTTagCompound nbttagcompound = (NBTTagCompound)par1Obj;
         return(TagMap.Equals(nbttagcompound.TagMap));
     }
     else
     {
         return(false);
     }
 }
示例#28
0
        /// <summary>
        /// reads in data from the NBTTagCompound into this MapDataBase
        /// </summary>
        public override void ReadFromNBT(NBTTagCompound par1NBTTagCompound)
        {
            Dimension = par1NBTTagCompound.GetByte("dimension");
            XCenter   = par1NBTTagCompound.GetInteger("xCenter");
            ZCenter   = par1NBTTagCompound.GetInteger("zCenter");
            Scale     = par1NBTTagCompound.GetByte("scale");

            if (Scale < 0)
            {
                Scale = 0;
            }

            if (Scale > 4)
            {
                Scale = 4;
            }

            short word0 = par1NBTTagCompound.GetShort("width");
            short word1 = par1NBTTagCompound.GetShort("height");

            if (word0 == 128 && word1 == 128)
            {
                Colors = par1NBTTagCompound.GetByteArray("colors");
            }
            else
            {
                byte[] abyte0 = par1NBTTagCompound.GetByteArray("colors");
                Colors = new byte[16384];
                int i = (128 - word0) / 2;
                int j = (128 - word1) / 2;

                for (int k = 0; k < word1; k++)
                {
                    int l = k + j;

                    if (l < 0 && l >= 128)
                    {
                        continue;
                    }

                    for (int i1 = 0; i1 < word0; i1++)
                    {
                        int j1 = i1 + i;

                        if (j1 >= 0 || j1 < 128)
                        {
                            Colors[j1 + l * 128] = abyte0[i1 + k * word0];
                        }
                    }
                }
            }
        }
        /// <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();
            }
        }
示例#30
0
        /// <summary>
        /// Writes a compressed NBTTagCompound to the OutputStream
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void writeNBTTagCompound(NBTTagCompound par1NBTTagCompound, DataOutputStream par2DataOutputStream) throws IOException
        protected virtual void WriteNBTTagCompound(NBTTagCompound par1NBTTagCompound, BinaryWriter par2DataOutputStream)
        {
            if (par1NBTTagCompound == null)
            {
                par2DataOutputStream.Write((short)-1);
            }
            else
            {
                byte[] abyte0 = CompressedStreamTools.Compress(par1NBTTagCompound);
                par2DataOutputStream.Write((short)abyte0.Length);
                par2DataOutputStream.Write(abyte0);
            }
        }