def rotateLeft(self):
        self._fakeEntities = None
        self._Blocks = swapaxes(self._Blocks, 1, 2)[:, ::-1, :]  # x=z; z=-x
        if "Biomes" in self.root_tag:
            self.root_tag["Biomes"].value = swapaxes(self.root_tag["Biomes"].value, 0, 1)[::-1, :]

        self.root_tag["Data"].value = swapaxes(self.root_tag["Data"].value, 1, 2)[:, ::-1, :]  # x=z; z=-x
        self._update_shape()

        blockrotation.RotateLeft(self.Blocks, self.Data)

        log.info(u"Relocating entities...")
        for entity in self.Entities:
            for p in "Pos", "Motion":
                if p == "Pos":
                    zBase = self.Length
                else:
                    zBase = 0.0
                newX = entity[p][2].value
                newZ = zBase - entity[p][0].value

                entity[p][0].value = newX
                entity[p][2].value = newZ
            entity["Rotation"][0].value -= 90.0
            if entity["id"].value in ("Painting", "ItemFrame") or MCEDIT_IDS.get(entity["id"]) in ('DEFS_ENTITIES_PAINTING', 'DEFS_ENTITIES_ITEM_FRAME'):
                x, z = entity["TileX"].value, entity["TileZ"].value
                newx = z
                newz = self.Length - x - 1

                entity["TileX"].value, entity["TileZ"].value = newx, newz
                facing = entity.get("Facing", entity.get("Direction"))
                if facing is None:
                    dirFacing = entity.get("Dir")
                    if dirFacing is not None:
                        if dirFacing.value == 0:
                            dirFacing.value = 2
                        elif dirFacing.value == 2:
                            dirFacing.value = 0
                        facing = dirFacing
                    else:
                        raise Exception("None of tags Facing/Direction/Dir found in entity %s during rotating -  %r" % (entity["id"].value, entity))
                facing.value = (facing.value - 1) % 4

        for tileEntity in self.TileEntities:
            if 'x' not in tileEntity:
                continue

            newX = tileEntity["z"].value
            newZ = self.Length - tileEntity["x"].value - 1

            tileEntity["x"].value = newX
            tileEntity["z"].value = newZ

        if "TileTicks" in self.root_tag:
            for tileTick in self.TileTicks:
                newX = tileTick["z"].value
                newZ = tileTick["x"].value

                tileTick["x"].value = newX
                tileTick["z"].value = newZ
Beispiel #2
0
    def rotateLeft(self):
        self._fakeEntities = None
        self._Blocks = swapaxes(self._Blocks, 1, 2)[:, ::-1, :]  # x=z; z=-x
        if "Biomes" in self.root_tag:
            self.root_tag["Biomes"].value = swapaxes(self.root_tag["Biomes"].value, 0, 1)[::-1, :]

        self.root_tag["Data"].value = swapaxes(self.root_tag["Data"].value, 1, 2)[:, ::-1, :]  # x=z; z=-x
        self._update_shape()

        blockrotation.RotateLeft(self.Blocks, self.Data)

        log.info(u"Relocating entities...")
        for entity in self.Entities:
            for p in "Pos", "Motion":
                if p == "Pos":
                    zBase = self.Length
                else:
                    zBase = 0.0
                newX = entity[p][2].value
                newZ = zBase - entity[p][0].value

                entity[p][0].value = newX
                entity[p][2].value = newZ
            entity["Rotation"][0].value -= 90.0
            if entity["id"].value in ("Painting", "ItemFrame") or MCEDIT_IDS.get(entity["id"]) in ('DEFS_ENTITIES_PAINTING', 'DEFS_ENTITIES_ITEM_FRAME'):
                x, z = entity["TileX"].value, entity["TileZ"].value
                newx = z
                newz = self.Length - x - 1

                entity["TileX"].value, entity["TileZ"].value = newx, newz
                facing = entity.get("Facing", entity.get("Direction"))
                if facing is None:
                    dirFacing = entity.get("Dir")
                    if dirFacing is not None:
                        if dirFacing.value == 0:
                            dirFacing.value = 2
                        elif dirFacing.value == 2:
                            dirFacing.value = 0
                        facing = dirFacing
                    else:
                        raise Exception("None of tags Facing/Direction/Dir found in entity %s during rotating -  %r" % (entity["id"].value, entity))
                facing.value = (facing.value - 1) % 4

        for tileEntity in self.TileEntities:
            if 'x' not in tileEntity:
                continue

            newX = tileEntity["z"].value
            newZ = self.Length - tileEntity["x"].value - 1

            tileEntity["x"].value = newX
            tileEntity["z"].value = newZ

        if "TileTicks" in self.root_tag:
            for tileTick in self.TileTicks:
                newX = tileTick["z"].value
                newZ = tileTick["x"].value

                tileTick["x"].value = newX
                tileTick["z"].value = newZ
