예제 #1
0
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)
예제 #2
0
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
예제 #3
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)
예제 #4
0
파일: entities.py 프로젝트: wcpe/mcedit2
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