diff --git a/level.py b/level.py index 3fd58e0..9f3dea7 100644 --- a/level.py +++ b/level.py @@ -4,12 +4,18 @@ Created on Jul 22, 2011 @author: Rio ''' +import blockrotation from box import BoundingBox +from collections import defaultdict +from entity import Entity, TileEntity import itertools from logging import getLogger -from mclevelbase import * -from collections import defaultdict 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__) 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 ### self has Width, Height, Length, and Blocks - materials = classicMaterials + materials = materials.classicMaterials isInfinite = False compressedTag = None @@ -273,7 +279,7 @@ class MCLevel(object): f.Entities, f.TileEntities = self._getFakeChunkEntities(cx, cz) - f.root_tag = TAG_Compound() + f.root_tag = nbt.TAG_Compound() return f @@ -416,7 +422,7 @@ class MCLevel(object): blocks = self.Blocks[slices[0], slices[2], slices[1]] if len(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: data = self.Data[slices[0], slices[2], slices[1]] @@ -741,7 +747,7 @@ class EntityLevel(MCLevel): self.addEntity(e) def addEntity(self, entityTag): - assert isinstance(entityTag, TAG_Compound) + assert isinstance(entityTag, nbt.TAG_Compound) self.Entities.append(entityTag) self._fakeEntities = None @@ -759,7 +765,7 @@ class EntityLevel(MCLevel): return entities[0] def addTileEntity(self, tileEntityTag): - assert isinstance(tileEntityTag, TAG_Compound) + assert isinstance(tileEntityTag, nbt.TAG_Compound) def differentPosition(a): diff --git a/tests.py b/tests.py index 58f9ea1..b1ee12b 100644 --- a/tests.py +++ b/tests.py @@ -12,6 +12,7 @@ try: except ImportError: from __init__ import * +from cStringIO import StringIO import itertools import unittest import tempfile @@ -88,21 +89,21 @@ class TestNBT(unittest.TestCase): "Create an indev level." "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." - level["About"] = TAG_Compound() - level["About"]["Author"] = TAG_String("codewarrior") + level["About"] = nbt.TAG_Compound() + level["About"]["Author"] = nbt.TAG_String("codewarrior") - level["Environment"] = TAG_Compound() - level["Environment"]["SkyBrightness"] = TAG_Byte(16) - level["Environment"]["SurroundingWaterHeight"] = TAG_Short(32) + level["Environment"] = nbt.TAG_Compound() + level["Environment"]["SkyBrightness"] = nbt.TAG_Byte(16) + level["Environment"]["SurroundingWaterHeight"] = nbt.TAG_Short(32) "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" - mapTag = TAG_Compound() + mapTag = nbt.TAG_Compound() mapTag.add(spawn) mapTag.name = "Map" level.add(mapTag) @@ -110,13 +111,13 @@ class TestNBT(unittest.TestCase): "I think it looks more familiar with [] syntax." l, w, h = 128, 128, 128 - mapTag["Height"] = TAG_Short(h) # y dimension - mapTag["Length"] = TAG_Short(l) # z dimension - mapTag["Width"] = TAG_Short(w) # x dimension + mapTag["Height"] = nbt.TAG_Short(h) # y dimension + mapTag["Length"] = nbt.TAG_Short(l) # z dimension + mapTag["Width"] = nbt.TAG_Short(w) # x dimension "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! "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." - mapTag["Data"] = TAG_Byte_Array() + mapTag["Data"] = nbt.TAG_Byte_Array() mapTag["Data"].value = zeros(l * w * h, dtype=uint8) return level @@ -136,7 +137,7 @@ class TestNBT(unittest.TestCase): level = self.testCreate() "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, " "we can replace the string tag's value instead of replacing the entire tag."