Beispiel #3
0
    def roll(self):
        " xxx rotate stuff - destroys biomes"
        self.root_tag.pop('Biomes', None)
        self._fakeEntities = None

        self._Blocks = swapaxes(self._Blocks, 2, 0)[:, :, ::-1]  # x=y; y=-x
        self.root_tag["Data"].value = swapaxes(self.root_tag["Data"].value, 2,
                                               0)[:, :, ::-1]
        self._update_shape()

        blockrotation.Roll(self.Blocks, self.Data)

        log.info(u"N/S Roll: Relocating entities...")
        for i, entity in enumerate(self.Entities):
            newX = self.Width - entity["Pos"][1].value
            newY = entity["Pos"][0].value
            entity["Pos"][0].value = newX
            entity["Pos"][1].value = newY
            newX = entity["Motion"][1].value
            newY = -entity["Motion"][0].value
            entity["Motion"][0].value = newX
            entity["Motion"][1].value = newY
            # I think this is right
            # Although rotation isn't that important as most entities can't rotate and mobs
            # don't serialize rotation.
            newX = entity["Rotation"][1].value
            newY = -entity["Rotation"][0].value
            entity["Rotation"][0].value = newX
            entity["Rotation"][1].value = newY

            if entity["id"].value in (
                    "Painting", "ItemFrame") or MCEDIT_IDS.get(
                        entity["id"].value) in ('DEFS_ENTITIES_PAINTING',
                                                'DEFS_ENTITIES_ITEM_FRAME'):
                newX = self.Width - entity["TileY"].value - 1
                newY = entity["TileX"].value
                entity["TileX"].value = newX
                entity["TileY"].value = newY

        for tileEntity in self.TileEntities:
            newX = self.Width - tileEntity["y"].value - 1
            newY = tileEntity["x"].value
            tileEntity["x"].value = newX
            tileEntity["y"].value = newY
        if hasattr(self, "TileTicks"):
            for tileTick in self.TileTicks:
                newX = self.Width - tileTick["y"].value - 1
                newY = tileTick["x"].value
                tileTick["x"].value = newX
                tileTick["y"].value = newY
    def roll(self):
        " xxx rotate stuff - destroys biomes"
        self.root_tag.pop('Biomes', None)
        self._fakeEntities = None

        self._Blocks = swapaxes(self._Blocks, 2, 0)[:, :, ::-1]  # x=y; y=-x
        self.root_tag["Data"].value = swapaxes(self.root_tag["Data"].value, 2, 0)[:, :, ::-1]
        self._update_shape()

        blockrotation.Roll(self.Blocks, self.Data)

        log.info(u"N/S Roll: Relocating entities...")
        for i, entity in enumerate(self.Entities):
            newX = self.Width - entity["Pos"][1].value
            newY = entity["Pos"][0].value
            entity["Pos"][0].value = newX
            entity["Pos"][1].value = newY
            newX = entity["Motion"][1].value
            newY = -entity["Motion"][0].value
            entity["Motion"][0].value = newX
            entity["Motion"][1].value = newY
            # I think this is right
            # Although rotation isn't that important as most entities can't rotate and mobs
            # don't serialize rotation.
            newX = entity["Rotation"][1].value
            newY = -entity["Rotation"][0].value
            entity["Rotation"][0].value = newX
            entity["Rotation"][1].value = newY

            if entity["id"].value in ("Painting", "ItemFrame") or MCEDIT_IDS.get(entity["id"]) in ('DEFS_ENTITIES_PAINTING', 'DEFS_ENTITIES_ITEM_FRAME'):
                newX = self.Width - entity["TileY"].value - 1
                newY = entity["TileX"].value
                entity["TileX"].value = newX
                entity["TileY"].value = newY

        for tileEntity in self.TileEntities:
            newX = self.Width - tileEntity["y"].value - 1
            newY = tileEntity["x"].value
            tileEntity["x"].value = newX
            tileEntity["y"].value = newY
        if hasattr(self, "TileTicks"):
            for tileTick in self.TileTicks:
                newX = self.Width - tileTick["y"].value - 1
                newY = tileTick["x"].value
                tileTick["x"].value = newX
                tileTick["y"].value = newY
    def flipVertical(self):
        " xxx delete stuff "
        self._fakeEntities = None

        blockrotation.FlipVertical(self.Blocks, self.Data)
        self._Blocks = self._Blocks[::-1, :, :]  # y=-y
        self.root_tag["Data"].value = self.root_tag["Data"].value[::-1, :, :]

        log.info(u"N/S Flip: Relocating entities...")
        for entity in self.Entities:
            entity["Pos"][1].value = self.Height - entity["Pos"][1].value
            entity["Motion"][1].value = -entity["Motion"][1].value
            entity["Rotation"][1].value = -entity["Rotation"][1].value
            if entity["id"].value in ("Painting", "ItemFrame") or MCEDIT_IDS.get(entity["id"]) in ('DEFS_ENTITIES_PAINTING', 'DEFS_ENTITIES_ITEM_FRAME'):
                entity["TileY"].value = self.Height - entity["TileY"].value - 1
        for tileEntity in self.TileEntities:
            tileEntity["y"].value = self.Height - tileEntity["y"].value - 1
        if "TileTicks" in self.root_tag:
            for tileTick in self.TileTicks:
                tileTick["y"].value = self.Height - tileTick["y"].value - 1
Beispiel #6
0
    def flipVertical(self):
        " xxx delete stuff "
        self._fakeEntities = None

        blockrotation.FlipVertical(self.Blocks, self.Data)
        self._Blocks = self._Blocks[::-1, :, :]  # y=-y
        self.root_tag["Data"].value = self.root_tag["Data"].value[::-1, :, :]

        log.info(u"N/S Flip: Relocating entities...")
        for entity in self.Entities:
            entity["Pos"][1].value = self.Height - entity["Pos"][1].value
            entity["Motion"][1].value = -entity["Motion"][1].value
            entity["Rotation"][1].value = -entity["Rotation"][1].value
            if entity["id"].value in ("Painting", "ItemFrame") or MCEDIT_IDS.get(entity["id"]) in ('DEFS_ENTITIES_PAINTING', 'DEFS_ENTITIES_ITEM_FRAME'):
                entity["TileY"].value = self.Height - entity["TileY"].value - 1
        for tileEntity in self.TileEntities:
            tileEntity["y"].value = self.Height - tileEntity["y"].value - 1
        if "TileTicks" in self.root_tag:
            for tileTick in self.TileTicks:
                tileTick["y"].value = self.Height - tileTick["y"].value - 1
