Friday, July 8, 2011

Background on the Tile Entity Bug

Figure I should give some details on what was going wrong and how I fixed it.  Especially since it effects all of Minecraft since 1.7, so Mojang and Bukkit should be interested in knowing the exact details for fixing it. In normal Minecraft his shows up as chests losing items and signs being cleared. While in AdventureCraft, people have their triggers all get wiped out and as expected quite upset. Now one of the best parts about AdventureCraft was I actually had an easy repro case due to map state being saved separate from save state. In particular the map Seal of Time, about two minutes into it would have the issue occur (took 15 runs through the point before I finally had the correct debug code in place to figure out the issue).  Now I will note the case in which it seems to happen is from teleporting, so you shouldn't see it in normal Minecraft single player. At least this is my guess since I couldn't reproduce it with normal movement by flying around.


  1. Chunk Starts To Unload
  2. As chunk unloads it marks all the tile entities as being deleted
  3. Chunk Finishes Unloading
  4. Next World tick when it goes to run the update callback for the tile entity finds its been deleted
  5. The world then requests the chunk that the tile entity is in which has been unloaded.  Its probably supposed to return back null but in this case reloads the Chunk instead.
  6. It then seeing it has a chunk tells the chunk to delete the tile entity
  7. The chunk gets unloaded again since it wasn't supposed to be loaded and saves out the chunk with all of the tile entities in it having been deleted by the last world tick
End result of this is you don't have any of the extra information available for your blocks. Meaning signs have no text, chest have no items, and triggers don't have any targets.

Now the proper way to fix this bug probably would have been to figure out why the chunk was being reloaded when asked for instead of returning null.  Since I had already spent two and half hours debugging what was going wrong instead I went for a simpler solution.  I added an additional boolean flag to the tile entity that marks if its been unloaded from the chunk.  Then if this flag is set the world tick won't even bother to request the tile entities chunk since the delete doesn't mean it needs to be deleted just that its no longer a valid tile entity reference.

Edit: Good news!  I was able to get Jeb to look at it and fixed it with a simple check to ensure the chunk is in memory first.  I forgot all about that function last night in a rush to fix it before I needed to drive to my brother's wedding.  He says there won't be a 1.7.4 but he's passed on the fix to the Bukkit team, so a fix should be in quickly for those of you playing SMP on a Bukkit server.

10 comments:

  1. Sooooooooo update or what I want to play I got it 2 days ago and was so mad that the signs would make me crash and have no words on them and that i had buttloads of empty chests !

    ReplyDelete
  2. Is there a way to edit a map outside of the game? i.e. to make a compass rose.

    ReplyDelete
  3. So is there anyway to restore the information into my triggers?
    I had entire structures that took hours to build that I had not on the map, but things that were to appear when you hit a trigger, do I have to rebuild them all?

    ReplyDelete
  4. I don't think Memory Block Data is wiped. You should be able to just trigger it or right click it with the cursor item and load saved data.

    ReplyDelete
  5. I sure hope you plan on adding the ability to control the actual time and place of lighting strikes, especially without precipitation...

    Somewhere along the line, anyway...

    The final boss in LotAC is on the verge of godhood, and I thought it would be pretty awesome to set up lighting strike attacks.

    ReplyDelete
  6. Is the game compatible with 1.7.3? I downloaded it and ran the file. When I install it either way and click start, the window closes, but the game doesn't pop up... :(

    ReplyDelete
  7. It's not compatible with 1.7.3 kid-techboy

    ReplyDelete
  8. Where's the update?Please, I need the update to 1.7.3!

    ReplyDelete
  9. He's away for 4 days, since this update.

    ReplyDelete