Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Chunks, Saving Data to, And So on
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Draco18s

Chunks, Saving Data to, And So on

By Draco18s, March 24, 2015 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted March 24, 2015

So, I seem to have a strange problem saving data to the chunk its associated with when the chunk is saved and unloaded.

 

Basically:

 

[22:22:57] [server thread/INFO]: Saving and pausing game...

[22:22:57] [server thread/INFO]: Saving chunks for level 'Copy of ASDF'/Overworld

[22:23:02] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:saveData:75]: Saving data for chunk [dim0](-4,0,16)

[22:23:02] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:saveData:81]: Saving tree: Tree[-61,67,265] 693

[22:23:02] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:saveData:81]: Saving tree: Tree[-58,64,271] 974

[22:23:07] [server thread/INFO]: Saving chunks for level 'Copy of ASDF'/Nether

[22:23:07] [server thread/INFO]: Saving chunks for level 'Copy of ASDF'/The End

[22:23:23] [Client thread/INFO] [sTDOUT]: [com.draco18s.wildlife.WildlifeEventHandler:chunkUnload:693]: Unloading Chunk: -4,16

[22:23:45] [server thread/INFO]: Saving and pausing game...

[22:23:45] [server thread/INFO]: Saving chunks for level 'Copy of ASDF'/Overworld

[22:23:48] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:saveData:75]: Saving data for chunk [dim0](-4,0,16)

[22:23:54] [server thread/INFO]: Saving chunks for level 'Copy of ASDF'/Nether

[22:23:54] [server thread/INFO]: Saving chunks for level 'Copy of ASDF'/The End

 

The data is saved (22:23:02).

 

Then the data is unloaded (22:23:23) as the player moved out of range.

 

Then the data (which is now been removed from memory) is saved again (22:23:48), resulting in data loss.

 

WTH.  Why is an unloaded chunk receiving a ChunkSave event?  Why does

if(event.getChunk().isChunkLoaded)

still return true for this actually-unloaded chunk?

 

How the hell do I fix this?

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Awesome_Spider    64

Awesome_Spider

Awesome_Spider    64

  • Dragon Slayer
  • Awesome_Spider
  • Forge Modder
  • 64
  • 892 posts
Posted March 24, 2015

That's weird. What version is this?

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted March 24, 2015

Forge v1291

 

1.7.10

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

diesieben07    7705

diesieben07

diesieben07    7705

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7705
  • 56508 posts
Posted March 24, 2015

You need to ignore unload events from the client.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted March 24, 2015

...that's odd, I thought I made sure to account for that.  But on that specific event, its missing.

 

Lets try this again.

 

Ah yes, that did it.  Thanks Diesieben. :)

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted March 26, 2015

You need to ignore unload events from the client.

 

Ok, this fixed it for SSP, but not SMP.

 

[23:16:22] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.WildlifeEventHandler:chunkSave:343]: Saved chunk [dim0](21,0,14)

[23:16:22] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:saveData:68]: Saved tree Tree[336,82,237] 956

[23:16:22] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:saveData:68]: Saved tree Tree[342,84,233] 144

[23:18:10] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:printChunkInfo:367]: Trees in chunk [dim0](21,0,14)

[23:18:10] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:printChunkInfo:370]:    Tree[336,82,237] 968

[23:18:10] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:printChunkInfo:370]:    Tree[342,84,233] 156

[23:20:23] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.WildlifeEventHandler:chunkUnload:366]: Unloaded chunk [dim0](21,0,14)

[23:20:23] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.WildlifeEventHandler:chunkSave:343]: Saved chunk [dim0](21,0,14)

[23:21:16] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:printChunkInfo:367]: Trees in chunk [dim0](21,0,14)

[23:21:16] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:printChunkInfo:374]:    [None]

 

Now what?

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Abastro    123

Abastro

Abastro    123

  • World Shaper
  • Abastro
  • Forge Modder
  • 123
  • 1075 posts
Posted March 26, 2015

I found that when it unloads chunks, it saves the data directly after unloading the chunks.

Maybe it is causing the issue.

  • Quote

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted March 26, 2015

I found that when it unloads chunks, it saves the data directly after unloading the chunks.

Maybe it is causing the issue.

 

Ok, so how do I fix it?

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Abastro    123

Abastro

Abastro    123

  • World Shaper
  • Abastro
  • Forge Modder
  • 123
  • 1075 posts
Posted March 26, 2015

