def loadFMLMapping(self): metadataTag = self.metadata.metadataTag fml = metadataTag.get('FML') if fml is None: return mid = fml.get('ModItemData') # MC 1.6 if mid is not None: log.info("Adding block IDs from FML for MC 1.6") blocktypes = PCBlockTypeSet() for entry in mid: ID = entry['ItemId'].value meta = entry['ordinal'].value name = entry['ItemType'].value if (ID, 0) not in blocktypes.statesByID: blocktypes.IDsByState[name] = ID, meta blocktypes.statesByID[ID, meta] = name blocktypes.blockJsons[name] = { 'displayName':name, 'internalName':name, 'blockState':'', } blocktypes.allBlocks.append(BlockType(ID, meta, blocktypes)) blocktypes.allBlocks.sort() self.blocktypes = blocktypes itemdata = fml.get('ItemData') # MC 1.7 if itemdata is not None: count = 0 log.info("Adding block IDs from FML for MC 1.7") blocktypes = PCBlockTypeSet() for entry in itemdata: ID = entry['V'].value name = entry['K'].value if (ID, 0) not in blocktypes.statesByID: count += 1 blocktypes.IDsByState[name] = ID, 0 blocktypes.statesByID[ID, 0] = name blocktypes.blockJsons[name] = { 'displayName':name, 'internalName':name, 'blockState':'', } blocktypes.allBlocks.append(BlockType(ID, 0, blocktypes)) blocktypes.allBlocks.sort() log.info("Added %d blocks.", count) self.blocktypes = blocktypes
def main(): from timeit import timeit blocktypes = PCBlockTypeSet() secs = timeit(lambda: yAxisTable(blocktypes), number=1) print("Time: %0.3f" % secs) assert secs < 0.1
def loadFMLMapping(self): metadataTag = self.metadata.metadataTag fml = metadataTag.get('FML') if fml is None: return itemdata = fml.get('ItemData') # MC 1.7 if itemdata is not None: count = 0 log.info("Adding block IDs from FML for MC 1.7") blocktypes = PCBlockTypeSet() replacedIDs = [] for entry in itemdata: ID = entry['V'].value name = entry['K'].value if name[0] != u'\x01': # 0x01 = blocks, 0x02 = items continue name = name[1:] if not name.startswith("minecraft:"): # we load 1.8 block IDs and mappings by default # FML IDs should be allowed to override some of them for 1.8 blocks not in 1.7. count += 1 replacedIDs.append(ID) fakeState = '[0]' nameAndState = name + fakeState log.debug("FML1.7: Adding %s = %d", name, ID) for vanillaMeta in range(15): # Remove existing Vanilla defs vanillaNameAndState = blocktypes.statesByID.get((ID, vanillaMeta)) blocktypes.blockJsons.pop(vanillaNameAndState, None) blocktypes.IDsByState[nameAndState] = ID, 0 blocktypes.statesByID[ID, 0] = nameAndState blocktypes.IDsByName[name] = ID blocktypes.namesByID[ID] = name blocktypes.defaultBlockstates[name] = fakeState blocktypes.blockJsons[nameAndState] = { 'displayName': name, 'internalName': name, 'blockState': '[0]', 'unknown': True, } replacedIDsSet = set(replacedIDs) blocktypes.allBlocks[:] = [b for b in blocktypes if b.ID not in replacedIDsSet] blocktypes.allBlocks.extend(BlockType(newID, 0, blocktypes) for newID in replacedIDs) blocktypes.allBlocks.sort() log.info("Added %d blocks.", count) self.blocktypes = blocktypes
def loadFMLMapping(self): metadataTag = self.metadata.metadataTag fml = metadataTag.get('FML') if fml is None: return itemdata = fml.get('ItemData') # MC 1.7 if itemdata is not None: count = 0 log.info("Adding block IDs from FML for MC 1.7") blocktypes = PCBlockTypeSet() for entry in itemdata: ID = entry['V'].value name = entry['K'].value if name[0] != u'\x01': continue name = name[1:] if ID not in blocktypes.namesByID: count += 1 log.debug("FML1.7: Adding %s = %d", name, ID) blocktypes.IDsByState[name] = ID, 0 blocktypes.statesByID[ID, 0] = name blocktypes.IDsByName[name] = ID blocktypes.namesByID[ID] = name blocktypes.blockJsons[name] = { 'displayName': name, 'internalName': name, 'blockState': '', } blocktypes.allBlocks.append(BlockType(ID, 0, blocktypes)) blocktypes.allBlocks.sort() log.info("Added %d blocks.", count) self.blocktypes = blocktypes
def xxxtest_yAxisTable(): from . import PCBlockTypeSet blocktypes = PCBlockTypeSet() table = yAxisTable(blocktypes) assert (table != blankRotationTable()).any(), "Table is blank" changed = False changedNames = set() for i in range(32768): for j in range(16): e = table[i, j] if e[0] != i or e[1] != j: changed = True name = blocktypes[i, j].internalName if name not in changedNames: # print("%s is changed" % name) changedNames.add(name) assert changed, "Table is unchanged"
def loadBlockMapping(self): if self.metadata.is1_8World(): itemStackVersion = VERSION_1_8 else: itemStackVersion = VERSION_1_7 blocktypes = PCBlockTypeSet(itemStackVersion) self.blocktypes = blocktypes metadataTag = self.metadata.metadataTag fml = metadataTag.get('FML') if fml is None: return itemTypes = blocktypes.itemTypes itemdata = fml.get('ItemData') # MC 1.7 if itemdata is not None: count = 0 log.info("Adding block IDs from FML for MC 1.7") replacedIDs = [] for entry in itemdata: ID = entry['V'].value name = entry['K'].value magic, name = name[0], name[1:] if magic == u'\x01': # 0x01 = blocks if not name.startswith("minecraft:"): # we load 1.9 block IDs and mappings by default # FML IDs should be allowed to override some of them for 1.8 blocks not in 1.7. count += 1 replacedIDs.append(ID) fakeState = '[meta=0]' nameAndState = name + fakeState log.debug("FML1.7: Adding %s = %d", name, ID) for vanillaMeta in range(15): # Remove existing Vanilla defs vanillaNameAndState = blocktypes.statesByID.get((ID, vanillaMeta)) blocktypes.blockJsons.pop(vanillaNameAndState, None) # Also remove Vanilla name<->state mapping blocktypes.IDsByState.pop(vanillaNameAndState, None) vanillaName = blocktypes.namesByID.get(ID) blocktypes.IDsByName.pop(vanillaName, None) blocktypes.defaultBlockstates.pop(vanillaName, None) blocktypes.IDsByState[nameAndState] = ID, 0 blocktypes.statesByID[ID, 0] = nameAndState blocktypes.IDsByName[name] = ID blocktypes.namesByID[ID] = name blocktypes.defaultBlockstates[name] = fakeState blocktypes.blockJsons[nameAndState] = { 'displayName': name, 'internalName': name, 'blockState': '[meta=0]', 'unknown': True, } if magic == u'\x02': # 0x02 = items if not name.startswith("minecraft:"): itemTypes.addFMLIDMapping(name, ID) replacedIDsSet = set(replacedIDs) blocktypes.discardIDs(replacedIDsSet) blocktypes.addBlocktypes(BlockType(newID, 0, blocktypes) for newID in replacedIDs) log.info("Added %d blocks.", count)
def loadBlockMapping(self): if self.metadata.is1_8World(): itemStackVersion = VERSION_1_8 else: itemStackVersion = VERSION_1_7 blocktypes = PCBlockTypeSet(itemStackVersion) self.blocktypes = blocktypes metadataTag = self.metadata.metadataTag fml = metadataTag.get('FML') if fml is None: return itemTypes = blocktypes.itemTypes itemdata = fml.get('ItemData') # MC 1.7 if itemdata is not None: count = 0 log.info("Adding block IDs from FML for MC 1.7") replacedIDs = [] for entry in itemdata: ID = entry['V'].value name = entry['K'].value magic, name = name[0], name[1:] if magic == u'\x01': # 0x01 = blocks if not name.startswith("minecraft:"): # we load 1.8 block IDs and mappings by default # FML IDs should be allowed to override some of them for 1.8 blocks not in 1.7. count += 1 replacedIDs.append(ID) fakeState = '[0]' nameAndState = name + fakeState log.debug("FML1.7: Adding %s = %d", name, ID) for vanillaMeta in range(15): # Remove existing Vanilla defs vanillaNameAndState = blocktypes.statesByID.get( (ID, vanillaMeta)) blocktypes.blockJsons.pop(vanillaNameAndState, None) blocktypes.IDsByState[nameAndState] = ID, 0 blocktypes.statesByID[ID, 0] = nameAndState blocktypes.IDsByName[name] = ID blocktypes.namesByID[ID] = name blocktypes.defaultBlockstates[name] = fakeState blocktypes.blockJsons[nameAndState] = { 'displayName': name, 'internalName': name, 'blockState': '[0]', 'unknown': True, } if magic == u'\x02': # 0x02 = items if not name.startswith("minecraft:"): itemTypes.addFMLIDMapping(name, ID) replacedIDsSet = set(replacedIDs) blocktypes.allBlocks[:] = [ b for b in blocktypes if b.ID not in replacedIDsSet ] blocktypes.allBlocks.extend( BlockType(newID, 0, blocktypes) for newID in replacedIDs) blocktypes.allBlocks.sort() log.info("Added %d blocks.", count)