]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Simplify commands to use Coords & Pos objects
authorIrtimaled <irtimaled@gmail.com>
Wed, 13 May 2020 18:49:57 +0000 (11:49 -0700)
committerIrtimaled <irtimaled@gmail.com>
Mon, 18 May 2020 00:31:27 +0000 (17:31 -0700)
14 files changed:
src/main/java/com/irtimaled/bbor/client/commands/Arguments.java [new file with mode: 0644]
src/main/java/com/irtimaled/bbor/client/commands/BeaconCommandBuilder.java
src/main/java/com/irtimaled/bbor/client/commands/BoxCommandBuilder.java
src/main/java/com/irtimaled/bbor/client/commands/CommandHelper.java
src/main/java/com/irtimaled/bbor/client/commands/ConfigCommand.java
src/main/java/com/irtimaled/bbor/client/commands/CustomCommand.java
src/main/java/com/irtimaled/bbor/client/commands/SeedCommand.java
src/main/java/com/irtimaled/bbor/client/commands/SpawningSphereCommand.java
src/main/java/com/irtimaled/bbor/client/providers/SpawningSphereProvider.java
src/main/java/com/irtimaled/bbor/client/renderers/MobSpawnerRenderer.java
src/main/java/com/irtimaled/bbor/common/MathHelper.java
src/main/java/com/irtimaled/bbor/common/models/Coords.java
src/main/java/com/irtimaled/bbor/common/models/Point.java
src/main/resources/assets/bbor/lang/en_us.json

diff --git a/src/main/java/com/irtimaled/bbor/client/commands/Arguments.java b/src/main/java/com/irtimaled/bbor/client/commands/Arguments.java
new file mode 100644 (file)
index 0000000..72c3ca1
--- /dev/null
@@ -0,0 +1,86 @@
+package com.irtimaled.bbor.client.commands;
+
+import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
+import com.mojang.brigadier.arguments.BoolArgumentType;
+import com.mojang.brigadier.arguments.DoubleArgumentType;
+import com.mojang.brigadier.arguments.IntegerArgumentType;
+import com.mojang.brigadier.arguments.StringArgumentType;
+import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import net.minecraft.command.CommandSource;
+import net.minecraft.command.arguments.BlockPosArgument;
+import net.minecraft.command.arguments.Vec3Argument;
+
+import java.util.function.Supplier;
+
+public class Arguments {
+    public static BlockPosArgument coords() {
+        return BlockPosArgument.blockPos();
+    }
+
+    public static Vec3Argument point() {
+        return Vec3Argument.vec3();
+    }
+
+    public static IntegerArgumentType integer() {
+        return IntegerArgumentType.integer();
+    }
+
+    public static IntegerArgumentType integer(int min, int max) {
+        return IntegerArgumentType.integer(min, max);
+    }
+
+    public static DoubleArgumentType doubleArg() {
+        return DoubleArgumentType.doubleArg();
+    }
+
+    public static StringArgumentType string() {
+        return StringArgumentType.greedyString();
+    }
+
+    public static BoolArgumentType bool() {
+        return BoolArgumentType.bool();
+    }
+
+    public static Coords getCoords(CommandContext<CommandSource> context, String name) throws CommandSyntaxException {
+        return new Coords(getArgumentValueOrDefault(context, name, Vec3Argument::getVec3, () -> context.getSource().getPos()));
+    }
+
+    public static Point getPoint(CommandContext<CommandSource> context, String name) throws CommandSyntaxException {
+        return new Point(getArgumentValueOrDefault(context, name, Vec3Argument::getVec3, () -> context.getSource().getPos()));
+    }
+
+    public static int getInteger(CommandContext<CommandSource> context, String name) throws CommandSyntaxException {
+        return getArgumentValueOrDefault(context, name, IntegerArgumentType::getInteger, () -> 0);
+    }
+
+    public static double getDouble(CommandContext<CommandSource> context, String name) throws CommandSyntaxException {
+        return getArgumentValueOrDefault(context, name, DoubleArgumentType::getDouble, () -> 0.0D);
+    }
+
+    public static String getString(CommandContext<CommandSource> context, String name) throws CommandSyntaxException {
+        return getArgumentValueOrDefault(context, name, StringArgumentType::getString, () -> "");
+    }
+
+    public static boolean getBool(CommandContext<CommandSource> context, String name) throws CommandSyntaxException {
+        return getArgumentValueOrDefault(context, name, BoolArgumentType::getBool, () -> false);
+    }
+
+
+    public static <T> T getArgumentValueOrDefault(CommandContext<CommandSource> context,
+                                                  String name,
+                                                  ArgumentFetcher<T> getValue,
+                                                  Supplier<T> defaultValue) throws CommandSyntaxException {
+        try {
+            return getValue.get(context, name);
+        } catch (IllegalArgumentException exception) {
+            return defaultValue.get();
+        }
+    }
+
+    @FunctionalInterface
+    private interface ArgumentFetcher<T> {
+        T get(CommandContext<CommandSource> context, String name) throws CommandSyntaxException;
+    }
+}
index 2259458eeb6c9fd9fe31b41984ad9ba95ef55534..ab9e7d5c65360bc4ca79dffa11eae5d48bb87883 100644 (file)
@@ -2,15 +2,11 @@ package com.irtimaled.bbor.client.commands;
 
 import com.irtimaled.bbor.client.providers.CustomBeaconProvider;
 import com.irtimaled.bbor.common.models.Coords;
