From 40dcd31bb052248ebfdea8d7910023c41e31596e Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 10:01:30 +0200 Subject: [PATCH] added direction dtection and command running based on that --- .../java/carpet/commands/DrawCommand.java | 62 +++++++++++++------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index b23a0d81..6d5ce171 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -8,6 +8,8 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; + import net.minecraft.block.Block; import net.minecraft.block.pattern.CachedBlockPosition; import net.minecraft.server.command.ServerCommandSource; @@ -73,23 +75,27 @@ public class DrawCommand { .then(argument("radius", IntegerArgumentType.integer(1)) .then(argument("height",IntegerArgumentType.integer(1)) .then(argument("pointing up?",BoolArgumentType.bool()) - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawConey(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c, "pointing up?"), - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawConey(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c, "pointing up?"), - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") + .then(argument("which direction?", StringArgumentType.string()) + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> selectCone(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"), + StringArgumentType.getString(c,"which direction?"), + BlockStateArgumentType.getBlockState(c, "block"), null) + ) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> selectCone(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"), + StringArgumentType.getString(c,"which direction?"), + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) ) ) ) @@ -264,12 +270,32 @@ public class DrawCommand { return 1; } + private static int selectCone(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, String direction, BlockStateArgument block, + Predicate replacement){ + if(direction=="x"){ + drawConex(source, pos, radius, height, pointup, block, replacement); + } + + if(direction=="y"){ + drawConey(source, pos, radius, height, pointup, block, replacement); + } + + if(direction=="z"){ + drawConez(source, pos, radius, height, pointup, block, replacement); + } + + if(direction!="x" && direction!="y" && direction!="z"){ + Messenger.m(source,"Invalid direction, must be \"x\",\"y\" or \"z\""); + } + return(1); + } + private static int drawConey(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, BlockStateArgument block, Predicate replacement) { return (int) drawConey(source, pos, radius, height, block, replacement, pointup, false); } - private static int drawConey(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, + private static double drawConey(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, Predicate replacement, boolean pointup, boolean solid) { int affected = 0; int offset = 0;