Last active
July 7, 2020 09:22
-
-
Save desht/b1f94fb410e578e15bf60e256c15ef64 to your computer and use it in GitHub Desktop.
Serializing & deserializing a GlobalPos in MC 1.16.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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