我的世界地形寻找

/ 0评 / 0

最近发现一个库(https://github.com/Cubitect/cubiomes),用于生成我的世界地形,那么,他自然就可以寻找任意地形了.比如寻找距离蘑菇岛最近的地形.

#include "generator.h"
#include "finders.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include <math.h>

#define RANGE 200
#define NUM_THREADS 8

typedef struct
{
    Generator g;
    int thread_id;
} ThreadData;

// 随机生成64位无符号整数
uint64_t generate_random_uint64()
{
    uint64_t random_number = 0;
    random_number |= ((uint64_t)rand() << 0);
    random_number |= ((uint64_t)rand() << 32);
    return random_number;
}

int calculateDistance(int x1, int y1, int x2, int y2)
{
    double distance;
    distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    return (int)distance; // 将结果转换为整数
}

// 线程执行的函数
void *searchBiome(void *arg)
{
    ThreadData *data = (ThreadData *)arg;
    Generator *g = &data->g;
    int scale = 1;

    while (1)
    {
        // 生成随机种子
        uint64_t seed = generate_random_uint64();
        applySeed(g, DIM_OVERWORLD, seed);

        // 获取出生点坐标
        Pos spawn = getSpawn(g);

        // 计算每个线程负责的x轴范围
        for (int x = spawn.x - RANGE; x < spawn.x + RANGE; x = x + 10)
        {
            for (int z = spawn.z - RANGE; z <= spawn.z + RANGE; z = z + 10)
            {
                int y = 63; // 通常的生物群系检查高度
                int biomeID = getBiomeAt(g, scale, x, y, z);

                if (biomeID == mushroom_fields)
                {
                    int distance = calculateDistance(spawn.x, spawn.z, x, z);W
                    printf("%d,%" PRId64 ",%d,%d,%d,%d,%d,%d,%d\n",
                           data->thread_id, (int64_t)seed, spawn.x, spawn.z, x, z, distance, abs(spawn.x - x), abs(spawn.z - z));
                    // 找到蘑菇岛后只跳出当前循环.
                    x = spawn.x + RANGE + 1;
                    z = spawn.z + RANGE + 1;
                }
            }
        }
    }

    return NULL;
}

int main()
{
    pthread_t threads[NUM_THREADS];
    ThreadData thread_data[NUM_THREADS];

    // 初始化随机数生成器
    srand(time(NULL));
    setbuf(stdout, NULL);

    for (int i = 0; i < NUM_THREADS; i++)
    {
        setupGenerator(&thread_data[i].g, MC_1_21, 0);
        thread_data[i].thread_id = i;
        pthread_create(&threads[i], NULL, searchBiome, (void *)&thread_data[i]);
    }

    // 等待所有线程结束(实际永远不会结束,因为线程不会退出)
    for (int i = 0; i < NUM_THREADS; i++)
    {
        pthread_join(threads[i], NULL);
    }

    return 0;
}

进一步可以继续查找各种参数,找到一个特别好的种子,他是基于一个非常大的随机数种子,这个算法还挺科学的,在正常的游玩中,不可能走到地图边界.

找到的两个种子,如果添加其他地形约束,只要在特定范围内继续寻找.

8052745656208620376,0,0,150,100,180,150,100
100465075787987974,-832,240,-662,110,214,170,130

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注