From 700e41b706dea8755592140b7586cd1faaeed73d Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 13 Dec 2018 20:30:54 +1000 Subject: [PATCH] Remove the final stage committer from the MultiStageReorder extent, as it caused issues and no longer appears to be entirely necessary. --- .../command/argument/ItemUseParser.java | 2 +- .../command/argument/NumberParser.java | 2 +- .../command/argument/StringParser.java | 2 +- .../extent/reorder/MultiStageReorder.java | 103 +----------------- .../transform/BlockTransformExtentTest.java | 69 ++++++++++++ 5 files changed, 76 insertions(+), 102 deletions(-) create mode 100644 worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java index 816516978..f6da447a1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java @@ -35,7 +35,7 @@ import com.sk89q.worldedit.world.World; public class ItemUseParser extends SimpleCommand> { - private final ItemParser itemParser = addParameter(new ItemParser("item", "minecraft:dye:15")); + private final ItemParser itemParser = addParameter(new ItemParser("item", "minecraft:bone_meal")); @Override public Contextual call(CommandArgs args, CommandLocals locals) throws CommandException { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberParser.java index 9c7f2fed2..349089e50 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberParser.java @@ -62,7 +62,7 @@ public class NumberParser implements CommandExecutor { @Override public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException { String value = args.next(); - return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList(); + return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringParser.java index 518024cd3..298f999e4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringParser.java @@ -57,7 +57,7 @@ public class StringParser implements CommandExecutor { @Override public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException { String value = args.next(); - return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList(); + return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index aa1694740..f4ee0a200 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -24,11 +24,8 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; -import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.function.operation.SetLocatedBlocks; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.util.LocatedBlock; import com.sk89q.worldedit.util.collection.LocatedBlockList; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; @@ -37,20 +34,16 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.ArrayList; -import java.util.Deque; import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; /** * Re-orders blocks into several stages. */ public class MultiStageReorder extends AbstractDelegateExtent implements ReorderingExtent { - private static Map priorityMap = new HashMap<>(); + private static final Map priorityMap = new HashMap<>(); static { // Late @@ -129,7 +122,8 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder priorityMap.put(BlockTypes.OAK_TRAPDOOR, PlacementPriority.LAST); priorityMap.put(BlockTypes.SPRUCE_TRAPDOOR, PlacementPriority.LAST); priorityMap.put(BlockTypes.DAYLIGHT_DETECTOR, PlacementPriority.LAST); - + priorityMap.put(BlockTypes.CAKE, PlacementPriority.LAST); + // Final BlockCategories.DOORS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.FINAL)); BlockCategories.BANNERS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.FINAL)); @@ -137,7 +131,6 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder priorityMap.put(BlockTypes.WALL_SIGN, PlacementPriority.FINAL); priorityMap.put(BlockTypes.CACTUS, PlacementPriority.FINAL); priorityMap.put(BlockTypes.SUGAR_CANE, PlacementPriority.FINAL); - priorityMap.put(BlockTypes.CAKE, PlacementPriority.FINAL); priorityMap.put(BlockTypes.PISTON_HEAD, PlacementPriority.FINAL); priorityMap.put(BlockTypes.MOVING_PISTON, PlacementPriority.FINAL); } @@ -253,97 +246,9 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder } List operations = new ArrayList<>(); for (PlacementPriority priority : PlacementPriority.values()) { - if (priority != PlacementPriority.FINAL) { - operations.add(new SetLocatedBlocks(getExtent(), stages.get(priority))); - } + operations.add(new SetLocatedBlocks(getExtent(), stages.get(priority))); } - operations.add(new FinalStageCommitter()); return new OperationQueue(operations); } - - private class FinalStageCommitter implements Operation { - private Extent extent = getExtent(); - - private final Set blocks = new HashSet<>(); - private final Map blockTypes = new HashMap<>(); - - public FinalStageCommitter() { - for (LocatedBlock entry : stages.get(PlacementPriority.FINAL)) { - final BlockVector3 pt = entry.getLocation(); - blocks.add(pt); - blockTypes.put(pt, entry.getBlock()); - } - } - - @Override - public Operation resume(RunContext run) throws WorldEditException { - while (!blocks.isEmpty()) { - BlockVector3 current = blocks.iterator().next(); - - final Deque walked = new LinkedList<>(); - - while (true) { - walked.addFirst(current); - - assert (blockTypes.containsKey(current)); - - final BlockStateHolder blockStateHolder = blockTypes.get(current); - - if (BlockCategories.DOORS.contains(blockStateHolder.getBlockType())) { - Property halfProperty = blockStateHolder.getBlockType().getProperty("half"); - if (blockStateHolder.getState(halfProperty).equals("lower")) { - // Deal with lower door halves being attached to the floor AND the upper half - BlockVector3 upperBlock = current.add(0, 1, 0); - if (blocks.contains(upperBlock) && !walked.contains(upperBlock)) { - walked.addFirst(upperBlock); - } - } - } else if (BlockCategories.RAILS.contains(blockStateHolder.getBlockType())) { - BlockVector3 lowerBlock = current.add(0, -1, 0); - if (blocks.contains(lowerBlock) && !walked.contains(lowerBlock)) { - walked.addFirst(lowerBlock); - } - } - - if (!blockStateHolder.getBlockType().getMaterial().isFragileWhenPushed()) { - // Block is not attached to anything => we can place it - break; - } - -// current = current.add(attachment.vector()).toBlockVector(); -// -// if (!blocks.contains(current)) { -// // We ran outside the remaining set => assume we can place blocks on this -// break; -// } -// - if (walked.contains(current)) { - // Cycle detected => This will most likely go wrong, but there's nothing we can do about it. - break; - } - } - - for (BlockVector3 pt : walked) { - extent.setBlock(pt, blockTypes.get(pt)); - blocks.remove(pt); - } - } - - for (LocatedBlockList stage : stages.values()) { - stage.clear(); - } - return null; - } - - @Override - public void cancel() { - } - - @Override - public void addStatusMessages(List messages) { - } - - } - } diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java new file mode 100644 index 000000000..e32b7c6cd --- /dev/null +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java @@ -0,0 +1,69 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.math.transform.Transform; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +@Ignore("A platform is currently required to get properties, preventing this test.") +public class BlockTransformExtentTest { + + private static final Transform ROTATE_90 = new AffineTransform().rotateY(-90); + private static final Transform ROTATE_NEG_90 = new AffineTransform().rotateY(90); + private final Set ignored = new HashSet<>(); + + @Before + public void setUp() throws Exception { + BlockTypes.register(new BlockType("worldedit:test")); + } + + @Test + public void testTransform() throws Exception { + for (BlockType type : BlockType.REGISTRY.values()) { + if (ignored.contains(type)) { + continue; + } + + BlockState base = type.getDefaultState(); + BlockState rotated = base; + + for (int i = 1; i < 4; i++) { + rotated = BlockTransformExtent.transform(base, ROTATE_90); + } + assertEquals(base, rotated); + rotated = base; + for (int i = 1; i < 4; i++) { + rotated = BlockTransformExtent.transform(base, ROTATE_NEG_90); + } + assertEquals(base, rotated); + } + } +} \ No newline at end of file