示例#1
0
  public static void writeEntityMetadata(NetOutput out, EntityMetadata[] metadata)
      throws IOException {
    for (EntityMetadata meta : metadata) {
      int id = MagicValues.value(Integer.class, meta.getType()) << 5 | meta.getId() & 0x1F;
      out.writeByte(id);
      switch (meta.getType()) {
        case BYTE:
          out.writeByte((Byte) meta.getValue());
          break;
        case SHORT:
          out.writeShort((Short) meta.getValue());
          break;
        case INT:
          out.writeInt((Integer) meta.getValue());
          break;
        case FLOAT:
          out.writeFloat((Float) meta.getValue());
          break;
        case STRING:
          out.writeString((String) meta.getValue());
          break;
        case ITEM:
          writeItem(out, (ItemStack) meta.getValue());
          break;
        case POSITION:
          Position pos = (Position) meta.getValue();
          out.writeInt(pos.getX());
          out.writeInt(pos.getY());
          out.writeInt(pos.getZ());
          break;
        case ROTATION:
          Rotation rot = (Rotation) meta.getValue();
          out.writeFloat(rot.getPitch());
          out.writeFloat(rot.getYaw());
          out.writeFloat(rot.getRoll());
          break;
        default:
          throw new IOException("Unmapped metadata type: " + meta.getType());
      }
    }

    out.writeByte(127);
  }
 @Override
 public void write(NetOutput out) throws IOException {
   out.writeInt(this.entityId);
   out.writeInt(this.attachedToId);
 }