Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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

    • When I try to open forge with java it says unable to install java but I can open java itself just fine. I've tried deleting and redownloading both forge and java but nothing changed. I also tried opening it from my files and from my desktop but it still gave me the same message. I don't think I'm doing anything wrong, I just click on forge and pressed open with java and java opens but only to give me the message saying " unable to install java there are errors in the following switches".   (this is just a picture of what i got from google not my exact message)
    • This is the capability inject and provider for one of my capabilities. All of them are coded the exact same way. public class CapabilityDamageTypes { @CapabilityInject(IDamageTypes.class) public static Capability<IDamageTypes> DAMAGE_TYPES_CAPABILITY = null; public static void register() { CapabilityManager.INSTANCE.register(IDamageTypes.class, new Storage(), new Factory()); } private static class Storage implements Capability.IStorage<IDamageTypes> { @Nullable @Override public INBT writeNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side) { CompoundNBT tag = new CompoundNBT(); tag.putFloat("slash", instance.getSlashDamage()); tag.putFloat("impact", instance.getImpactDamage()); tag.putFloat("puncture", instance.getPunctureDamage()); tag.putFloat("fire", instance.getFireDamage()); tag.putFloat("lightning", instance.getLightningDamage()); tag.putFloat("ice", instance.getIceDamage()); tag.putFloat("dark", instance.getDarkDamage()); tag.putFloat("holy", instance.getHolyDamage()); tag.putFloat("magic", instance.getMagicDamage()); tag.putString("mobDamageType", instance.getMobDamageType()); return tag; } @Override public void readNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side, INBT nbt) { float slash = ((CompoundNBT) nbt).getFloat("slash"); float impact = ((CompoundNBT) nbt).getFloat("impact"); float puncture = ((CompoundNBT) nbt).getFloat("puncture"); float fire = ((CompoundNBT) nbt).getFloat("fire"); float lightning = ((CompoundNBT) nbt).getFloat("lightning"); float ice = ((CompoundNBT) nbt).getFloat("ice"); float dark = ((CompoundNBT) nbt).getFloat("dark"); float holy = ((CompoundNBT) nbt).getFloat("holy"); float magic = ((CompoundNBT) nbt).getFloat("magic"); String mobDamageType = ((CompoundNBT) nbt).getString("mobDamageType"); instance.setSlashDamage(slash); instance.setImpactDamage(impact); instance.setPunctureDamage(puncture); instance.setFireDamage(fire); instance.setLightningDamage(lightning); instance.setIceDamage(ice); instance.setDarkDamage(dark); instance.setHolyDamage(holy); instance.setMagicDamage(magic); instance.setMobDamageType(mobDamageType); } } private static class Factory implements Callable<IDamageTypes> { @Override public IDamageTypes call() throws Exception { return new DamageTypes(0, 0, 0, 0, 0, 0, 0, 0, 0, "IMPACT"); } } } package com.cwjn.hardstuckintegration.Capabilities.DamageTypes; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class DamageTypesProvider implements ICapabilitySerializable<CompoundNBT> { //private final DamageTypes damage = new DamageTypes(); //private final LazyOptional<IDamageTypes> damageOptional = LazyOptional.of(() -> damage); private DamageTypes damage; private LazyOptional<IDamageTypes> damageOptional; public void invalidate() { damageOptional.invalidate(); } public DamageTypesProvider(float I, float P, float S, float F, float L, float IC, float D, float H, float M, String mobDamageType) { damage = new DamageTypes(I, P, S, F, L, IC, D, H, M, mobDamageType); damageOptional = LazyOptional.of(() -> damage); } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return cap == CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY ? damageOptional.cast() : LazyOptional.empty(); } @Override public CompoundNBT serializeNBT() { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY == null) { return new CompoundNBT(); } else { return (CompoundNBT) CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.writeNBT(damage, null); } } @Override public void deserializeNBT(CompoundNBT nbt) { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY != null) { CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.readNBT(damage, null, nbt); } } }  
    • I got it now I installed the java 16 jdk instead of 8. Now it works thanks!  
    • net.minecraft.ResourceLocationException: Non [a-z0-9/._-] character in path of location: minecraft:textures/models/armor/gold_layer_١.png     at net.minecraft.resources.ResourceLocation.<init>(ResourceLocation.java:37) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.resources.ResourceLocation.<init>(ResourceLocation.java:42) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.getArmorResource(HumanoidArmorLayer.java:146) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_117118_(HumanoidArmorLayer.java:60) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_6494_(HumanoidArmorLayer.java:36) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_6494_(HumanoidArmorLayer.java:23) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.LivingEntityRenderer.m_7392_(LivingEntityRenderer.java:126) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.MobRenderer.m_7392_(SourceFile:45) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.MobRenderer.m_7392_(SourceFile:18) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.EntityRenderDispatcher.m_114384_(EntityRenderDispatcher.java:129) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.LevelRenderer.m_109517_(LevelRenderer.java:1280) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.LevelRenderer.m_109599_(LevelRenderer.java:1076) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109089_(GameRenderer.java:1050) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:830) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1039) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:659) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:186) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:45) ~[fmlloader-1.17.1-37.0.126.jar%2322!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90) [bootstraplauncher-0.1.17.jar:?] {}   (This the crash report(
    • Also you should consider reading the README.txt file (there it explains how to set up the workspace and what to do on specific errors)
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.