Beispiel #7
0
    def copyWithOffset(cls, tileEntity, copyOffset, staticCommands, moveSpawnerPos, first, cancelCommandBlockOffset=False):
        # You'll need to use this function twice
        # The first time with first equals to True
        # The second time with first equals to False
        eTag = deepcopy(tileEntity)
        eTag['x'] = nbt.TAG_Int(tileEntity['x'].value + copyOffset[0])
        eTag['y'] = nbt.TAG_Int(tileEntity['y'].value + copyOffset[1])
        eTag['z'] = nbt.TAG_Int(tileEntity['z'].value + copyOffset[2])

        def num(x):
            try:
                return int(x)
            except ValueError:
                return float(x)

        def coordX(x, argument):
            if first:
                x = str(num(x)) + '!' + str(num(x) + copyOffset[0])
            elif argument and x.find("!") >= 0:
                x = x[x.index("!") + 1:]
                x = str(num(x) + copyOffset[0])
            elif not argument and x.find("!") >= 0:
                x = x[:x.index("!")]
            return x

        def coordY(y, argument):
            if first:
                y = str(num(y)) + '!' + str(num(y) + copyOffset[1])
            elif argument and y.find("!") >= 0:
                y = y[y.index("!") + 1:]
                y = str(num(y) + copyOffset[1])
            elif not argument and y.find("!") >= 0:
                y = y[:y.index("!")]
            return y

        def coordZ(z, argument):
            if first:
                z = str(num(z)) + '!' + str(num(z) + copyOffset[2])
            elif argument and z.find("!") >= 0:
                z = z[z.index("!") + 1:]
                z = str(num(z) + copyOffset[2])
            elif not argument and z.find("!") >= 0:
                z = z[:z.index("!")]
            return z

        def coords(x, y, z, argument):
            if x[0] != "~":
                x = coordX(x, argument)
            if y[0] != "~":
                y = coordY(y, argument)
            if z[0] != "~":
                z = coordZ(z, argument)
            return x, y, z

        if eTag['id'].value == 'MobSpawner' or MCEDIT_IDS.get(eTag['id'].value) == 'DEF_BLOCKS_MOB_SPAWNER':
            mobs = []
            if 'SpawnData' in eTag:
                mob = eTag['SpawnData']
                if mob:
                    mobs.append(mob)
            if 'SpawnPotentials' in eTag:
                potentials = eTag['SpawnPotentials']
                for p in potentials:
                    if 'properties' in p:
                        mobs.extend(p["Properties"])
                    elif 'Entity' in p:
                        mobs.extend(p["Entity"])

            for mob in mobs:
                # Why do we get a unicode object as tag 'mob'?
                if "Pos" in mob and mob != "Pos":
                    if first:
                        pos = Entity.pos(mob)
                        x, y, z = [str(part) for part in pos]
                        x, y, z = coords(x, y, z, moveSpawnerPos)
                        mob['Temp1'] = nbt.TAG_String(x)
                        mob['Temp2'] = nbt.TAG_String(y)
                        mob['Temp3'] = nbt.TAG_String(z)
                    elif 'Temp1' in mob and 'Temp2' in mob and 'Temp3' in mob:
                        x = mob['Temp1']
                        y = mob['Temp2']
                        z = mob['Temp3']
                        del mob['Temp1']
                        del mob['Temp2']
                        del mob['Temp3']
                        parts = []
                        for part in (x, y, z):
                            part = str(part)
                            part = part[13:len(part) - 2]
                            parts.append(part)
                        x, y, z = parts
                        pos = [float(p) for p in coords(x, y, z, moveSpawnerPos)]
                        Entity.setpos(mob, pos)

        if (eTag['id'].value == "Control" or MCEDIT_IDS.get(eTag['id'].value) == 'DEF_BLOCKS_COMMAND_BLOCK') and not cancelCommandBlockOffset:
            command = eTag['Command'].value
            oldCommand = command

            def selectorCoords(selector):
                old_selector = selector
                try:
                    char_num = 0
                    new_selector = ""
                    dont_copy = 0
                    if len(selector) > 4:
                        if '0' <= selector[3] <= '9':
                            new_selector = selector[:3]
                            end_char_x = selector.find(',', 4, len(selector) - 1)
                            if end_char_x == -1:
                                end_char_x = len(selector) - 1
                            x = selector[3:end_char_x]
                            x = coordX(x, staticCommands)
                            new_selector += x + ','

                            end_char_y = selector.find(',', end_char_x + 1, len(selector) - 1)
                            if end_char_y == -1:
                                end_char_y = len(selector) - 1
                            y = selector[end_char_x + 1:end_char_y]
                            y = coordY(y, staticCommands)
                            new_selector += y + ','

                            end_char_z = selector.find(',', end_char_y + 1, len(selector) - 1)
                            if end_char_z == -1:
                                end_char_z = len(selector) - 1
                            z = selector[end_char_y + 1:end_char_z]
                            z = coordZ(z, staticCommands)
                            new_selector += z + ',' + selector[end_char_z + 1:]

                        else:
                            for char in selector:
                                if dont_copy != 0:
                                    dont_copy -= 1
                                else:
                                    if (char != 'x' and char != 'y' and char != 'z') or letter:
                                        new_selector += char
                                        if char == '[' or char == ',':
                                            letter = False
                                        else:
                                            letter = True

                                    elif char == 'x' and not letter:
                                        new_selector += selector[char_num:char_num + 2]
                                        char_x = char_num + 2
                                        end_char_x = selector.find(',', char_num + 3, len(selector) - 1)
                                        if end_char_x == -1:
                                            end_char_x = len(selector) - 1
                                        x = selector[char_x:end_char_x]
                                        dont_copy = len(x) + 1
                                        x = coordX(x, staticCommands)
                                        new_selector += x

                                    elif char == 'y' and not letter:
                                        new_selector += selector[char_num:char_num + 2]
                                        char_y = char_num + 2
                                        end_char_y = selector.find(',', char_num + 3, len(selector) - 1)
                                        if end_char_y == -1:
                                            end_char_y = len(selector) - 1
                                        y = selector[char_y:end_char_y]
                                        dont_copy = len(y) + 1
                                        y = coordY(y, staticCommands)
                                        new_selector += y

                                    elif char == 'z' and not letter:
                                        new_selector += selector[char_num:char_num + 2]
                                        char_z = char_num + 2
                                        end_char_z = selector.find(',', char_num + 3, len(selector) - 1)
                                        if end_char_z == -1:
                                            end_char_z = len(selector) - 1
                                        z = selector[char_z:end_char_z]
                                        dont_copy = len(z) + 1
                                        z = coordZ(z, staticCommands)
                                        new_selector += z
                                char_num += 1
                    else:
                        new_selector = old_selector

                except:
                    new_selector = old_selector
                finally:
                    return new_selector

            try:
                execute = False
                Slash = False
                if command[0] == "/":
                    command = command[1:]
                    Slash = True

                # Adjust command coordinates.
                words = command.split(' ')

                i = 0
                for word in words:
                    if word[0] == '@':
                        words[i] = selectorCoords(word)
                    i += 1

                if command.startswith('execute'):
                    stillExecuting = True
                    execute = True
                    saving_command = ""
                    while stillExecuting:
                        if Slash:
                            saving_command += '/'
                        x, y, z = words[2:5]
                        words[2:5] = coords(x, y, z, staticCommands)
                        if words[5] == 'detect':
                            x, y, z = words[6:9]
                            words[6:9] = coords(x, y, z, staticCommands)
                            saving_command += ' '.join(words[:9])
                            words = words[9:]
                        else:
                            saving_command += ' '.join(words[:5])
                            words = words[5:]
                        command = ' '.join(words)
                        saving_command += ' '
                        Slash = False
                        if command[0] == "/":
                            command = command[1:]
                            Slash = True
                        words = command.split(' ')
                        if not command.startswith('execute'):
                            stillExecuting = False

                if (command.startswith('tp') and len(words) == 5) or command.startswith(
                        'particle') or command.startswith('replaceitem block') or (
                            command.startswith('spawnpoint') and len(words) == 5) or command.startswith('stats block') or (
                            command.startswith('summon') and len(words) >= 5):
                    x, y, z = words[2:5]
                    words[2:5] = coords(x, y, z, staticCommands)
                elif command.startswith('blockdata') or command.startswith('setblock') or (
                            command.startswith('setworldspawn') and len(words) == 4):
                    x, y, z = words[1:4]
                    words[1:4] = coords(x, y, z, staticCommands)
                elif command.startswith('playsound') and len(words) >= 6:
                    x, y, z = words[3:6]
                    words[3:6] = coords(x, y, z, staticCommands)
                elif command.startswith('clone'):
                    x1, y1, z1, x2, y2, z2, x, y, z = words[1:10]
                    x1, y1, z1 = coords(x1, y1, z1, staticCommands)
                    x2, y2, z2 = coords(x2, y2, z2, staticCommands)
                    x, y, z = coords(x, y, z, staticCommands)

                    words[1:10] = x1, y1, z1, x2, y2, z2, x, y, z
                elif command.startswith('fill'):
                    x1, y1, z1, x2, y2, z2 = words[1:7]
                    x1, y1, z1 = coords(x1, y1, z1, staticCommands)
                    x2, y2, z2 = coords(x2, y2, z2, staticCommands)

                    words[1:7] = x1, y1, z1, x2, y2, z2
                elif command.startswith('spreadplayers'):
                    x, z = words[1:3]
                    if x[0] != "~":
                        x = coordX(x, staticCommands)
                    if z[0] != "~":
                        z = coordZ(z, staticCommands)

                    words[1:3] = x, z
                elif command.startswith('worldborder center') and len(words) == 4:
                    x, z = words[2:4]
                    if x[0] != "~":
                        x = coordX(x, staticCommands)
                    if z[0] != "~":
                        z = coordZ(z, staticCommands)

                    words[2:4] = x, z
                if Slash:
                    command = '/'
                else:
                    command = ""
                command += ' '.join(words)

                if execute:
                    command = saving_command + command
                eTag['Command'].value = command
            except:
                eTag['Command'].value = oldCommand

        return eTag
