diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java index 604a6e31..89b14a8f 100644 --- a/api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java @@ -44,7 +44,7 @@ public abstract class Brush { * @param player The player who is performing the paint action. * @param brushSettings The brush settings to be applied while painting. * @see #performEdit(Player, Consumer) - * @see #setBlock(EditSession, Block, Material) + * @see #setBlock(EditSession, BlockVector3, Material) */ public abstract void paint(Location location, Player player, BrushSettings brushSettings); @@ -52,15 +52,12 @@ public abstract class Brush { * Sets the material of a block in an EditSession. * * @param session The EditSession to perform the block update in. - * @param block The block to update. + * @param vector3 The block to update. * @param material The material to set the block to. * @throws MaxChangedBlocksException If the maximum number of changed blocks is exceeded. */ - protected void setBlock(EditSession session, Block block, Material material) throws MaxChangedBlocksException { - BlockVector3 vector = BlockVector3.at(block.getX(), block.getY(), block.getZ()); - if (session.getMask() == null || session.getMask().test(vector)) { - session.setBlock(vector, BukkitAdapter.asBlockType(material)); - } + public void setBlock(EditSession session, BlockVector3 vector3, Material material) throws MaxChangedBlocksException { + session.setBlock(vector3, BukkitAdapter.asBlockType(material)); } /** @@ -70,7 +67,7 @@ protected void setBlock(EditSession session, Block block, Material material) thr * @param player The player performing the edit. * @param edit A Consumer functional interface that defines the actions to be taken within the edit session. */ - protected void performEdit(Player player, Consumer edit) { + public void performEdit(Player player, Consumer edit) { BukkitPlayer wrapped = BukkitAdapter.adapt(player); LocalSession localSession = WorldEdit.getInstance().getSessionManager().get(wrapped); try (EditSession editsession = localSession.createEditSession(wrapped)) { @@ -87,11 +84,12 @@ protected void performEdit(Player player, Consumer edit) { * * @param brushSettings The brush settings to be checked against. * @param player The player using the brush. + * @param session The EditSession object used for performing the checks. * @param block The block being checked. - * @return true if the block passes all the default checks, false otherwise. + * @return true if the block passes the default checks, false otherwise. */ - protected boolean passesDefaultChecks(BrushSettings brushSettings, Player player, Block block) { - return passesMaskCheck(brushSettings, block) && passesSurfaceCheck(brushSettings, player, block); + public boolean passesDefaultChecks(BrushSettings brushSettings, Player player, EditSession session, Block block) { + return passesMaskCheck(brushSettings, session, block) && passesSurfaceCheck(brushSettings, player, block); } /** @@ -102,7 +100,7 @@ protected boolean passesDefaultChecks(BrushSettings brushSettings, Player player * @param block The block being checked. * @return true if the block passes the surface check, false otherwise. */ - protected boolean passesSurfaceCheck(BrushSettings brushSettings, Player player, Block block) { + public boolean passesSurfaceCheck(BrushSettings brushSettings, Player player, Block block) { return Surface.isOnSurface(block, brushSettings.getSurfaceMode(), player.getLocation()); } @@ -110,10 +108,17 @@ protected boolean passesSurfaceCheck(BrushSettings brushSettings, Player player, * Checks if a given block passes the mask check defined by the brush settings. * * @param brushSettings The brush settings to be checked against. + * @param session The EditSession object used for performing the mask check. * @param block The block being checked. * @return true if the block passes the mask check, false otherwise. */ - protected boolean passesMaskCheck(BrushSettings brushSettings, Block block) { - return !brushSettings.isMaskEnabled() || block.getType().equals(brushSettings.getMask()); + public boolean passesMaskCheck(BrushSettings brushSettings, EditSession session, Block block) { + return switch (brushSettings.getMaskMode()) { + case INTERFACE -> block.getType().equals(brushSettings.getMask()); + case WORLDEDIT -> session.getMask() == null || session.getMask().test( + BlockVector3.at(block.getX(), block.getY(), block.getZ()) + ); + case DISABLED -> true; + }; } } diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/BrushSettings.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/BrushSettings.java index cbab521b..542649a9 100644 --- a/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/BrushSettings.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/BrushSettings.java @@ -1,10 +1,10 @@ package net.thenextlvl.gopaint.api.brush.setting; import net.thenextlvl.gopaint.api.brush.Brush; +import net.thenextlvl.gopaint.api.model.MaskMode; import net.thenextlvl.gopaint.api.model.SurfaceMode; import org.bukkit.Axis; import org.bukkit.Material; -import org.jetbrains.annotations.ApiStatus; import java.util.List; import java.util.Random; @@ -40,18 +40,15 @@ public interface BrushSettings { * Retrieves the mask material used by the brush settings. * * @return The mask material. - * @deprecated the mask-material is going to be replaced with a WorldEdit Mask */ - @Deprecated(since = "1.1.0-SNAPSHOT") - @ApiStatus.ScheduledForRemoval(inVersion = "1.2.0") Material getMask(); /** - * Checks if the mask is enabled. + * Retrieves the mask mode used by the brush settings. * - * @return true if the mask is enabled, false otherwise. + * @return The mask mode used by the brush settings. */ - boolean isMaskEnabled(); + MaskMode getMaskMode(); /** * Returns the surface mode used by the brush settings. diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/PlayerBrushSettings.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/PlayerBrushSettings.java index cfa2ec96..7ea20b5a 100644 --- a/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/PlayerBrushSettings.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/PlayerBrushSettings.java @@ -4,7 +4,6 @@ import org.bukkit.Material; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; /** @@ -49,6 +48,11 @@ public interface PlayerBrushSettings extends BrushSettings, InventoryHolder { */ void cycleBrushForward(); + /** + * Cycle the mask mode of the brush. + */ + void cycleMaskMode(); + /** * Cycle the surface mode of the brush. */ @@ -216,10 +220,7 @@ public interface PlayerBrushSettings extends BrushSettings, InventoryHolder { * The mask determines whether the brush applies its effect only to blocks matching the material specified * * @param type The Material type to set as the mask. - * @deprecated the mask-material is going to be replaced with a WorldEdit Mask */ - @Deprecated(since = "1.1.1") - @ApiStatus.ScheduledForRemoval(inVersion = "1.2.0") void setMask(Material type); /** @@ -231,16 +232,6 @@ public interface PlayerBrushSettings extends BrushSettings, InventoryHolder { */ void setSize(int size); - /** - * Toggles the mask state of the brush. - *

- * The mask state determines whether the brush applies its effect only to blocks - * matching the material specified by {@link PlayerBrushSettings#setMask(Material)}. - * If the mask is enabled, the brush will only affect blocks of the specified material. - * If the mask is disabled, the brush will affect blocks of any material. - */ - void toggleMask(); - /** * Updates the inventory of the player brush settings. *

diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/model/MaskMode.java b/api/src/main/java/net/thenextlvl/gopaint/api/model/MaskMode.java new file mode 100644 index 00000000..68a6aea1 --- /dev/null +++ b/api/src/main/java/net/thenextlvl/gopaint/api/model/MaskMode.java @@ -0,0 +1,40 @@ +package net.thenextlvl.gopaint.api.model; + +import com.sk89q.worldedit.EditSession; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import net.thenextlvl.gopaint.api.brush.Brush; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import org.bukkit.block.Block; + +import java.util.Arrays; +import java.util.Optional; + +@Getter +@RequiredArgsConstructor +public enum MaskMode { + /** + * This enumeration represents that no mask should be applied. + */ + DISABLED("Disabled"), + /** + * This enumeration represents that the mask material defined in the interface should be applied + * + * @see Brush#passesMaskCheck(BrushSettings, EditSession, Block) + */ + INTERFACE("Interface"), + /** + * This enumeration represents the complex mask defined by WorldEdit + * + * @see Brush#passesMaskCheck(BrushSettings, EditSession, Block) + */ + WORLDEDIT("WorldEdit"); + + private final String name; + + public static Optional byName(String name) { + return Arrays.stream(values()) + .filter(maskMode -> maskMode.getName().equals(name)) + .findAny(); + } +} diff --git a/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java b/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java index b9eec9de..e3a01366 100644 --- a/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java +++ b/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java @@ -13,6 +13,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.thenextlvl.gopaint.api.brush.BrushController; import net.thenextlvl.gopaint.api.brush.BrushRegistry; +import net.thenextlvl.gopaint.api.model.MaskMode; import net.thenextlvl.gopaint.brush.CraftBrushController; import net.thenextlvl.gopaint.brush.CraftBrushRegistry; import net.thenextlvl.gopaint.command.GoPaintCommand; @@ -51,7 +52,7 @@ public class GoPaintPlugin extends JavaPlugin implements Listener { )).build()); private final FileIO configFile = new GsonFile<>(IO.of(getDataFolder(), "config.json"), new PluginConfig( - new PluginConfig.Generic(Material.FEATHER, 100, 10, 50, Axis.Y, 50, 50, new ArrayList<>(), true, true, Material.SPONGE, SurfaceMode.DIRECT), + new PluginConfig.Generic(Material.FEATHER, 100, 10, 50, Axis.Y, 50, 50, new ArrayList<>(), true, Material.SPONGE, MaskMode.INTERFACE, SurfaceMode.DIRECT), new PluginConfig.Thickness(1, 5), new PluginConfig.Angle(2, 5, 10, 40, 85), new PluginConfig.Fracture(2, 5) diff --git a/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftItemBrushSettings.java b/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftItemBrushSettings.java index 562f6bb6..94a04d46 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftItemBrushSettings.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftItemBrushSettings.java @@ -22,6 +22,7 @@ import lombok.Getter; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.ItemBrushSettings; +import net.thenextlvl.gopaint.api.model.MaskMode; import net.thenextlvl.gopaint.api.model.SurfaceMode; import org.bukkit.Axis; import org.bukkit.Material; @@ -38,6 +39,7 @@ public final class CraftItemBrushSettings implements ItemBrushSettings { private final List blocks; private final Axis axis; private final SurfaceMode surfaceMode; + private final MaskMode maskMode; private final int size; private final int chance; private final int thickness; @@ -49,11 +51,6 @@ public final class CraftItemBrushSettings implements ItemBrushSettings { private static final Random random = new Random(); - @Override - public boolean isMaskEnabled() { - return getMask() != null; - } - @Override public Material getRandomBlock() { return getBlocks().get(getRandom().nextInt(getBlocks().size())); @@ -95,6 +92,8 @@ public static ItemBrushSettings parse(Brush brush, ItemMeta itemMeta) { .toList()); } else if (line.startsWith("Mask: ")) { builder.mask(Material.matchMaterial(line.substring(6))); + } else if (line.startsWith("Mask Mode: ")) { + MaskMode.byName(line.substring(11)).ifPresent(builder::maskMode); } else if (line.startsWith("Surface Mode: ")) { SurfaceMode.byName(line.substring(14)).ifPresent(builder::surfaceMode); } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftPlayerBrushSettings.java b/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftPlayerBrushSettings.java index 213bfea9..f59afe82 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftPlayerBrushSettings.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftPlayerBrushSettings.java @@ -27,6 +27,7 @@ import net.thenextlvl.gopaint.GoPaintPlugin; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings; +import net.thenextlvl.gopaint.api.model.MaskMode; import net.thenextlvl.gopaint.api.model.SurfaceMode; import net.thenextlvl.gopaint.brush.standard.*; import net.thenextlvl.gopaint.util.GUI; @@ -50,7 +51,6 @@ public final class CraftPlayerBrushSettings implements PlayerBrushSettings { private final GoPaintPlugin plugin; - private boolean maskEnabled; private boolean enabled; private int size; private int chance; @@ -61,6 +61,7 @@ public final class CraftPlayerBrushSettings implements PlayerBrushSettings { private int mixingStrength; private double angleHeightDifference; private Axis axis; + private MaskMode maskMode; private SurfaceMode surfaceMode; private @Setter Brush brush; @@ -73,7 +74,7 @@ public CraftPlayerBrushSettings(GoPaintPlugin plugin) { this.plugin = plugin; surfaceMode = plugin.config().generic().surfaceMode(); - maskEnabled = plugin.config().generic().maskEnabled(); + maskMode = plugin.config().generic().maskMode(); enabled = plugin.config().generic().enabledByDefault(); chance = plugin.config().generic().defaultChance(); thickness = plugin.config().thickness().defaultThickness(); @@ -261,8 +262,12 @@ public void decreaseAngleHeightDifference(int amount) { } @Override - public void toggleMask() { - maskEnabled = !maskEnabled; + public void cycleMaskMode() { + maskMode = switch (maskMode) { + case INTERFACE -> MaskMode.WORLDEDIT; + case WORLDEDIT -> MaskMode.DISABLED; + case DISABLED -> MaskMode.INTERFACE; + }; updateInventory(); } @@ -331,11 +336,15 @@ public void export(ItemStack itemStack) { .map(NamespacedKey::asMinimalString) .collect(Collectors.joining(", ")))); - if (isMaskEnabled()) { + if (!getMaskMode().equals(MaskMode.DISABLED)) { + lore.add("Mask Mode: " + getMaskMode().getName()); + } + if (getMaskMode().equals(MaskMode.INTERFACE)) { lore.add("Mask: " + getMask().getKey().asMinimalString()); } + if (!getSurfaceMode().equals(SurfaceMode.DISABLED)) { - lore.add("Surface Mode: " + surfaceMode.getName()); + lore.add("Surface Mode: " + getSurfaceMode().getName()); } itemStack.editMeta(itemMeta -> { diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/AngleBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/AngleBrush.java index 9cf87352..460efb15 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/AngleBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/AngleBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Height; @@ -42,11 +43,12 @@ public AngleBrush() { public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); - blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) + blocks.filter(block -> passesDefaultChecks(brushSettings, player, session, block)) .filter(block -> Height.getAverageHeightDiffAngle(block.getLocation(), 1) >= 0.1 && Height.getAverageHeightDiffAngle(block.getLocation(), brushSettings.getAngleDistance()) >= Math.tan(Math.toRadians(brushSettings.getAngleHeightDifference()))) - .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/BucketBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/BucketBrush.java index 52f66001..275e1a6d 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/BucketBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/BucketBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.ConnectedBlocks; @@ -44,8 +45,9 @@ public void paint(Location location, Player player, BrushSettings brushSettings) performEdit(player, session -> { List blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false).toList(); Stream connectedBlocks = ConnectedBlocks.getConnectedBlocks(location, blocks); - connectedBlocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) - .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); + connectedBlocks.filter(block -> passesDefaultChecks(brushSettings, player, session, block)) + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/DiscBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/DiscBrush.java index 229e2dd1..539dbc93 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/DiscBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/DiscBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Sphere; @@ -41,8 +42,9 @@ public DiscBrush() { public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), brushSettings.getAxis(), false); - blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) - .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); + blocks.filter(block -> passesDefaultChecks(brushSettings, player, session, block)) + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/FractureBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/FractureBrush.java index 69a7877d..a609aad6 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/FractureBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/FractureBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Height; @@ -42,7 +43,7 @@ public FractureBrush() { public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); - blocks.filter(block -> passesMaskCheck(brushSettings, block)) + blocks.filter(block -> passesMaskCheck(brushSettings, session, block)) .filter(block -> Height.getAverageHeightDiffFracture( block.getLocation(), Height.getNearestNonEmptyBlock(block.getLocation()), @@ -53,7 +54,8 @@ public void paint(Location location, Player player, BrushSettings brushSettings) Height.getNearestNonEmptyBlock(block.getLocation()), brushSettings.getFractureDistance() ) >= 0.1) - .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/GradientBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/GradientBrush.java index 1a0063e6..2db21601 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/GradientBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/GradientBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Sphere; @@ -40,24 +41,28 @@ public GradientBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - double y = location.getBlockY() - (brushSettings.getSize() / 2d); Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); - blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)).filter(block -> { - double rate = (block.getLocation().distance(location) - (brushSettings.getSize() / 2d) - * ((100d - brushSettings.getFalloffStrength()) / 100d)) - / ((brushSettings.getSize() / 2d) - (brushSettings.getSize() / 2d) - * ((100d - brushSettings.getFalloffStrength()) / 100d)); - - return brushSettings.getRandom().nextDouble() > rate; - }).forEach(block -> { - int random = (int) (((block.getLocation().getBlockY() - y) / brushSettings.getSize() - * brushSettings.getBlocks().size()) + (brushSettings.getRandom().nextDouble() * 2 - 1) - * (brushSettings.getMixingStrength() / 100d)); - - int index = Math.clamp(random, 0, brushSettings.getBlocks().size() - 1); - - setBlock(session, block, brushSettings.getBlocks().get(index)); - }); + blocks.filter(block -> passesDefaultChecks(brushSettings, player, session, block)) + .filter(block -> brushSettings.getRandom().nextDouble() > getRate(location, brushSettings, block)) + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> { + int random = getRandom(brushSettings, vector3); + int index = Math.clamp(random, 0, brushSettings.getBlocks().size() - 1); + setBlock(session, vector3, brushSettings.getBlocks().get(index)); + }); }); } + + private static int getRandom(BrushSettings brushSettings, BlockVector3 vector3) { + var y = vector3.getY() - (brushSettings.getSize() / 2d); + var mixingStrength = brushSettings.getMixingStrength() / 100d; + var random = brushSettings.getRandom().nextDouble() * 2 - 1; + var size = (vector3.getY() - y) / brushSettings.getSize() * brushSettings.getBlocks().size(); + return (int) (size + random * mixingStrength); + } + + private static double getRate(Location location, BrushSettings brushSettings, Block block) { + double size = (brushSettings.getSize() / 2d) * ((100d - brushSettings.getFalloffStrength()) / 100d); + return (block.getLocation().distance(location) - size) / ((brushSettings.getSize() / 2d) - size); + } } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/OverlayBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/OverlayBrush.java index a689ed9e..3a460c93 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/OverlayBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/OverlayBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Sphere; @@ -42,9 +43,10 @@ public OverlayBrush() { public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); - blocks.filter(block -> passesMaskCheck(brushSettings, block)) + blocks.filter(block -> passesMaskCheck(brushSettings, session, block)) .filter(block -> isOverlay(block, brushSettings.getThickness())) - .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/PaintBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/PaintBrush.java index baec9d8c..0c2d71e8 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/PaintBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/PaintBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import core.i18n.file.ComponentBundle; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.thenextlvl.gopaint.api.brush.Brush; @@ -89,11 +90,12 @@ public void paint(Location target, Player player, BrushSettings brushSettings) { for (int y = 0; y <= maxCount; y++) { var point = spline.getPoint((y / maxCount) * (locations.size() - 1)).toLocation(world).getBlock(); - if (point.isEmpty() || !passesDefaultChecks(brushSettings, player, point)) { + if (point.isEmpty() || !passesDefaultChecks(brushSettings, player, session, point)) { continue; } - setBlock(session, point, brushSettings.getRandomBlock()); + var vector3 = BlockVector3.at(block.getX(), block.getY(), block.getZ()); + setBlock(session, vector3, brushSettings.getRandomBlock()); } }); }); diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/SphereBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/SphereBrush.java index 75eac0ad..e9b58feb 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/SphereBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/SphereBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Sphere; @@ -41,8 +42,9 @@ public SphereBrush() { public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); - blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) - .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); + blocks.filter(block -> passesDefaultChecks(brushSettings, player, session, block)) + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/SplatterBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/SplatterBrush.java index bc67f917..ffb91214 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/SplatterBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/SplatterBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Sphere; @@ -41,19 +42,16 @@ public SplatterBrush() { public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); - blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) - .forEach(block -> { - double rate = (block.getLocation().distance(location) - ((double) brushSettings.getSize() / 2.0) - * ((100.0 - (double) brushSettings.getFalloffStrength()) / 100.0)) - / (((double) brushSettings.getSize() / 2.0) - ((double) brushSettings.getSize() / 2.0) - * ((100.0 - (double) brushSettings.getFalloffStrength()) / 100.0)); - - if (brushSettings.getRandom().nextDouble() <= rate) { - return; - } - - setBlock(session, block, brushSettings.getRandomBlock()); - }); + blocks.filter(block -> passesDefaultChecks(brushSettings, player, session, block)) + .filter(block -> brushSettings.getRandom().nextDouble() > getRate(location, brushSettings, block)) + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } + + private static double getRate(Location location, BrushSettings brushSettings, Block block) { + var size = (double) brushSettings.getSize() / 2.0; + var falloff = (100.0 - (double) brushSettings.getFalloffStrength()) / 100.0; + return (block.getLocation().distance(location) - size * falloff) / (size - size * falloff); + } } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/SprayBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/SprayBrush.java index 619f4e59..d883e55c 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/SprayBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/SprayBrush.java @@ -18,6 +18,7 @@ */ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Sphere; @@ -41,9 +42,10 @@ public SprayBrush() { public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); - blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) + blocks.filter(block -> passesDefaultChecks(brushSettings, player, session, block)) .filter(block -> brushSettings.getRandom().nextInt(100) < brushSettings.getChance()) - .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/standard/UnderlayBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/standard/UnderlayBrush.java index 76750a39..2c1d5bc8 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/standard/UnderlayBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/standard/UnderlayBrush.java @@ -1,5 +1,6 @@ package net.thenextlvl.gopaint.brush.standard; +import com.sk89q.worldedit.math.BlockVector3; import net.thenextlvl.gopaint.api.brush.Brush; import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; import net.thenextlvl.gopaint.api.math.Sphere; @@ -24,9 +25,10 @@ public UnderlayBrush() { public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); - blocks.filter(block -> passesMaskCheck(brushSettings, block)) + blocks.filter(block -> passesMaskCheck(brushSettings, session, block)) .filter(block -> isUnderlay(block, brushSettings.getThickness())) - .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); + .map(block -> BlockVector3.at(block.getX(), block.getY(), block.getZ())) + .forEach(vector3 -> setBlock(session, vector3, brushSettings.getRandomBlock())); }); } diff --git a/src/main/java/net/thenextlvl/gopaint/listener/InteractListener.java b/src/main/java/net/thenextlvl/gopaint/listener/InteractListener.java index 2c69d18f..e85fbbed 100644 --- a/src/main/java/net/thenextlvl/gopaint/listener/InteractListener.java +++ b/src/main/java/net/thenextlvl/gopaint/listener/InteractListener.java @@ -73,8 +73,6 @@ public void onClick(PlayerInteractEvent event) { ? plugin.brushController().parseBrushSettings(item).orElse(null) : plugin.brushController().getBrushSettings(player); - event.setCancelled(true); - if (settings == null || settings.getBlocks().isEmpty()) return; if (!(settings instanceof PlayerBrushSettings playerSettings) || playerSettings.isEnabled()) { @@ -82,5 +80,7 @@ public void onClick(PlayerInteractEvent event) { () -> settings.getBrush().paint(location, player, settings), false, true ); } else plugin.bundle().sendMessage(player, "brush.disabled"); + + event.setCancelled(true); } } diff --git a/src/main/java/net/thenextlvl/gopaint/listener/InventoryListener.java b/src/main/java/net/thenextlvl/gopaint/listener/InventoryListener.java index 90c24366..f14677ba 100644 --- a/src/main/java/net/thenextlvl/gopaint/listener/InventoryListener.java +++ b/src/main/java/net/thenextlvl/gopaint/listener/InventoryListener.java @@ -51,18 +51,18 @@ public void menuClick(InventoryClickEvent event) { } return; } + event.setCancelled(true); var playerBrush = plugin.brushController().getBrushSettings(player); if (event.getRawSlot() == 10 || event.getRawSlot() == 1 || event.getRawSlot() == 19) { - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { if (!event.getCursor().getType().isBlock()) { if (!event.getCursor().getType().equals(plugin.config().generic().defaultBrush())) { playerBrush.export(event.getCursor()); } } - } else if (event.getClick().equals(ClickType.RIGHT)) { + } else if (event.getClick().isRightClick()) { playerBrush.toggle(); } - event.setCancelled(true); } else if (event.getRawSlot() == 11 || event.getRawSlot() == 2 || event.getRawSlot() == 20) { if (event.getClick().equals(ClickType.LEFT)) { playerBrush.cycleBrushForward(); @@ -71,44 +71,42 @@ public void menuClick(InventoryClickEvent event) { } else if (event.getClick().isShiftClick()) { player.openInventory(GUI.generateBrushes()); } - event.setCancelled(true); } else if (event.getRawSlot() == 12 || event.getRawSlot() == 3 || event.getRawSlot() == 21) { var brush = playerBrush.getBrush(); if (brush instanceof SprayBrush) { - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { playerBrush.increaseChance(); - } else if (event.getClick().equals(ClickType.RIGHT)) { + } else if (event.getClick().isRightClick()) { playerBrush.decreaseChance(); } } else if (brush instanceof OverlayBrush || brush instanceof UnderlayBrush) { - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { playerBrush.increaseThickness(); - } else if (event.getClick().equals(ClickType.RIGHT)) { + } else if (event.getClick().isRightClick()) { playerBrush.decreaseThickness(); } } else if (brush instanceof FractureBrush) { - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { playerBrush.increaseFractureDistance(); - } else if (event.getClick().equals(ClickType.RIGHT)) { + } else if (event.getClick().isRightClick()) { playerBrush.decreaseFractureDistance(); } } else if (brush instanceof AngleBrush) { - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { playerBrush.increaseAngleDistance(); - } else if (event.getClick().equals(ClickType.RIGHT)) { + } else if (event.getClick().isRightClick()) { playerBrush.decreaseAngleDistance(); } } else if (brush instanceof GradientBrush || brush instanceof PaintBrush || brush instanceof SplatterBrush) { - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { playerBrush.increaseFalloffStrength(); - } else if (event.getClick().equals(ClickType.RIGHT)) { + } else if (event.getClick().isRightClick()) { playerBrush.decreaseFalloffStrength(); } } else if (brush instanceof DiscBrush) { playerBrush.cycleAxis(); } - event.setCancelled(true); } else if (event.getRawSlot() == 13 || event.getRawSlot() == 4 || event.getRawSlot() == 22) { var brush = playerBrush.getBrush(); if (brush instanceof AngleBrush) { @@ -122,13 +120,12 @@ public void menuClick(InventoryClickEvent event) { playerBrush.decreaseAngleHeightDifference(15); } } else if (brush instanceof GradientBrush) { - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { playerBrush.increaseMixingStrength(); - } else if (event.getClick().equals(ClickType.RIGHT)) { + } else if (event.getClick().isRightClick()) { playerBrush.decreaseMixingStrength(); } } - event.setCancelled(true); } else if (event.getRawSlot() == 14 || event.getRawSlot() == 5 || event.getRawSlot() == 23) { if (event.getClick().equals(ClickType.LEFT)) { playerBrush.increaseBrushSize(1); @@ -139,38 +136,31 @@ public void menuClick(InventoryClickEvent event) { } else if (event.getClick().equals(ClickType.SHIFT_RIGHT)) { playerBrush.decreaseBrushSize(10); } - event.setCancelled(true); } else if (event.getRawSlot() == 15 || event.getRawSlot() == 6 || event.getRawSlot() == 24) { - playerBrush.toggleMask(); - event.setCancelled(true); + playerBrush.cycleMaskMode(); } else if (event.getRawSlot() == 16 || event.getRawSlot() == 7 || event.getRawSlot() == 25) { playerBrush.cycleSurfaceMode(); - event.setCancelled(true); } else if ((event.getRawSlot() >= 37 && event.getRawSlot() <= 41) - || (event.getRawSlot() >= 46 && event.getRawSlot() <= 50)) { + || (event.getRawSlot() >= 46 && event.getRawSlot() <= 50)) { int slot; if (event.getRawSlot() >= 37 && event.getRawSlot() <= 41) { slot = event.getRawSlot() - 36; } else { slot = event.getRawSlot() - 45; } - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { if (event.getCursor().getType().isBlock() && event.getCursor().getType().isSolid()) { playerBrush.addBlock(event.getCursor().getType(), slot); } - } else if (event.getClick().equals(ClickType.RIGHT)) { + } else if (event.getClick().isRightClick()) { playerBrush.removeBlock(slot); } - event.setCancelled(true); } else if (event.getRawSlot() == 43 || event.getRawSlot() == 52) { - if (event.getClick().equals(ClickType.LEFT)) { + if (event.getClick().isLeftClick()) { if (event.getCursor().getType().isBlock() && event.getCursor().getType().isSolid()) { playerBrush.setMask(event.getCursor().getType()); } } - event.setCancelled(true); - } else { - event.setCancelled(true); } } diff --git a/src/main/java/net/thenextlvl/gopaint/model/PluginConfig.java b/src/main/java/net/thenextlvl/gopaint/model/PluginConfig.java index 2239d97e..635348ec 100644 --- a/src/main/java/net/thenextlvl/gopaint/model/PluginConfig.java +++ b/src/main/java/net/thenextlvl/gopaint/model/PluginConfig.java @@ -1,6 +1,7 @@ package net.thenextlvl.gopaint.model; import com.google.gson.annotations.SerializedName; +import net.thenextlvl.gopaint.api.model.MaskMode; import net.thenextlvl.gopaint.api.model.SurfaceMode; import org.bukkit.Axis; import org.bukkit.Material; @@ -24,8 +25,8 @@ public record Generic( @SerializedName("default-mixing-strength") int defaultMixingStrength, @SerializedName("disabled-worlds") List disabledWorlds, @SerializedName("enabled-by-default") boolean enabledByDefault, - @SerializedName("mask-enabled") boolean maskEnabled, @SerializedName("default-mask") Material defaultMask, + @SerializedName("mask-mode") MaskMode maskMode, @SerializedName("surface-mode") SurfaceMode surfaceMode ) { } diff --git a/src/main/java/net/thenextlvl/gopaint/util/GUI.java b/src/main/java/net/thenextlvl/gopaint/util/GUI.java index f61f510e..5e335eb9 100644 --- a/src/main/java/net/thenextlvl/gopaint/util/GUI.java +++ b/src/main/java/net/thenextlvl/gopaint/util/GUI.java @@ -22,7 +22,6 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.thenextlvl.gopaint.GoPaintPlugin; import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings; -import net.thenextlvl.gopaint.brush.setting.CraftPlayerBrushSettings; import net.thenextlvl.gopaint.brush.standard.*; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -35,7 +34,7 @@ public class GUI { private static final GoPaintPlugin plugin = JavaPlugin.getPlugin(GoPaintPlugin.class); - public static Inventory create(CraftPlayerBrushSettings pb) { + public static Inventory create(PlayerBrushSettings pb) { Inventory inv = Bukkit.createInventory(null, 54, Component.text("goPaint Menu", NamedTextColor.DARK_BLUE)); update(inv, pb); return inv; @@ -56,9 +55,8 @@ public static Inventory generateBrushes() { } private static void formatDefault(Inventory inventory) { - for (int slot = 0; slot < inventory.getSize(); slot++) { - inventory.setItem(slot, Items.create(Material.GRAY_STAINED_GLASS_PANE, 1, "§7", "")); - } + var placeholder = Items.create(Material.GRAY_STAINED_GLASS_PANE); + for (int slot = 0; slot < inventory.getSize(); slot++) inventory.setItem(slot, placeholder); } public static void update(Inventory inventory, PlayerBrushSettings settings) { @@ -69,21 +67,21 @@ public static void update(Inventory inventory, PlayerBrushSettings settings) { // goPaint toggle if (settings.isEnabled()) { - inventory.setItem(1, Items.create(Material.LIME_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(1, Items.create(Material.LIME_STAINED_GLASS_PANE)); inventory.setItem(10, Items.create(plugin.config().generic().defaultBrush(), 1, "§6goPaint Brush", "§a§lEnabled\n\n§7Left click with item to export\n§7Right click to toggle" )); - inventory.setItem(19, Items.create(Material.LIME_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(19, Items.create(Material.LIME_STAINED_GLASS_PANE)); } else { - inventory.setItem(1, Items.create(Material.RED_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(1, Items.create(Material.RED_STAINED_GLASS_PANE)); inventory.setItem(10, Items.create(plugin.config().generic().defaultBrush(), 1, "§6goPaint Brush", "§c§lDisabled\n\n§7Left click with item to export\n§7Right click to toggle" )); - inventory.setItem(19, Items.create(Material.RED_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(19, Items.create(Material.RED_STAINED_GLASS_PANE)); } // Brushes + Chance - inventory.setItem(2, Items.create(Material.ORANGE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(2, Items.create(Material.ORANGE_STAINED_GLASS_PANE)); String clicks = "\n§7Shift click to select\n§7Click to cycle brush\n\n"; @@ -99,113 +97,102 @@ public static void update(Inventory inventory, PlayerBrushSettings settings) { inventory.setItem(11, Items.createHead(brush.getHeadValue(), 1, "§6Selected Brush type", clicks + lore )); - inventory.setItem(20, Items.create(Material.ORANGE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(20, Items.create(Material.ORANGE_STAINED_GLASS_PANE)); // chance if (brush instanceof SprayBrush) { - inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(12, Items.create(Material.GOLD_NUGGET, 1, "§6Place chance: §e" + settings.getChance() + "%", "\n§7Left click to increase\n§7Right click to decrease" )); - inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE)); } // axis if (brush instanceof DiscBrush) { - inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(12, Items.create(Material.COMPASS, 1, "§6Axis: §e" + settings.getAxis(), "\n§7Click to change" )); - inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE)); } // thickness if (brush instanceof OverlayBrush || brush instanceof UnderlayBrush) { - inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(12, Items.create(Material.BOOK, 1, "§6Layer Thickness: §e" + settings.getThickness(), "\n§7Left click to increase\n§7Right click to decrease" )); - inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE)); } // angle settings if (brush instanceof AngleBrush) { - inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(12, Items.create(Material.DAYLIGHT_DETECTOR, 1, "§6Angle Check Distance: §e" + settings.getAngleDistance(), "\n§7Left click to increase\n§7Right click to decrease" )); - inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE)); - inventory.setItem(4, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(4, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(13, Items.create(Material.BLAZE_ROD, 1, "§6Maximum Angle: §e" + settings.getAngleHeightDifference() + "°", "\n§7Left click to increase\n§7Right click to decrease\n§7Shift click to change by 15" )); - inventory.setItem(22, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(22, Items.create(Material.WHITE_STAINED_GLASS_PANE)); } // fracture settings if (brush instanceof FractureBrush) { - inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(12, Items.create(Material.DAYLIGHT_DETECTOR, 1, "§6Fracture Check Distance: §e" + settings.getFractureDistance(), "\n§7Left click to increase\n§7Right click to decrease" )); - inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE)); } // angle settings if (brush instanceof GradientBrush) { - inventory.setItem(4, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(4, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(13, Items.create(Material.MAGMA_CREAM, 1, "§6Mixing Strength: §e" + settings.getMixingStrength() + "%", "\n§7Left click to increase\n§7Right click to decrease" )); - inventory.setItem(22, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(22, Items.create(Material.WHITE_STAINED_GLASS_PANE)); } if (brush instanceof SplatterBrush || brush instanceof PaintBrush || brush instanceof GradientBrush) { - inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(12, Items.create(Material.BLAZE_POWDER, 1, "§6Falloff Strength: §e" + settings.getFalloffStrength() + "%", "\n§7Left click to increase\n§7Right click to decrease" )); - inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE)); } // Size - inventory.setItem(5, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(5, Items.create(Material.WHITE_STAINED_GLASS_PANE)); inventory.setItem(14, Items.create(Material.BROWN_MUSHROOM, 1, "§6Brush Size: §e" + settings.getSize(), "\n§7Left click to increase\n§7Right click to decrease\n§7Shift click to change by 10" )); - inventory.setItem(23, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); - - // Mask toggle - if (settings.isMaskEnabled()) { - inventory.setItem(6, Items.create(Material.LIME_STAINED_GLASS_PANE, 1, "§7", "")); - inventory.setItem(15, Items.create(Material.JACK_O_LANTERN, 1, - "§6Mask", - "§a§lEnabled\n\n§7Click to toggle" - )); - inventory.setItem(24, Items.create(Material.LIME_STAINED_GLASS_PANE, 1, "§7", "")); - } else { - inventory.setItem(6, Items.create(Material.RED_STAINED_GLASS_PANE, 1, "§7", "")); - inventory.setItem(15, Items.create(Material.CARVED_PUMPKIN, 1, "§6Mask", "§c§lDisabled\n\n§7Click to toggle")); - inventory.setItem(24, Items.create(Material.RED_STAINED_GLASS_PANE, 1, "§7", "")); - } + inventory.setItem(23, Items.create(Material.WHITE_STAINED_GLASS_PANE)); - // Surface Mode toggle + // Mask Mode switch + addMaskModeSwitch(inventory, settings); + + // Surface Mode switch addSurfaceModeSwitch(inventory, settings); // Place Block for (int x = 37; x <= 41; x++) { - inventory.setItem(x, Items.create(Material.YELLOW_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(x, Items.create(Material.YELLOW_STAINED_GLASS_PANE)); } for (int x = 46; x <= 50; x++) { inventory.setItem(x, Items.create(Material.BARRIER, 1, "§cEmpty Slot", "\n§7Click with a block to set")); @@ -229,10 +216,35 @@ public static void update(Inventory inventory, PlayerBrushSettings settings) { } // Mask Block - inventory.setItem(43, Items.create(Material.YELLOW_STAINED_GLASS_PANE, 1, "§7", "")); + inventory.setItem(43, Items.create(Material.YELLOW_STAINED_GLASS_PANE)); inventory.setItem(52, Items.create(settings.getMask(), 1, "§6Current Mask", "\n§7Left click with a block to change")); } + private static void addMaskModeSwitch(Inventory inventory, PlayerBrushSettings settings) { + var pane = switch (settings.getMaskMode()) { + case DISABLED -> Material.RED_STAINED_GLASS_PANE; + case INTERFACE -> Material.LIME_STAINED_GLASS_PANE; + case WORLDEDIT -> Material.ORANGE_STAINED_GLASS_PANE; + }; + var color = switch (settings.getMaskMode()) { + case DISABLED -> "§c"; + case INTERFACE -> "§a"; + case WORLDEDIT -> "§6"; + }; + var icon = switch (settings.getMaskMode()) { + case DISABLED -> Material.CARVED_PUMPKIN; + case INTERFACE -> Material.JACK_O_LANTERN; + case WORLDEDIT -> Material.WOODEN_AXE; + }; + + inventory.setItem(6, Items.create(pane)); + inventory.setItem(15, Items.create(icon, 1, + "§6Mask Mode", + color + "§l" + settings.getMaskMode().getName() + "\n\n§7Click to cycle" + )); + inventory.setItem(24, Items.create(pane)); + } + private static void addSurfaceModeSwitch(Inventory inventory, PlayerBrushSettings settings) { Material pane = switch (settings.getSurfaceMode()) { case DIRECT -> Material.LIME_STAINED_GLASS_PANE; @@ -245,12 +257,12 @@ private static void addSurfaceModeSwitch(Inventory inventory, PlayerBrushSetting case RELATIVE -> "§6"; }; - inventory.setItem(7, Items.create(pane, 1, "§7", "")); + inventory.setItem(7, Items.create(pane)); inventory.setItem(16, Items.create(Material.LIGHT_WEIGHTED_PRESSURE_PLATE, 1, "§6Surface Mode", - color + "§l" + settings.getSurfaceMode().getName() + "\n\n§7Click to toggle" + color + "§l" + settings.getSurfaceMode().getName() + "\n\n§7Click to cycle" )); - inventory.setItem(25, Items.create(pane, 1, "§7", "")); + inventory.setItem(25, Items.create(pane)); } } diff --git a/src/main/java/net/thenextlvl/gopaint/util/Items.java b/src/main/java/net/thenextlvl/gopaint/util/Items.java index 9b407ef7..459bff3f 100644 --- a/src/main/java/net/thenextlvl/gopaint/util/Items.java +++ b/src/main/java/net/thenextlvl/gopaint/util/Items.java @@ -32,8 +32,7 @@ public final class Items { public static ItemStack create(Material material, int amount, String name, String lore) { - ItemStack itemStack = new ItemStack(material); - itemStack.setAmount(amount); + var itemStack = new ItemStack(material, amount); itemStack.editMeta(itemMeta -> { if (!lore.isEmpty()) { String[] loreListArray = lore.split("\n"); @@ -50,8 +49,14 @@ public static ItemStack create(Material material, int amount, String name, Strin return itemStack; } + public static ItemStack create(Material material) { + var itemStack = new ItemStack(material); + itemStack.editMeta(itemMeta -> itemMeta.setHideTooltip(true)); + return itemStack; + } + public static ItemStack createHead(String texture, int amount, String name, String lore) { - ItemStack head = create(Material.PLAYER_HEAD, amount, name, lore); + var head = create(Material.PLAYER_HEAD, amount, name, lore); head.editMeta(SkullMeta.class, skullMeta -> { var profile = Bukkit.createProfile(UUID.randomUUID()); profile.setProperty(new ProfileProperty("textures", texture));