From 1fa5f4d72528c970c9a36b19b929a254d80dcb99 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 10 Jun 2021 16:19:23 +0100 Subject: [PATCH] Begin fixing layer brush - Required new argument parser, which should ultimately be made into a singe blockstate parser for best results, and proper tab-completion - The layer brush itself is broken because of the changes to internal block retrieval from legacy --- .../boydti/fawe/object/brush/LayerBrush.java | 7 ++-- .../object/brush/mask/LayerBrushMask.java | 5 ++- .../worldedit/command/BrushCommands.java | 13 ++++--- .../extension/platform/Annotations.java | 6 ++++ .../platform/PlatformCommandManager.java | 3 ++ .../internal/annotation/PatternList.java | 36 +++++++++++++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/PatternList.java diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java index 6a9859653..15903a174 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java @@ -25,8 +25,8 @@ public class LayerBrush implements Brush { private final BlockState[] layers; private RecursiveVisitor visitor; - public LayerBrush(BlockState[] layers) { - this.layers = layers; + public LayerBrush(Pattern[] layers) { + this.layers = Arrays.stream(layers).map(p -> p.applyBlock(BlockVector3.ZERO).toBlockState()).toArray(BlockState[]::new); } @Override @@ -41,7 +41,7 @@ public class LayerBrush implements Brush { BlockVectorSet visited = visitor.getVisited(); visitor = new RecursiveVisitor(new LayerBrushMask(editSession, visitor, layers, adjacent), pos -> { int depth = visitor.getDepth(); - BlockState currentPattern = layers[depth]; + Pattern currentPattern = layers[depth]; return currentPattern.apply(editSession, pos, pos); }, layers.length - 1); for (BlockVector3 pos : visited) { @@ -50,4 +50,5 @@ public class LayerBrush implements Brush { Operations.completeBlindly(visitor); visitor = null; } + } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/mask/LayerBrushMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/mask/LayerBrushMask.java index 529549af2..3b5a2a9cb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/mask/LayerBrushMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/mask/LayerBrushMask.java @@ -4,12 +4,15 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.world.block.BlockState; +import java.util.Arrays; + public class LayerBrushMask extends AbstractExtentMask { private final EditSession editSession; @@ -33,7 +36,7 @@ public class LayerBrushMask extends AbstractExtentMask { @Override public boolean test(BlockVector3 pos) { - int depth = visitor.getDepth() + 1; + int depth = (visitor.getDepth() + 1) % layers.length; if (depth > 1) { boolean found = false; BlockState previous = layers[depth - 1]; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 96c1df9a7..b73161d49 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -96,6 +96,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.SingleBlockTypeMask; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.internal.annotation.PatternList; import com.sk89q.worldedit.internal.annotation.ClipboardMask; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.math.BlockVector3; @@ -108,7 +109,6 @@ import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; import com.sk89q.worldedit.world.block.BlockID; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -632,10 +632,13 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.layer") public void surfaceLayer(InjectedValueAccess context, @Arg(desc = "Expression") - Expression radius, List blockLayers) + Expression radius, + @Arg(desc = "List of comma-separated patterns") + @PatternList() + List patternLayers) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - set(context, new LayerBrush(blockLayers.toArray(new BlockState[0]))).setSize(radius); + set(context, new LayerBrush(patternLayers.toArray(new Pattern[0]))).setSize(radius); } @Command( @@ -683,7 +686,9 @@ public class BrushCommands { @Arg(desc = "double", def = "1") double points, @Arg(desc = "double", def = "1") - double distance, List commandStr) + double distance, + @Arg(desc = "List of comma-separated commands") + List commandStr) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); set(context, diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Annotations.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Annotations.java index 399b1833a..0a5b74d9e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Annotations.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Annotations.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.extension.platform; import com.google.auto.value.AutoAnnotation; +import com.sk89q.worldedit.internal.annotation.PatternList; import com.sk89q.worldedit.internal.annotation.Radii; /** @@ -32,6 +33,11 @@ class Annotations { return new AutoAnnotation_Annotations_radii(value); } + @AutoAnnotation + static PatternList patternList() { + return new AutoAnnotation_Annotations_patternList(); + } + private Annotations() { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 114e76f93..7a379b819 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -261,6 +261,9 @@ public final class PlatformCommandManager { SideEffectConverter.register(commandManager); HeightConverter.register(commandManager); OffsetConverter.register(worldEdit, commandManager); + commandManager.registerConverter(Key.of(com.sk89q.worldedit.function.pattern.Pattern.class, Annotations.patternList()), + CommaSeparatedValuesConverter.wrap(commandManager.getConverter(Key.of( + com.sk89q.worldedit.function.pattern.Pattern.class)).get())); registerBindings(new ConsumeBindings(worldEdit, this)); registerBindings(new PrimitiveBindings(worldEdit)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/PatternList.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/PatternList.java new file mode 100644 index 000000000..30bef0e8c --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/PatternList.java @@ -0,0 +1,36 @@ +/* + * 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.internal.annotation; + +import org.enginehub.piston.inject.InjectAnnotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotates a {@code List} parameter to inject a list of BlockStates. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +@InjectAnnotation +public @interface PatternList { +}