Esempio n. 1
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)

    Version = nbtattr.NBTCompoundAttr('Version', WorldVersionRef)

    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)
Esempio n. 2
0
class PCItemFrameEntityRef(PCPaintingEntityRefBase):
    Item = nbtattr.NBTCompoundAttr("Item", ItemRef)
Esempio n. 3
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]
Esempio n. 4
0
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

    entityID = NotImplemented

    id = nbtattr.NBTAttr("id", 't')
    Position = nbtattr.NBTVectorAttr("Pos", 'd')
    Motion = nbtattr.NBTVectorAttr("Motion", 'd')
    Rotation = nbtattr.NBTListAttr("Rotation", 'f')

    FallDistance = nbtattr.NBTAttr("FallDistance", 'f')
    Fire = nbtattr.NBTAttr("Fire", 's')
    Air = nbtattr.NBTAttr("Air", 's')
    OnGround = nbtattr.NBTAttr("OnGround", 'b')
    Dimension = nbtattr.NBTAttr("Dimension", 'i')
    Invulnerable = nbtattr.NBTAttr("Invulnerable", 'b')
    PortalCooldown = nbtattr.NBTAttr("PortalCooldown", 'i')
    CustomName = nbtattr.NBTAttr("CustomName", 't')
    CustomNameVisible = nbtattr.NBTAttr("CustomNameVisible", 'b')
    Silent = nbtattr.NBTAttr("Silent", 'b')

    Passengers = nbtattr.NBTCompoundListAttr("Passengers", PCEntityRef)

    Glowing = nbtattr.NBTAttr("Glowing", 'b')
    Tags = nbtattr.NBTListAttr("Tags", 's')

    CommandStats = nbtattr.NBTCompoundAttr('CommandStats', CommandStatsRef)

    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
        entity.UUID = uuid.uuid1()

        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