Exemplo n.º 1
0
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
Exemplo n.º 2
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

    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
Exemplo n.º 3
0
class MobAttributeModifierRef(nbtattr.NBTCompoundRef):
    Name = nbtattr.NBTAttr('Name', 't')
    Amount = nbtattr.NBTAttr('Amount', 'd')
    Operation = nbtattr.NBTAttr('Operation', 'i')

    UUID = nbtattr.NBTUUIDAttr()
Exemplo n.º 4
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]
Exemplo n.º 5
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