diff --git a/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index a0d5ad090..dc634ed2f 100644 --- a/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -106,7 +106,7 @@ public class BlockTransformExtent extends AbstractDelegateExtent { * @param registry the registry * @return the same block */ - private static BaseBlock transform(BaseBlock block, Transform transform, BlockRegistry registry) { + public static BaseBlock transform(BaseBlock block, Transform transform, BlockRegistry registry) { return transform(block, transform, registry, block); } diff --git a/src/main/resources/com/sk89q/worldedit/world/registry/blocks.json b/src/main/resources/com/sk89q/worldedit/world/registry/blocks.json index 92410c465..f4a08d736 100644 --- a/src/main/resources/com/sk89q/worldedit/world/registry/blocks.json +++ b/src/main/resources/com/sk89q/worldedit/world/registry/blocks.json @@ -919,7 +919,7 @@ "facing": { "values": { "north": { "data": 0, "direction": [0, 0, -1] }, - "south": { "data": 1, "direction": [0, 0, 1] }, + "south": { "data": 0, "direction": [0, 0, 1] }, "east": { "data": 1, "direction": [1, 0, 0] }, "west": { "data": 1, "direction": [-1, 0, 0] }, "east_ascending": { "data": 2, "direction": [1, 1, 0] }, @@ -929,6 +929,7 @@ "north_ascending": { "data": 4, "direction": [0, 1, -1] }, "north_descending": { "data": 4, "direction": [0, -1, 1] }, "south_ascending": { "data": 5, "direction": [0, 1, 1] }, + "south_descending": { "data": 5, "direction": [0, -1, -1] }, "southeast": { "data": 6, "direction": [1, 0, 1] }, "southwest": { "data": 7, "direction": [-1, 0, 1] }, "northwest": { "data": 8, "direction": [-1, 0, -1] }, @@ -969,7 +970,7 @@ "facing": { "values": { "north": { "data": 0, "direction": [0, 0, -1] }, - "south": { "data": 1, "direction": [0, 0, 1] }, + "south": { "data": 0, "direction": [0, 0, 1] }, "east": { "data": 1, "direction": [1, 0, 0] }, "west": { "data": 1, "direction": [-1, 0, 0] }, "east_ascending": { "data": 2, "direction": [1, 1, 0] }, @@ -979,6 +980,7 @@ "north_ascending": { "data": 4, "direction": [0, 1, -1] }, "north_descending": { "data": 4, "direction": [0, -1, 1] }, "south_ascending": { "data": 5, "direction": [0, 1, 1] }, + "south_descending": { "data": 5, "direction": [0, -1, -1] }, "southeast": { "data": 6, "direction": [1, 0, 1] }, "southwest": { "data": 7, "direction": [-1, 0, 1] }, "northwest": { "data": 8, "direction": [-1, 0, -1] }, @@ -2320,7 +2322,7 @@ "facing": { "values": { "north": { "data": 0, "direction": [0, 0, -1] }, - "south": { "data": 1, "direction": [0, 0, 1] }, + "south": { "data": 0, "direction": [0, 0, 1] }, "east": { "data": 1, "direction": [1, 0, 0] }, "west": { "data": 1, "direction": [-1, 0, 0] }, "east_ascending": { "data": 2, "direction": [1, 1, 0] }, @@ -2330,6 +2332,7 @@ "north_ascending": { "data": 4, "direction": [0, 1, -1] }, "north_descending": { "data": 4, "direction": [0, -1, 1] }, "south_ascending": { "data": 5, "direction": [0, 1, 1] }, + "south_descending": { "data": 5, "direction": [0, -1, -1] }, "southeast": { "data": 6, "direction": [1, 0, 1] }, "southwest": { "data": 7, "direction": [-1, 0, 1] }, "northwest": { "data": 8, "direction": [-1, 0, -1] }, @@ -2457,7 +2460,15 @@ "east": { "data": 1, "direction": [1, 0, 0] }, "south": { "data": 3, "direction": [0, 0, 1] }, "west": { "data": 2, "direction": [-1, 0, 0] }, - "north": { "data": 4, "direction": [0, 0, -1] } + "north": { "data": 4, "direction": [0, 0, -1] }, + "ground_south": { "data": 5, "direction": [0, 1, 1] }, + "ground_north": { "data": 5, "direction": [0, 1, -1] }, + "ground_east": { "data": 6, "direction": [1, 1, 0] }, + "ground_west": { "data": 6, "direction": [-1, 1, 0] }, + "ceiling_south": { "data": 7, "direction": [0, -1, -1] }, + "ceiling_north": { "data": 7, "direction": [0, -1, 1] }, + "ceiling_east": { "data": 0, "direction": [1, -1, 0] }, + "ceiling_west": { "data": 0, "direction": [-1, -1, 0] } } }, "powered": { @@ -3286,6 +3297,17 @@ "legacyId": 94, "id": "minecraft:powered_repeater", "unlocalizedName": "tile.diode", + "states": { + "facing": { + "dataMask": 3, + "values": { + "north": { "data": 0, "direction": [0, 0, -1] }, + "east": { "data": 1, "direction": [1, 0, 0] }, + "south": { "data": 2, "direction": [0, 0, 1] }, + "west": { "data": 3, "direction": [-1, 0, 0] } + } + } + }, "material": { "renderedAsNormalBlock": false, "fullCube": false, @@ -5006,6 +5028,17 @@ "legacyId": 145, "id": "minecraft:anvil", "unlocalizedName": "tile.anvil", + "states": { + "facing": { + "dataMask": 3, + "values": { + "south": { "data": 0, "direction": [0, 0, 1] }, + "north": { "data": 0, "direction": [0, 0, -1] }, + "west": { "data": 1, "direction": [-1, 0, 0] }, + "east": { "data": 1, "direction": [1, 0, 0] } + } + } + }, "material": { "renderedAsNormalBlock": false, "fullCube": false, @@ -5191,6 +5224,17 @@ "legacyId": 150, "id": "minecraft:powered_comparator", "unlocalizedName": "tile.comparator", + "states": { + "facing": { + "dataMask": 3, + "values": { + "north": { "data": 0, "direction": [0, 0, -1] }, + "east": { "data": 1, "direction": [1, 0, 0] }, + "south": { "data": 2, "direction": [0, 0, 1] }, + "west": { "data": 3, "direction": [-1, 0, 0] } + } + } + }, "material": { "renderedAsNormalBlock": false, "fullCube": false, @@ -5433,7 +5477,7 @@ "facing": { "values": { "north": { "data": 0, "direction": [0, 0, -1] }, - "south": { "data": 1, "direction": [0, 0, 1] }, + "south": { "data": 0, "direction": [0, 0, 1] }, "east": { "data": 1, "direction": [1, 0, 0] }, "west": { "data": 1, "direction": [-1, 0, 0] }, "east_ascending": { "data": 2, "direction": [1, 1, 0] }, @@ -5443,6 +5487,7 @@ "north_ascending": { "data": 4, "direction": [0, 1, -1] }, "north_descending": { "data": 4, "direction": [0, -1, 1] }, "south_ascending": { "data": 5, "direction": [0, 1, 1] }, + "south_descending": { "data": 5, "direction": [0, -1, -1] }, "southeast": { "data": 6, "direction": [1, 0, 1] }, "southwest": { "data": 7, "direction": [-1, 0, 1] }, "northwest": { "data": 8, "direction": [-1, 0, -1] }, diff --git a/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java b/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java new file mode 100644 index 000000000..d85f9c2c4 --- /dev/null +++ b/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java @@ -0,0 +1,79 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.extent.transform; + +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockData; +import com.sk89q.worldedit.blocks.BlockType; +import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.math.transform.Transform; +import com.sk89q.worldedit.world.registry.BlockRegistry; +import com.sk89q.worldedit.world.registry.LegacyBlockRegistry; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +public class BlockTransformExtentTest { + + private final Transform ROTATE_90 = new AffineTransform().rotateY(-90); + private final Transform ROTATE_NEG_90 = new AffineTransform().rotateY(90); + private final Set ignored = new HashSet(); + + @Before + public void setUp() throws Exception { + ignored.add(BlockType.BED); // Broken in existing rotation code? + ignored.add(BlockType.WOODEN_DOOR); // Complicated + ignored.add(BlockType.IRON_DOOR); // Complicated + ignored.add(BlockType.STONE_BUTTON); // Existing rotation code doesn't handle down/up directions + ignored.add(BlockType.WOODEN_BUTTON); // Existing rotation code doesn't handle down/up directions + ignored.add(BlockType.END_PORTAL); // Not supported in existing rotation code + } + + @Test + public void testTransform() throws Exception { + BlockRegistry blockRegistry = new LegacyBlockRegistry(); + for (BlockType type : BlockType.values()) { + if (ignored.contains(type)) { + continue; + } + + BaseBlock orig = new BaseBlock(type.getID()); + for (int i = 1; i < 4; i++) { + BaseBlock rotated = BlockTransformExtent.transform(new BaseBlock(orig), ROTATE_90, blockRegistry); + BaseBlock reference = new BaseBlock(orig.getType(), BlockData.rotate90(orig.getType(), orig.getData())); + assertThat(type + "#" + type.getID() + " rotated " + (90 * i) + " degrees did not match BlockData.rotate90()'s expected result", rotated, equalTo(reference)); + orig = rotated; + } + + orig = new BaseBlock(type.getID()); + for (int i = 0; i < 4; i++) { + BaseBlock rotated = BlockTransformExtent.transform(new BaseBlock(orig), ROTATE_NEG_90, blockRegistry); + BaseBlock reference = new BaseBlock(orig.getType(), BlockData.rotate90Reverse(orig.getType(), orig.getData())); + assertThat(type + "#" + type.getID() + " rotated " + (-90 * i) + " degrees did not match BlockData.rotate90Reverse()'s expected result", rotated, equalTo(reference)); + orig = rotated; + } + } + } +} \ No newline at end of file