Online UUID Fix
警告: 安装此模组或进行任何 UUID 迁移之前,请务必备份整个世界文件夹。UUID 更改会影响玩家数据、进度、统计数据和宠物所有权。系统不支持自动回滚。
注意: 本模组的代码由 AI(Anthropic 的 Claude)协助生成。请自行承担使用风险,并在部署到生产服务器前审查代码。
一个用于 Fabric 的服务端模组,专为离线模式服务器设计,可为玩家分配真实的 Mojang/Microsoft UUID,而非原版离线模式下的 UUID。
当服务器以离线模式运行(online-mode=false)时,Minecraft 会使用本地哈希算法根据玩家的用户名生成 UUID。这意味着同一位玩家在离线模式服务器上获得的 UUID 与在线模式服务器上的不同,导致无法兼容来自在线服务器的玩家数据,并在玩家更改用户名时引发问题。
该模组在登录时拦截 UUID 分配,并从 Mojang API 获取真实 UUID;对于非 Mojang 账户或 API 不可用的情况,则回退至原版离线模式 UUID。
要求
- Minecraft 1.21.11
- Fabric Loader 0.18.2+
- 仅限服务端 — 无需安装在客户端
安装
- 从发布页面下载
modid-1.0.0.jar,或自行构建(见下文)
- 将其放入服务器的
mods/ 文件夹中
- 启动服务器 — 无需配置
模组将在首次登录时记录解析出的 UUID:
[OnlineUuidFix] Resolved Steve -> xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
UUID 查找结果会缓存至 config/online-uuid-fix/uuid-cache.json,因此每个用户名仅调用一次 Mojang API。
从源码构建
要求:JDK 21(Eclipse Adoptium — 请安装 JDK,而非 JRE)
# Windows — 如果同时安装了 JDK 和 JRE,请设置 JDK
$env:JAVA_HOME = "C:\Program Files\Eclipse Adoptium\jdk-21.0.10.7-hotspot"
./gradlew build
输出 jar 包:build/libs/modid-1.0.0.jar
将现有服务器迁移至在线 UUID
如果你的服务器已经存储了基于离线 UUID 的玩家数据,你需要将这些文件重命名为正确的在线 UUID,否则玩家将重新开始游戏。
玩家数据存储位置如下:
world/playerdata/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.dat
world/advancements/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json
world/stats/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json
逐步迁移指南
1. 找到每位玩家的离线 UUID(当前文件名)
文件名即为服务器分配的 UUID。列出 world/playerdata/ 目录即可查看所有文件。
2. 找到玩家的真实在线 UUID
可在 namemc.com 上查询,或直接使用 Mojang API:
https://api.mojang.com/users/profiles/minecraft/<username>
响应中的 id 字段为不带连字符的 UUID — 请按 8-4-4-4-12 的模式插入连字符。
你也可以使用以下计算器:
https://minecraft.wiki/w/Calculators/Player_UUID
3. 重命名文件
在服务器停止运行的状态下,重命名每个文件:
world/playerdata/<offline-uuid>.dat → world/playerdata/<online-uuid>.dat
world/advancements/<offline-uuid>.json → world/advancements/<online-uuid>.json
world/stats/<offline-uuid>.json → world/stats/<online-uuid>.json
4. 安装此模组后启动服务器
新登录的玩家现在将获得在线 UUID,这与已重命名的文件相匹配。
迁移未涵盖的内容
宠物和驯服动物
宠物所有权存储在宠物的 NBT 数据中,作为拥有者的 UUID。重命名玩家文件后,宠物仍会引用旧的离线 UUID,从而无法识别玩家为其拥有者。
有两种解决方法:
选项 A — 游戏内命令(服务器必须正在运行)
站在宠物旁边并运行:
/execute as @e[type=wolf,distance=..10] run data modify entity @s Owner set from entity @p UUID
这将把 10 格范围内所有狼的所有权重新分配给最近的玩家。根据需要替换 wolf 为其他宠物类型(例如 cat、parrot、horse),并调整距离。
选项 B — NBTExplorer(服务器必须离线)
使用 NBTExplorer 直接编辑世界 NBT 数据:
- 在区域文件中搜索旧的离线 UUID 字符串
- 将所有出现的地方替换为新的在线 UUID
进度(Advancements)
进度存储在单独的 .json 文件中(不在 .dat 文件内)。这些文件也需要重命名 — 参见上面的第 3 步。
其他玩家的物品栏
如果需要将一位玩家的物品栏复制到另一位玩家(例如合并账号):
- 备份两个
.dat 文件
- 将源玩家的
.dat 文件复制并重命名为目标玩家的 UUID
- 目标玩家随后将拥有源玩家的物品栏、经验值和位置
这不会转移宠物所有权 — 请参阅上述说明。
工作原理
该模组通过 Mixin 注入到 net.minecraft.core.UUIDUtil.createOfflinePlayerUUID 中。每当服务器需要根据用户名生成离线 UUID 时,模组首先查询 Mojang API(api.mojang.com/users/profiles/minecraft/<name>)。如果返回结果,则使用该 UUID。如果 API 返回 404(无 Mojang 账户)或不可用,则使用原始的原版离线 UUID 作为回退方案。
Online UUID Fix
Warning: Always back up your entire world folder before installing this mod or performing any UUID migration. UUID changes affect player data, advancements, stats, and pet ownership. There is no automatic rollback.
Note: This mod's code was generated with the assistance of AI (Claude by Anthropic). Use it at your own risk and review the code before deploying on a production server.
A Fabric server-side mod for offline-mode servers that assigns players their real Mojang/Microsoft UUID instead of the vanilla offline UUID.
When a server runs in offline mode (online-mode=false), Minecraft generates a UUID from the player's username using a local hash. This means the same player gets a different UUID than they would on an online-mode server, breaking compatibility with player data from online servers and causing issues when players switch usernames.
This mod intercepts UUID assignment at login and fetches the real UUID from the Mojang API, falling back to the vanilla offline UUID for non-Mojang accounts or when the API is unreachable.
Requirements
- Minecraft 1.21.11
- Fabric Loader 0.18.2+
- Server-side only — does not need to be installed on clients
Installation
- Download
modid-1.0.0.jar from the releases or build it yourself (see below)
- Drop it into your server's
mods/ folder
- Start the server — no configuration needed
The mod will log resolved UUIDs on first login:
[OnlineUuidFix] Resolved Steve -> xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
UUID lookups are cached to config/online-uuid-fix/uuid-cache.json so the Mojang API is only called once per username.
Building from source
Requirements: JDK 21 (Eclipse Adoptium — install the JDK, not JRE)
# Windows — set JDK if you have both JDK and JRE installed
$env:JAVA_HOME = "C:\Program Files\Eclipse Adoptium\jdk-21.0.10.7-hotspot"
./gradlew build
Output jar: build/libs/modid-1.0.0.jar
Migrating an existing server to online UUIDs
If your server already has player data stored under offline UUIDs, you need to rename those files to the correct online UUIDs, otherwise players will start fresh.
Player data is stored in:
world/playerdata/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.dat
world/advancements/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json
world/stats/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json
Step-by-step migration
1. Find each player's offline UUID (the current filename)
The file is named after the UUID the server assigned. List world/playerdata/ to see all files.
2. Find the player's real online UUID
Look it up at namemc.com or use the Mojang API directly:
https://api.mojang.com/users/profiles/minecraft/<username>
The id field in the response is the UUID without dashes — insert dashes in the pattern 8-4-4-4-12.
You can also use the calculator at:
https://minecraft.wiki/w/Calculators/Player_UUID
3. Rename the files
With the server stopped, rename each file:
world/playerdata/<offline-uuid>.dat → world/playerdata/<online-uuid>.dat
world/advancements/<offline-uuid>.json → world/advancements/<online-uuid>.json
world/stats/<offline-uuid>.json → world/stats/<online-uuid>.json
4. Start the server with this mod installed
New logins will now receive the online UUID, which matches the renamed files.
What migration does NOT cover
Pets and tamed animals
Pet ownership is stored inside the pet's NBT data as the owner's UUID. After renaming player files, pets will still reference the old offline UUID and won't recognize the player as their owner.
There are two ways to fix this:
Option A — In-game command (server must be running)
Stand next to the pets and run:
/execute as @e[type=wolf,distance=..10] run data modify entity @s Owner set from entity @p UUID
This reassigns ownership of all wolves within 10 blocks to the nearest player. Replace wolf with other pet types (e.g. cat, parrot, horse) and adjust the distance as needed.
Option B — NBTExplorer (server must be offline)
Use NBTExplorer to edit world NBT data directly:
- Search for the old offline UUID string in region files
- Replace each occurrence with the new online UUID
Advancements
Advancements are stored in separate .json files (not inside .dat). These also need to be renamed — see step 3 above.
Other players' inventories
If you need to copy a player's inventory to another player (e.g. merging accounts):
- Back up both
.dat files
- Copy and rename the source player's
.dat to the target player's UUID
- The target player will then have the source player's inventory, XP, and position
This will not transfer pet ownership — see the note above.
How it works
The mod injects into net.minecraft.core.UUIDUtil.createOfflinePlayerUUID via a Mixin. Every time the server would generate an offline UUID from a username, the mod first queries the Mojang API (api.mojang.com/users/profiles/minecraft/<name>). If a result is returned, that UUID is used instead. If the API returns 404 (no Mojang account) or is unreachable, the original vanilla offline UUID is used as a fallback.
评论 0
登录后参与评分
还没有评论,来抢沙发吧