Skip to content
Permalink
Browse files

Fix flipping of chests and stairs (#526)

* Fix flipping of chests and stairs

* Check if the new property value is valid before updating

* Only for horizontal flips double chests/stairs should be modified
  • Loading branch information
Brokkonaut authored and me4502 committed Nov 12, 2019
1 parent 23a3929 commit 89bc664f69da9fcfe9b225d805d5684f2dfab37f
@@ -25,6 +25,7 @@
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty;
@@ -162,6 +163,38 @@ public BaseBlock getFullBlock(BlockVector3 position) {
}
}
}
} else if (property.getName().equals("type") && transform instanceof AffineTransform) {
// chests
if (((AffineTransform) transform).isHorizontalFlip()) {
String value = (String) block.getState(property);
String newValue = null;
if ("left".equals(value)) {
newValue = "right";
} else if ("right".equals(value)) {
newValue = "left";
}
if (newValue != null && enumProp.getValues().contains(newValue)) {
result = result.with(enumProp, newValue);
}
}
} else if (property.getName().equals("shape") && transform instanceof AffineTransform) {
// stairs
if (((AffineTransform) transform).isHorizontalFlip()) {
String value = (String) block.getState(property);
String newValue = null;
if ("outer_left".equals(value)) {
newValue = "outer_right";
} else if ("outer_right".equals(value)) {
newValue = "outer_left";
} else if ("inner_left".equals(value)) {
newValue = "inner_right";
} else if ("inner_right".equals(value)) {
newValue = "inner_left";
}
if (newValue != null && enumProp.getValues().contains(newValue)) {
result = result.with(enumProp, newValue);
}
}
}
} else if (property instanceof IntegerProperty) {
IntegerProperty intProp = (IntegerProperty) property;
@@ -312,6 +312,14 @@ public Transform combine(Transform other) {
}
}

/**
* Returns if this affine transform is representing a horizontal flip.
*/
public boolean isHorizontalFlip() {
// use the determinant of the x-z submatrix to check if this is a horizontal flip
return m00 * m22 - m02 * m20 < 0;
}

@Override
public String toString() {
return String.format("Affine[%g %g %g %g, %g %g %g %g, %g %g %g %g]}", m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23);

0 comments on commit 89bc664

Please sign in to comment.
You can’t perform that action at this time.