Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)
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
Posted (edited)
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
Posted

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/

Posted (edited)
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
Posted (edited)
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
Posted

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

 

Posted (edited)
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
Posted
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.

Posted

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/

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

Posted
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/

Posted (edited)

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/

Posted (edited)
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
Posted (edited)
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/

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.