Fenixin/Minecraft-Region-Fixer

Replacing Chunks from Backup fails to find correct region file

Closed this issue · 1 comments

I was using your awesome tool to fix a world which got broken during it's upgrade to 1.13, however I had some issues getting it to replace chunks from a backup:
When trying to replace a chunk I get the following message:

The region file doesn't exist in the backup directory: ..\..\Workspace\Backup\region/r.-6.6875.4.9375.mca

Environment:

OS: Windows 10
Python: 3.7.4
regionfixer: 0.3.1

Steps to reproduce:

Create a new world in minecraft and create a copy of it, which will simulate a Backup. Using NBT Explorer, corrupt a chunk. In this example, I changed PosX and PosY, to create a wrong located chunk. I modified chunk -16/-16, which is located in r.-1.-1.mca at offset 16/16.

A scan reveals the broken chunk correctly:

Chunk problems:
----------------------------------
| Problem | Wrong located  Total |
----------------------------------
|  Count  |       1         782  |
----------------------------------

trying to replace the chunk however produces an error:

python regionfixer.py --replace-wrong-located --backup ..\..\Workspace\Dummy_Backup\ ..\..\Workspace\Dummy\
####### Replacing chunks with status: Wrong located ########

------ New chunk to replace. Coords: x = -16; z = -16 ------
The region file doesn't exist in the backup directory: ..\..\Workspace\Dummy_Backup\region/r.-0.5.-0.5.mca

0 replaced of a total of 1 chunks with status: Wrong located

Proposed Solution:

The program is trying to access the region file r.-0.5.-0.5.mca instead of r.-1.-1.mca.
It's using floating point numbers instead of integers while converting from chunk coordinates to region coordinates, so chunk -16/-16 becomes region -0.5/-0.5, when it should be -1/-1.

Replace single slashes with double slashes on lines 1387 and 1388 in regionfixer_core/world.py to force integer division:

def get_chunk_region(chunkX, chunkZ):
    """ Returns the name of the region file given global chunk
        coords """

    regionX = chunkX // 32
    regionZ = chunkZ // 32

    region_name = 'r.' + str(regionX) + '.' + str(regionZ) + '.mca'

    return region_name

In my original error message, it should access the region file at 6 / 4 instead of at 6.6875 / 4.9375.
After modifying world.py this way, the error disappeared and all broken chunks were correctly replaced from the backup.

Hello!

Thank you very much for you thorough bug report and solution. This is already in the branch fixes and it will be in master when I do some reviews int he issues.

I'm closing this, feel free to reopen if there is anything you want to add.

Again, thanks!