Skip to content

Commit

Permalink
destroyed all the annoying tabs (replaced with 4 spaces)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLinker committed Mar 23, 2011
1 parent 9cf59e0 commit 4b7c45e
Show file tree
Hide file tree
Showing 4 changed files with 463 additions and 463 deletions.
24 changes: 12 additions & 12 deletions generate_level_dat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
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")
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)
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)

print level.pretty_tree()
#level.write_file("level.dat")
#level.write_file("level.dat")
98 changes: 49 additions & 49 deletions nbt/chunk.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
""" Handle a single chunk of data (16x16x128 blocks) """
class Chunk(object):
def __init__(self, x, z, length):
self.coords = x,z
self.length = length
def __repr__(self):
return "("+str(self.coords[0])+","+str(self.coords[1])+"): "+str(self.length)
def __init__(self, x, z, length):
self.coords = x,z
self.length = length
def __repr__(self):
return "("+str(self.coords[0])+","+str(self.coords[1])+"): "+str(self.length)

def ByteToHex(byteStr):
return "".join(["%02X " % ord(x) for x in byteStr]).strip()
return "".join(["%02X " % ord(x) for x in byteStr]).strip()

""" Convenience class for dealing with a Block/data byte array """
class BlockArray(object):
def __init__(self, blocksBytes, dataBytes):
self.blocksList = [ord(b) for b in blocksBytes] # A list of bytes
self.dataList = [ord(b) for b in dataBytes]
def __init__(self, blocksBytes, dataBytes):
self.blocksList = [ord(b) for b in blocksBytes] # A list of bytes
self.dataList = [ord(b) for b in dataBytes]

# Get all data entries
def get_all_data(self):
bits = []
for b in self.dataList:
bits.append((b >> 15) & 15) # Big end of the byte
bits.append(b & 15) # Little end of the byte
return bits
# Get a given X,Y,Z
def get_block(self, x,y,z):
"""
Laid out like:
(0,0,0), (0,1,0), (0,2,0) ... (0,127,0), (0,0,1), (0,1,1), (0,2,1) ... (0,127,1), (0,0,2) ... (0,127,15), (1,0,0), (1,1,0) ... (15,127,15)
blocks = []
for x in xrange(15):
for z in xrange(15):
for y in xrange(127):
blocks.append(Block(x,y,z))
"""
offset = y + z*128 + x*128*16
return self.blocksList[offset]
# Get all data entries
def get_all_data(self):
bits = []
for b in self.dataList:
bits.append((b >> 15) & 15) # Big end of the byte
bits.append(b & 15) # Little end of the byte
return bits
# Get a given X,Y,Z
def get_block(self, x,y,z):
"""
Laid out like:
(0,0,0), (0,1,0), (0,2,0) ... (0,127,0), (0,0,1), (0,1,1), (0,2,1) ... (0,127,1), (0,0,2) ... (0,127,15), (1,0,0), (1,1,0) ... (15,127,15)
blocks = []
for x in xrange(15):
for z in xrange(15):
for y in xrange(127):
blocks.append(Block(x,y,z))
"""
offset = y + z*128 + x*128*16
return self.blocksList[offset]

# Get a given X,Y,Z
def get_data(self, x,y,z):
offset = y + z*128 + x*128*16
#print "Offset: "+str(offset)
if (offset % 2 == 1):
# offset is odd
index = (offset-1)/2
b = self.dataList[index]
#print "Byte: %02X" % b
return (b >>15) & 15 # Get big end of byte
else:
# offset is even
index = offset/2
b = self.dataList[index]
#print "Byte: %02X" % b
return b & 15
# Get a given X,Y,Z
def get_data(self, x,y,z):
offset = y + z*128 + x*128*16
#print "Offset: "+str(offset)
if (offset % 2 == 1):
# offset is odd
index = (offset-1)/2
b = self.dataList[index]
#print "Byte: %02X" % b
return (b >>15) & 15 # Get big end of byte
else:
# offset is even
index = offset/2
b = self.dataList[index]
#print "Byte: %02X" % b
return b & 15

0 comments on commit 4b7c45e

Please sign in to comment.