Ejemplo n.º 1
0
 public static ItemStack readItem(NetInput in) throws IOException {
   short item = in.readShort();
   if (item < 0) {
     return null;
   } else {
     return new ItemStack(item, in.readByte(), in.readShort(), readNBT(in));
   }
 }
Ejemplo n.º 2
0
  public static EntityMetadata[] readEntityMetadata(NetInput in) throws IOException {
    List<EntityMetadata> ret = new ArrayList<EntityMetadata>();
    byte b;
    while ((b = in.readByte()) != 127) {
      int typeId = (b & 0xE0) >> 5;
      int id = b & 0x1F;
      MetadataType type = MagicValues.key(MetadataType.class, typeId);
      Object value;
      switch (type) {
        case BYTE:
          value = in.readByte();
          break;
        case SHORT:
          value = in.readShort();
          break;
        case INT:
          value = in.readInt();
          break;
        case FLOAT:
          value = in.readFloat();
          break;
        case STRING:
          value = in.readString();
          break;
        case ITEM:
          value = readItem(in);
          break;
        case POSITION:
          value = new Position(in.readInt(), in.readInt(), in.readInt());
          break;
        case ROTATION:
          value = new Rotation(in.readFloat(), in.readFloat(), in.readFloat());
          break;
        default:
          throw new IOException("Unknown metadata type id: " + typeId);
      }

      ret.add(new EntityMetadata(id, type, value));
    }

    return ret.toArray(new EntityMetadata[ret.size()]);
  }