Maybe saving the unloaded chunks in a map in Chunk Unload Event?

  • Quote

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted March 26, 2015

Clunky, but it should work.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted April 5, 2015

For the love of god.

 

[13:08:51] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.WildlifeEventHandler:chunkGen:423]: Generated chunk [dim0](-17,0,-3)

[13:08:51] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:addTree:146]: Tree[-262,66,-41] 1061 added to chunk [dim0](-17,0,-3)

[13:08:51] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:addTree:146]: Tree[-261,66,-41] 7993 added to chunk [dim0](-17,0,-3)

[13:08:51] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.util.TreeDataHooks:addTree:146]: Tree[-257,73,-48] 5064 added to chunk [dim0](-17,0,-3)

[13:11:17] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.WildlifeEventHandler:chunkUnload:433]: Unloaded chunk [dim0](-17,0,-3)

[13:11:22] [server thread/INFO] [sTDOUT]: [com.draco18s.wildlife.WildlifeEventHandler:chunkLoad:385]: Loaded chunk [dim0](-17,0,-3)

 

Now I have chunks that generate and never get a save call before they're unloaded.  This is just as bad as getting a save call after I purged the data from memory.

 

width=240 height=240http://static.fjcdn.com/pictures/Rage_562aea_329374.jpg[/img]

 

Do none of these events make god damn sense?  I should not have to build a data structure to track what chunks are in what state so that I don't inadvertently trash data I still need or overwrite good data with bad.  The game already freaking does this, but it can't be arsed to inform me!

 

I'm about ready to store the data in an indestructible bedrock-level tileentity.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Abastro    123

Abastro

Abastro    123

  • World Shaper
  • Abastro
  • Forge Modder
  • 123
  • 1075 posts
Posted April 5, 2015

... I don't know why those issues can ever happen, from this code.. (Note that mine is 1.7.10.1160 so it can be different)

    /**
     * Unloads chunks that are marked to be unloaded. This is not guaranteed to unload every such chunk.
     */
    public boolean unloadQueuedChunks()
    {
        if (!this.worldObj.levelSaving)
        {
            for (ChunkCoordIntPair forced : this.worldObj.getPersistentChunks().keySet())
            {
                this.chunksToUnload.remove(ChunkCoordIntPair.chunkXZ2Int(forced.chunkXPos, forced.chunkZPos));
            }

            for (int i = 0; i < 100; ++i)
            {
                if (!this.chunksToUnload.isEmpty())
                {
                    Long olong = (Long)this.chunksToUnload.iterator().next();
                    Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(olong.longValue());

                    if (chunk != null)
                    {
                        chunk.onChunkUnload();
                        this.safeSaveChunk(chunk);
                        this.safeSaveExtraChunkData(chunk);
                        this.loadedChunks.remove(chunk);
                        ForgeChunkManager.putDormantChunk(ChunkCoordIntPair.chunkXZ2Int(chunk.xPosition, chunk.zPosition), chunk);
                        if(loadedChunks.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){
                            DimensionManager.unloadWorld(this.worldObj.provider.dimensionId);
                            return currentChunkProvider.unloadQueuedChunks();
                        }
                    }

                    this.chunksToUnload.remove(olong);
                    this.loadedChunkHashMap.remove(olong.longValue());
                }
            }

            if (this.currentChunkLoader != null)
            {
                this.currentChunkLoader.chunkTick();
            }
        }

        return this.currentChunkProvider.unloadQueuedChunks();
    }

