Jump to content

Checking if chunk is loaded?


jredfox
 Share

Recommended Posts

I tried 

System.out.println("First Check:" + e.world.isChunkGeneratedAt(chunkX,chunkZ));

but, it said true when I was checking a chunk 100 blocks away. It returned true since the chunk generated that far away was already stored on the disk how should I test for actual loaded chunks?

Edited by jredfox
Link to comment
Share on other sites

18 minutes ago, jabelar said:

Well the Chunk class has an isLoaded() method. So what about world.getChunkFromChunkCoords(chunkX, chunkY).isLoaded()?

calling world get chunk will provide the chunk if not loaded and will always return true I believe. In 1.7.10 there was a world.chunkExists(chunkX,chunkZ) where it sounded like it checked only loaded?

Edited by jredfox
Link to comment
Share on other sites

7 minutes ago, jabelar said:

There is a chunkExists() method in the ChunkProvider class. So world.getChunkProvider().chunkExists(chunkX, chunkY) looks promising..

it says chunkExists I believe it returns whether or not it's been generated not if it's currently loaded into memory helpful but, wrong boolean

Edited by jredfox
Link to comment
Share on other sites

If you look at the ChunkProviderServer code I think the chunkExists() is actually just the loaded chunks. There is another method called isChunkGeneratedAt(). Also, if you look at the implementation of the chunkExists() it looks at the id2ChunkMap which it also uses for methods like getLoadedChunkCount(). So it seems to be loaded chunks.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

7 minutes ago, jabelar said:

If you look at the ChunkProviderServer code I think the chunkExists() is actually just the loaded chunks. There is another method called isChunkGeneratedAt(). Also, if you look at the implementation of the chunkExists() it looks at the id2ChunkMap which it also uses for methods like getLoadedChunkCount(). So it seems to be loaded chunks.

maybe I could do both? Either way it seems to be protected weird
 

return world.isChunkLoaded() && world.chunkProivder.chunkExists();

 

ChunkProvider.chunkExists()doesn't seem to be a method for the interface :( I could check for chunk provider loaded  chunk method

I think I should always use the world's implementation instead of chunk providers since that should always work but, the method is protected I don't want to use reflection why is it protected?

Edited by jredfox
Link to comment
Share on other sites

4 minutes ago, jabelar said:

The world.isChunkLoaded() just calls the chunkExists() method. You don't need both.

WorldServer is protected why? I feel this should always be public especially with checking stuff like chunks are loaded
 

    protected boolean isChunkLoaded(int x, int z, boolean allowEmpty)
    {
        return this.getChunkProvider().chunkExists(x, z);
    }

 

Edited by jredfox
Link to comment
Share on other sites

not sure if this is proper but, I got it working would prefer no reflection this is something that should always be visable:
 

   /**
    * uses reflection since the world method is protected
    */
   public static boolean isChunkLoaded(World w,int x,int z,boolean allowEmpty)
   {
	   try
	   {
		   Method m = FieldAcess.chunkLoaded;
		   m.setAccessible(true);
		   return (Boolean) m.invoke(w, x,z,allowEmpty);
	   }
	   catch(Throwable t)
	   {
		   t.printStackTrace();
	   }
	   return false;
   }

 

Link to comment
Share on other sites

  • Don't call setAccessible every time.
  • You almost never want to catch Throwable.
  • That is not how you handle an exception.

 

1 hour ago, jredfox said:

WorldServer is protected why?

Because in vanilla Minecraft it is not needed outside the world class. So it's protected. You need to stop expecting Minecraft to have a nice API.

Edited by diesieben07
Link to comment
Share on other sites

37 minutes ago, diesieben07 said:
  • Don't call setAccessible every time.
  • You almost never want to catch Throwable.
  • That is not how you handle an exception.

 

Because in vanilla Minecraft it is not needed outside the world class. So it's protected. You need to stop expecting Minecraft to have a nice API.

If I don't the world throws an Illegal Security exception I tried just setting it accessible only once on startup it sometimes fails if the world becomes a new instance. And it is needed outside the world class for modded terrain generation if they are optimized  that is

Edited by jredfox
Link to comment
Share on other sites

Just now, jredfox said:

If I don't the world throws an Illegal Security exception I tried just setting it accessible once it fails if the world becomes a new instance.

