Jump to content

[Solved] [1.16] How do I access all registered dimensions?


xBigEllx

Recommended Posts

Hello. I'm creating a mod that needs to access all registered Vanilla and mod dimension Ids.

 

In 1.15, it was possible to use the following:

for (DimensionType type : DimensionType.getAll()) {}

From there, I could access each of their dimension Ids. This seems to have changed in 1.16 and I can't figure out another way to access these dimensions.

 

I have tried accessing the "WORLD_TYPES" Forge registry by using the following:

for (ForgeWorldType type : ForgeRegistries.WORLD_TYPES.getValues()) {}

Unfortunately, it appears that this is also not the correct way to do it as there are no values in here.

 

Any help is appreciated.

Edited by xBigEllx
Link to comment
Share on other sites

DimensionTypes are dynamic since they are now data driven. This means that the associated data can only be accessed whenever a world is loaded. You can get access to this through MinecraftServer#registryAccess which gives you an instance of DynamicRegistries. There is a convenient method there for grabbing the registry called DynamicRegistries#dimensionTypes. Registry is an instance of Iterable on the value.

  • Like 1
Link to comment
Share on other sites

Thank you, that's just what I needed. However, I needed to change the names of some of the methods I was calling, as it seems they were obfuscated (I think that's the correct term).

 

Here is the code I used to access all dimension types:

for (DimensionType type : world.getServer().func_244267_aX().func_230520_a_()) {}

 

Here is the code I used to access all dimension Ids:

for (ResourceLocation location : world.getServer().func_244267_aX().func_230520_a_().keySet()) {}

 

Link to comment
Share on other sites

  • xBigEllx changed the title to [Solved] [1.16] How do I access all registered dimensions?
  • 2 years later...

// Get all dimensions

MinecraftServer server = ...
Registry<DimensionType> dimensionRegistry = server.registryAccess().registryOrThrow(Registries.DIMENSION_TYPE);

for (Map.Entry<ResourceKey<DimensionType>, DimensionType> dimensionEntry : dimensionRegistry.entrySet()) {
  ResourceKey<DimensionType> dimensionKey = dimensionEntry.getKey();
  DimensionType dimension = dimensionEntry.getValue();
}

Working on 1.20.1, if someone is still interested in the latest version of Minecraft.

Link to comment
Share on other sites

  

On 4/8/2021 at 6:03 AM, xBigEllx said:

Hello. I'm creating a mod that needs to access all registered Vanilla and mod dimension Ids.

 

In 1.15, it was possible to use the following:

for (DimensionType type : DimensionType.getAll()) {}

From there, I could access each of their dimension Ids. This seems to have changed in 1.16 and I can't figure out another way to access these dimensions.

 

I have tried accessing the "WORLD_TYPES" Forge registry by using the following:

for (ForgeWorldType type : ForgeRegistries.WORLD_TYPES.getValues()) {}

Unfortunately, it appears that this is also not the correct way to do it as there are no values in here.

 

Any help is appreciated.

 

 

In Minecraft 1.16+, use `DimensionManager` to access dimension IDs. Iterate through registered dimensions with `DimensionManager.getRegistry().keySet()`, enabling access to both vanilla and mod-added dimensions.

Edit: All good?

Edited by NinaKunze
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.