Ejemplo n.º 1
0
 def add_data_to_tag(self, tag):
     tag.tags.append(TAG_String(name='id', value=self.i_id))
     tag.tags.append(TAG_Short(name='Damage', value=int(self.damage)))
     tag.tags.append(TAG_Byte(name='Count', value=1))
     subtag = TAG_Compound()
     subtag.name = 'tag'
     did_append = False
     if len(self.enchants) > 0:
         enchant = TAG_List(name='ench', type=TAG_Compound)
         for ench in self.enchants:
             enchant.tags.append(ench.getNBTTag())
         subtag.tags.append(enchant)
         did_append = True
     if len(self.attributes) > 0:
         attributes = TAG_List(name='AttributeModifiers', type=TAG_Compound)
         for attribute in self.attributes:
             attributes.tags.append(attribute.getNBTTag())
         subtag.tags.append(attributes)
         did_append = True
     if self.name is not None or len(self.lore) > 0:
         display = TAG_Compound()
         display.name = 'display'
         if self.name is not None:
             display.tags.append(TAG_String(name='Name', value=self.name))
         if len(self.lore) > 0:
             lore_tag = TAG_List(name='Lore', type=TAG_String)
             for lore in self.lore:
                 lore_tag.tags.append(TAG_String(value=lore))
             display.tags.append(lore_tag)
         subtag.tags.append(display)
         did_append = True
     if did_append:
         tag.tags.append(subtag)
Ejemplo n.º 2
0
    def value(self):
        if self.type_ == list:
            tag = TAG_Compound(self.name)
            tag.tags = [x.value for x in self._value]
            return tag

        if self.type_ == NBTFile:
            x = NBTFile()
            x.name = self.name
            x.tags = [x.value for x in self._value]
            return x

        if self.type_ == TAG_Compound:
            tag = TAG_Compound(name=self.name)
            tag.tags = [x.value for x in self._value]
            tag.name = self.name
            return tag

        if self.type_ == TAG_Int_Array:
            tag = TAG_Int_Array(name=self.name)
            tag.value = self._value
            return tag

        if self.type_ == TAG_List:
            tag = TAG_List(type=self.extra, name=self.name)
            tag.tags = [x.value for x in self._value]
            tag.name = self.name
            return tag

        return self.type_(value=self._value, name=self.name)
Ejemplo n.º 3
0
 def add_data_to_tag(self, tag):
     tag.tags.append(TAG_String(name='id', value=self.i_id))
     tag.tags.append(TAG_Short(name='Damage', value=int(self.damage)))
     tag.tags.append(TAG_Byte(name='Count', value=1))
     subtag = TAG_Compound()
     subtag.name = 'tag'
     did_append = False
     if len(self.enchants) > 0:
         enchant = TAG_List(name='ench', type=TAG_Compound)
         for ench in self.enchants:
             enchant.tags.append(ench.getNBTTag())
         subtag.tags.append(enchant)
         did_append = True
     if len(self.attributes) > 0:
         attributes = TAG_List(name='AttributeModifiers', type=TAG_Compound)
         for attribute in self.attributes:
             attributes.tags.append(attribute.getNBTTag())
         subtag.tags.append(attributes)
         did_append = True
     if self.name is not None or len(self.lore) > 0:
         display = TAG_Compound()
         display.name = 'display'
         if self.name is not None:
             display.tags.append(TAG_String(name='Name', value=self.name))
         if len(self.lore) > 0:
             lore_tag = TAG_List(name='Lore', type=TAG_String)
             for lore in self.lore:
                 lore_tag.tags.append(TAG_String(value=lore))
             display.tags.append(lore_tag)
         subtag.tags.append(display)
         did_append = True
     if did_append:
         tag.tags.append(subtag)
Ejemplo n.º 4
0
def generate_level():
    level = NBTFile()  # Blank NBT
    level.name = "Data"
    level.tags.extend([
        TAG_Long(name="Time", value=1),
        TAG_Long(name="LastPlayed", value=int(time.time())),
        TAG_Int(name="SpawnX", value=0),
        TAG_Int(name="SpawnY", value=2),
        TAG_Int(name="SpawnZ", value=0),
        TAG_Long(name="SizeOnDisk", value=0),
        TAG_Long(name="RandomSeed", value=random.randrange(1, 9999999999)),
        TAG_Int(name="version", value=19132),
        TAG_String(name="LevelName", value="Testing")
    ])

    player = TAG_Compound()
    player.name = "Player"
    player.tags.extend(
        [TAG_Int(name="Score", value=0),
         TAG_Int(name="Dimension", value=0)])
    inventory = TAG_Compound()
    inventory.name = "Inventory"
    player.tags.append(inventory)
    level.tags.append(player)

    return level
Ejemplo n.º 5
0
def generate_level():
    level = NBTFile() # Blank NBT
    level.name = "Data"
    level.tags.extend([
        TAG_Long(name="Time", value=1),
        TAG_Long(name="LastPlayed", value=int(time.time())),
        TAG_Int(name="SpawnX", value=0),
        TAG_Int(name="SpawnY", value=2),
        TAG_Int(name="SpawnZ", value=0),
        TAG_Long(name="SizeOnDisk", value=0),
        TAG_Long(name="RandomSeed", value=random.randrange(1,9999999999)),
        TAG_Int(name="version", value=19132),
        TAG_String(name="LevelName", value="Testing")
    ])
    
    player = TAG_Compound()
    player.name = "Player"
    player.tags.extend([
        TAG_Int(name="Score", value=0),
        TAG_Int(name="Dimension", value=0)
    ])
    inventory = TAG_Compound()
    inventory.name = "Inventory"
    player.tags.append(inventory)
    level.tags.append(player)
    
    return level
