class PCTileEntitySignRef(PCTileEntityRefBase): tileEntityID = "Sign" Text1 = nbtattr.NBTAttr("Text1", 't', "") Text2 = nbtattr.NBTAttr("Text2", 't', "") Text3 = nbtattr.NBTAttr("Text3", 't', "") Text4 = nbtattr.NBTAttr("Text4", 't', "")
class PCEntityMobRefBase(PCEntityRefBase): # xxx add rootTag[Health] as Short (1.8) or Float(1.9)? @property def Health(self): if 'HealF' in self.rootTag: return self.rootTag['HealF'].value elif 'Health' in self.rootTag: return self.rootTag['Health'].value else: self.rootTag['Health'] = nbt.TAG_Short(0.) self.rootTag['HealF'] = nbt.TAG_Float(0.) return 0 @Health.setter def Health(self, val): if 'HealF' in self.rootTag: self.rootTag['HealF'].value = val elif 'Health' in self.rootTag: self.rootTag['Health'].value = val else: self.rootTag['Health'] = nbt.TAG_Short(val) self.rootTag['HealF'] = nbt.TAG_Float(val) AbsorptionAmount = nbtattr.NBTAttr('AbsorptionAmount', 'f') HurtTime = nbtattr.NBTAttr('HurtTime', 's') HurtByTimestamp = nbtattr.NBTAttr('HurtByTimestamp', 'i') DeathTime = nbtattr.NBTAttr('DeathTime', 's') Attributes = nbtattr.NBTCompoundListAttr('Attributes', MobAttributeRef) ActiveEffects = nbtattr.NBTCompoundListAttr('ActiveEffects', MobPotionEffectRef)
class PCTileEntityControlRef(PCTileEntityRefBase): tileEntityID = "Control" Command = nbtattr.NBTAttr("Command", nbt.TAG_String, "") CustomName = nbtattr.NBTAttr("CustomName", nbt.TAG_String, "") SuccessCount = nbtattr.NBTAttr("SuccessCount", nbt.TAG_Int, 0) TrackOutput = nbtattr.NBTAttr("TrackOutput", nbt.TAG_Byte, 1)
class PCTileEntityControlRef(PCTileEntityRefBase): tileEntityID = "Control" Command = nbtattr.NBTAttr("Command", 't', "") CustomName = nbtattr.NBTAttr("CustomName", 't', "") SuccessCount = nbtattr.NBTAttr("SuccessCount", 'i', 0) TrackOutput = nbtattr.NBTAttr("TrackOutput", 'b', 1)
class CommandStatsRef(nbtattr.NBTCompoundRef): SuccessCountObjective = nbtattr.NBTAttr('SuccessCountObjective', 't') SuccessCountName = nbtattr.NBTAttr('SuccessCountName', 't') AffectedBlocksObjective = nbtattr.NBTAttr('AffectedBlocksObjective', 't') AffectedBlocksName = nbtattr.NBTAttr('AffectedBlocksName', 't') AffectedEntitiesObjective = nbtattr.NBTAttr('AffectedEntitiesObjective', 't') AffectedEntitiesName = nbtattr.NBTAttr('AffectedEntitiesName', 't') AffectedItemsObjective = nbtattr.NBTAttr('AffectedItemsObjective', 't') AffectedItemsName = nbtattr.NBTAttr('AffectedItemsName', 't') QueryResultObjective = nbtattr.NBTAttr('QueryResultObjective', 't') QueryResultName = nbtattr.NBTAttr('QueryResultName', 't')
class PCRabbitEntityRef(PCEntityMobRefBase): # Possible values: # 0: Brown # 1: White # 2: Black # 3: Black&White # 4: Gold # 5: Salt&Pepper # 99: Killer RabbitType = nbtattr.NBTAttr("RabbitType", 'i', 0) MoreCarrotTicks = nbtattr.NBTAttr("MoreCarrotTicks", 'i', 0)
class AnvilWorldMetadata(object): def __init__(self, metadataTag): self.metadataTag = metadataTag self.rootTag = metadataTag["Data"] self.dirty = False # --- NBT Tag variables --- SizeOnDisk = nbtattr.NBTAttr('SizeOnDisk', nbt.TAG_Long, 0) RandomSeed = nbtattr.NBTAttr('RandomSeed', nbt.TAG_Long, 0) Time = nbtattr.NBTAttr('Time', nbt.TAG_Long, 0) # Age of the world in ticks. 20 ticks per second; 24000 ticks per day. LastPlayed = nbtattr.NBTAttr('LastPlayed', nbt.TAG_Long, time.time() * 1000) LevelName = nbtattr.NBTAttr('LevelName', nbt.TAG_String, "Untitled World") MapFeatures = nbtattr.NBTAttr('MapFeatures', nbt.TAG_Byte, 1) GameType = nbtattr.NBTAttr('GameType', nbt.TAG_Int, 0) # 0 for survival, 1 for creative version = nbtattr.NBTAttr('version', nbt.TAG_Int, VERSION_ANVIL) def worldSpawnPosition(self): return Vector(*[self.rootTag[i].value for i in ("SpawnX", "SpawnY", "SpawnZ")]) def setWorldSpawnPosition(self, pos): for name, val in zip(("SpawnX", "SpawnY", "SpawnZ"), pos): self.rootTag[name] = nbt.TAG_Int(val)
class PCTileEntityRefBase(object): def __init__(self, rootTag, chunk=None): self.rootTag = rootTag self.chunk = chunk def raw_tag(self): return self.rootTag id = nbtattr.NBTAttr("id", nbt.TAG_String) Position = nbtattr.KeyedVectorAttr('x', 'y', 'z', nbt.TAG_Int, 0) def copy(self): return self.copyWithOffset(Vector(0, 0, 0)) def copyWithOffset(self, copyOffset, newEntityClass=None): if newEntityClass is None: newEntityClass = self.__class__ tag = self.rootTag.copy() entity = newEntityClass(tag) entity.Position = self.Position + copyOffset if tag["id"].value in ("Painting", "ItemFrame"): tag["TileX"].value += copyOffset[0] tag["TileY"].value += copyOffset[1] tag["TileZ"].value += copyOffset[2] return self.__class__(tag) def dirty(self): self.chunk.dirty = True @property def blockTypes(self): return self.chunk.blocktypes
class PCPaintingEntityRefBase(PCEntityRefBase): # XXXXXXXXX # in 1.8, TilePos is the block the painting is IN # in 1.7, TilePos is the block the painting is ON TilePos = nbtattr.KeyedVectorAttr('TileX', 'TileY', 'TileZ', nbt.TAG_Int, (0, 0, 0)) # XXXXXXXXXXX # in 1.7 and before, this tag is called "Direction" # in some version before that, it is called "Dir" and its enums are different! Facing = nbtattr.NBTAttr('Facing', nbt.TAG_Byte, 0) SouthFacing = 0 WestFacing = 1 NorthFacing = 2 EastFacing = 3 _mceditFacings = { faces.FaceSouth: SouthFacing, faces.FaceWest: WestFacing, faces.FaceNorth: NorthFacing, faces.FaceEast: EastFacing, } def facingForMCEditFace(self, face): return self._mceditFacings.get(face, None)
class PCEntityRef(object): def __init__(self, rootTag, chunk=None): self.rootTag = rootTag self.chunk = chunk def raw_tag(self): return self.rootTag id = nbtattr.NBTAttr("id", nbt.TAG_String) Position = nbtattr.NBTVectorAttr("Pos", nbt.TAG_Double) Motion = nbtattr.NBTVectorAttr("Motion", nbt.TAG_Double) Rotation = nbtattr.NBTListAttr("Rotation", nbt.TAG_Float) UUID = nbtattr.NBTUUIDAttr() def copy(self): return self.copyWithOffset(Vector(0, 0, 0)) def copyWithOffset(self, copyOffset, newEntityClass=None): if newEntityClass is None: newEntityClass = self.__class__ tag = self.rootTag.copy() entity = newEntityClass(tag) entity.Position = self.Position + copyOffset return PCEntityRef(tag, None) def dirty(self): self.chunk.dirty = True
class PCEntityRefBase(object): def __init__(self, rootTag, chunk=None): self.rootTag = rootTag self.chunk = chunk self.parent = None # xxx used by WorldEditor for newly created, non-chunked refs def raw_tag(self): return self.rootTag @classmethod def create(cls): rootTag = nbt.TAG_Compound() ref = cls(rootTag) nbtattr.SetNBTDefaults(ref) return ref id = nbtattr.NBTAttr("id", nbt.TAG_String) Position = nbtattr.NBTVectorAttr("Pos", nbt.TAG_Double) Motion = nbtattr.NBTVectorAttr("Motion", nbt.TAG_Double) Rotation = nbtattr.NBTListAttr("Rotation", nbt.TAG_Float) UUID = nbtattr.NBTUUIDAttr() def copy(self): return self.copyWithOffset(Vector(0, 0, 0)) def copyWithOffset(self, copyOffset, newEntityClass=None): if newEntityClass is None: newEntityClass = self.__class__ tag = self.rootTag.copy() entity = newEntityClass(tag) entity.Position = self.Position + copyOffset return self.__class__(tag) @property def dirty(self): if self.chunk: return self.chunk.dirty return True @dirty.setter def dirty(self, value): if self.chunk: self.chunk.dirty = value @property def blockTypes(self): if self.chunk: return self.chunk.blocktypes if self.parent: return self.parent.blocktypes return None
class PCTileEntityRefBase(object): def __init__(self, rootTag, chunk=None): self.rootTag = rootTag self.chunk = chunk def raw_tag(self): return self.rootTag @classmethod def create(cls): rootTag = nbt.TAG_Compound() ref = cls(rootTag) nbtattr.SetNBTDefaults(ref) return ref tileEntityID = NotImplemented id = nbtattr.NBTAttr("id", 't') Position = nbtattr.KeyedVectorAttr('x', 'y', 'z', nbt.TAG_Int, 0) def copy(self): return self.copyWithOffset(Vector(0, 0, 0)) def copyWithOffset(self, copyOffset, newEntityClass=None): if newEntityClass is None: newEntityClass = self.__class__ tag = self.rootTag.copy() entity = newEntityClass(tag) entity.Position = self.Position + copyOffset return self.__class__(tag) @property def dirty(self): if self.chunk: return self.chunk.dirty return True @dirty.setter def dirty(self, value): if self.chunk: self.chunk.dirty = value @property def blockTypes(self): return self.chunk.blocktypes
class AnvilWorldMetadata(object): def __init__(self, metadataTag): self.metadataTag = metadataTag self.rootTag = metadataTag["Data"] self.dirty = False # --- NBT Tag variables --- SizeOnDisk = nbtattr.NBTAttr('SizeOnDisk', nbt.TAG_Long, 0) RandomSeed = nbtattr.NBTAttr('RandomSeed', nbt.TAG_Long, 0) Time = nbtattr.NBTAttr( 'Time', nbt.TAG_Long, 0 ) # Age of the world in ticks. 20 ticks per second; 24000 ticks per day. LastPlayed = nbtattr.NBTAttr('LastPlayed', nbt.TAG_Long, time.time() * 1000) LevelName = nbtattr.NBTAttr('LevelName', nbt.TAG_String, "Untitled World") MapFeatures = nbtattr.NBTAttr('MapFeatures', nbt.TAG_Byte, 1) GameType = nbtattr.NBTAttr('GameType', nbt.TAG_Int, 0) # 0 for survival, 1 for creative version = nbtattr.NBTAttr('version', nbt.TAG_Int, VERSION_ANVIL) def worldSpawnPosition(self): return Vector( *[self.rootTag[i].value for i in ("SpawnX", "SpawnY", "SpawnZ")]) def setWorldSpawnPosition(self, pos): for name, val in zip(("SpawnX", "SpawnY", "SpawnZ"), pos): self.rootTag[name] = nbt.TAG_Int(val) def is1_8World(self): # Minecraft 1.8 adds a dozen tags to level.dat/Data. These tags are removed if # the world is played in 1.7 (and all of the items are removed too!) # Use some of these tags to decide whether to use 1.7 format ItemStacks or 1.8 format ones. # In 1.8, the stack's "id" is a string, but in 1.7 it is an int. tags = (t in self.rootTag for t in ('BorderCenterX', 'BorderCenterZ', 'BorderDamagePerBlock', 'BorderSafeZone', 'BorderSize')) return any(tags)
class PCTileEntityRefBase(object): def __init__(self, rootTag, chunk=None): self.rootTag = rootTag self.chunk = chunk def raw_tag(self): return self.rootTag id = nbtattr.NBTAttr("id", nbt.TAG_String) @property def Position(self): return Vector(*[self.rootTag[c].value for c in 'xyz']) @Position.setter def Position(self, pos): for a, p in zip('xyz', pos): self.rootTag[a] = nbt.TAG_Int(p) def copy(self): return self.copyWithOffset(Vector(0, 0, 0)) def copyWithOffset(self, copyOffset, newEntityClass=None): if newEntityClass is None: newEntityClass = self.__class__ tag = self.rootTag.copy() entity = newEntityClass(tag) entity.Position = self.Position + copyOffset if tag["id"].value in ("Painting", "ItemFrame"): tag["TileX"].value += copyOffset[0] tag["TileY"].value += copyOffset[1] tag["TileZ"].value += copyOffset[2] return self.__class__(tag) def dirty(self): self.chunk.dirty = True @property def blockTypes(self): return self.chunk.blocktypes
class DrawerItemStackRef(nbtattr.NBTCompoundRef): def __init__(self, rootTag=None, parent=None): if rootTag is None: rootTag = nbt.TAG_Compound() nbtattr.SetNBTDefaults(self) super(DrawerItemStackRef, self).__init__(rootTag, parent) Damage = nbtattr.NBTAttr("Meta", nbt.TAG_Short, 0) Count = nbtattr.NBTAttr("Count", nbt.TAG_Int, 1) @property def id(self): if self.blockTypes is None: log.warn("No blocktypes available, returning id") return self.rootTag["Item"].value try: itemType = self.blockTypes.itemTypes[self.rootTag["Item"].value] return itemType.internalName except KeyError: log.warn("No ItemType defined for %s, returning id" % self.rootTag["Item"].value) return self.rootTag["Item"].value @id.setter def id(self, value): if isinstance(value, ItemType): self.rootTag["Item"] = nbt.TAG_Short(value.ID) if value.meta is not None: self.Damage = value.meta elif isinstance(value, int): self.rootTag["Item"] = nbt.TAG_Short(value) elif isinstance(value, basestring): if self.blockTypes is None: raise ValueError("DrawerItemStackRef must be parented to assign string IDs") self.rootTag["Item"] = nbt.TAG_Short(self.blockTypes.itemTypes[value].ID) else: raise TypeError("Invalid type for ItemStackRef.id: %r", type(value)) self.dirty = True @property def itemType(self): if self.blockTypes is None: raise ValueError("Cannot get itemType for this item. BlockTypes not set. ") try: itemType = self.blockTypes.itemTypes[self.rootTag["Item"].value, self.Damage] return itemType except KeyError: raise ValueError("Cannot get itemType for this item. BlockTypes has no item for %s." % self.rootTag["Item"].value) @itemType.setter def itemType(self, value): if not isinstance(value, ItemType): raise TypeError("Expected ItemType, got %r", type(value)) self.id = value @property def raw_id(self): return self.rootTag["Item"].value @raw_id.setter def raw_id(self, value): if isinstance(value, int): self.rootTag["Item"] = nbt.TAG_Short(value) elif isinstance(value, basestring): if self.blockTypes is None: raise ValueError("DrawerItemStackRef must be parented to assign string IDs") self.rootTag["Item"] = nbt.TAG_Short(self.blockTypes.itemTypes[value].ID) else: raise TypeError("Invalid type for ItemStack.id: %r", type(value)) self.dirty = True @staticmethod def tagIsItem(tag): if tag.tagID != nbt.ID_COMPOUND: return False return "Item" in tag and "Meta" in tag and "Count" in tag
class MobPotionEffectRef(nbtattr.NBTCompoundRef): Id = nbtattr.NBTAttr('Id', 'b') Amplifier = nbtattr.NBTAttr('Amplifier', 'b') Duration = nbtattr.NBTAttr('Duration', 'i') Ambient = nbtattr.NBTAttr('Ambient', 'b') ShowParticles = nbtattr.NBTAttr('ShowParticles', 'b')
class MobAttributeRef(nbtattr.NBTCompoundRef): Name = nbtattr.NBTAttr('Name', 't') Base = nbtattr.NBTAttr('Base', 'd') Modifiers = nbtattr.NBTCompoundListAttr('Modifiers', MobAttributeModifierRef)
class PCPaintingEntityRef(PCPaintingEntityRefBase): Motive = nbtattr.NBTAttr("Motive", nbt.TAG_String)
class PCVillagerEntityRef(PCEntityRefBase): Profession = nbtattr.NBTAttr("Profession", nbt.TAG_Int, 0)
class ItemRef(nbtattr.NBTCompoundRef): def __init__(self, rootTag=None, parent=None): if rootTag is None: rootTag = nbt.TAG_Compound() nbtattr.SetNBTDefaults(self) super(ItemRef, self).__init__(rootTag, parent) Damage = nbtattr.NBTAttr("Damage", nbt.TAG_Short, 0) Count = nbtattr.NBTAttr("Count", nbt.TAG_Byte, 1) tag = nbtattr.NBTAttr("tag", nbt.TAG_Compound) @property def id(self): idTag = self.rootTag["id"] if idTag.tagID == nbt.ID_SHORT: if self.blockTypes is None: log.warn("No blocktypes available, returning id") return idTag.value try: itemType = self.blockTypes.itemTypes[idTag.value] return itemType.internalName except KeyError: log.warn("No ItemType defined for %s, returning id" % idTag.value) return idTag.value else: return idTag.value @id.setter def id(self, value): if "id" not in self.rootTag: # no id tag - freshly minted item tag # get proper tag type from blocktypes if self.blockTypes is None: raise NoParentError( "ItemRef must be parented to a world before assigning id for the first time." ) if self.blockTypes.itemStackVersion == VERSION_1_7: self.rootTag["id"] = nbt.TAG_Short(0) elif self.blockTypes.itemStackVersion == VERSION_1_8: self.rootTag["id"] = nbt.TAG_String("minecraft:air") else: raise AssertionError("Unexpected itemStackVersion: %s", self.blockTypes.itemStackVersion) idTag = self.rootTag["id"] if isinstance(value, ItemType): if idTag.tagID == nbt.ID_STRING: idTag.value = value.internalName else: idTag.value = value.ID if value.meta is not None: self.Damage = value.meta elif isinstance(value, int): if idTag.tagID == nbt.ID_SHORT: self.rootTag["id"].value = value elif idTag.tagID == nbt.ID_STRING: if self.blockTypes is None: raise NoParentError( "ItemRef must be parented to a world before assigning numeric IDs to an 1.8 ItemStack." ) itemType = self.blockTypes.itemTypes[value] self.rootTag["id"].value = itemType.internalName elif isinstance(value, basestring): if idTag.tagID == nbt.ID_STRING: self.rootTag["id"].value = value elif idTag.tagID == nbt.ID_SHORT: if self.blockTypes is None: raise NoParentError( "ItemRef must be parented to a world before assigning textual IDs to an 1.7 ItemStack." ) itemType = self.blockTypes.itemTypes[value] self.rootTag["id"].value = itemType.ID else: raise TypeError("Invalid type for ItemRef.id: %r", type(value)) self.dirty = True @property def itemType(self): ID = self.rootTag["id"].value if self.blockTypes is None: raise ValueError( "Cannot get itemType for this item. BlockTypes not set. ") try: itemType = self.blockTypes.itemTypes[ID, self.Damage] return itemType except KeyError: raise ValueError( "Cannot get itemType for this item. BlockTypes has no item for %s." % ID) @itemType.setter def itemType(self, value): if not isinstance(value, ItemType): raise TypeError("Expected ItemType, got %r", type(value)) self.id = value @property def raw_id(self): return self.rootTag["id"].value @raw_id.setter def raw_id(self, value): if isinstance(value, int): self.rootTag["id"] = nbt.TAG_Short(value) elif isinstance(value, basestring): self.rootTag["id"] = nbt.TAG_String(value) else: raise TypeError("Invalid type for ItemRef.id: %r", type(value)) self.dirty = True @staticmethod def tagIsItem(tag): if tag.tagID != nbt.ID_COMPOUND: return False return "id" in tag and "Damage" in tag and "Count" in tag
class PCPaintingEntityRef(PCPaintingEntityRefBase): Motive = nbtattr.NBTAttr("Motive", 't')
class ItemStackRef(ItemRef): Slot = nbtattr.NBTAttr("Slot", nbt.TAG_Byte)
class PCBatEntityRef(PCEntityMobRefBase): BatFlags = nbtattr.NBTAttr("BatFlags", 'b', 0)
class AnvilPlayerRef(object): def __init__(self, adapter, playerUUID): self.playerUUID = playerUUID self.adapter = adapter self.rootTag = adapter.getPlayerTag(playerUUID) self.dirty = False # # @property # def rootTag(self): # if self.playerTag is None or self.playerTag() is None: # tag = self.adapter.getPlayerTag(self.playerName) # self.playerTag = weakref.ref(tag) # # return tag # return self.playerTag() UUID = nbtattr.NBTUUIDAttr() id = nbtattr.NBTAttr("id", nbt.TAG_String) Position = nbtattr.NBTVectorAttr("Pos", nbt.TAG_Double) Motion = nbtattr.NBTVectorAttr("Motion", nbt.TAG_Double) Rotation = nbtattr.NBTListAttr("Rotation", nbt.TAG_Float) Air = nbtattr.NBTAttr('Air', nbt.TAG_Short, 300) AttackTime = nbtattr.NBTAttr('AttackTime', nbt.TAG_Short, 0) DeathTime = nbtattr.NBTAttr('DeathTime', nbt.TAG_Short, 0) Fire = nbtattr.NBTAttr('Fire', nbt.TAG_Short, -20) Health = nbtattr.NBTAttr('Health', nbt.TAG_Short, 20) HurtTime = nbtattr.NBTAttr('HurtTime', nbt.TAG_Short, 0) Score = nbtattr.NBTAttr('Score', nbt.TAG_Int, 0) FallDistance = nbtattr.NBTAttr('FallDistance', nbt.TAG_Float, 0) OnGround = nbtattr.NBTAttr('OnGround', nbt.TAG_Byte, 0) Dimension = nbtattr.NBTAttr('OnGround', nbt.TAG_Int, 0) Inventory = nbtattr.NBTListAttr('Inventory', nbt.TAG_Compound) GAMETYPE_SURVIVAL = 0 GAMETYPE_CREATIVE = 1 GAMETYPE_ADVENTURE = 2 GameType = nbtattr.NBTAttr('playerGameType', nbt.TAG_Int, GAMETYPE_SURVIVAL) abilities = nbtattr.NBTCompoundAttr("abilities", PlayerAbilitiesAttrs) def setAbilities(self, gametype): # Assumes GAMETYPE_CREATIVE is the only mode with these abilities set, # which is true for now. Future game modes may not hold this to be # true, however. if gametype == self.GAMETYPE_CREATIVE: self.abilities.instabuild = True self.abilities.mayfly = True self.abilities.invulnerable = True else: self.abilities.flying = True self.abilities.instabuild = True self.abilities.mayfly = True self.abilities.invulnerable = True def setGameType(self, gametype): self.GameType = gametype self.setAbilities(gametype) @property def Spawn(self): return [self.rootTag[i].value for i in ("SpawnX", "SpawnY", "SpawnZ")] @Spawn.setter def Spawn(self, pos): for name, val in zip(("SpawnX", "SpawnY", "SpawnZ"), pos): self.rootTag[name] = nbt.TAG_Int(val) def save(self): if self.dirty: self.adapter.savePlayerTag(self.rootTag, self.playerUUID) self.dirty = False _dimNames = { -1:"DIM-1", 0:"", 1:"DIM1", } _dimNumbers = {v:k for k, v in _dimNames.iteritems()} @property def dimName(self): return self._dimNames[self.Dimension] @dimName.setter def dimName(self, name): self.Dimension = self._dimNumbers[name]
class PCChickenEntityRef(PCEntityMobRefBase): IsChickenJockey = nbtattr.NBTAttr("IsChickenJockey", 'b', 0) EggLayTime = nbtattr.NBTAttr("EggLayTime", 'i', 0)
class PlayerAbilitiesAttrs(nbtattr.CompoundAttrs): mayBuild = nbtattr.NBTAttr('mayBuild', nbt.TAG_Byte, 0) instabuild = nbtattr.NBTAttr('instabuild', nbt.TAG_Byte, 0) flying = nbtattr.NBTAttr('flying', nbt.TAG_Byte, 0) mayfly = nbtattr.NBTAttr('mayfly', nbt.TAG_Byte, 0) invulnerable = nbtattr.NBTAttr('invulnerable', nbt.TAG_Byte, 0)
class PCPigEntityRef(PCEntityMobRefBase): Saddle = nbtattr.NBTAttr("Saddle", 'b', 0)
class AnvilWorldMetadata(object): def __init__(self, metadataTag): self.metadataTag = metadataTag self.rootTag = metadataTag["Data"] self.dirty = False # --- NBT Tag variables --- SizeOnDisk = nbtattr.NBTAttr('SizeOnDisk', nbt.TAG_Long, 0) RandomSeed = nbtattr.NBTAttr('RandomSeed', nbt.TAG_Long, 0) Time = nbtattr.NBTAttr( 'Time', nbt.TAG_Long, 0 ) # Age of the world in ticks. 20 ticks per second; 24000 ticks per day. DayTime = nbtattr.NBTAttr('DayTime', nbt.TAG_Long, 0) # Amount of ticks since Day 1, 6:00 LastPlayed = nbtattr.NBTAttr('LastPlayed', nbt.TAG_Long, time.time() * 1000) Difficulty = nbtattr.NBTAttr('Difficulty', nbt.TAG_Byte, 0) LevelName = nbtattr.NBTAttr('LevelName', nbt.TAG_String, "Untitled World") hardcore = nbtattr.NBTAttr('hardcore', nbt.TAG_Byte, False) allowCommands = nbtattr.NBTAttr('allowCommands', nbt.TAG_Byte, False) DifficultyLocked = nbtattr.NBTAttr('DifficultyLocked', nbt.TAG_Byte, False) generatorName = nbtattr.NBTAttr('generatorName', nbt.TAG_String, "default") generatorOptions = nbtattr.NBTAttr( 'generatorOptions', nbt.TAG_String, "") #Default is different for every generatorType MapFeatures = nbtattr.NBTAttr('MapFeatures', nbt.TAG_Byte, 1) GameType = nbtattr.NBTAttr('GameType', nbt.TAG_Int, 0) # 0 for survival, 1 for creative version = nbtattr.NBTAttr('version', nbt.TAG_Int, VERSION_ANVIL) Spawn = nbtattr.KeyedVectorAttr('SpawnX', 'SpawnY', 'SpawnZ', nbt.TAG_Int) def is1_8World(self): # Minecraft 1.8 adds a dozen tags to level.dat/Data. These tags are removed if # the world is played in 1.7 (and all of the items are removed too!) # Use some of these tags to decide whether to use 1.7 format ItemStacks or 1.8 format ones. # In 1.8, the stack's "id" is a TAG_String, but in 1.7 it is a TAG_Short. tags = ('BorderCenterX', 'BorderCenterZ', 'BorderDamagePerBlock', 'BorderSafeZone', 'BorderSize') return any(tag in self.rootTag for tag in tags)
class PCSheepEntityRef(PCEntityMobRefBase): Sheared = nbtattr.NBTAttr("Sheared", 'b', 0) # Same values as wool colors Color = nbtattr.NBTAttr("Color", 'b', 0)
class PCVillagerEntityRef(PCEntityMobRefBase): Profession = nbtattr.NBTAttr("Profession", 'i', 0)