pyflakes helped fixes: level.py, tests.py: unravel import all of mclevelbase module in level.py and fix a few unravel related issues with tests.py

This commit is contained in:
David Sowder 2012-03-04 09:04:53 -06:00
parent 3aac456cf5
commit fb6b4aa05a
2 changed files with 28 additions and 21 deletions

View File

@ -4,12 +4,18 @@ Created on Jul 22, 2011
@author: Rio @author: Rio
''' '''
import blockrotation
from box import BoundingBox from box import BoundingBox
from collections import defaultdict
from entity import Entity, TileEntity
import itertools import itertools
from logging import getLogger from logging import getLogger
from mclevelbase import *
from collections import defaultdict
import materials import materials
from math import floor
from mclevelbase import ChunkMalformed, ChunkNotPresent, exhaust
import nbt
from numpy import argmax, swapaxes, zeros, zeros_like
import os.path
log = getLogger(__name__) log = getLogger(__name__)
warn, error, info, debug = log.warn, log.error, log.info, log.debug warn, error, info, debug = log.warn, log.error, log.info, log.debug
@ -127,7 +133,7 @@ class MCLevel(object):
### common to Creative, Survival and Indev. these routines assume ### common to Creative, Survival and Indev. these routines assume
### self has Width, Height, Length, and Blocks ### self has Width, Height, Length, and Blocks
materials = classicMaterials materials = materials.classicMaterials
isInfinite = False isInfinite = False
compressedTag = None compressedTag = None
@ -273,7 +279,7 @@ class MCLevel(object):
f.Entities, f.TileEntities = self._getFakeChunkEntities(cx, cz) f.Entities, f.TileEntities = self._getFakeChunkEntities(cx, cz)
f.root_tag = TAG_Compound() f.root_tag = nbt.TAG_Compound()
return f return f
@ -416,7 +422,7 @@ class MCLevel(object):
blocks = self.Blocks[slices[0], slices[2], slices[1]] blocks = self.Blocks[slices[0], slices[2], slices[1]]
if len(blocksToReplace): if len(blocksToReplace):
blocktable = self.blockReplaceTable(blocksToReplace) blocktable = self.blockReplaceTable(blocksToReplace)
shouldRetainData = (self.materials == alphaMaterials) and all([blockrotation.SameRotationType(blockInfo, b) for b in blocksToReplace]) shouldRetainData = (self.materials == materials.alphaMaterials) and all([blockrotation.SameRotationType(blockInfo, b) for b in blocksToReplace])
if hasattr(self, "Data") and shouldRetainData: if hasattr(self, "Data") and shouldRetainData:
data = self.Data[slices[0], slices[2], slices[1]] data = self.Data[slices[0], slices[2], slices[1]]
@ -741,7 +747,7 @@ class EntityLevel(MCLevel):
self.addEntity(e) self.addEntity(e)
def addEntity(self, entityTag): def addEntity(self, entityTag):
assert isinstance(entityTag, TAG_Compound) assert isinstance(entityTag, nbt.TAG_Compound)
self.Entities.append(entityTag) self.Entities.append(entityTag)
self._fakeEntities = None self._fakeEntities = None
@ -759,7 +765,7 @@ class EntityLevel(MCLevel):
return entities[0] return entities[0]
def addTileEntity(self, tileEntityTag): def addTileEntity(self, tileEntityTag):
assert isinstance(tileEntityTag, TAG_Compound) assert isinstance(tileEntityTag, nbt.TAG_Compound)
def differentPosition(a): def differentPosition(a):

View File