-import com.mojang.brigadier.StringReader;
-import com.mojang.brigadier.arguments.IntegerArgumentType;
 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
 import com.mojang.brigadier.context.CommandContext;
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import net.minecraft.command.CommandSource;
 import net.minecraft.command.Commands;
-import net.minecraft.command.arguments.BlockPosArgument;
-import net.minecraft.util.math.BlockPos;
 
 class BeaconCommandBuilder {
     private static final String LEVEL = "level";
@@ -18,20 +14,10 @@ class BeaconCommandBuilder {
     static LiteralArgumentBuilder<CommandSource> build(String command) {
         return Commands.literal(command)
                 .then(Commands.literal(ArgumentNames.ADD)
-                        .then(Commands.argument(LEVEL, IntegerArgumentType.integer())
-                                .executes(context -> {
-                                    BlockPos pos = new BlockPos(context.getSource().getPos());
-                                    int level = IntegerArgumentType.getInteger(context, LEVEL);
-                                    addBeacon(context, pos, level);
-                                    return 0;
-                                })
-                                .then(Commands.argument(ArgumentNames.POS, BlockPosArgument.blockPos())
-                                        .executes(context -> {
-                                            BlockPos pos = BlockPosArgument.getBlockPos(context, ArgumentNames.POS);
-                                            int level = IntegerArgumentType.getInteger(context, LEVEL);
-                                            addBeacon(context, pos, level);
-                                            return 0;
-                                        })))
+                        .then(Commands.argument(LEVEL, Arguments.integer(1,4))
+                                .executes(BeaconCommandBuilder::addBeacon)
+                                .then(Commands.argument(ArgumentNames.POS, Arguments.coords())
+                                        .executes(BeaconCommandBuilder::addBeacon)))
                 )
                 .then(Commands.literal(ArgumentNames.CLEAR)
                         .executes(context -> {
@@ -40,25 +26,23 @@ class BeaconCommandBuilder {
                             CommandHelper.feedback(context, "bbor.commands.beacon.cleared.all");
                             return 0;
                         })
-                        .then(Commands.argument(ArgumentNames.POS, BlockPosArgument.blockPos())
+                        .then(Commands.argument(ArgumentNames.POS, Arguments.coords())
                                 .executes(context -> {
-                                    BlockPos pos = BlockPosArgument.getBlockPos(context, ArgumentNames.POS);
-                                    boolean removed = CustomBeaconProvider.remove(new Coords(pos));
+                                    Coords coords = Arguments.getCoords(context, ArgumentNames.POS);
+                                    boolean removed = CustomBeaconProvider.remove(coords);
 
                                     String format = removed ? "bbor.commands.beacon.cleared" : "bbor.commands.beacon.notFound";
-                                    CommandHelper.feedback(context, format, pos.getX(), pos.getY(), pos.getZ());
+                                    CommandHelper.feedback(context, format, coords.getX(), coords.getY(), coords.getZ());
                                     return 0;
                                 })));
     }
 
-    private static void addBeacon(CommandContext<CommandSource> context, BlockPos pos, int level) throws CommandSyntaxException {
-        if (level < 1 || level > 4) {
-            throw CommandHelper.getException("bbor.commandArgument.invalid",
-                    "bbor.commands.beacon.expectedLevelInRange")
-                    .createWithContext(new StringReader(context.getInput()));
-        }
+    private static int addBeacon(CommandContext<CommandSource> context) throws CommandSyntaxException {
+        Coords coords = Arguments.getCoords(context, ArgumentNames.POS);
+        int level = Arguments.getInteger(context, LEVEL);
 
-        CustomBeaconProvider.add(new Coords(pos), level);
-        CommandHelper.feedback(context, "bbor.commands.beacon.added", pos.getX(), pos.getY(), pos.getZ(), level);
+        CustomBeaconProvider.add(coords, level);
+        CommandHelper.feedback(context, "bbor.commands.beacon.added", coords.getX(), coords.getY(), coords.getZ(), level);
+        return 0;
     }
 }
index ab2272ffd3c4164cba4781badab0dd716e90e60f..422eda0fca8f0db10ea48efb54cd9c79766841b3 100644 (file)
@@ -3,29 +3,19 @@ package com.irtimaled.bbor.client.commands;
 import com.irtimaled.bbor.client.providers.CustomBoxProvider;
 import com.irtimaled.bbor.common.models.Coords;
 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import net.minecraft.command.CommandSource;
 import net.minecraft.command.Commands;
-import net.minecraft.command.arguments.BlockPosArgument;
-import net.minecraft.util.math.BlockPos;
 
 class BoxCommandBuilder {
     static LiteralArgumentBuilder<CommandSource> build(String command) {
         return Commands.literal(command)
                 .then(Commands.literal(ArgumentNames.ADD)
-                        .then(Commands.argument(ArgumentNames.FROM, BlockPosArgument.blockPos())
-                                .then(Commands.argument(ArgumentNames.TO, BlockPosArgument.blockPos())
-                                        .executes(context -> {
-                                            BlockPos from = BlockPosArgument.getBlockPos(context, ArgumentNames.FROM);
-                                            BlockPos to = BlockPosArgument.getBlockPos(context, ArgumentNames.TO);
-                                            Coords minCoords = getMinCoords(from, to);
-                                            Coords maxCoords = getMaxCoords(from, to);
-                                            CustomBoxProvider.add(minCoords, maxCoords);
-
-                                            CommandHelper.feedback(context, "bbor.commands.box.added",
-                                                    from.getX(), from.getY(), from.getZ(),
-                                                    to.getX(), to.getY(), to.getZ());
-                                            return 0;
-                                        }))))
+                        .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
+                                .executes(BoxCommandBuilder::addBox)
+                                .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
+                                        .executes(BoxCommandBuilder::addBox))))
                 .then(Commands.literal(ArgumentNames.CLEAR)
                         .executes(context -> {
                             CustomBoxProvider.clear();
@@ -33,11 +23,11 @@ class BoxCommandBuilder {
                             CommandHelper.feedback(context, "bbor.commands.box.cleared.all");
                             return 0;
                         })
-                        .then(Commands.argument(ArgumentNames.FROM, BlockPosArgument.blockPos())
-                                .then(Commands.argument(ArgumentNames.TO, BlockPosArgument.blockPos())
+                        .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
+                                .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
                                         .executes(context -> {
-                                            BlockPos from = BlockPosArgument.getBlockPos(context, ArgumentNames.FROM);
-                                            BlockPos to = BlockPosArgument.getBlockPos(context, ArgumentNames.TO);
+                                            Coords from = Arguments.getCoords(context, ArgumentNames.FROM);
+                                            Coords to = Arguments.getCoords(context, ArgumentNames.TO);
                                             Coords minCoords = getMinCoords(from, to);
                                             Coords maxCoords = getMaxCoords(from, to);
                                             boolean removed = CustomBoxProvider.remove(minCoords, maxCoords);
@@ -50,11 +40,24 @@ class BoxCommandBuilder {
                                         }))));
     }
 
-    private static Coords getMaxCoords(BlockPos from, BlockPos to) {
+    private static int addBox(CommandContext<CommandSource> context) throws CommandSyntaxException {
+        Coords from = Arguments.getCoords(context, ArgumentNames.FROM);
+        Coords to = Arguments.getCoords(context, ArgumentNames.TO);
+        Coords minCoords = getMinCoords(from, to);
+        Coords maxCoords = getMaxCoords(from, to);
+        CustomBoxProvider.add(minCoords, maxCoords);
+
+        CommandHelper.feedback(context, "bbor.commands.box.added",
+                from.getX(), from.getY(), from.getZ(),
+                to.getX(), to.getY(), to.getZ());
+        return 0;
+    }
+
+    private static Coords getMaxCoords(Coords from, Coords to) {
         return new Coords(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
     }
 
-    private static Coords getMinCoords(BlockPos from, BlockPos to) {
+    private static Coords getMinCoords(Coords from, Coords to) {
         return new Coords(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));
     }
 }
index c7cbb0dd11625949d95a3dff4afb9b263b30b819..cdb7260e1b6dd5c7738a3a67f546cf3aec433381 100644 (file)
@@ -1,29 +1,11 @@
 package com.irtimaled.bbor.client.commands;
 
 import com.mojang.brigadier.context.CommandContext;
-import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
 import net.minecraft.command.CommandSource;
-import net.minecraft.util.text.ITextComponent;
 import net.minecraft.util.text.TextComponentTranslation;
 
 class CommandHelper {
     static void feedback(CommandContext<CommandSource> context, String format, Object... values) {
         context.getSource().sendFeedback(new TextComponentTranslation(format, values), false);
     }
-
-    static SimpleCommandExceptionType getException(String message, String... values) {
-        ITextComponent textComponent = new TextComponentTranslation(message);
-
-        int length = values.length;
-        if (length > 0) {
-            textComponent.appendText(" (");
-            for (int idx = 0; idx < length; idx++) {
-                if (idx > 0) textComponent.appendText(", ");
-                ITextComponent suggestion = new TextComponentTranslation(values[idx]);
-                textComponent.appendSibling(suggestion);
-            }
-            textComponent.appendText(")");
-        }
-        return new SimpleCommandExceptionType(textComponent);
-    }
 }
index 0cb9a1be36d2d9f564ea3165386aac9f72bc8b76..a371f1749d8e6b1302c1941ab62c85872adeeb9b 100644 (file)
@@ -4,8 +4,6 @@ import com.irtimaled.bbor.client.config.ConfigManager;
 import com.irtimaled.bbor.client.config.Setting;
 import com.irtimaled.bbor.client.gui.SettingsScreen;
 import com.mojang.brigadier.CommandDispatcher;
-import com.mojang.brigadier.arguments.BoolArgumentType;
-import com.mojang.brigadier.arguments.IntegerArgumentType;
 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
 import net.minecraft.command.CommandSource;
 import net.minecraft.command.Commands;
@@ -62,16 +60,16 @@ public class ConfigCommand {
         LiteralArgumentBuilder<CommandSource> command = Commands.literal(setting.getName());
         switch (setting.getType()) {
             case 'B':
-                return command.then(Commands.argument(VALUE, BoolArgumentType.bool())
+                return command.then(Commands.argument(VALUE, Arguments.bool())
                         .executes(context -> {
-                            boolean value = BoolArgumentType.getBool(context, VALUE);
+                            boolean value = Arguments.getBool(context, VALUE);
                             ((Setting<Boolean>) setting).set(value);
                             return 0;
                         }));
             case 'I':
-                return command.then(Commands.argument(VALUE, IntegerArgumentType.integer())
+                return command.then(Commands.argument(VALUE, Arguments.integer())
                         .executes(context -> {
-                            int value = IntegerArgumentType.getInteger(context, VALUE);
+                            int value = Arguments.getInteger(context, VALUE);
                             ((Setting<Integer>) setting).set(value);
                             return 0;
                         }));
index d7373237b7f82500bcc278d53d9c5d779b8c8383..184a860ffae10659f718a090726a69472a99702e 100644 (file)
@@ -21,7 +21,7 @@ public class CustomCommand {
                             CustomBoxProvider.clear();
                             CustomBeaconProvider.clear();
 
-                            CommandHelper.feedback(context, "bbor.commands.box.cleared.all");
+                            CommandHelper.feedback(context, "bbor.commands.custom.cleared.all");
                             return 0;
                         }));
         commandDispatcher.register(command);
index 9937a161a2f069ded5303d74179f6f429d179ca7..879f1b902569bfd8ce0e437a8d41b018484bff2d 100644 (file)
@@ -2,7 +2,6 @@ package com.irtimaled.bbor.client.commands;
 
 import com.irtimaled.bbor.client.providers.SlimeChunkProvider;
 import com.mojang.brigadier.CommandDispatcher;
-import com.mojang.brigadier.arguments.StringArgumentType;
 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
 import net.minecraft.command.Commands;
 import net.minecraft.command.ISuggestionProvider;
@@ -13,9 +12,9 @@ public class SeedCommand {
 
     public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
         LiteralArgumentBuilder command = Commands.literal(COMMAND)
-                .then(Commands.argument(SEED, StringArgumentType.string())
+                .then(Commands.argument(SEED, Arguments.string())
                         .executes(context -> {
-                            String argument = StringArgumentType.getString(context, SEED);
+                            String argument = Arguments.getString(context, SEED);
                             handleSeedCommand(argument);
                             return 0;
                         }));
index cf3594675920757d2c0b031048688ac92dff1e99..312c1fc8dd93cb493d9f74b5d6153c1f78a4eb8c 100644 (file)
@@ -4,11 +4,12 @@ import com.irtimaled.bbor.client.Player;
 import com.irtimaled.bbor.client.providers.SpawningSphereProvider;
 import com.mojang.brigadier.CommandDispatcher;
 import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import net.minecraft.client.Minecraft;
+import net.minecraft.command.CommandSource;
 import net.minecraft.command.Commands;
 import net.minecraft.command.ISuggestionProvider;
-import net.minecraft.command.arguments.Vec3Argument;
-import net.minecraft.util.math.Vec3d;
 import net.minecraft.world.EnumLightType;
 import net.minecraft.world.World;
 
@@ -19,21 +20,9 @@ public class SpawningSphereCommand {
     public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
         LiteralArgumentBuilder command = Commands.literal(COMMAND)
                 .then(Commands.literal(ArgumentNames.SET)
-                        .then(Commands.argument(ArgumentNames.POS, Vec3Argument.vec3())
-                                .executes(context -> {
-                                    Vec3d pos = Vec3Argument.getVec3(context, ArgumentNames.POS);
-                                    SpawningSphereProvider.setSphere(pos.x, pos.y, pos.z);
-
-                                    CommandHelper.feedback(context, "bbor.commands.spawningSphere.set");
-                                    return 0;
-                                }))
-                        .executes(context -> {
-                            Vec3d pos = context.getSource().getPos();
-                            SpawningSphereProvider.setSphere(pos.x, pos.y, pos.z);
-
-                            CommandHelper.feedback(context, "bbor.commands.spawningSphere.set");
-                            return 0;
-                        }))
+                        .then(Commands.argument(ArgumentNames.POS, Arguments.point())
+                                .executes(SpawningSphereCommand::setSphere))
+                        .executes(SpawningSphereCommand::setSphere))
                 .then(Commands.literal(ArgumentNames.CLEAR)
                         .executes(context -> {
                             boolean cleared = SpawningSphereProvider.clear();
@@ -66,6 +55,13 @@ public class SpawningSphereCommand {
         commandDispatcher.register(command);
     }
 
+    public static int setSphere(CommandContext<CommandSource> context) throws CommandSyntaxException {
+        SpawningSphereProvider.setSphere(Arguments.getPoint(context, ArgumentNames.POS).snapXZ(0.5d));
+
+        CommandHelper.feedback(context, "bbor.commands.spawningSphere.set");
+        return 0;
+    }
+
     private static class Counts {
         private int spawnable = 0;
         private int nightSpawnable = 0;
index a5a2a1ef9393cd9c4e15a2f18fe0c002456caa09..056b18b3de7695c90ab400e3c88f4e4806c711c4 100644 (file)
@@ -22,9 +22,7 @@ public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxS
     private static BoundingBoxSpawningSphere spawningSphere;
     private static Integer dimensionId;
 
-    public static void setSphere(double x, double y, double z) {
-        Point point = new Point(snapToNearestHalf(x), y, snapToNearestHalf(z));
-
+    public static void setSphere(Point point) {
         if (spawningSphere != null && spawningSphere.getPoint().equals(point)) return;
         clear();
 
@@ -33,13 +31,6 @@ public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxS
         lastBoundingBox = null;
     }
 
-    private static double snapToNearestHalf(double value) {
-        int floor = MathHelper.floor(value);
-        int fraction = MathHelper.floor((value - floor) * 4.0);
-        if (fraction % 2 == 1) fraction++;
-        return floor + (fraction / 4.0);
-    }
-
     public static boolean clear() {
         if (spawningSphere != null) {
             lastBoundingBox = null;
index 74b057adb94d7e28a382c6c98ffb8963ea59ad4e..2408aca5049b43df807bfcd710b47a6bad945032 100644 (file)
@@ -27,7 +27,7 @@ public class MobSpawnerRenderer extends AbstractRenderer<BoundingBoxMobSpawner>
     }
 
     private void renderActivationLine(OffsetPoint centerPoint) {
-        OffsetPoint playerPos = new OffsetPoint(Player.getX(), Player.getY(), Player.getZ());
+        OffsetPoint playerPos = new OffsetPoint(Player.getPoint());
         double distance = centerPoint.getDistance(playerPos);
         if (distance <= 20) {
             Color color = distance > 18 ? Color.RED : distance > 16 ? Colors.DARK_ORANGE : Color.GREEN;
index f780c16e53a09770550600eb4bc5e7ca8a44a269..9548239c0cc465a697bd2d2425b2cb5dd75a6313 100644 (file)
@@ -5,4 +5,13 @@ public class MathHelper {
         int intValue = (int) value;
         return value >= intValue ? intValue : intValue - 1;
     }
+
+    public static double snapToNearest(double value, double nearest) {
+        double multiplier = 2.0 / nearest;
+        int floor = floor(value);
+        int fraction = floor((value - floor) * multiplier);
+        int midpoint = (int) (multiplier / 2);
+        if (fraction % midpoint == 1) fraction++;
+        return floor + (fraction / multiplier);
+    }
 }
index 0768652d4ab6842d257a32216a9a4fb22f20675e..df3c36e679f7e76fc5d4588ee3461aafcb17d71f 100644 (file)
@@ -2,7 +2,8 @@ package com.irtimaled.bbor.common.models;
 
 import com.irtimaled.bbor.common.MathHelper;
 import com.irtimaled.bbor.common.TypeHelper;
-import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.Vec3d;
+import net.minecraft.util.math.Vec3i;
 
 public class Coords {
     private final int x;
@@ -21,10 +22,12 @@ public class Coords {
         this.z = MathHelper.floor(z);
     }
 
-    public Coords(BlockPos blockPos) {
-        this(blockPos.getX(), blockPos.getY(), blockPos.getZ());
+    public Coords(Vec3i pos) {
+        this(pos.getX(), pos.getY(), pos.getZ());
     }
 
+    public Coords(Vec3d pos) { this(pos.x, pos.y, pos.z); }
+
     public int getX() {
         return x;
     }
index 772bc1d725b4c109c3dd02905c998365a73d23be..a049d8379770ed61f3c1f6dd671761a9013c17d2 100644 (file)
@@ -1,6 +1,8 @@
 package com.irtimaled.bbor.common.models;
 
+import com.irtimaled.bbor.common.MathHelper;
 import com.irtimaled.bbor.common.TypeHelper;
+import net.minecraft.util.math.Vec3d;
 
 public class Point {
     private final double x;
@@ -19,6 +21,12 @@ public class Point {
         this.z = Coords.getZ();
     }
 
+    public Point(Vec3d pos) {
+        this.x = pos.x;
+        this.y = pos.y;
+        this.z = pos.z;
+    }
+
     public double getX() {
         return x;
     }
@@ -35,6 +43,12 @@ public class Point {
         return new Point(this.x + x, this.y + y, this.z + z);
     }
 
+    public Point snapXZ(double nearest) {
+        double x = MathHelper.snapToNearest(this.x, nearest);
+        double z = MathHelper.snapToNearest(this.z, nearest);
+        return new Point(x, this.y, z);
+    }
+
     public double getDistance(Point point) {
         double dx = this.x - point.x;
         double dy = this.y - point.y;
index aaea887cf72395c5fc24c73430080c4f0f2f0aa0..7ff6045bebcc77c72c4df24e31b3d785603532c4 100644 (file)
   "bbor.commands.beacon.cleared.all": "All custom beacons cleared",
   "bbor.commands.beacon.cleared": "Custom beacon cleared at [x=%d, y=%d, z=%d]",
   "bbor.commands.beacon.notFound": "No custom beacon found at [x=%d, y=%d, z=%d]",
-  "bbor.commands.beacon.expectedLevelInRange": "expected level between 1 and 4",
 
   "bbor.commands.box.added": "Box added with start [x=%d, y=%d, z=%d] and end [x=%d, y=%d, z=%d]",
   "bbor.commands.box.cleared.all": "All boxes cleared",
   "bbor.commands.box.cleared": "Box cleared with start [x=%d, y=%d, z=%d] and end [x=%d, y=%d, z=%d]",
   "bbor.commands.box.notFound": "No box found with start [x=%d, y=%d, z=%d] and end [x=%d, y=%d, z=%d]",
 
-  "bbor.commandArgument.invalid": "Invalid argument",
-
   "bbor.commands.spawningSphere.set": "Spawning sphere set",
   "bbor.commands.spawningSphere.notSet": "No spawning sphere set",
   "bbor.commands.spawningSphere.cleared": "Spawning sphere cleared",