Beispiel #8
0
def ids_loader(game_version, namespace=u"minecraft"):
    """Load the whole files from mcver directory.
    :game_version: str/unicode: the game version for which the resources will be loaded.
    namespace: unicode: the name to be put in front of some IDs. default to 'minecraft'."""
    log.info("Loading resources for MC %s" % game_version)
    global MCEDIT_DEFS
    global MCEDIT_IDS
    MCEDIT_DEFS = {}
    MCEDIT_IDS = {}
    d = os.path.join('mcver', game_version)
    if os.path.isdir(d):
        for file_name in os.listdir(d):
            if os.path.splitext(file_name)[-1].lower() == '.json':
                data = None
                log.info("Found %s" % file_name)
                data = _get_data(os.path.join(d, file_name))
                if data:
                    # We use here names coming from the 'minecraft:name_of_the_stuff' ids
                    # The second part of the name is present in the first file used (for MC 1.11) in the 'idStr' value).
                    # The keys of MCEDIT_DEFS are built by concatening the file base name and the idStr
                    # References to MCEDIT_DEFS elements are stored in MCEDIT_IDS dict.
                    # If an element "load" is defined in the JSON data, it must be a string corresponding to another game version.
                    # The corresponding file will be loaded before parsing the data.
                    log.info("Loading...")
                    prefix = os.path.splitext(file_name)[0]
                    deps = []
                    r = ''
                    _data = {}
                    first = True
                    while type(r) in (str, unicode):
                        if first:
                            r = _parse_data(data, prefix, namespace,
                                            MCEDIT_DEFS, MCEDIT_IDS)
                            first = False
                        else:
                            r = _parse_data(_data, prefix, namespace,
                                            MCEDIT_DEFS, MCEDIT_IDS)
                        if type(r) in (str, unicode):
                            v = game_version
                            if len(deps):
                                v = deps[-1]
                            log.info("Found dependency for %s %s" %
                                     (v, prefix))
                            deps.append(r)
                            _data = _get_data(
                                os.path.join('mcver', r, file_name))
                        else:
                            defs, ids = r
                            MCEDIT_DEFS.update(defs)
                            MCEDIT_IDS.update(ids)
                    if deps:
                        deps.reverse()
                        log.info("Loading definitions dependencies")
                        _data = {}
                        for dep in deps:
                            _file_name = os.path.join('mcver', dep, file_name)
                            if os.path.exists(_file_name):
                                log.info("Found %s" % _file_name)
                                _data.update(_get_data(_file_name))
                            else:
                                log.info("Could not find %s" % _file_name)
                        _data.update(data)
                        _defs, _ids = _parse_data(_data,
                                                  prefix,
                                                  namespace,
                                                  MCEDIT_DEFS,
                                                  MCEDIT_IDS,
                                                  ignore_load=True)
                        MCEDIT_DEFS.update(_defs)
                        MCEDIT_IDS.update(_ids)
                    log.info("Done")
    else:
        log.info("MC %s resources not found." % game_version)
    # Override the module objects to expose them outside when (re)importing.
    pymclevel.MCEDIT_DEFS = MCEDIT_DEFS
    pymclevel.MCEDIT_IDS = MCEDIT_IDS
    log.info("Loaded %s defs and %s ids" % (len(MCEDIT_DEFS), len(MCEDIT_IDS)))
    return MCEDIT_DEFS, MCEDIT_IDS
    def flipEastWest(self):
        if "Biomes" in self.root_tag:
            self.root_tag["Biomes"].value = self.root_tag["Biomes"].value[:, ::-1]

        self._fakeEntities = None

        blockrotation.FlipEastWest(self.Blocks, self.Data)
        self._Blocks = self._Blocks[:, ::-1, :]  # z=-z
        self.root_tag["Data"].value = self.root_tag["Data"].value[:, ::-1, :]

        eastWestPaintingMap = [2, 1, 0, 3]

        log.info(u"E/W Flip: Relocating entities...")
        for entity in self.Entities:

            try:
                entity["Pos"][2].value = self.Length - entity["Pos"][2].value
            except:
                pass
            try:
                entity["Motion"][2].value = -entity["Motion"][2].value
            except:
                pass

            try:
                entity["Rotation"][0].value = entity["Rotation"][0].value * -1.0 + 180
            except:
                pass

            # Special logic for old width painting as TileX/TileZ favours -x/-z

            try:
                if entity["id"].value in ("Painting", "ItemFrame") or MCEDIT_IDS.get(entity["id"]) in ('DEFS_ENTITIES_PAINTING', 'DEFS_ENTITIES_ITEM_FRAME'):
                    facing = entity.get("Facing", entity.get("Direction"))
                    if facing is None:
                        dirFacing = entity.get("Dir")
                        if dirFacing is not None:
                            if dirFacing.value == 0:
                                dirFacing.value = 2
                            elif dirFacing.value == 2:
                                dirFacing.value = 0
                            facing = dirFacing
                        else:
                            raise Exception("None of tags Facing/Direction/Dir found in entity %s during flipping -  %r" % (entity["id"].value, entity))

                if entity["id"].value == "Painting" or MCEDIT_IDS.get(entity["id"]) == 'DEFS_ENTITIES_PAINTING':
                    if facing.value == 1:
                        entity["TileZ"].value = self.Length - entity["TileZ"].value - 2 + self.paintingMap[entity["Motive"].value] % 2
                    elif facing.value == 3:
                        entity["TileZ"].value = self.Length - entity["TileZ"].value - self.paintingMap[entity["Motive"].value] % 2
                    else:
                        entity["TileZ"].value = self.Length - entity["TileZ"].value - 1
                    if facing.value == 0:
                        entity["TileX"].value = entity["TileX"].value + 1 - self.paintingMap[entity["Motive"].value] % 2
                    elif facing.value == 2:
                        entity["TileX"].value = entity["TileX"].value - 1 + self.paintingMap[entity["Motive"].value] % 2
                    facing.value = eastWestPaintingMap[facing.value]
                elif entity["id"].value == "ItemFrame" or MCEDIT_IDS.get(entity["id"]) == 'DEFS_ENTITIES_ITEM_FRAME':
                    entity["TileZ"].value = self.Length - entity["TileZ"].value - 1
                    facing.value = eastWestPaintingMap[facing.value]
            except:
                pass

        for tileEntity in self.TileEntities:
            tileEntity["z"].value = self.Length - tileEntity["z"].value - 1

        if "TileTicks" in self.root_tag:
            for tileTick in self.TileTicks:
                tileTick["z"].value = self.Length - tileTick["z"].value - 1
