Posted September 6, 20214 yr How can I convert a resource key to a string(or other serializable type) and then back to a resource key? I need this for storing dimensions for /homes and /warps! Is this even possible? I read the docs on resource location but I can’t seem to find anything on resource key!
September 6, 20214 yr Author 5 hours ago, diesieben07 said: A ResourceKey is just two ResourceLocations. One for the type of registry and one for the element within that registry. For example: ResourceKey.create(new ResourceLocation("minecraft", "block"), new ResourceLocation("minecraft", "stone")) This describes the ResourceKey for the registry entry "minecraft:stone" within the "minecraft:block" registry. You can serialize a ResourceKey by serializing both ResourceLocations. Or, if you know that it will always be a certain registry, you only need to serialize the 2nd ResourceLocation and fill the other one in when deserializing. Thanks for the help, I just have one more question. ResourceKey.location only returns one resource location(I believe the registry). How would I get both?(entry and registry)
September 7, 20214 yr Author On 9/6/2021 at 4:43 AM, diesieben07 said: A ResourceKey is just two ResourceLocations. One for the type of registry and one for the element within that registry. For example: ResourceKey.create(new ResourceLocation("minecraft", "block"), new ResourceLocation("minecraft", "stone")) This describes the ResourceKey for the registry entry "minecraft:stone" within the "minecraft:block" registry. You can serialize a ResourceKey by serializing both ResourceLocations. Or, if you know that it will always be a certain registry, you only need to serialize the 2nd ResourceLocation and fill the other one in when deserializing. ResourceKey.create(ResourceLocation, ResourceLocation) is not visible. So I am using this! ResourceKey<Level> dimension = ResourceKey.create(ResourceKey.createRegistryKey(new ResourceLocation(worldRegistry)), new ResourceLocation(worldEntry));
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.