Jump to content

[1.16.5][SOLVED] How to get the current dimension where the player is in?


Recommended Posts

Posted (edited)

Hello Helper and Reader,

I am prepairing a litle mod for myself.
This mod works from version 1.7.10 up to 1.15.2 at the current time. I am prepairing now version 1.16.5 and after it 1.17.1 and 1.18.1. 

I have now a problem with the dimension ID.

Version <1.15.2 I used:

dimensionID = world.dimension.getType().getId();

thats it.

As I read correctly. Version 1.16+ does not provide the ID as it anymore. So I need to find a workaround.
Something like:

switch (world.getDimensionType().getLocation().getPath()) {
    case "overworld": dimensionID = 0;
    case "the_nether": dimensionID = -1;
    case "the_end": dimensionID = 1;
}

Or:

if (world.getDimensionKey().getLocation() == DimensionType.OVERWORLD_ID) {
    dimensionID = 0;
} else if (world.getDimensionKey().getLocation() == DimensionType.THE_NETHER_ID) {
    dimensionID = -1;
} else if (world.getDimensionKey().getLocation() == DimensionType.THE_END_ID) {
    dimensionID = 1;
}

The goal is to have the variable dimensionID assigned to the ID of the dimension.

 

May you show me a working version?
I would be very thankful if you can show me a working version for 1.17.1 and 1.18.1 if they differ to much.

 

Yours sincerely Padder

 

SOLUTION:

world.getDimension() == World.OVERWORLD
// OR World.END World.NETHER
Edited by Padder
Solution added
Posted

@diesieben07

I need the numerical ID because I provide an API with a lot of minecraft data (for example the dimension). I do not have the know how to change the API so i have to send it the data he wants to get (and yes the api is outdated, otherwise I do not have to update the mod on my own). The API is for minecraft vanilla only. It will not have support for added dimensions in mods and thats why I will just need "overworld", "the_end" and "the_nether".

That is what I am asking for. How to get the current dimension? I assign the "ID" on my own.

Posted

I am working in Java.. but I don't know how to use World#dimension();. For all years working with Java it seems syntactically wrong .And my IDE does not like it either. Please tell me more, about it.

To give you more input, how I am using it:
 

ClientWorld world = Minecraft.getInstance().world;
assert world != null;
worldTime = world.getDayTime();
isDayTime = world.isDaytime();
rainStrength = world.rainingStrength;
isRaining = world.isRaining();
dimensionID .......

I have
world.getDimensionKey() --- return RegestryKey<World>
world.getDimensionType() --- return DimensionType
world.getDimensionRenderInfo() --- return DimensionRenderInfo

Hope this helps.

Posted

Ok. Then working with getDimensionKey() - This returns a RegistryKey<World> so i looked up how the dimensions are saved in this method.
Found: 

RegistryKey.getOrCreateKey(Registry.WORLD_KEY, new ResourceLocation("overworld"));

(as an example for "overworld")

So I compared wordl.getDimensionKey() === RegistryKey.getOrCreateKey(...)

This is a working! Now my api gets to know in which dimension I am.

Great Thank you diesieben07 ^^

Have a nice day.

Posted

diesieben07

What are you recommending instead of it.
I try to be clear as possible:

I want to have a function or variable, which is telling me in which dimension I are.

// 1.16.5
world.getDimension() == RegistryKey.getOrCreateKey(Registry.WORLD_KEY, new ResourceLocation("overworld"))

// 1.17.1
world.dimension() == ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation("overworld"))

This is working after more than 12 hours of searching, and now you are telling me I should not use it.

 

I dont want to get hints to find that on my own. I want to get a clear answer.

Which function.. which variable.. which statement can I use to get programmatically the dimension (or dimension ID) of the player?

Your hint with World#dimension() wasn't wrong, but my solution with that hint seems to be wrong. So please be clear! Or tell me where I should ask for it.

  • Padder changed the title to [1.16.5][SOLVED] How to get the current dimension where the player is in?

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.