Jump to content

[1.17.1] Converting resource key to and from string!


X_ZombieSlayer_X

Recommended Posts

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)

Link to comment
Share on other sites

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));

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.