Ejemplo n.º 6
0
 def __init__(self, playerName, xpos, ypos, zpos):
         self.filename = "%s.dat" % (playerName)
         self.player = NBTFile()
         motion = TAG_List(name = "Motion", type = TAG_Double)
         motion.insert(0, TAG_Double(value = 0))
         motion.insert(1, TAG_Double(value = 0))
         motion.insert(2, TAG_Double(value = 0))
         pos = TAG_List(name = "Pos", type = TAG_Double)
         pos.insert(0, TAG_Double(value = xpos))
         pos.insert(1, TAG_Double(value = ypos))
         pos.insert(2, TAG_Double(value = zpos))
         rotation = TAG_List(name = "Rotation", type = TAG_Float)
         rotation.insert(0, TAG_Float(value = 0))
         rotation.insert(1, TAG_Float(value = 0))
         abilities = TAG_Compound()
         abilities.name = "abilities"
         abilities.tags.extend([
                 TAG_Byte(name = "flying", value = 0),
                 TAG_Byte(name = "instabuild", value = 0),
                 TAG_Byte(name = "invulnerable", value = 0),
                 TAG_Byte(name = "mayfly", value = 0)
         ])
         self.player.tags.extend([
                 TAG_Byte(name = "OnGround", value = 1),
                 TAG_Byte(name = "Sleeping", value = 0),
                 TAG_Short(name = "Air", value = 300),
                 TAG_Short(name = "AttackTime", value = 0),
                 TAG_Short(name = "DeathTime", value = 0),
                 TAG_Short(name = "Fire", value = -20),
                 TAG_Short(name = "Health", value = 20),
                 TAG_Short(name = "HurtTime", value = 0),
                 TAG_Short(name = "SleepTimer", value = 0),
                 TAG_Int(name = "Dimension", value = 0),
                 TAG_Int(name = "foodLevel", value = 20),
                 TAG_Int(name = "foodTickTimer", value = 0),
                 TAG_Int(name = "playerGameType", value = 0),
                 TAG_Int(name = "SpawnX", value = xpos),
                 TAG_Int(name = "SpawnY", value = ypos),
                 TAG_Int(name = "SpawnZ", value = zpos),
                 TAG_Int(name = "XpLevel", value = 0),
                 TAG_Int(name = "XpTotal", value = 0),
                 TAG_Float(name = "fallDistance", value = 0),
                 TAG_Float(name = "foodExhaustionLevel", value = 0),
                 TAG_Float(name = "foodSaturationLevel", value = 5),
                 TAG_Float(name = "XpP", value = 0),
                 TAG_List(name = "Inventory", type = TAG_Compound),
                 motion,
                 pos,
                 rotation,
                 abilities
         ])
Ejemplo n.º 7
0
 def process_entity(self, entity, randomitems):
         slot = 0
         updated = False
         items = items_from_nbt(entity["Items"])
         if sum(items.values()) == 0:
                 print("empty chest found")
                 itemlist = TAG_List(type=TAG_Compound)
                 for randomitem in randomitems:
                         if slot < 27:
                                 if random.uniform(0,100) < float(randomitem[3]):
                                         item = TAG_Compound()
                                         try:
                                                 quantity = int(randomitem[2])
                                         except ValueError:
                                                 try:
                                                         lowrand, highrand = randomitem[2].split('-')
                                                         quantity = random.randrange(int(lowrand), int(highrand) + 1)
                                                 except ValueError:
                                                         print("ERROR: Invalid quantity range.  Defaulting to 1.")
                                                         line = ''
                                                         for section in randomitem:
                                                                 line += ' ' + section
                                                         print(line)
                                                         quantity = 1
                                         if quantity > 127:
                                                 quantity = 127
                                         elif quantity < 1:
                                                 quantity = 1
                                         item.tags.extend([
                                                 TAG_Byte(name="Count", value=quantity),
                                                 TAG_Byte(name="Slot", value=slot),
                                                 TAG_Short(name="Damage", value=int(randomitem[1])),
                                                 TAG_Short(name="id", value=int(randomitem[0]))
                                         ])
                                         if len(randomitem) > 4:
                                                 enchants = TAG_List(name="ench", type=TAG_Compound)
                                                 count = 4
                                                 try:
                                                         while len(randomitem) > count:
                                                                 enchant = TAG_Compound()
                                                                 enchant.tags.extend([
                                                                         TAG_Short(name="id", value=int(randomitem[count])),
                                                                         TAG_Short(name="lvl", value=int(randomitem[count+1]))
                                                                 ])
                                                                 enchants.insert((count-4)/2,enchant)
                                                                 count += 2
                                                         tag = TAG_Compound()
                                                         tag.tags.extend([enchants])
                                                         tag.name = "tag"
                                                         item.tags.extend([tag])
                                                 except IndexError:
                                                         print("ERROR: invalid enchant data")
                                                         line = ''
                                                         for section in randomitem:
                                                                 line += ' ' + section
                                                         print(line)
                                         itemlist.insert(slot,item)
                                         slot += 1
                                         updated = True
                 if updated:
                         entity["Items"] = itemlist
         return updated