过程

首先 我们知道月相会影响什么?

可以看到 最明显的就是对史莱姆的生成

接下来我们就打开服务端核心 找到 EntitySlime 然后搜索 "40"

果不其然 我们搜索到了以下内容

然后对这个方法逐行分析

super.P() 应该就是生成,然后再看 255行 isSlimeChunk 是否为史莱姆区块跳过

然后向上看, 能影响生成的只有251行了 进行拆分

biomebase == Biomes.h && this.locY > 50.0D && this.locY < 70.0D && this.random.nextFloat() < 0.5F && this.random.nextFloat() < this.world.G() && this.world.getLightLevel(new BlockPosition(this)) <= this.random.nextInt(8)

此时我们发现了怀疑对象, this.world.G()

接下来我们点进去看看实现

结论

破案!所以获取月相的办法就是 NMS.World.G()

可以得知这个月相的算法是 (世界时间 / 24000 % 8 + 8 ) % 8

所以在不用NMS的时候 可以直接取到世界时间然后进行计算

    public int getMoonPhase(World world) {
        return (int) (world.getFullTime() / 24000L % 8L + 8L) % 8;
    }