That is not true and not how reflection works.

 

Just now, jredfox said:

And it is needed outside the world class for modded terrain generation if they are optimized  that is

Minecraft is not written with mods in mind.

Link to comment
Share on other sites

4 hours ago, diesieben07 said:

That is not true and not how reflection works.

 

Minecraft is not written with mods in mind.

well I got the crash report as stated above when the object of the world was created as a new instance rarely but, it did happen as well as it occurring when I was trying to access player methods because I didn't set it accessible every time just once in pre init.

Link to comment
Share on other sites

I'm still really confused why you're using the reflection and stuff. Are you sure that the chunk provider chunkExists() doesn't work? That is public method and is exactly what the protected method WorldServer.isChunkLoaded() calls. That method is used by all the vanilla code such as isAreaLoaded(), isBlockLoaded() and so forth.

 

You should only need the public method world.getChunkProvider().chunkExists().

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

On 5/24/2018 at 10:36 AM, jabelar said:

I'm still really confused why you're using the reflection and stuff. Are you sure that the chunk provider chunkExists() doesn't work? That is public method and is exactly what the protected method WorldServer.isChunkLoaded() calls. That method is used by all the vanilla code such as isAreaLoaded(), isBlockLoaded() and so forth.

 

You should only need the public method world.getChunkProvider().chunkExists().

it won't always work with modded worlds and that's the issue.

Link to comment
Share on other sites

3 hours ago, jredfox said:

it won't always work with modded worlds and that's the issue.

Why? Why would a mod change that part of the ChunkProvider? Most modded dimensions change the ChunkGenerator but don't fool around with ChunkProvider. But if they did the custom ChunkProvider would need to implement the IChunkProvider interface. That interface requires an implementation of the getLoadedChunk() method which only returns loaded chunk (null if not loaded).

 

The getLoadedChunk() for the vanilla ChunkProviderServer accesses the same map I already mentioned, so the chunkExists() is legit at least when ChunkProviderServer is used.

 

In any case, what mods change this functionality? They all need a sense of what is loaded even if they change how things load, and the interface requires an implementation of the getLoadedChunk() method. 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

So I looked through the source of a number of mods that create major dimension stuff. Like Twilight Forest, Advanced Rocketry, AbysmalCraft etc. and none of them create any custom chunk providers. Advanced Rocketry looks like it does but they actually misnamed their classes -- the ones they call "ChunkProvider" actually implement IChunkGenerator not IChunkProvider.

 

The main mod I can find quickly that does create custom IChunkProvider implementations is GalactiCraft. They always return true for the chunkExists(). Now, you might think that is a problem but I'm thinking that it might actually be correct -- you'd have to figure out what they're doing but they probably had a good reason for this.  Remember that the chunkExists() is checked by things like the World classes when they are doing all sorts of things like looking for entities and such. So if they're reporting true for this then I guess it means that for those specific custom providers that the chunk exists ("loaded") at all times. I don't know much about GalactiCraft's loading but they do explain that there is generally loading and such going on: https://wiki.micdoodle8.com/wiki/Sealed_space#Chunk_loading

 

Any, generally the point of an interface is that it is supposed to be honored. So I doubt if any quality mod would report that chunks are loaded when they are not.

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

On 5/26/2018 at 5:54 PM, jabelar said:

Why? Why would a mod change that part of the ChunkProvider? Most modded dimensions change the ChunkGenerator but don't fool around with ChunkProvider. But if they did the custom ChunkProvider would need to implement the IChunkProvider interface. That interface requires an implementation of the getLoadedChunk() method which only returns loaded chunk (null if not loaded).

 

The getLoadedChunk() for the vanilla ChunkProviderServer accesses the same map I already mentioned, so the chunkExists() is legit at least when ChunkProviderServer is used.

 

In any case, what mods change this functionality? They all need a sense of what is loaded even if they change how things load, and the interface requires an implementation of the getLoadedChunk() method. 

you think of it wrongly the world loaded chunks is what I am worried about not necessarily the chunk provider might have an if else statement for modded worlds or just plain not using it always for chunk provider.


If you looked at another method checking for chunk generated at checks both the world and chunk provider

Anyways this thread is solved

Edited by jredfox
Link to comment
Share on other sites

21 minutes ago, jredfox said:

