From 35c2a74c5224f2737b0f4353bd440a2fd6b4b475 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Thu, 11 Jun 2020 17:01:27 -0400 Subject: [PATCH] Implement more masks --- .../main/java/com/boydti/fawe/FaweAPI.java | 21 -------- .../boydti/fawe/function/mask/AirMask.java | 19 ------- .../boydti/fawe/function/mask/LiquidMask.java | 19 ------- .../boydti/fawe/function/mask/XAxisMask.java | 4 ++ .../boydti/fawe/function/mask/YAxisMask.java | 3 ++ .../boydti/fawe/function/mask/ZAxisMask.java | 3 ++ .../fawe/object/mask/AdjacentAnyMask.java | 3 +- .../boydti/fawe/object/mask/SurfaceMask.java | 3 +- .../com/boydti/fawe/util/MaskTraverser.java | 14 ++++++ .../sk89q/worldedit/command/MaskCommands.java | 19 ------- .../extension/factory/MaskFactory.java | 20 ++------ .../factory/parser/mask/AirMaskParser.java | 19 ------- .../factory/parser/mask/LiquidMaskParser.java | 19 ------- .../factory/parser/mask/XAxisMaskParser.java | 48 ++++++++++++++++++ .../factory/parser/mask/YAxisMaskParser.java | 49 +++++++++++++++++++ .../factory/parser/mask/ZAxisMaskParser.java | 49 +++++++++++++++++++ 16 files changed, 178 insertions(+), 134 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/XAxisMaskParser.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/YAxisMaskParser.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ZAxisMaskParser.java diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java index 245db7791..f725f7e39 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -117,27 +117,6 @@ public class FaweAPI { // return parser != null; // } - public static T getParser(Class parserClass) { - try { - Field field = AbstractFactory.class.getDeclaredField("parsers"); - field.setAccessible(true); - ArrayList parsers = new ArrayList<>(); - parsers.addAll((List) field.get(WorldEdit.getInstance().getMaskFactory())); - parsers.addAll((List) field.get(WorldEdit.getInstance().getBlockFactory())); - parsers.addAll((List) field.get(WorldEdit.getInstance().getItemFactory())); - parsers.addAll((List) field.get(WorldEdit.getInstance().getPatternFactory())); - for (InputParser parser : parsers) { - if (parserClass.isAssignableFrom(parser.getClass())) { - return (T) parser; - } - } - return null; - } catch (Throwable e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - /** * You can either use a IQueueExtent or an EditSession to change blocks
* - The IQueueExtent skips a bit of overhead so it's marginally faster
diff --git a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/AirMask.java b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/AirMask.java index 75099c30f..48d7f3e17 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/AirMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/AirMask.java @@ -1,22 +1,3 @@ -/* - * 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.boydti.fawe.function.mask; import com.sk89q.worldedit.extent.Extent; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/LiquidMask.java b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/LiquidMask.java index 0eb2f6def..cde52cc5e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/LiquidMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/LiquidMask.java @@ -1,22 +1,3 @@ -/* - * 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.boydti.fawe.function.mask; import com.sk89q.worldedit.extent.Extent; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/XAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/XAxisMask.java index 2a82b89ef..dbee08f69 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/XAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/XAxisMask.java @@ -9,6 +9,10 @@ public class XAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; + public XAxisMask(Extent extent) { + + } + @Override public boolean test(Extent extent, BlockVector3 vector) { if (layer == -1) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/YAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/YAxisMask.java index 219da3012..3eff19eb2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/YAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/YAxisMask.java @@ -9,6 +9,9 @@ public class YAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; + public YAxisMask(Extent extent) { + } + @Override public boolean test(Extent extent, BlockVector3 vector) { if (layer == -1) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/ZAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/ZAxisMask.java index d76c88e08..7f584c3ca 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/function/mask/ZAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/function/mask/ZAxisMask.java @@ -9,6 +9,9 @@ public class ZAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; + public ZAxisMask(Extent extent) { + } + @Override public boolean test(Extent extent, BlockVector3 vector) { if (layer == -1) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java index c9603a5d6..0f0ea9698 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; @@ -14,7 +15,7 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { private final CachedMask mask; private final MutableBlockVector3 mutable; - public AdjacentAnyMask(Mask mask) { + public AdjacentAnyMask(AbstractExtentMask mask) { this.mask = CachedMask.cache(mask); mutable = new MutableBlockVector3(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java index 266f5e587..de5e901c5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object.mask; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.BlockMaskBuilder; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; @@ -11,7 +12,7 @@ public class SurfaceMask extends AdjacentAnyMask { super(getMask(extent)); } - public static Mask getMask(Extent extent) { + public static AbstractExtentMask getMask(Extent extent) { return new BlockMaskBuilder() .addTypes(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR) .addAll(b -> !b.getMaterial().isMovementBlocker()) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/MaskTraverser.java b/worldedit-core/src/main/java/com/boydti/fawe/util/MaskTraverser.java index a5e4897ff..6ed28593a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/MaskTraverser.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/MaskTraverser.java @@ -4,6 +4,8 @@ import com.boydti.fawe.object.mask.ResettableMask; 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.mask.MaskIntersection; + import java.lang.reflect.Field; import java.util.Collection; @@ -38,6 +40,18 @@ public class MaskTraverser { } catch (NoSuchFieldException | IllegalAccessException ignored) { } } + if (mask instanceof MaskIntersection) { + MaskIntersection mask1 = (MaskIntersection) mask; + try { + Field field = mask1.getClass().getDeclaredField("masks"); + field.setAccessible(true); + Collection masks = (Collection) field.get(mask); + for (Mask next : masks) { + reset(next, newExtent); + } + } catch (NoSuchFieldException | IllegalAccessException ignored) { + } + } try { Field field = current.getDeclaredField("mask"); field.setAccessible(true); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/MaskCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/MaskCommands.java index 1668a1231..773313b94 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/MaskCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/MaskCommands.java @@ -7,10 +7,7 @@ //import com.boydti.fawe.object.mask.BiomeMask; //import com.boydti.fawe.object.mask.BlockLightMask; //import com.boydti.fawe.object.mask.BrightnessMask; -//import com.boydti.fawe.object.mask.DataMask; //import com.boydti.fawe.object.mask.ExtremaMask; -//import com.boydti.fawe.object.mask.IdDataMask; -//import com.boydti.fawe.object.mask.IdMask; //import com.boydti.fawe.object.mask.LightMask; //import com.boydti.fawe.object.mask.OpacityMask; //import com.boydti.fawe.object.mask.ROCAngleMask; @@ -171,22 +168,6 @@ // } // // @Command( -// name = "#id", -// desc = "Restrict to initial id" -// ) -// public Mask id(Extent extent) { -// return new IdMask(extent); -// } -// -// @Command( -// name = "#data", -// desc = "Restrict to initial data" -// ) -// public Mask data(Extent extent) { -// return new DataMask(extent); -// } -// -// @Command( // name = "#iddata", // desc = "Restrict to initial block id and data" // ) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java index 144d3c2fc..d11c479d9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java @@ -20,22 +20,7 @@ package com.sk89q.worldedit.extension.factory; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.extension.factory.parser.mask.AirMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.BlockStateMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.BlocksMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.FalseMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.LiquidMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser; -import com.sk89q.worldedit.extension.factory.parser.mask.TrueMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.*; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; @@ -81,6 +66,9 @@ public final class MaskFactory extends AbstractFactory { register(new TrueMaskParser(worldEdit)); register(new AirMaskParser(worldEdit)); register(new LiquidMaskParser(worldEdit)); + register(new XAxisMaskParser(worldEdit)); + register(new YAxisMaskParser(worldEdit)); + register(new ZAxisMaskParser(worldEdit)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/AirMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/AirMaskParser.java index aa18cdf7a..e8c5ef423 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/AirMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/AirMaskParser.java @@ -1,22 +1,3 @@ -/* - * 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.extension.factory.parser.mask; import com.boydti.fawe.function.mask.AirMask; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/LiquidMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/LiquidMaskParser.java index ce3769d48..444ac1c40 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/LiquidMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/LiquidMaskParser.java @@ -1,22 +1,3 @@ -/* - * 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.extension.factory.parser.mask; import com.boydti.fawe.function.mask.LiquidMask; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/XAxisMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/XAxisMaskParser.java new file mode 100644 index 000000000..d33eb0749 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/XAxisMaskParser.java @@ -0,0 +1,48 @@ +/* + * 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.extension.factory.parser.mask; + +import com.boydti.fawe.function.mask.XAxisMask; +import com.google.common.collect.ImmutableList; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.internal.registry.SimpleInputParser; + +import java.util.List; + +public class XAxisMaskParser extends SimpleInputParser { + + private final List aliases = ImmutableList.of("#xaxis"); + + public XAxisMaskParser(WorldEdit worldEdit) { + super(worldEdit); + } + + @Override + public List getMatchedAliases() { + return aliases; + } + + @Override + public Mask parseFromSimpleInput(String input, ParserContext context) { + return new XAxisMask(context.getExtent()); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/YAxisMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/YAxisMaskParser.java new file mode 100644 index 000000000..12108010d --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/YAxisMaskParser.java @@ -0,0 +1,49 @@ +/* + * 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.extension.factory.parser.mask; + +import com.boydti.fawe.function.mask.XAxisMask; +import com.boydti.fawe.function.mask.YAxisMask; +import com.google.common.collect.ImmutableList; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.internal.registry.SimpleInputParser; + +import java.util.List; + +public class YAxisMaskParser extends SimpleInputParser { + + private final List aliases = ImmutableList.of("#yaxis"); + + public YAxisMaskParser(WorldEdit worldEdit) { + super(worldEdit); + } + + @Override + public List getMatchedAliases() { + return aliases; + } + + @Override + public Mask parseFromSimpleInput(String input, ParserContext context) { + return new YAxisMask(context.getExtent()); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ZAxisMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ZAxisMaskParser.java new file mode 100644 index 000000000..754c2876d --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ZAxisMaskParser.java @@ -0,0 +1,49 @@ +/* + * 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.extension.factory.parser.mask; + +import com.boydti.fawe.function.mask.XAxisMask; +import com.boydti.fawe.function.mask.ZAxisMask; +import com.google.common.collect.ImmutableList; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.internal.registry.SimpleInputParser; + +import java.util.List; + +public class ZAxisMaskParser extends SimpleInputParser { + + private final List aliases = ImmutableList.of("#zaxis"); + + public ZAxisMaskParser(WorldEdit worldEdit) { + super(worldEdit); + } + + @Override + public List getMatchedAliases() { + return aliases; + } + + @Override + public Mask parseFromSimpleInput(String input, ParserContext context) { + return new ZAxisMask(context.getExtent()); + } +}