Exemple #1
0
 /// <summary>
 /// Converts a Minecraft NBT format player file to c#raft xml
 /// </summary>
 /// <param name="fileName">Filepath of nbt</param>
 internal void ConvertPlayerNBT(string fileName)
 {
     FileStream s = null;
     NBTFile nbt = null;
     try
     {
         ClientSurrogate p = new ClientSurrogate();
         s = new FileStream(fileName, FileMode.Open);
         nbt = NBTFile.OpenFile(s, 1);
         foreach (KeyValuePair<string, NBTTag> sa in nbt.Contents)
         {
             switch (sa.Key)
             {
                 case "Health":
                     p.Health = sa.Value.Payload;
                     break;
                 case "Pos":
                     p.X = sa.Value.Payload[2].Payload;
                     p.Y = sa.Value.Payload[1].Payload;
                     p.Z = sa.Value.Payload[0].Payload;
                     break;
                 case "Rotation":
                     p.Pitch = sa.Value.Payload[1].Payload;
                     p.Yaw = sa.Value.Payload[0].Payload;
                     break;
                 case "playerGameType":
                     p.GameMode = (byte)sa.Value.Payload;
                     break;
                 case "foodLevel":
                     p.Food = (short)sa.Value.Payload;
                     break;
                 case "foodSaturationLevel":
                     p.FoodSaturation = sa.Value.Payload;
                     break;
                 case "Inventory":
                     Inventory inv = new Inventory();
                     foreach (NBTTag tag in sa.Value.Payload)
                     {
                         inv.AddItem((short)tag.Payload["id"].Payload, (sbyte)tag.Payload["Count"].Payload,
                                     (short)tag.Payload["Damage"].Payload, false);
                     }
                     p.Inventory = inv;
                     break;
             }
         }
         SavePlayerXml(p, fileName);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error converting file" + fileName + " to C#raft format");
         Console.WriteLine(ex);
     }
     finally
     {
         if (s != null)
             s.Dispose();
         if (nbt != null)
             nbt.Dispose();
     }
 }
        // TODO: Move a bunch of this to DataFile.cs
        private void Load()
        {
            if (!File.Exists(DataFile))
                return;

            ClientSurrogate client;
            using (FileStream rx = File.OpenRead(DataFile))
                client = (ClientSurrogate)Xml.Deserialize(rx);
            Position.X = client.X;
            Position.Y = client.Y + 1; // Players drop one block upon spawning
            Position.Z = client.Z;
            Position.Yaw = client.Yaw;
            Position.Pitch = client.Pitch;
            if (client.Inventory == null) return;
            Inventory = new Inventory {Handle = 0};
            ItemStack[] slots = new ItemStack[client.Inventory.SlotCount];
            for (short i = 0; i < client.Inventory.SlotCount; i++)
            {
                slots[i] = ItemStack.Void;
                if (!ItemStack.IsVoid(client.Inventory.Slots[i]))
                {
                    slots[i].Type = client.Inventory.Slots[i].Type;
                    slots[i].Count = client.Inventory.Slots[i].Count;
                    slots[i].Durability = client.Inventory.Slots[i].Durability;
                    slots[i].Slot = i;
                }
                // Using the default indexer on Inventory ensures all event handlers are correctly hooked up
                this.Inventory[i] = slots[i];
            }
            Inventory.Associate(this);
            GameMode = client.GameMode;
        }
Exemple #3
0
        public void InitializeInventory()
        {
            if (Inventory == null)
            {
                Inventory = new Inventory(this);

                for (short i = 0; i < Inventory.SlotCount; i++) // Void inventory slots (for Holding)
                {
                    Inventory[i] = ItemHelper.Void;
                }
                var item = ItemHelper.GetInstance(278);
                item.Count = 1;
                item.Durability = 0;
                Inventory[Inventory.ActiveSlot] = item;
            }

            Inventory.UpdateClient();
        }
Exemple #4
0
        public void InitializeInventory()
        {
            if (Inventory == null)
            {
                Inventory = new Inventory(this);

                for (short i = 0; i < Inventory.SlotCount; i++) // Void inventory slots (for Holding)
                {
                    Inventory[i] = ItemStack.Void;
                }

                Inventory[Inventory.ActiveSlot] = new ItemStack(278, 1, 0);
            }

            Inventory.UpdateClient();
        }