From b019825f7030cec6550f223fb9600280823bf373 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Mon, 20 Jun 2016 15:11:12 -1000 Subject: [PATCH] Stairs now rotate more sensibly around the x/z axes --- src/mceditlib/blocktypes/rotation.py | 40 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/mceditlib/blocktypes/rotation.py b/src/mceditlib/blocktypes/rotation.py index 5487fee..f8a02d3 100644 --- a/src/mceditlib/blocktypes/rotation.py +++ b/src/mceditlib/blocktypes/rotation.py @@ -40,10 +40,10 @@ class BlockRotations(object): 'north': 'up', }, 'z': { - 'east': 'up', 'up': 'west', 'west': 'down', 'down': 'east', + 'east': 'up', } } @@ -75,6 +75,22 @@ class BlockRotations(object): 'south_east': 'north_east', } + + halfFacingMappings = { + 'y': {}, + 'x': { + ('top', 'south'): ('bottom', 'south'), + ('bottom', 'south'): ('bottom', 'north'), + ('bottom', 'north'): ('top', 'north'), + ('top', 'north'): ('top', 'south'), + }, + 'z': { + ('top', 'west'): ('bottom', 'west'), + ('bottom', 'west'): ('bottom', 'east'), + ('bottom', 'east'): ('top', 'east'), + ('top', 'east'): ('top', 'west'), + } + } def __init__(self, blocktypes): self.blocktypes = blocktypes @@ -93,20 +109,29 @@ class BlockRotations(object): def buildTable(self, axis, aboutFace=False): mapping = self.mappings[axis] axisMapping = self.axisMappings[axis] + halfFacingMap = self.halfFacingMappings[axis] if aboutFace: mapping90 = mapping mapping = {k: mapping90[v] for k, v in mapping90.iteritems()} + if axis in 'xz': + mapping['down_x'] = 'up_x' + mapping['down_z'] = 'up_z' + mapping['up_x'] = 'down_x' + mapping['up_z'] = 'down_z' + + halfFacingMap90 = halfFacingMap + halfFacingMap = {k: halfFacingMap90[v] for k, v in halfFacingMap90.iteritems()} table = blankRotationTable() rotIncrement = 8 if aboutFace else 4 for block in self.blocktypes: - state = block.stateDict + oldState = state = block.stateDict if not len(state): continue - + # First pass: facing=north and similar newState = {} for k, v in state.items(): @@ -151,7 +176,7 @@ class BlockRotations(object): axis = axisMapping.get(axis, axis) state['axis'] = axis - # For stairs/slabs: if x or z axis and 180-degree rotation, flip "half" + # For slabs: if x or z axis and 180-degree rotation, flip "half" if axis in 'xz' and aboutFace: if 'half' in state: @@ -160,6 +185,13 @@ class BlockRotations(object): elif state['half'] == 'top': state['half'] = 'bottom' + # For stairs, x or z axis: flip "half" upward or flip east/west to roll + + if 'half' in oldState and 'facing' in oldState: + newHalfFacing = halfFacingMap.get((oldState['half'], oldState['facing'])) + if newHalfFacing: + state['half'], state['facing'] = newHalfFacing + #print("Changed %s \nto %s" % (stateString, newStateString)) newBlock = self.matchingState(block.internalName, state)