def ids_loader(game_version, namespace=u"minecraft", json_dict=False, timestamps=False):
    """Load the whole files from mcver directory.
    :game_version: str/unicode: the game version for which the resources will be loaded.
    :namespace: unicode: the name to be put in front of some IDs. default to 'minecraft'.
    :json_dict: bool: Whether to return a ran dict from the JSon file(s) instead of the (MCEDIT_DEFS, MCEDIT_IDS) pair.
    :timestamp: bool: wheter the return also the loaded file timestamp."""
    log.info("Loading resources for MC %s"%game_version)
    global MCEDIT_DEFS
    global MCEDIT_IDS
    MCEDIT_DEFS = {}
    MCEDIT_IDS = {}
    if json_dict:
        _json = {}
    if timestamps:
        _timestamps = {}
    d = os.path.join('mcver', game_version)

    # If version 1.2.4 files are not found, try to load the one for the closest
    # lower version (like 1.2.3 or 1.2).
    if not os.path.isdir(d) and game_version != "Unknown":
        log.info("No definitions found for MC %s. Trying to find ones for the closest lower version." % game_version)
        ver_dirs = os.listdir('mcver')
        ver_dirs.append(game_version)
        ver_dirs.sort(key=LooseVersion)
        idx = ver_dirs.index(game_version) - 1
        ver = ver_dirs[idx]
        d = os.path.join('mcver', ver)
        log.info("Closest lower version found is %s." % ver)

    if os.path.isdir(d):
        for file_name in os.listdir(d):
            if os.path.splitext(file_name)[-1].lower() == '.json':
                log.info("Found %s" % file_name)
                path_name = os.path.join(d, file_name)
                data = _get_data(path_name)
                if timestamps:
                    _timestamps[path_name] = os.stat(path_name).st_mtime
                if data:
                    # We use here names coming from the 'minecraft:name_of_the_stuff' ids
                    # The second part of the name is present in the first file used (for MC 1.11) in the 'idStr' value).
                    # The keys of MCEDIT_DEFS are built by concatening the file base name and the idStr
                    # References to MCEDIT_DEFS elements are stored in MCEDIT_IDS dict.
                    # If an element "load" is defined in the JSON data, it must be a string corresponding to another game version.
                    # The corresponding file will be loaded before parsing the data.
                    log.info("Loading...")
                    prefix = os.path.splitext(file_name)[0]
                    deps = []
                    r = ''
                    _data = {}
                    first = True
                    while type(r) in (str, unicode):
                        if first:
                            r = _parse_data(data, prefix, namespace, MCEDIT_DEFS, MCEDIT_IDS)
                            if json_dict:
                                _json.update(data)
                            first = False
                        else:
                            r = _parse_data(_data, prefix, namespace, MCEDIT_DEFS, MCEDIT_IDS)
                            if json_dict:
                                _json.update(_data)
                        if isinstance(r, (str, unicode)):
                            v = game_version
                            if len(deps):
                                v = deps[-1]
                            log.info("Found dependency for %s %s"%(v, prefix))
                            deps.append(r)
                            _data = _get_data(os.path.join('mcver', r, file_name))
                        else:
                            defs, ids = r
                            MCEDIT_DEFS.update(defs)
                            MCEDIT_IDS.update(ids)
                    if deps:
                        deps.reverse()
                        log.info("Loading definitions dependencies")
                        _data = {}
                        for dep in deps:
                            _file_name = os.path.join('mcver', dep, file_name)
                            if os.path.exists(_file_name):
                                log.info("Found %s"%_file_name)
                                #_data.update(_get_data(_file_name))
                                update(_data, _get_data(_file_name))
                                if timestamps:
                                    _timestamps[_file_name] = os.stat(_file_name).st_mtime
                            else:
                                log.info("Could not find %s"%_file_name)
                        update(_data, data)
                        #_data.update(data)
                        _defs, _ids = _parse_data(_data, prefix, namespace, MCEDIT_DEFS, MCEDIT_IDS, ignore_load=True)
                        update(MCEDIT_DEFS, _defs)
                        update(MCEDIT_IDS, _ids)
                        #MCEDIT_DEFS.update(_defs)
                        #MCEDIT_IDS.update(_ids)
                        if json_dict:
                            _json.update(_data)
                    log.info("Done")
    else:
        log.info("MC %s resources not found."%game_version)
    # Override the module objects to expose them outside when (re)importing.
    pymclevel.MCEDIT_DEFS = MCEDIT_DEFS
    pymclevel.MCEDIT_IDS = MCEDIT_IDS
    log.info("Loaded %s defs and %s ids"%(len(MCEDIT_DEFS), len(MCEDIT_IDS)))
    toreturn = (MCEDIT_DEFS, MCEDIT_IDS)
    if json_dict:
        toreturn = _json
    if '--dump-defs' in sys.argv:
        dump_f_name = 'defs_ids-%s.json' % game_version
        log.info("Dumping definitions as Json data in '%s'." % dump_f_name)
        with open(dump_f_name, 'w') as f:
            f.write("#" * 80)
            f.write("\nDEFS\n")
            f.write(json.dumps(MCEDIT_DEFS, indent=4))
            f.write("\n\n" + "#" * 80)
            f.write("\nIDS\n")
            f.write(json.dumps(MCEDIT_IDS, indent=4))
            f.close()
    if timestamps:
        toreturn += (_timestamps,)
    return toreturn
