Permalink
Browse files

refactor level formats out to different files, add testing framework …

…and test files
  • Loading branch information...
1 parent 5b39487 commit 6b9e82c2e4d74f5fc4f250607c94f776b2e52875 @codewarrior0 committed Jul 24, 2011
View
@@ -1,2 +1,9 @@
-from mclevel import *
-import items
+from mclevel import fromFile, loadWorld, loadWorldNumber, saveFileDir, minecraftDir
+from indev import *
+from infiniteworld import *
+from java import *
+from level import *
+from schematic import *
+from materials import *
+
+import items
View
134 box.py
@@ -1,154 +1,154 @@
import itertools
class BoundingBox (object):
-
- def __init__(self, origin = (0,0,0), size = (0,0,0)):
+
+ def __init__(self, origin=(0, 0, 0), size=(0, 0, 0)):
if isinstance(origin, BoundingBox):
self._origin = list(origin._origin)
self._size = list(origin._size)
else:
- self._origin, self._size = list(map(int, origin)),list(map(int, size))
-
+ self._origin, self._size = list(map(int, origin)), list(map(int, size))
+
def getMinx(self): return self.origin[0];
def getMiny(self): return self.origin[1];
def getMinz(self): return self.origin[2];
-
- def getMaxx(self): return self.origin[0]+self.size[0];
- def getMaxy(self): return self.origin[1]+self.size[1];
- def getMaxz(self): return self.origin[2]+self.size[2];
-
+
+ def getMaxx(self): return self.origin[0] + self.size[0];
+ def getMaxy(self): return self.origin[1] + self.size[1];
+ def getMaxz(self): return self.origin[2] + self.size[2];
+
def setMinx(self, x):
self.size[0] -= x - self.origin[0]
self.origin[0] = x;
-
- def setMiny(self,y):
+
+ def setMiny(self, y):
self.size[1] -= y - self.origin[1]
self.origin[1] = y
-
- def setMinz(self,z):
+
+ def setMinz(self, z):
self.size[2] -= z - self.origin[2]
self.origin[2] = z
-
-
+
+
def setMaxx(self, x):
if x < self.origin[0]:
x = self.origin[0];
-
+
self.size[0] = x - self.origin[0]
-
- def setMaxy(self, y):
+
+ def setMaxy(self, y):
if y < self.origin[1]:
y = self.origin[1];
-
+
self.size[1] = y - self.origin[1]
-
- def setMaxz(self, z):
+
+ def setMaxz(self, z):
if z < self.origin[2]:
z = self.origin[2];
-
+
self.size[2] = z - self.origin[2]
-
-
+
+
minx = property(getMinx, setMinx);
miny = property(getMiny, setMiny);
minz = property(getMinz, setMinz);
-
+
maxx = property(getMaxx, setMaxx);
maxy = property(getMaxy, setMaxy);
maxz = property(getMaxz, setMaxz);
-
- def getMincx(self): return self.origin[0]>>4;
- def getMincz(self): return self.origin[2]>>4;
-
- def getMaxcx(self): return ((self.origin[0]+self.size[0]-1)>>4)+1;
- def getMaxcz(self): return ((self.origin[2]+self.size[2]-1)>>4)+1;
-
+
+ def getMincx(self): return self.origin[0] >> 4;
+ def getMincz(self): return self.origin[2] >> 4;
+
+ def getMaxcx(self): return ((self.origin[0] + self.size[0] - 1) >> 4) + 1;
+ def getMaxcz(self): return ((self.origin[2] + self.size[2] - 1) >> 4) + 1;
+
mincx = property(getMincx, None, None, "The smallest chunk position contained in this box");
mincz = property(getMincz, None, None, "The smallest chunk position contained in this box");
-
+
maxcx = property(getMaxcx, None, None, "The largest chunk position contained in this box");
maxcz = property(getMaxcz, None, None, "The largest chunk position contained in this box");
-
+
def getOrigin(self): return self._origin;
def setOrigin(self, o): self._origin = list(o);
-
+
def getSize(self): return self._size;
def setSize(self, s): self._size = list(s);
-
+
origin = property(getOrigin, setOrigin)
size = property(getSize, setSize)
-
+
def getWidth(self): return self._size[0];
def getHeight(self): return self._size[1];
def getLength(self): return self._size[2];
-
+
def setWidth(self, w): self.size[0] = max(0, int(w))
def setHeight(self, h): self.size[1] = max(0, int(h))
def setLength(self, l): self.size[2] = max(0, int(l))
-
+
width = property(getWidth, setWidth, None, "The dimension along the X axis");
height = property(getHeight, setHeight, None, "The dimension along the Y axis");
length = property(getLength, setLength, None, "The dimension along the Z axis");
-
-
- def getMaximum(self): return map(lambda a,b:a+b, self._origin, self._size)
-
+
+
+ def getMaximum(self): return map(lambda a, b:a + b, self._origin, self._size)
+
maximum = property(getMaximum, None, None, "The endpoint of the box; origin plus size.")
-
- def getVolume(self): return reduce(lambda a,b:a*b, self.size)
+
+ def getVolume(self): return reduce(lambda a, b:a * b, self.size)
volume = property(getVolume, None, None, "The volume of the box in blocks")
-
+
@property
def chunkPositions(self):
#iterate through all of the chunk positions within this selection box
- return itertools.product(xrange(self.mincx,self.maxcx), xrange(self.mincz, self.maxcz));
-
-
+ return itertools.product(xrange(self.mincx, self.maxcx), xrange(self.mincz, self.maxcz));
+
+
@property
def isChunkAligned(self):
return (self.origin[0] & 0xf == 0) and (self.origin[2] & 0xf == 0)
-
+
def intersect(self, box):
""" return a box containing the area self and box have in common"""
newbox = BoundingBox()
-
+
if self.minx > box.maxx or self.maxx < box.minx: return BoundingBox()
newbox.minx = max(self.minx, box.minx)
newbox.maxx = min(self.maxx, box.maxx)
-
+
if self.miny > box.maxy or self.maxy < box.miny: return BoundingBox()
newbox.miny = max(self.miny, box.miny)
newbox.maxy = min(self.maxy, box.maxy)
if self.minz > box.maxz or self.maxz < box.minz: return BoundingBox()
newbox.minz = max(self.minz, box.minz)
newbox.maxz = min(self.maxz, box.maxz)
-
-
-
- print "Intersect of {0} and {1}: {2}".format(self, box, newbox)
+
+
+
+ #print "Intersect of {0} and {1}: {2}".format(self, box, newbox)
return newbox
-
+
def union(self, box):
newbox = BoundingBox()
newbox.minx = min(self.minx, box.minx)
newbox.maxx = max(self.maxx, box.maxx)
-
+
newbox.miny = min(self.miny, box.miny)
newbox.maxy = max(self.maxy, box.maxy)
newbox.minz = min(self.minz, box.minz)
newbox.maxz = max(self.maxz, box.maxz)
return newbox
-
+
def __contains__(self, pos):
- x,y,z = pos;
- if x<self.minx or x>=self.maxx: return False
- if y<self.miny or y>=self.maxy: return False
- if z<self.minz or z>=self.maxz: return False
-
+ x, y, z = pos;
+ if x < self.minx or x >= self.maxx: return False
+ if y < self.miny or y >= self.maxy: return False
+ if z < self.minz or z >= self.maxz: return False
+
return True;
-
+
def __cmp__(self, b):
- return cmp( (self.origin, self.size), (b.origin, b.size) )
-
+ return cmp((self.origin, self.size), (b.origin, b.size))
+
def __repr__(self):
return "BoundingBox({0}, {1})".format(self.origin, self.size)
View
@@ -0,0 +1,43 @@
+'''
+Created on Jul 23, 2011
+
+@author: Rio
+'''
+from mclevelbase import *
+
+__all__ = "Entity, TileEntity".split(", ")
+
+class TileEntity(object):
+ @classmethod
+ def pos(cls, tag):
+ return [tag[a].value for a in 'xyz']
+
+ @classmethod
+ def setpos(cls, tag, pos):
+ for a, p in zip('xyz', pos):
+ tag[a] = TAG_Int(p)
+
+class Entity(object):
+ @classmethod
+ def pos(cls, tag):
+ if "Pos" not in tag:
+ print tag
+ return [a.value for a in tag["Pos"]]
+
+ @classmethod
+ def setpos(cls, tag, pos):
+ tag["Pos"] = TAG_List([TAG_Int(p) for p in pos])
+
+ @classmethod
+ def copyWithOffset(cls, entity, copyOffset):
+ eTag = deepcopy(entity)
+
+ positionTags = map(lambda p, co: nbt.TAG_Double(p.value+co), eTag["Pos"], copyOffset)
+ eTag["Pos"] = TAG_List(positionTags)
+
+ if eTag["id"].value == "Painting":
+ eTag["TileX"].value += copyOffset[0]
+ eTag["TileY"].value += copyOffset[1]
+ eTag["TileZ"].value += copyOffset[2]
+
+ return eTag
Oops, something went wrong.

0 comments on commit 6b9e82c

Please sign in to comment.