So it surely unloads the chunk before it saves the chunk data..

  (Chunk#onChunkUnload surely marks the chunk as unloaded)

The only another way the ChunkSave event got called is WorldServer#saveAllChunks(), which is only called when world is saved..

  • Quote

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted April 6, 2015

So it surely unloads the chunk before it saves the chunk data..

  (Chunk#onChunkUnload surely marks the chunk as unloaded)

The only another way the ChunkSave event got called is WorldServer#saveAllChunks(), which is only called when world is saved..

 

So, in other words, I need two events to happen for me to safely say "this data is no longer relevant."  First a chunkUnload, then a chunkSave (but watch out, saves can happen any time!)

 

Yeah.  While I'm sure that that makes sense, its a complete hassle from a "I want this to work" perspective.  E.g. "chunkUnload" should be the last thing that happens to a chunk before it's loaded again.  The event should be telling mods "this chunk is leaving, whatever cleanup you need to do, do it."

 

       loaded
          V
gen -> (active) <-> save
                     V
                  unloaded

 

Instead, the flow chart actually looks like this:

 

       loaded
          V
gen -> (active) <-> save
          V
       unloaded -> save

 

Note the two instances of "save."  They are not identical, but it is impossible to tell the difference between them without storing extra data as the events trigger.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

diesieben07    7705

diesieben07

diesieben07    7705

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7705
  • 56508 posts
Posted April 6, 2015

I'll just throw this in here:

"Just" use a WeakHashMap and don't even bother handling the unload.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted April 6, 2015

I'll just throw this in here:

"Just" use a WeakHashMap and don't even bother handling the unload.

 

Can't.  The save/load and tick operations happen on separate threads (that is, strait up using a HashMap causes concurrent modification exceptions) and there is no "ConcurrentWeakHashMap."

 

Not to mention that I tick the data, so its kind of important to know if the chunk the data is associated with is active.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

diesieben07    7705

diesieben07

diesieben07    7705

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7705
  • 56508 posts
Posted April 6, 2015

Ok. Here goes (not saying that this is ideal, this stuff needs to be fixed up. A lot of it was probably broken (because let's face it, this is broken) when the threaded chunk saving was introduced):

 

First, there is a "ConcurrentWeakHashMap", as always Guava to the rescue:

ConcurrentMap<Chunk, V> map = new MapMaker().weakKeys().concurrencyLevel(2).makeMap();

 

While exploring this path, I found the following: onChunkUnload sets

isChunkLoaded

to false. So in chunk unload you do nothing. Then in chunk save you check if isChunkLoaded is false and if so unload your data (you don't even need the WeakHashMap then).

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted April 6, 2015

While exploring this path, I found the following: onChunkUnload sets

isChunkLoaded

to false. So in chunk unload you do nothing. Then in chunk save you check if isChunkLoaded is false and if so unload your data (you don't even need the WeakHashMap then).

 

Thanks for the digging, as always, diesieben07.

I've only managed to glean so much from the SRG'd vanilla source on my own.  Most of what I've figured out has been from observing the behavior of a single chunk as I interact with the system and with suggestions as I run into stumbling blocks.

 

There's a number of headaches going on with this code, and this is only one part of it.  It seems that even with a 3-chunk-deferred-radius for the generation of the data, it still doesn't find all of the trees, especially in a jungle.  Neither Keybounce nor I can figure out why.  But that's a problem for another thread.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • LessyDoggy
      Forge 1.12.2 Installing Bug

      By LessyDoggy · Posted 1 hour ago

      So I used forge 1.16.5 but now I cant change it too 1.12.2 no mather what. I have tried Installing client, Installing server and extract but nothing works. I even removed forge 1.16.5 from my computer but I still have that verison on and idk how to change it.
    • Yourskillx2
      !!Keeps crashing during launch!!

      By Yourskillx2 · Posted 1 hour ago

      I have a decent sized mod pack with around 90 mods and every time I go to launch the game, it loads some stuff then crashes with exit code 0, I cannot figure out if its a mod in the pack doing it, like maybe not a release version or if it just doesn't work with Mc like its supposed to.
    • IMaironI
      server error

      By IMaironI · Posted 8 hours ago

      2021-03-06-8.log
    • diesieben07
      server error

      By diesieben07 · Posted 8 hours ago

      Like I already said: The logs folder.
    • prototype204
      Attacking/Hitting issue

      By prototype204 · Posted 8 hours ago

      I am no longer able to attack animals or mobs in the game, however they are still able to attack me. I checked to verify that the mods I downloaded weren't the issue. I think they might be an error code in forge 1.16.5 however if anyone knows what I could do to fix this. P.S. I could still break bricks. 
  • Topics

    • LessyDoggy
      0
      Forge 1.12.2 Installing Bug

      By LessyDoggy
      Started 1 hour ago

    • Yourskillx2
      0
      !!Keeps crashing during launch!!

      By Yourskillx2
      Started 1 hour ago

    • IMaironI
      13
      server error

      By IMaironI
      Started 12 hours ago

    • prototype204
      0
      Attacking/Hitting issue

      By prototype204
      Started 8 hours ago

    • BeardlessBrady
      3
      [1.16.5] Adding arguments to DeferredRegister and RegistryObject

      By BeardlessBrady
      Started 12 hours ago

  • Who's Online (See full list)

    • zlappedx3
    • DavidM
    • troublemaker_47
    • VecsonON
    • Kreepydude
    • chaseoqueso
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Chunks, Saving Data to, And So on
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community