Beispiel #11
0
    def flipEastWest(self):
        if "Biomes" in self.root_tag:
            self.root_tag["Biomes"].value = self.root_tag[
                "Biomes"].value[:, ::-1]

        self._fakeEntities = None

        blockrotation.FlipEastWest(self.Blocks, self.Data)
        self._Blocks = self._Blocks[:, ::-1, :]  # z=-z
        self.root_tag["Data"].value = self.root_tag["Data"].value[:, ::-1, :]

        eastWestPaintingMap = [2, 1, 0, 3]

        log.info(u"E/W Flip: Relocating entities...")
        for entity in self.Entities:

            try:
                entity["Pos"][2].value = self.Length - entity["Pos"][2].value
            except:
                pass
            try:
                entity["Motion"][2].value = -entity["Motion"][2].value
            except:
                pass

            try:
                entity["Rotation"][
                    0].value = entity["Rotation"][0].value * -1.0 + 180
            except:
                pass

            # Special logic for old width painting as TileX/TileZ favours -x/-z

            try:
                if entity["id"].value in ("Painting",
                                          "ItemFrame") or MCEDIT_IDS.get(
                                              entity["id"].value) in (
                                                  'DEFS_ENTITIES_PAINTING',
                                                  'DEFS_ENTITIES_ITEM_FRAME'):
                    facing = entity.get("Facing", entity.get("Direction"))
                    if facing is None:
                        dirFacing = entity.get("Dir")
                        if dirFacing is not None:
                            if dirFacing.value == 0:
                                dirFacing.value = 2
                            elif dirFacing.value == 2:
                                dirFacing.value = 0
                            facing = dirFacing
                        else:
                            raise Exception(
                                "None of tags Facing/Direction/Dir found in entity %s during flipping -  %r"
                                % (entity["id"].value, entity))

                if entity["id"].value == "Painting" or MCEDIT_IDS.get(
                        entity["id"].value) == 'DEFS_ENTITIES_PAINTING':
                    if facing.value == 1:
                        entity["TileZ"].value = self.Length - entity[
                            "TileZ"].value - 2 + self.paintingMap[
                                entity["Motive"].value] % 2
                    elif facing.value == 3:
                        entity["TileZ"].value = self.Length - entity[
                            "TileZ"].value - self.paintingMap[
                                entity["Motive"].value] % 2
                    else:
                        entity["TileZ"].value = self.Length - entity[
                            "TileZ"].value - 1
                    if facing.value == 0:
                        entity["TileX"].value = entity[
                            "TileX"].value + 1 - self.paintingMap[
                                entity["Motive"].value] % 2
                    elif facing.value == 2:
                        entity["TileX"].value = entity[
                            "TileX"].value - 1 + self.paintingMap[
                                entity["Motive"].value] % 2
                    facing.value = eastWestPaintingMap[facing.value]
                elif entity["id"].value == "ItemFrame" or MCEDIT_IDS.get(
                        entity["id"].value) == 'DEFS_ENTITIES_ITEM_FRAME':
                    entity["TileZ"].value = self.Length - entity[
                        "TileZ"].value - 1
                    facing.value = eastWestPaintingMap[facing.value]
            except:
                pass

        for tileEntity in self.TileEntities:
            tileEntity["z"].value = self.Length - tileEntity["z"].value - 1

        if "TileTicks" in self.root_tag:
            for tileTick in self.TileTicks:
                tileTick["z"].value = self.Length - tileTick["z"].value - 1
