Beispiel #1
0
        public static Tag ReadTagType(EndianBinaryReader r, byte type)
        {
            switch (type)
            {
            case 0:
                return(TagEnd.Read(r));

            case 1:
                return(TagByte.Read(r));

            case 2:
                return(TagShort.Read(r));

            case 3:
                return(TagInt.Read(r));

            case 4:
                return(TagLong.Read(r));

            case 5:
                return(TagFloat.Read(r));

            case 6:
                return(TagDouble.Read(r));

            case 7:
                return(TagByteArray.Read(r));

            case 8:
                return(TagString.Read(r));

            case 9:
                return(TagListReader.Read(r));

            case 10:
                return(TagCompound.Read(r));

            case 11:
                return(TagIntArray.Read(r));

            default:
                throw new NotImplementedException("NBT Tag type: " + type);
            }
        }
Beispiel #2
0
        public Tag ExportTag()
        {
            tc ["SleepTimer"] = new TagShort(SleepTimer);

            TagList <TagDouble> motion = new TagList <TagDouble>();

            motion [0]      = new TagDouble(Motion [0]);
            motion [1]      = new TagDouble(Motion [1]);
            motion [2]      = new TagDouble(Motion [2]);
            tc ["Motion"]   = motion;
            tc ["OnGround"] = new TagByte()
            {
                Byte = OnGround
            };
            tc ["HurtTime"] = new TagShort(HurtTime);
            tc ["Health"]   = new TagShort(Health);

            tc ["Dimension"] = new TagInt(Dimension);
            tc ["Air"]       = new TagShort(Air);

            if (tc ["Inventory"] is TagList <TagCompound> == false)
            {
                tc ["Inventory"] = new TagList <TagCompound>();
            }
            TagList <TagCompound> inv = tc ["Inventory"] as TagList <TagCompound>;

            for (byte n = 0; n < 104; n++)
            {
                SlotItem item = null;
                if (n < 36)
                {
                    item = Inventory [n];
                }
                if (n >= 80 && n < 84)
                {
                    item = InventoryCraft [n - 80];
                }
                if (n >= 100)
                {
                    item = InventoryWear [n - 100];
                }

                TagCompound ti = null;

                //Find slot item
                foreach (TagCompound itc in inv)
                {
                    if (itc ["Slot"].Byte == n)
                    {
                        ti = itc;
                        break;
                    }
                }

                if (item == null)
                {
                    if (ti != null)
                    {
                        inv.Remove(ti);
                    }
                    continue;
                }
                if (ti == null)
                {
                    ti = new TagCompound();
                    inv.Add(ti);
                }

                ti ["id"]     = new TagShort((short)item.ItemID);
                ti ["Damage"] = new TagShort((short)item.Uses);
                ti ["Count"]  = new TagByte((byte)item.Count);
                ti ["Slot"]   = new TagByte(n);
            }
            inv.Sort((x, y) => x ["Slot"].Byte - y ["Slot"].Byte);

            TagList <TagDouble> p = new TagList <TagDouble>();

            p [0]               = new TagDouble(Pos.X);
            p [1]               = new TagDouble(Pos.Y);
            p [2]               = new TagDouble(Pos.Z);
            tc ["Pos"]          = p;
            tc ["AttackTime"]   = new TagShort(AttackTime);
            tc ["Sleeping"]     = new TagByte(Sleeping);
            tc ["Fire"]         = new TagShort(Fire);
            tc ["FallDistance"] = new TagFloat(FallDistance);
            TagList <TagFloat> rot = new TagList <TagFloat>();

            rot [0]          = new  TagFloat(Rotation [0]);
            rot [1]          = new  TagFloat(Rotation [1]);
            tc ["Rotation"]  = rot;
            tc ["DeathTime"] = new TagShort(DeathTime);

            if (Spawn != null)
            {
                tc ["SpawnX"] = new TagInt(Spawn.X);
                tc ["SpawnY"] = new TagInt(Spawn.Y);
                tc ["SpawnZ"] = new TagInt(Spawn.Z);
            }

            tc ["foodExhaustionLevel"] = new TagFloat(foodExhaustionLevel);
            tc ["foodTickTimer"]       = new TagInt(foodTickTimer);
            tc ["foodSaturationLevel"] = new TagFloat(foodSaturationLevel);
            tc ["foodLevel"]           = new TagInt(foodLevel);
            tc ["XpLevel"]             = new TagInt(XpLevel);
            tc ["XpTotal"]             = new TagInt(XpTotal);
            tc ["Xp"]             = new TagInt(Xp);
            tc ["playerGameType"] = new TagInt(playerGameType);

            return(tc);
        }