コード例 #1
0
ファイル: Mob.cs プロジェクト: mctraveler/MineSharp
        protected override void ExportMeta(Metadata meta)
        {
            meta.SetByte(0, (sbyte)(
			         (Onfire ? 0x01 : 0) |
                (Crouched ? 0x02 : 0) |
                (Riding ? 0x04 : 0) |
                (Sprinting ? 0x08 : 0) |
                (Eating ? 0x10 : 0)
			         ));
            meta.SetInt(1, Oxygen);
            meta.SetInt(8, (Potion.R << 16) | (Potion.G << 8) | Potion.B);
            meta.SetInt(12, Maturity);
        }
コード例 #2
0
ファイル: Entity.cs プロジェクト: mctraveler/MineSharp
        protected void UpdateMeta(Metadata meta)
        {
            foreach (var kvp in meta.Fields)
            {
                switch (kvp.Key)
                {
                    case 0: //Index 0, flags
				
                        sbyte flag = kvp.Value.Byte;
                        Onfire = (flag & 0x01) != 0;
                        Crouched = (flag & 0x01) != 0;
                        Riding = (flag & 0x01) != 0;
                        Sprinting = (flag & 0x01) != 0;
                        Eating = (flag & 0x01) != 0;
                        Debug.Assert((flag & 0xC0) == 0);
                        break;
			
                    case 1://Index 1, drowning
                        Oxygen = kvp.Value.Short;
                        Debug.Assert(Oxygen <= 300 & Oxygen > -20);
                        break;
					
                    case 5: //Horses
                        break;
                    case 6: //Horses
                        break;

                    case 8://Index 8, potion color
                        int c = kvp.Value.Int;
                        Potion = Color.FromArgb(0, (c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF);
                        Debug.Assert((c & 0xFF000000) == 0);
                        break;

                    case 18: //Horses
                        break;
                    case 19: //Boat
                        break;

                    default:
                        switch (kvp.Value.Type)
                        {
                            case MetaType.Byte:
                                if (ImportMeta(kvp.Key, kvp.Value.Byte))
                                    continue;
                                break;
                            case MetaType.Short:
                                if (ImportMeta(kvp.Key, kvp.Value.Short))
                                    continue;
                                break;
                            case MetaType.Int:
                                if (ImportMeta(kvp.Key, kvp.Value.Int))
                                    continue;
                                break;
                            case MetaType.String:
                                if (ImportMeta(kvp.Key, kvp.Value.String))
                                    continue;
                                break;
                            case MetaType.Item:
                                if (ImportMeta(kvp.Key, kvp.Value.Item))
                                    continue;
                                break;
                            case MetaType.Float:
                                if (ImportMeta(kvp.Key, kvp.Value.Float))
                                    continue;
                                break;
                            #if DEBUGPACKET
                            default:
                                throw new NotImplementedException("Unhandled metadata type " + kvp.Value);
                            #endif
                        }
                        break;
                }
            }
        }
コード例 #3
0
ファイル: Metadata.cs プロジェクト: mctraveler/MineSharp
 public static Metadata Read(EndianBinaryReader r)
 {
     Metadata m = new Metadata();
     
     while (true)
     {
         byte f = r.ReadByte();
         if (f == 0x7F)
             return m;
         
         MetaField mf = new MetaField(f & 0x1F, (MetaType)(f >> 5));
         switch (mf.Type)
         {
             case MetaType.Byte:
                 mf.Byte = r.ReadSByte();
                 break;
             case MetaType.Short:
                 mf.Short = r.ReadInt16();
                 break;
             case MetaType.Int:
                 mf.Int = r.ReadInt32();
                 break;
             case MetaType.Float:
                 mf.Float = r.ReadSingle();
                 break;
             case MetaType.String:
                 mf.String = Packet.ReadString8(r);
                 break;
             case MetaType.Item:
                 mf.Item = SlotItem.Read(r);
                 break;
             case MetaType.Vector:
                 mf.Vector = new CoordInt();
                 mf.Vector.X = r.ReadInt32();
                 mf.Vector.Y = r.ReadInt32();
                 mf.Vector.Z = r.ReadInt32();
                 break;
             case MetaType.VectorF:
                 mf.VectorF = new CoordDouble();
                 mf.VectorF.X = r.ReadSingle();
                 mf.VectorF.Y = r.ReadSingle();
                 mf.VectorF.Z = r.ReadSingle();
                 break;
             default:
                 throw new NotImplementedException();
         }
         m.Fields.Add(mf.ID, mf);				
     }
 }
コード例 #4
0
ファイル: Metadata.cs プロジェクト: mctraveler/MineSharp
 public static void Write(EndianBinaryWriter w, Metadata m)
 {
     if (m == null)
     {
         w.Write((byte)0x7F);
         return;
     }
     foreach (MetaField mf in m.Fields.Values)
     {
         w.Write((byte)((int)mf.Type << 5 | mf.ID));
         switch (mf.Type)
         {
             case MetaType.Byte:
                 w.Write(mf.Byte);
                 break;
             case MetaType.Short:
                 w.Write(mf.Short);
                 break;
             case MetaType.Int:
                 w.Write(mf.Int);
                 break;
             case MetaType.Float:
                 w.Write(mf.Float);
                 break;
             case MetaType.String:
                 Packet.WriteString8(w, mf.String);
                 break;
             case MetaType.Item:
                 //when this is true, we can remove that parameter
                 SlotItem.Write(w, mf.Item); 
                 break;
             case MetaType.Vector:
                 w.Write(mf.Vector.X);
                 w.Write(mf.Vector.Y);
                 w.Write(mf.Vector.Z);
                 break;
             case MetaType.VectorF:
                 w.Write((float)mf.VectorF.X);
                 w.Write((float)mf.VectorF.Y);
                 w.Write((float)mf.VectorF.Z);
                 break;
             default:
                 throw new NotImplementedException();
         }
     }
     w.Write((byte)0x7F);
 }
コード例 #5
0
        protected void UpdateMeta(Metadata meta)
        {
            foreach (var kvp in meta.Fields)
            {
                switch (kvp.Key)
                {
                case 0:     //Index 0, flags

                    sbyte flag = kvp.Value.Byte;
                    Onfire    = (flag & 0x01) != 0;
                    Crouched  = (flag & 0x01) != 0;
                    Riding    = (flag & 0x01) != 0;
                    Sprinting = (flag & 0x01) != 0;
                    Eating    = (flag & 0x01) != 0;
                    Debug.Assert((flag & 0xC0) == 0);
                    break;

                case 1:    //Index 1, drowning
                    Oxygen = kvp.Value.Short;
                    Debug.Assert(Oxygen <= 300 & Oxygen > -20);
                    break;

                case 5:     //Horses
                    break;

                case 6:     //Horses
                    break;

                case 8:    //Index 8, potion color
                    int c = kvp.Value.Int;
                    Potion = Color.FromArgb(0, (c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF);
                    Debug.Assert((c & 0xFF000000) == 0);
                    break;

                case 18:     //Horses
                    break;

                case 19:     //Boat
                    break;

                default:
                    switch (kvp.Value.Type)
                    {
                    case MetaType.Byte:
                        if (ImportMeta(kvp.Key, kvp.Value.Byte))
                        {
                            continue;
                        }
                        break;

                    case MetaType.Short:
                        if (ImportMeta(kvp.Key, kvp.Value.Short))
                        {
                            continue;
                        }
                        break;

                    case MetaType.Int:
                        if (ImportMeta(kvp.Key, kvp.Value.Int))
                        {
                            continue;
                        }
                        break;

                    case MetaType.String:
                        if (ImportMeta(kvp.Key, kvp.Value.String))
                        {
                            continue;
                        }
                        break;

                    case MetaType.Item:
                        if (ImportMeta(kvp.Key, kvp.Value.Item))
                        {
                            continue;
                        }
                        break;

                    case MetaType.Float:
                        if (ImportMeta(kvp.Key, kvp.Value.Float))
                        {
                            continue;
                        }
                        break;

#if DEBUG
                    default:
                        throw new NotImplementedException("Unhandled metadata type " + kvp.Value);
#endif
                    }
                    break;
                }
            }
        }