Beispiel #12
0
    def copyWithOffset(cls, tileEntity, copyOffset, staticCommands, moveSpawnerPos, first, cancelCommandBlockOffset=False):
        # You'll need to use this function twice
        # The first time with first equals to True
        # The second time with first equals to False
        eTag = deepcopy(tileEntity)
        eTag['x'] = nbt.TAG_Int(tileEntity['x'].value + copyOffset[0])
        eTag['y'] = nbt.TAG_Int(tileEntity['y'].value + copyOffset[1])
        eTag['z'] = nbt.TAG_Int(tileEntity['z'].value + copyOffset[2])

        def num(x):
            try:
                return int(x)
            except ValueError:
                return float(x)

        def coordX(x, argument):
            if first:
                x = str(num(x)) + '!' + str(num(x) + copyOffset[0])
            elif argument and x.find("!") >= 0:
                x = x[x.index("!") + 1:]
                x = str(num(x) + copyOffset[0])
            elif not argument and x.find("!") >= 0:
                x = x[:x.index("!")]
            return x

        def coordY(y, argument):
            if first:
                y = str(num(y)) + '!' + str(num(y) + copyOffset[1])
            elif argument and y.find("!") >= 0:
                y = y[y.index("!") + 1:]
                y = str(num(y) + copyOffset[1])
            elif not argument and y.find("!") >= 0:
                y = y[:y.index("!")]
            return y

        def coordZ(z, argument):
            if first:
                z = str(num(z)) + '!' + str(num(z) + copyOffset[2])
            elif argument and z.find("!") >= 0:
                z = z[z.index("!") + 1:]
                z = str(num(z) + copyOffset[2])
            elif not argument and z.find("!") >= 0:
                z = z[:z.index("!")]
            return z

        def coords(x, y, z, argument):
            if x[0] != "~":
                x = coordX(x, argument)
            if y[0] != "~":
                y = coordY(y, argument)
            if z[0] != "~":
                z = coordZ(z, argument)
            return x, y, z

        if eTag['id'].value == 'MobSpawner' or MCEDIT_IDS.get(eTag['id'].value) == 'DEF_BLOCKS_MOB_SPAWNER':
            mobs = []
            if 'SpawnData' in eTag:
                mob = eTag['SpawnData']
                if mob:
                    mobs.append(mob)
            if 'SpawnPotentials' in eTag:
                potentials = eTag['SpawnPotentials']
                for p in potentials:
                    if 'properties' in p:
                        mobs.extend(p["Properties"])
                    elif 'Entity' in p:
                        mobs.extend(p["Entity"])

            for mob in mobs:
                # Why do we get a unicode object as tag 'mob'?
                if "Pos" in mob and mob != "Pos":
                    if first:
                        pos = Entity.pos(mob)
                        x, y, z = [str(part) for part in pos]
                        x, y, z = coords(x, y, z, moveSpawnerPos)
                        mob['Temp1'] = nbt.TAG_String(x)
                        mob['Temp2'] = nbt.TAG_String(y)
                        mob['Temp3'] = nbt.TAG_String(z)
                    elif 'Temp1' in mob and 'Temp2' in mob and 'Temp3' in mob:
                        x = mob['Temp1']
                        y = mob['Temp2']
                        z = mob['Temp3']
                        del mob['Temp1']
                        del mob['Temp2']
                        del mob['Temp3']
                        parts = []
                        for part in (x, y, z):
                            part = str(part)
                            part = part[13:len(part) - 2]
                            parts.append(part)
                        x, y, z = parts
                        pos = [float(p) for p in coords(x, y, z, moveSpawnerPos)]
                        Entity.setpos(mob, pos)

        if (eTag['id'].value == "Control" or MCEDIT_IDS.get(eTag['id'].value) == 'DEF_BLOCKS_COMMAND_BLOCK') and not cancelCommandBlockOffset:
            command = eTag['Command'].value
            oldCommand = command

            def selectorCoords(selector):
                old_selector = selector
                try:
                    char_num = 0
                    new_selector = ""
                    dont_copy = 0
                    if len(selector) > 4:
                        if '0' <= selector[3] <= '9':
                            new_selector = selector[:3]
                            end_char_x = selector.find(',', 4, len(selector) - 1)
                            if end_char_x == -1:
                                end_char_x = len(selector) - 1
                            x = selector[3:end_char_x]
                            x = coordX(x, staticCommands)
                            new_selector += x + ','

                            end_char_y = selector.find(',', end_char_x + 1, len(selector) - 1)
                            if end_char_y == -1:
                                end_char_y = len(selector) - 1
                            y = selector[end_char_x + 1:end_char_y]
                            y = coordY(y, staticCommands)
                            new_selector += y + ','

                            end_char_z = selector.find(',', end_char_y + 1, len(selector) - 1)
                            if end_char_z == -1:
                                end_char_z = len(selector) - 1
                            z = selector[end_char_y + 1:end_char_z]
                            z = coordZ(z, staticCommands)
                            new_selector += z + ',' + selector[end_char_z + 1:]

                        else:
                            for char in selector:
                                if dont_copy != 0:
                                    dont_copy -= 1
                                else:
                                    if (char != 'x' and char != 'y' and char != 'z') or letter:
                                        new_selector += char
                                        if char == '[' or char == ',':
                                            letter = False
                                        else:
                                            letter = True

                                    elif char == 'x' and not letter:
                                        new_selector += selector[char_num:char_num + 2]
                                        char_x = char_num + 2
                                        end_char_x = selector.find(',', char_num + 3, len(selector) - 1)
                                        if end_char_x == -1:
                                            end_char_x = len(selector) - 1
                                        x = selector[char_x:end_char_x]
                                        dont_copy = len(x) + 1
                                        x = coordX(x, staticCommands)
                                        new_selector += x

                                    elif char == 'y' and not letter:
                                        new_selector += selector[char_num:char_num + 2]
                                        char_y = char_num + 2
                                        end_char_y = selector.find(',', char_num + 3, len(selector) - 1)
                                        if end_char_y == -1:
                                            end_char_y = len(selector) - 1
                                        y = selector[char_y:end_char_y]
                                        dont_copy = len(y) + 1
                                        y = coordY(y, staticCommands)
                                        new_selector += y

                                    elif char == 'z' and not letter:
                                        new_selector += selector[char_num:char_num + 2]
                                        char_z = char_num + 2
                                        end_char_z = selector.find(',', char_num + 3, len(selector) - 1)
                                        if end_char_z == -1:
                                            end_char_z = len(selector) - 1
                                        z = selector[char_z:end_char_z]
                                        dont_copy = len(z) + 1
                                        z = coordZ(z, staticCommands)
                                        new_selector += z
                                char_num += 1
                    else:
                        new_selector = old_selector

                except:
                    new_selector = old_selector
                finally:
                    return new_selector

            try:
                execute = False
                Slash = False
                if command[0] == "/":
                    command = command[1:]
                    Slash = True

                # Adjust command coordinates.
                words = command.split(' ')

                i = 0
                for word in words:
                    if word[0] == '@':
                        words[i] = selectorCoords(word)
                    i += 1

                if command.startswith('execute'):
                    stillExecuting = True
                    execute = True
                    saving_command = ""
                    while stillExecuting:
                        if Slash:
                            saving_command += '/'
                        x, y, z = words[2:5]
                        words[2:5] = coords(x, y, z, staticCommands)
                        if words[5] == 'detect':
                            x, y, z = words[6:9]
                            words[6:9] = coords(x, y, z, staticCommands)
                            saving_command += ' '.join(words[:9])
                            words = words[9:]
                        else:
                            saving_command += ' '.join(words[:5])
                            words = words[5:]
                        command = ' '.join(words)
                        saving_command += ' '
                        Slash = False
                        if command[0] == "/":
                            command = command[1:]
                            Slash = True
                        words = command.split(' ')
                        if not command.startswith('execute'):
                            stillExecuting = False

                if (command.startswith('tp') and len(words) == 5) or command.startswith(
                        'particle') or command.startswith('replaceitem block') or (
                            command.startswith('spawnpoint') and len(words) == 5) or command.startswith('stats block') or (
                            command.startswith('summon') and len(words) >= 5):
                    x, y, z = words[2:5]
                    words[2:5] = coords(x, y, z, staticCommands)
                elif command.startswith('blockdata') or command.startswith('setblock') or (
                            command.startswith('setworldspawn') and len(words) == 4):
                    x, y, z = words[1:4]
                    words[1:4] = coords(x, y, z, staticCommands)
                elif command.startswith('playsound') and len(words) >= 6:
                    x, y, z = words[3:6]
                    words[3:6] = coords(x, y, z, staticCommands)
                elif command.startswith('clone'):
                    x1, y1, z1, x2, y2, z2, x, y, z = words[1:10]
                    x1, y1, z1 = coords(x1, y1, z1, staticCommands)
                    x2, y2, z2 = coords(x2, y2, z2, staticCommands)
                    x, y, z = coords(x, y, z, staticCommands)

                    words[1:10] = x1, y1, z1, x2, y2, z2, x, y, z
                elif command.startswith('fill'):
                    x1, y1, z1, x2, y2, z2 = words[1:7]
                    x1, y1, z1 = coords(x1, y1, z1, staticCommands)
                    x2, y2, z2 = coords(x2, y2, z2, staticCommands)

                    words[1:7] = x1, y1, z1, x2, y2, z2
                elif command.startswith('spreadplayers'):
                    x, z = words[1:3]
                    if x[0] != "~":
                        x = coordX(x, staticCommands)
                    if z[0] != "~":
                        z = coordZ(z, staticCommands)

                    words[1:3] = x, z
                elif command.startswith('worldborder center') and len(words) == 4:
                    x, z = words[2:4]
                    if x[0] != "~":
                        x = coordX(x, staticCommands)
                    if z[0] != "~":
                        z = coordZ(z, staticCommands)

                    words[2:4] = x, z
                if Slash:
                    command = '/'
                else:
                    command = ""
                command += ' '.join(words)

                if execute:
                    command = saving_command + command
                eTag['Command'].value = command
            except:
                eTag['Command'].value = oldCommand

        return eTag