you think of it wrongly the world loaded chunks is what I am worried about not necessarily the chunk provider might have an if else statement for modded worlds or just plain not using it always for chunk provider.


If you looked at another method checking for chunk generated at checks both the world and chunk provider

 

While there is no harm in doing a useless check, it makes no sense really. There are no examples of vanilla or popular mods that do that. And why would a mod return a wrong value for an important interface? And lastly, if any mod did change the whole chunk loading system so much that you can't trust the loading interface then your world check cannot be trusted either!

 

To really make the point: WorldServer class (which no one ever modifies) has method isChunkLoaded() which has the following source:

    protected boolean isChunkLoaded(int x, int z, boolean allowEmpty)
    {
        return this.getChunkProvider().chunkExists(x, z);
    }

 

This isChunkLoaded() method is the ONLY thing used to check chunk loading in all the following methods (which no one ever change):

  • World#isAreaLoaded()
  • World#isBlockLoaded()
  • World#updateEntities()
  • WorldServer#tickPlayers()
  • World#getEntitiesInAABB()
  • etc.

And these methods are relied on by almost everything else. Like World#getBlockState() calls isBlockLoaded() which calls isChunkLoaded().

 

If all the important functionality in the game relies on the chunk providers chunkExists() method. I really don't get why your mod would require anything else. 

 

But no harm if you want to do extra checks I guess.

 

 

 

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I used multiple biomes by setting the type to minecraft:multi_noise. The dimension is working fine now, but I was wondering if there is a way to supress this warning when creating a new world: Warning! These settings are using experimental features. These settings are experimental and could one day stop working. Do you wish to proceed?
    • Hi. Please help. Forge keep crashing on my pc (error code 1). This happened after i updated my PC to the latest windows 11 update. I have tried updating my GPU driver, reinstall java and reinstall minecraft, but i still got this error code 1. Any help is appreciated. Thanks.  
    • here are the logs https://gist.github.com/Myrious/13e16642c4afe9c0286691571bd136f0
    • I Start Up the game get a crash before forge even starts to load Crash Log-https://gist.github.com/keepinitreal247/c1024110beca289019a0177ddecfc910
    • The game crashed whilst initializing game. Error: net.minecraftforge.fml.ModLoadingExceptionForge encountered an error during the sided_setup event phase . Got crash exit code -1 for minecraft forge 1.19.3 It works before i instal my mods the list of mods i got are: Macaw's: paintings, paths, lights, roofs, windows, trapdoors, fences, doors + optifine 1.19.3  +  Shaders: BSL, Sildurs-high,extreme, extreme VL + Resource packs: SFT_FREE, HelHeim R29, SkylineArt free, Clear_Glass_Pack, Unity, Round trees, Fresh animations, Better-Leaves  ---- Minecraft Crash Report ---- // Hi. I'm Minecraft, and I'm a crashaholic. Time: 2023-01-29 01:34:45 Description: Rendering overlay java.lang.NoClassDefFoundError: net/minecraftforge/common/extensions/IForgeModelBaker     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at net.minecraft.client.resources.model.ModelBakery.lambda$bakeModels$9(ModelBakery.java:209) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}     at java.util.HashMap$KeySet.forEach(HashMap.java:1008) ~[?:?] {}     at net.minecraft.client.resources.model.ModelBakery.m_245909_(ModelBakery.java:204) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}     at net.minecraft.client.resources.model.ModelManager.m_245476_(ModelManager.java:166) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.resources.model.ModelManager.m_246937_(ModelManager.java:89) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:runtimedistcleaner:A}     at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646) ~[?:?] {}     at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483) ~[?:?] {}     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}     at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {re:computing_frames}     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {re:computing_frames}     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} Caused by: java.lang.ClassNotFoundException: net.minecraftforge.common.extensions.IForgeModelBaker     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     ... 28 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {} -- Overlay render details -- Details:     Overlay name: net.minecraft.client.gui.screens.LoadingOverlay Stacktrace:     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:1337) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:mtr.mixins.json:GameRendererMixin,pl:mixin:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1135) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:713) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.m_239872_(Main.java:212) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.0.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {} -- Last reload -- Details:     Reload number: 1     Reload reason: initial     Finished: No     Packs: vanilla
  • Topics

×
×
  • Create New...

Important Information

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