Skip to content

Instantly share code, notes, and snippets.

@desht
Last active July 7, 2020 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desht/b1f94fb410e578e15bf60e256c15ef64 to your computer and use it in GitHub Desktop.
Save desht/b1f94fb410e578e15bf60e256c15ef64 to your computer and use it in GitHub Desktop.
Serializing & deserializing a GlobalPos in MC 1.16.1
public static CompoundNBT serializeGlobalPos(GlobalPos globalPos) {
CompoundNBT tag = new CompoundNBT();
tag.put("pos", net.minecraft.nbt.NBTUtil.writeBlockPos(globalPos.getPos()));
tag.putString("dim", globalPos.func_239646_a_().func_240901_a_().toString());
return tag;
}
public static GlobalPos deserializeGlobalPos(CompoundNBT tag) {
RegistryKey<World> k = RegistryKey.func_240903_a_(Registry.WORLD_KEY, new ResourceLocation(tag.getString("dim")));
return GlobalPos.func_239648_a_(k, NBTUtil.readBlockPos(tag.getCompound("pos")));
}
public static ServerWorld getWorldForGlobalPos(GlobalPos pos) {
return ServerLifecycleHooks.getCurrentServer().getWorld(pos.func_239646_a_());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment