예제 #1
0
파일: Players.py 프로젝트: kamyu2/NBT
 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
         ])
예제 #2
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