public static Packet read(ByteBuffer buffer) {
        byte packetId = buffer.get();
        if (packetId == ID_HELLO_PACKET)
            return new HelloPacket(buffer);
        if (packetId == ID_WORLD_UPDATE_PACKET)
            return new WorldUpdatesPacket(buffer);
        if (packetId == ID_WINDOW_PACKET)
            return new WindowPacket(buffer);
        if (packetId == ID_WORLD_REGION_PACKET)
            return new WorldRegionPacket(buffer);
        if (packetId == ID_ENTITIES_PACKET)
            return new EntitiesPacket(buffer);
        if (packetId == ID_DWARF_REQUEST_PACKET)
            return new DwarfRequestPacket(buffer);
        if (packetId == ID_PLAYER_UPDATE_PACKET)
            return new PlayerUpdatePacket(buffer);
        throw new RuntimeException("Unknown packet id: " + packetId);
    }