Jump to content

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


Padder

Recommended Posts

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
Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Compare this list (client-side-only mods) with your mods: https://www.dropbox.com/scl/fi/yeldxfv8ed60e4uflc2fi/Client-Side-Only-Modlist.xlsx?rlkey=8376c5bk7b33je2tad4p3ybrg&st=qf6osvit&dl=0  
    • Crashlog: https://paste.ee/p/WrGYD I'm thinking the problem might be a client side mod but ive already checked the mod list like 5 times and still cant find the problem
    • I'm unable to join my local forge servers. When running my forge servers of seemingly any version (tested 1.18 to 1.21.1) I get an error message [Forge Version Check/WARN] [ne.mi.fm.VersionChecker/]: Failed to process update information The server continues to start up and run, however I'm unable to join. Looking for solutions? Full error message: (note last "thead warning" error seems to be unrelated and only happened once for 1.20.1) Forge version check warning has happened for every version. [09:52:31] [Forge Version Check/WARN] [ne.mi.fm.VersionChecker/]: Failed to process update information java.net.http.HttpConnectTimeoutException: HTTP connect timed out         at jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:950) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:133) ~[java.net.http:?] {}         at net.minecraftforge.fml.VersionChecker$1.openUrlString(VersionChecker.java:142) ~[fmlcore-1.20.1-47.3.10.jar%23102!/:?] {}         at net.minecraftforge.fml.VersionChecker$1.process(VersionChecker.java:180) ~[fmlcore-1.20.1-47.3.10.jar%23102!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {}         at net.minecraftforge.fml.VersionChecker$1.run(VersionChecker.java:117) ~[fmlcore-1.20.1-47.3.10.jar%23102!/:?] {} Caused by: java.net.http.HttpConnectTimeoutException: HTTP connect timed out         at jdk.internal.net.http.ResponseTimerEvent.handle(ResponseTimerEvent.java:68) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientImpl.purgeTimeoutsAndReturnNextDeadline(HttpClientImpl.java:1788) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:1385) ~[java.net.http:?] {} Caused by: java.net.ConnectException: HTTP connect timed out         at jdk.internal.net.http.ResponseTimerEvent.handle(ResponseTimerEvent.java:69) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientImpl.purgeTimeoutsAndReturnNextDeadline(HttpClientImpl.java:1788) ~[java.net.http:?] {}         at jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:1385) ~[java.net.http:?] {} [09:52:31] [Yggdrasil Key Fetcher/ERROR] [mojang/YggdrasilServicesKeyInfo]: Failed to request yggdrasil public key com.mojang.authlib.exceptions.AuthenticationUnavailableException: Cannot contact authentication server         at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:119) ~[authlib-4.0.43.jar%2375!/:?] {}         at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:91) ~[authlib-4.0.43.jar%2375!/:?] {}         at com.mojang.authlib.yggdrasil.YggdrasilServicesKeyInfo.fetch(YggdrasilServicesKeyInfo.java:94) ~[authlib-4.0.43.jar%2375!/:?] {}         at com.mojang.authlib.yggdrasil.YggdrasilServicesKeyInfo.lambda$get$1(YggdrasilServicesKeyInfo.java:81) ~[authlib-4.0.43.jar%2375!/:?] {}         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572) ~[?:?] {}         at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358) ~[?:?] {}         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?] {}         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?] {}         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?] {}         at java.lang.Thread.run(Thread.java:1575) ~[?:?] {} Caused by: java.net.SocketTimeoutException: Connect timed out         at sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546) ~[?:?] {}         at sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:592) ~[?:?] {}         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[?:?] {}         at java.net.Socket.connect(Socket.java:760) ~[?:?] {}         at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:304) ~[?:?] {}         at sun.net.NetworkClient.doConnect(NetworkClient.java:178) ~[?:?] {}         at sun.net.www.http.HttpClient.openServer(HttpClient.java:531) ~[?:?] {}         at sun.net.www.http.HttpClient.openServer(HttpClient.java:636) ~[?:?] {}         at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264) ~[?:?] {}         at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:377) ~[?:?] {}         at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193) ~[?:?] {}         at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1273) ~[?:?] {}         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1114) ~[?:?] {}         at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179) ~[?:?] {}         at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1676) ~[?:?] {}         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1600) ~[?:?] {}         at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223) ~[?:?] {}         at com.mojang.authlib.HttpAuthenticationService.performGetRequest(HttpAuthenticationService.java:140) ~[authlib-4.0.43.jar%2375!/:?] {}         at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:96) ~[authlib-4.0.43.jar%2375!/:?] {}         ... 9 more [09:52:31] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 5985ms or 119 ticks behind
    • Remove the mod tempad from the mods-folder
    • Hi, deleting the config folder did not appear to work, what mod are you referring to I could try to delete to fix the problem?
  • Topics

×
×
  • Create New...

Important Information

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