Beispiel #13
0
def ids_loader(game_version,
               namespace=u"minecraft",
               json_dict=False,
               timestamps=False):
    """Load the whole files from mcver directory.
    :game_version: str/unicode: the game version for which the resources will be loaded.
    :namespace: unicode: the name to be put in front of some IDs. default to 'minecraft'.
    :json_dict: bool: Whether to return a ran dict from the JSon file(s) instead of the (MCEDIT_DEFS, MCEDIT_IDS) pair.
    :timestamp: bool: wheter the return also the loaded file timestamp."""
    log.info("Loading resources for MC %s" % game_version)
    global MCEDIT_DEFS
    global MCEDIT_IDS
    MCEDIT_DEFS = {}
    MCEDIT_IDS = {}
    if json_dict:
        _json = {}
    if timestamps:
        _timestamps = {}
    d = os.path.join('mcver', game_version)

    # If version 1.2.4 files are not found, try to load the one for the closest
    # lower version (like 1.2.3 or 1.2).
    if not os.path.isdir(d) and game_version != "Unknown":
        log.info(
            "No definitions found for MC %s. Trying to find ones for the closest lower version."
            % game_version)
        ver_dirs = os.listdir('mcver')
        ver_dirs.append(game_version)
        ver_dirs.sort(key=LooseVersion)
        idx = ver_dirs.index(game_version) - 1
        ver = ver_dirs[idx]
        d = os.path.join('mcver', ver)
        log.info("Closest lower version found is %s." % ver)

    if os.path.isdir(d):
        for file_name in os.listdir(d):
            if os.path.splitext(file_name)[-1].lower() == '.json':
                log.info("Found %s" % file_name)
                path_name = os.path.join(d, file_name)
                data = _get_data(path_name)
                if timestamps:
                    _timestamps[path_name] = os.stat(path_name).st_mtime
                if data:
                    # We use here names coming from the 'minecraft:name_of_the_stuff' ids
                    # The second part of the name is present in the first file used (for MC 1.11) in the 'idStr' value).
                    # The keys of MCEDIT_DEFS are built by concatening the file base name and the idStr
                    # References to MCEDIT_DEFS elements are stored in MCEDIT_IDS dict.
                    # If an element "load" is defined in the JSON data, it must be a string corresponding to another game version.
                    # The corresponding file will be loaded before parsing the data.
                    log.info("Loading...")
                    prefix = os.path.splitext(file_name)[0]
                    deps = []
                    r = ''
                    _data = {}
                    first = True
                    while type(r) in (str, unicode):
                        if first:
                            r = _parse_data(data, prefix, namespace,
                                            MCEDIT_DEFS, MCEDIT_IDS)
                            if json_dict:
                                _json.update(data)
                            first = False
                        else:
                            r = _parse_data(_data, prefix, namespace,
                                            MCEDIT_DEFS, MCEDIT_IDS)
                            if json_dict:
                                _json.update(_data)
                        if isinstance(r, (str, unicode)):
                            v = game_version
                            if len(deps):
                                v = deps[-1]
                            log.info("Found dependency for %s %s" %
                                     (v, prefix))
                            deps.append(r)
                            _data = _get_data(
                                os.path.join('mcver', r, file_name))
                        else:
                            defs, ids = r
                            MCEDIT_DEFS.update(defs)
                            MCEDIT_IDS.update(ids)
                    if deps:
                        deps.reverse()
                        log.info("Loading definitions dependencies")
                        _data = {}
                        for dep in deps:
                            _file_name = os.path.join('mcver', dep, file_name)
                            if os.path.exists(_file_name):
                                log.info("Found %s" % _file_name)
                                #_data.update(_get_data(_file_name))
                                update(_data, _get_data(_file_name))
                                if timestamps:
                                    _timestamps[_file_name] = os.stat(
                                        _file_name).st_mtime
                            else:
                                log.info("Could not find %s" % _file_name)
                        update(_data, data)
                        #_data.update(data)
                        _defs, _ids = _parse_data(_data,
                                                  prefix,
                                                  namespace,
                                                  MCEDIT_DEFS,
                                                  MCEDIT_IDS,
                                                  ignore_load=True)
                        update(MCEDIT_DEFS, _defs)
                        update(MCEDIT_IDS, _ids)
                        #MCEDIT_DEFS.update(_defs)
                        #MCEDIT_IDS.update(_ids)
                        if json_dict:
                            _json.update(_data)
                    log.info("Done")
    else:
        log.info("MC %s resources not found." % game_version)
    # Override the module objects to expose them outside when (re)importing.
    pymclevel.MCEDIT_DEFS = MCEDIT_DEFS
    pymclevel.MCEDIT_IDS = MCEDIT_IDS
    log.info("Loaded %s defs and %s ids" % (len(MCEDIT_DEFS), len(MCEDIT_IDS)))
    toreturn = (MCEDIT_DEFS, MCEDIT_IDS)
    if json_dict:
        toreturn = _json
    if '--dump-defs' in sys.argv:
        dump_f_name = 'defs_ids-%s.json' % game_version
        log.info("Dumping definitions as Json data in '%s'." % dump_f_name)
        with open(dump_f_name, 'w') as f:
            f.write("#" * 80)
            f.write("\nDEFS\n")
            f.write(json.dumps(MCEDIT_DEFS, indent=4))
            f.write("\n\n" + "#" * 80)
            f.write("\nIDS\n")
            f.write(json.dumps(MCEDIT_IDS, indent=4))
            f.close()
    if timestamps:
        toreturn += (_timestamps, )
    return toreturn