Skip to content

Commit

Permalink
fix vehicle.py tradpoor handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Oct 8, 2015
1 parent a2b09b0 commit 3b2684f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
Binary file modified python2-scripts.zip
Binary file not shown.
4 changes: 3 additions & 1 deletion python2-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ def rotateBlock(block,amount):
return Block(block.id, (block.data & ~0x03) | (((block.data & 0x03) + amount) & 0x03))
elif block.id == 96 or block.id == 167:
# trapdoors
return Block(block.id, (block.data & ~0x03) | (((block.data & 0x03) - amount) & 0x03))
meta = block.data
return Block(block.id, (meta & ~0x03) |
Vehicle.stairDirectionsClockwise[(Vehicle.stairToClockwise[meta & 0x03] - amount) % 4])
elif block.id in Vehicle.DOORS:
meta = block.data
if meta & 0x08:
Expand Down
Binary file modified python3-scripts.zip
Binary file not shown.
18 changes: 13 additions & 5 deletions python3-scripts/mcpipy/sierpinski3d.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#
# Code under the MIT license by Alexander Pruss
#
#
# Code under the MIT license by Alexander Pruss
#

from mc import *
import drawing
from sys import argv
import mcpi.settings as settings
import ast

RAINBOW = (WOOL_RED,WOOL_PINK,WOOL_ORANGE,WOOL_YELLOW,WOOL_GREEN,WOOL_BLUE,WOOL_LIGHT_BLUE,WOOL_PURPLE)

TAN30 = sqrt(3.)/3
SQRT32 = sqrt(3./2)

def parseBlock(s):
try:
return ast.literal_eval(s)
except:
return globals()[s.upper()]

def distance(a,b):
return sqrt((a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2)

Expand All @@ -28,7 +35,7 @@ def drawTetrahedron(height, apex, block):
for point in bottom:
a = float(i)/height
triangle.append(((1-a)*apex[0]+a*point[0],apex[1]-i,(1-a)*apex[2]+a*point[2]))
d.face(triangle,block)
d.face(triangle,block)
return triangle

def average(a,b):
Expand Down Expand Up @@ -59,7 +66,8 @@ def sierpinski(height, x,y,z, level):
tetrahedra = sierpinski(height,pos.x,pos.y+height,pos.z,levels)
mc.postToChat("Drawing")
if len(argv) >= 2 and '__' not in argv[1]:
block = lambda level : eval(argv[1])
specifiedBlock = parseBlock(argv[1])
block = lambda level : specifiedBlock
else:
block = lambda level : RAINBOW[level % len(RAINBOW)]
for tet in tetrahedra:
Expand Down
22 changes: 11 additions & 11 deletions python3-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,14 @@ def load(self,filename):
result = re.search("=\\s*(.*)",data)
if result is None:
raise ValueError
self.baseAngle,self.highWater,v = literal_eval(result.group(1).replace("Block",""))
self.baseVehicle = {}
for key,value in list(v.items()):
if isinstance(value,tuple):
if len(value) > 1:
self.baseVehicle[key] = Block(value[0], value[1])
else:
self.baseVehicle[key] = Block(value[0])
else:
self.baseVehicle[key] = Block(value)

# Check to ensure only function called is Block() by getting literal_eval to
# raise an exception when "Block" is removed and the result isn't a literal.
# This SHOULD make the eval call safe, though USE AT YOUR OWN RISK. Ideally,
# one would walk the ast parse tree and use a whitelist.
literal_eval(result.group(1).replace("Block",""))

self.baseAngle,self.highWater,self.baseVehicle = eval(result.group(1))

self.curLocation = None

Expand Down Expand Up @@ -301,7 +299,9 @@ def rotateBlock(block,amount):
return Block(block.id, (block.data & ~0x03) | (((block.data & 0x03) + amount) & 0x03))
elif block.id == 96 or block.id == 167:
# trapdoors
return Block(block.id, (block.data & ~0x03) | (((block.data & 0x03) - amount) & 0x03))
meta = block.data
return Block(block.id, (meta & ~0x03) |
Vehicle.stairDirectionsClockwise[(Vehicle.stairToClockwise[meta & 0x03] - amount) % 4])
elif block.id in Vehicle.DOORS:
meta = block.data
if meta & 0x08:
Expand Down

0 comments on commit 3b2684f

Please sign in to comment.