From aa6f39f15fc9a8e83a92c0685094d7939c47120d Mon Sep 17 00:00:00 2001 From: David Vierra Date: Thu, 14 Oct 2010 14:54:30 -1000 Subject: [PATCH] clamp source box of extractSchematic return a schematic of the desired shape filled with air in the parts where there was nothing to extract --- mclevel.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/mclevel.py b/mclevel.py index 724a1ab..4a57d0b 100644 --- a/mclevel.py +++ b/mclevel.py @@ -886,7 +886,10 @@ class MCLevel(object): def extractSchematic(self, box): x,y,z = box.origin w,h,l = box.size + destX = destY = destZ = 0; + if y<0: + destY -= y h += y y = 0; if y+h>self.Height: @@ -895,13 +898,34 @@ class MCLevel(object): if h<=0: return - box.origin = x,y,z - box.size = w,h,l - + if self.Width: + if x < 0: + destX -= x; + x = 0; + w += x + if x + w > self.Width: + w = self.Width - x + if w <= 0: return + + if z < 0: + destZ -= z; + z = 0; + l += z + if z + l > self.Length: + l = self.Length - z + + if l <= 0: return + + + + + box = BoundingBox ( (x,y,z), (w,h,l) ) + + tempSchematic = MCSchematic(shape=box.size) tempSchematic.materials = self.materials - tempSchematic.copyBlocksFrom(self, box, (0,0,0)) + tempSchematic.copyBlocksFrom(self, box, (destX, destY, destZ)) return tempSchematic fromFile = MCLevel.fromFile