@ -12,6 +12,7 @@ try:
except ImportError: except ImportError:
from __init__ import * from __init__ import *
from cStringIO import StringIO
import itertools import itertools
import unittest import unittest
import tempfile import tempfile
@ -88,21 +89,21 @@ class TestNBT(unittest.TestCase):
"Create an indev level." "Create an indev level."
"The root of an NBT file is always a TAG_Compound." "The root of an NBT file is always a TAG_Compound."
level = TAG_Compound(name="MinecraftLevel") level = nbt.TAG_Compound(name="MinecraftLevel")
"Subtags of a TAG_Compound are automatically named when you use the [] operator." "Subtags of a TAG_Compound are automatically named when you use the [] operator."
level["About"] = TAG_Compound() level["About"] = nbt.TAG_Compound()
level["About"]["Author"] = TAG_String("codewarrior") level["About"]["Author"] = nbt.TAG_String("codewarrior")
level["Environment"] = TAG_Compound() level["Environment"] = nbt.TAG_Compound()
level["Environment"]["SkyBrightness"] = TAG_Byte(16) level["Environment"]["SkyBrightness"] = nbt.TAG_Byte(16)
level["Environment"]["SurroundingWaterHeight"] = TAG_Short(32) level["Environment"]["SurroundingWaterHeight"] = nbt.TAG_Short(32)
"You can also create and name a tag before adding it to the compound." "You can also create and name a tag before adding it to the compound."
spawn = TAG_List((TAG_Short(100), TAG_Short(45), TAG_Short(55))) spawn = nbt.TAG_List((nbt.TAG_Short(100), nbt.TAG_Short(45), nbt.TAG_Short(55)))
spawn.name = "Spawn" spawn.name = "Spawn"
mapTag = TAG_Compound() mapTag = nbt.TAG_Compound()
mapTag.add(spawn) mapTag.add(spawn)
mapTag.name = "Map" mapTag.name = "Map"
level.add(mapTag) level.add(mapTag)
@ -110,13 +111,13 @@ class TestNBT(unittest.TestCase):
"I think it looks more familiar with [] syntax." "I think it looks more familiar with [] syntax."
l, w, h = 128, 128, 128 l, w, h = 128, 128, 128
mapTag["Height"] = TAG_Short(h) # y dimension mapTag["Height"] = nbt.TAG_Short(h) # y dimension
mapTag["Length"] = TAG_Short(l) # z dimension mapTag["Length"] = nbt.TAG_Short(l) # z dimension
mapTag["Width"] = TAG_Short(w) # x dimension mapTag["Width"] = nbt.TAG_Short(w) # x dimension
"Byte arrays are stored as numpy.uint8 arrays. " "Byte arrays are stored as numpy.uint8 arrays. "
mapTag["Blocks"] = TAG_Byte_Array() mapTag["Blocks"] = nbt.TAG_Byte_Array()
mapTag["Blocks"].value = zeros(l * w * h, dtype=uint8) # create lots of air! mapTag["Blocks"].value = zeros(l * w * h, dtype=uint8) # create lots of air!
"The blocks array is indexed (y,z,x) for indev levels, so reshape the blocks" "The blocks array is indexed (y,z,x) for indev levels, so reshape the blocks"
@ -127,7 +128,7 @@ class TestNBT(unittest.TestCase):
"This is a great way to learn the power of numpy array slicing and indexing." "This is a great way to learn the power of numpy array slicing and indexing."
mapTag["Data"] = TAG_Byte_Array() mapTag["Data"] = nbt.TAG_Byte_Array()
mapTag["Data"].value = zeros(l * w * h, dtype=uint8) mapTag["Data"].value = zeros(l * w * h, dtype=uint8)
return level return level
@ -136,7 +137,7 @@ class TestNBT(unittest.TestCase):
level = self.testCreate() level = self.testCreate()
"Most of the value types work as expected. Here, we replace the entire tag with a TAG_String" "Most of the value types work as expected. Here, we replace the entire tag with a TAG_String"
level["About"]["Author"] = TAG_String("YARRR~!") level["About"]["Author"] = nbt.TAG_String("YARRR~!")
"Because the tag type usually doesn't change, " "Because the tag type usually doesn't change, "
"we can replace the string tag's value instead of replacing the entire tag." "we can replace the string tag's value instead of replacing the entire tag."