From 67e3ed3229b2fab7047e588b776dd73e5bc81e21 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sat, 18 Apr 2020 13:49:07 +0200 Subject: [PATCH 01/34] Added draw command --- .../java/carpet/commands/DrawCommand.java | 90 ++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 41fbcda6..c1d3c510 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -21,6 +21,7 @@ import net.minecraft.server.world.ServerWorld; import java.util.List; import java.util.function.Predicate; +import java.lang.Math.abs; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -52,7 +53,35 @@ public class DrawCommand BlockStateArgumentType.getBlockState(c,"block"), BlockPredicateArgumentType.getBlockPredicate(c, "filter") - )))))))); + )))))))). + then(literal("diamond"). + then(argument("centre",BlockPosArgumentType.blockPos()). + then(argument("radius",IntegerArgumentType.integer(1)). + then(argument("block",BlockStateArgumentType.blockState()). + executes((c)->drawDiamond( + c.getSource(), + BlockPosArgumentType.getBlockPos(c,"centre"), + IntegerArgumentType.getInteger(c,"radius"), + BlockStateArgumentType.getBlockState(c,"block"), + null + ). + then(literal("replace"). + then(argument("filter",BlockPredicateArgumentType.blockPredicate()). + executes((c)->drawDiamond( + c.getSource(), + BlockPosArgumentType.getBlockPos(c, "centre"), + IntegerArgumentType.getInteger(c, "radius"), + BlockStateArgumentType.getBlockState(c,"block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) + ) + ) + ) + ) + ) + ) + ) + ); dispatcher.register(command); } @@ -161,4 +190,63 @@ public class DrawCommand { return (x * x) + (y * y) + (z * z); } + + private static int manhattan(int x1, int y1, int z1, int x2, int y2, int z2){ + return abs(x1-x2)+abs(y1-y2)+abs(z1-z2) + } + + private static int drawDiamond(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, + Predicate replacement){ + int affected =0; + + BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); + + List list = Lists.newArrayList(); + + ServerWorld world=source.getWorld(); + + CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; + + for(int x=-radius; x<=radius;++x){ + + for(int y=-radius; y<=radius; ++y){ + + for(int z=-radius; z<=radius; ++z){ + + if(manhattan(0,0,0,x,y,z)!=radius){continue}; + + mbpos.set(pos.getX()+x, pos.getY()+y, pos.getZ()+z); + + if (replacement == null || replacement.test(new CachedBlockPosition( world, mbpos, true))){ + BlockEntity tileentity = world.getBlockEntity(mbpos); + + if (tileentity instanceof Inventory){ + ((Inventory)tileentity).clear(); + } + + if (block.setBlockState(world, mbpos,2)){ + list.add(mbpos.toImmutable()); + ++affected; + } + } + } + } + } + + CarpetSettings.impendingFillSkipUpdates = false; + + if (CarpetSettings.fillUpdates) + { + + for (BlockPos blockpos1 : list) + { + Block blokc = world.getBlockState(blockpos1).getBlock(); + world.updateNeighbors(blockpos1, blokc); + } + } + + Messenger.m(source, "gi Filled "+affected+" blocks"); + + return 1; + } } From dab41bb0cef214624ff0f54891dd64f40c17e741 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sat, 18 Apr 2020 14:07:24 +0200 Subject: [PATCH 02/34] FIxed some stuff Still borken asf, but im not sure how to fix --- .../java/carpet/commands/DrawCommand.java | 181 ++++++++---------- 1 file changed, 75 insertions(+), 106 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index c1d3c510..f576967e 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -21,79 +21,55 @@ import net.minecraft.server.world.ServerWorld; import java.util.List; import java.util.function.Predicate; -import java.lang.Math.abs; +import java.lang.Math; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; -public class DrawCommand -{ - public static void register(CommandDispatcher dispatcher) - { - LiteralArgumentBuilder command = literal("draw"). - requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)). - then(literal("sphere"). - then(argument("center",BlockPosArgumentType.blockPos()). - then(argument("radius",IntegerArgumentType.integer(1)). - then(argument("block",BlockStateArgumentType.blockState()). - executes((c)-> drawCircle( - c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - BlockStateArgumentType.getBlockState (c,"block"), - null - ) - ). - then(literal("replace"). - then(argument("filter",BlockPredicateArgumentType.blockPredicate()) - .executes((c)-> drawCircle( - c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), +public class DrawCommand { + public static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder command = literal("draw") + .requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)) + .then(literal("sphere").then(argument("center", BlockPosArgumentType.blockPos()) + .then(argument("radius", IntegerArgumentType.integer(1)) + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawCircle(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + BlockStateArgumentType.getBlockState(c, "block"), null)) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawCircle(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c, + "filter"))))))))) + .then(literal("diamond").then(argument("centre", BlockPosArgumentType.blockPos()) + .then(argument("radius", IntegerArgumentType.integer(1)).then( + argument("block", BlockStateArgumentType.blockState()).executes((c) -> drawDiamond( + c.getSource(), BlockPosArgumentType.getBlockPos(c, "centre"), + IntegerArgumentType.getInteger(c, "radius"), + BlockStateArgumentType.getBlockState(c, "block"), null) + .then(literal("replace").then( + argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawDiamond(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "centre"), IntegerArgumentType.getInteger(c, "radius"), - BlockStateArgumentType.getBlockState(c,"block"), + BlockStateArgumentType.getBlockState(c, + "block"), BlockPredicateArgumentType.getBlockPredicate(c, - "filter") - )))))))). - then(literal("diamond"). - then(argument("centre",BlockPosArgumentType.blockPos()). - then(argument("radius",IntegerArgumentType.integer(1)). - then(argument("block",BlockStateArgumentType.blockState()). - executes((c)->drawDiamond( - c.getSource(), - BlockPosArgumentType.getBlockPos(c,"centre"), - IntegerArgumentType.getInteger(c,"radius"), - BlockStateArgumentType.getBlockState(c,"block"), - null - ). - then(literal("replace"). - then(argument("filter",BlockPredicateArgumentType.blockPredicate()). - executes((c)->drawDiamond( - c.getSource(), - BlockPosArgumentType.getBlockPos(c, "centre"), - IntegerArgumentType.getInteger(c, "radius"), - BlockStateArgumentType.getBlockState(c,"block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") - ) - ) - ) - ) - ) - ) - ) - ) - ); + "filter")))))))))); dispatcher.register(command); } - private static int drawCircle(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, - Predicate replacement) - { - return drawCircle(source, pos, (double)radius, (double)radius, (double)radius, block, replacement, false); + Predicate replacement) { + return drawCircle(source, pos, (double) radius, (double) radius, (double) radius, block, replacement, false); } - private static int drawCircle(ServerCommandSource source, BlockPos pos, double radiusX, double radiusY, double radiusZ, - BlockStateArgument block, Predicate replacement, boolean solid) - { + + private static int drawCircle(ServerCommandSource source, BlockPos pos, double radiusX, double radiusY, + double radiusZ, BlockStateArgument block, Predicate replacement, boolean solid) { int affected = 0; ServerWorld world = source.getWorld(); @@ -138,30 +114,25 @@ public class DrawCommand } if (!solid) { - if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) { + if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 + && lengthSq(xn, yn, nextZn) <= 1) { continue; } } CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; - for (int xmod = -1; xmod < 2; xmod+= 2) - { - for (int ymod = -1; ymod < 2; ymod += 2) - { - for (int zmod = -1; zmod < 2; zmod += 2) - { - mbpos.set(pos.getX()+xmod*x, pos.getY()+ymod*y, pos.getZ()+zmod*z); - if (replacement == null || replacement.test( - new CachedBlockPosition( world, mbpos, true))) - { + for (int xmod = -1; xmod < 2; xmod += 2) { + for (int ymod = -1; ymod < 2; ymod += 2) { + for (int zmod = -1; zmod < 2; zmod += 2) { + mbpos.set(pos.getX() + xmod * x, pos.getY() + ymod * y, pos.getZ() + zmod * z); + if (replacement == null + || replacement.test(new CachedBlockPosition(world, mbpos, true))) { BlockEntity tileentity = world.getBlockEntity(mbpos); - if (tileentity instanceof Inventory) - { - ((Inventory)tileentity).clear(); + if (tileentity instanceof Inventory) { + ((Inventory) tileentity).clear(); } - if (block.setBlockState(world, mbpos,2)) - { + if (block.setBlockState(world, mbpos, 2)) { list.add(mbpos.toImmutable()); ++affected; } @@ -173,58 +144,58 @@ public class DrawCommand } } } - if (CarpetSettings.fillUpdates) - { + if (CarpetSettings.fillUpdates) { - for (BlockPos blockpos1 : list) - { + for (BlockPos blockpos1 : list) { Block blokc = world.getBlockState(blockpos1).getBlock(); world.updateNeighbors(blockpos1, blokc); // or always version???? } } - Messenger.m(source, "gi Filled "+affected+" blocks"); + Messenger.m(source, "gi Filled " + affected + " blocks"); return 1; } - private static double lengthSq(double x, double y, double z) - { + + private static double lengthSq(double x, double y, double z) { return (x * x) + (y * y) + (z * z); } - private static int manhattan(int x1, int y1, int z1, int x2, int y2, int z2){ - return abs(x1-x2)+abs(y1-y2)+abs(z1-z2) + private static int manhattan(int x1, int y1, int z1, int x2, int y2, int z2) { + return Math.abs(x1 - x2) + Math.abs(y1 - y2) + Math.abs(z1 - z2); } - private static int drawDiamond(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, - Predicate replacement){ - int affected =0; + private static int drawDiamond(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, + Predicate replacement) { + int affected = 0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); List list = Lists.newArrayList(); - ServerWorld world=source.getWorld(); + ServerWorld world = source.getWorld(); CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; - for(int x=-radius; x<=radius;++x){ + for (int x = -radius; x <= radius; ++x) { - for(int y=-radius; y<=radius; ++y){ + for (int y = -radius; y <= radius; ++y) { - for(int z=-radius; z<=radius; ++z){ + for (int z = -radius; z <= radius; ++z) { - if(manhattan(0,0,0,x,y,z)!=radius){continue}; + if (manhattan(0, 0, 0, x, y, z) != radius) { + continue; + } - mbpos.set(pos.getX()+x, pos.getY()+y, pos.getZ()+z); + mbpos.set(pos.getX() + x, pos.getY() + y, pos.getZ() + z); - if (replacement == null || replacement.test(new CachedBlockPosition( world, mbpos, true))){ + if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { BlockEntity tileentity = world.getBlockEntity(mbpos); - if (tileentity instanceof Inventory){ - ((Inventory)tileentity).clear(); + if (tileentity instanceof Inventory) { + ((Inventory) tileentity).clear(); } - - if (block.setBlockState(world, mbpos,2)){ + + if (block.setBlockState(world, mbpos, 2)) { list.add(mbpos.toImmutable()); ++affected; } @@ -235,17 +206,15 @@ public class DrawCommand CarpetSettings.impendingFillSkipUpdates = false; - if (CarpetSettings.fillUpdates) - { + if (CarpetSettings.fillUpdates) { - for (BlockPos blockpos1 : list) - { + for (BlockPos blockpos1 : list) { Block blokc = world.getBlockState(blockpos1).getBlock(); world.updateNeighbors(blockpos1, blokc); } } - Messenger.m(source, "gi Filled "+affected+" blocks"); + Messenger.m(source, "gi Filled " + affected + " blocks"); return 1; } From 08e42523ba6ad46f9c58c4407fccd88d82d78b22 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sat, 18 Apr 2020 14:12:26 +0200 Subject: [PATCH 03/34] I thinks this helped? --- src/main/java/carpet/commands/DrawCommand.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index f576967e..6d726477 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -165,7 +165,13 @@ public class DrawCommand { } private static int drawDiamond(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, - Predicate replacement) { + Predicate replacement) { + return (int) drawDiamond(source, pos, radius, block, replacement, false); + } + + private static double drawDiamond(ServerCommandSource source, BlockPos pos, int radius, + BlockStateArgument block, + Predicate replacement, boolean solid) { int affected = 0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); From fe9ad4b29789d094cb691292b9022a6a4cd2d1af Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sat, 18 Apr 2020 18:31:18 +0200 Subject: [PATCH 04/34] I hope this works I copy pasted above code and edited a bit to see if it works (Btw, that is basically how I did #224) --- .../java/carpet/commands/DrawCommand.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 6d726477..d1a561e8 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -45,21 +45,28 @@ public class DrawCommand { BlockStateArgumentType.getBlockState(c, "block"), BlockPredicateArgumentType.getBlockPredicate(c, "filter"))))))))) - .then(literal("diamond").then(argument("centre", BlockPosArgumentType.blockPos()) - .then(argument("radius", IntegerArgumentType.integer(1)).then( - argument("block", BlockStateArgumentType.blockState()).executes((c) -> drawDiamond( - c.getSource(), BlockPosArgumentType.getBlockPos(c, "centre"), - IntegerArgumentType.getInteger(c, "radius"), - BlockStateArgumentType.getBlockState(c, "block"), null) - .then(literal("replace").then( - argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawDiamond(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "centre"), - IntegerArgumentType.getInteger(c, "radius"), - BlockStateArgumentType.getBlockState(c, - "block"), - BlockPredicateArgumentType.getBlockPredicate(c, - "filter")))))))))); + .then(literal("diamond").then(argument("center", BlockPosArgumentType.blockPos()) + .then(argument("radius", IntegerArgumentType.integer(1)) + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawDiamond(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + BlockStateArgumentType.getBlockState(c, "block"), null)) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawDiamond(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) + ) + ) + ) + ) + ) + ) + ); dispatcher.register(command); } @@ -169,8 +176,7 @@ public class DrawCommand { return (int) drawDiamond(source, pos, radius, block, replacement, false); } - private static double drawDiamond(ServerCommandSource source, BlockPos pos, int radius, - BlockStateArgument block, + private static int drawDiamond(ServerCommandSource source, BlockPos pos, int radius,BlockStateArgument block, Predicate replacement, boolean solid) { int affected = 0; From 11f1ce61b795fc8aba45d12a533ef6808541de9f Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sat, 18 Apr 2020 22:23:34 +0200 Subject: [PATCH 05/34] Added cone y not --- .../java/carpet/commands/DrawCommand.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index d1a561e8..6fba527e 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -6,6 +6,7 @@ import carpet.utils.Messenger; import com.google.common.collect.Lists; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import net.minecraft.block.Block; import net.minecraft.block.pattern.CachedBlockPosition; @@ -66,6 +67,38 @@ public class DrawCommand { ) ) ) + ) + .then(literal("cone") + .then(argument("center", BlockPosArgumentType.blockPos()) + .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) -> drawCone(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) -> drawCone(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") + ) + ) + ) + ) + ) + ) + ) + ) + ) ); dispatcher.register(command); } @@ -230,4 +263,67 @@ public class DrawCommand { return 1; } + + private static int drawCone(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, BlockStateArgument block, + Predicate replacement) { + return (int) drawCone(source, pos, radius, height, block, replacement, pointup, false); + } + + private static int drawCone(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, + Predicate replacement, boolean pointup, boolean solid) { + int affected = 0; + int offset = 0; + if(pointup){ + offset=height; + } + BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); + + List list = Lists.newArrayList(); + + ServerWorld world = source.getWorld(); + + CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; + + for (int x = -radius; x <= radius; ++x) { + + for (int y = -offset; y <= height+1-offset; ++y) { + + for (int z = -radius; z <= radius; ++z) { + + if (x*x+z*z>(radius/height*y)*(radius/height*y)) { + continue; + } + + mbpos.set(pos.getX() + x, pos.getY() + y + offset, pos.getZ() + z); + + if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { + BlockEntity tileentity = world.getBlockEntity(mbpos); + + if (tileentity instanceof Inventory) { + ((Inventory) tileentity).clear(); + } + + if (block.setBlockState(world, mbpos, 2)) { + list.add(mbpos.toImmutable()); + ++affected; + } + } + } + } + } + + CarpetSettings.impendingFillSkipUpdates = false; + + if (CarpetSettings.fillUpdates) { + + for (BlockPos blockpos1 : list) { + Block blokc = world.getBlockState(blockpos1).getBlock(); + world.updateNeighbors(blockpos1, blokc); + } + } + + Messenger.m(source, "gi Filled " + affected + " blocks"); + + return 1; + } } From 776eec05b2d6bf885c4d3ce0f62edff7aa3bea44 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 09:10:32 +0200 Subject: [PATCH 06/34] I think that fixed it But now its conctantly crashing --- src/main/java/carpet/commands/DrawCommand.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 6fba527e..5ba454d7 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -274,7 +274,7 @@ public class DrawCommand { int affected = 0; int offset = 0; if(pointup){ - offset=height; + offset=height+1; } BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); @@ -286,16 +286,15 @@ public class DrawCommand { for (int x = -radius; x <= radius; ++x) { - for (int y = -offset; y <= height+1-offset; ++y) { + for (int y = 2-offset; y <= height-offset+1; ++y) { for (int z = -radius; z <= radius; ++z) { - if (x*x+z*z>(radius/height*y)*(radius/height*y)) { + if (!(x*x+z*z<=(radius/height*y)*(radius/height*y))) { continue; } mbpos.set(pos.getX() + x, pos.getY() + y + offset, pos.getZ() + z); - if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { BlockEntity tileentity = world.getBlockEntity(mbpos); From 432c2a8394426c3f03c3cd8c4ad7beb0717ebc1b Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 09:23:47 +0200 Subject: [PATCH 07/34] Now it works But if it is pointing up, it has a flat top --- src/main/java/carpet/commands/DrawCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 5ba454d7..d49f8cb7 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -274,7 +274,7 @@ public class DrawCommand { int affected = 0; int offset = 0; if(pointup){ - offset=height+1; + offset=height; } BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); @@ -286,7 +286,7 @@ public class DrawCommand { for (int x = -radius; x <= radius; ++x) { - for (int y = 2-offset; y <= height-offset+1; ++y) { + for (int y = -offset; y <= height-offset-1; ++y) { for (int z = -radius; z <= radius; ++z) { From 6d5c7ed3bd427098827b7dd3586b0aa46dde2d3d Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 09:29:41 +0200 Subject: [PATCH 08/34] Ok, NOW it works! --- src/main/java/carpet/commands/DrawCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index d49f8cb7..c6c9edcd 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -274,7 +274,7 @@ public class DrawCommand { int affected = 0; int offset = 0; if(pointup){ - offset=height; + offset=height-1; } BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); From 25e8543a116078a46ae633fa8befc4755606d86b Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 09:32:41 +0200 Subject: [PATCH 09/34] changing name to drawConey So later I can add drawConex and draw Conez methods --- src/main/java/carpet/commands/DrawCommand.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index c6c9edcd..a17123d3 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -74,7 +74,7 @@ public class DrawCommand { .then(argument("height",IntegerArgumentType.integer(1)) .then(argument("pointing up?",BoolArgumentType.bool()) .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawCone(c.getSource(), + .executes((c) -> drawConey(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), @@ -83,7 +83,7 @@ public class DrawCommand { ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawCone(c.getSource(), + .executes((c) -> drawConey(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), @@ -264,12 +264,12 @@ public class DrawCommand { return 1; } - private static int drawCone(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, BlockStateArgument block, + private static int drawConey(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, BlockStateArgument block, Predicate replacement) { - return (int) drawCone(source, pos, radius, height, block, replacement, pointup, false); + return (int) drawConey(source, pos, radius, height, block, replacement, pointup, false); } - private static int drawCone(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, + private static int drawConey(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, Predicate replacement, boolean pointup, boolean solid) { int affected = 0; int offset = 0; From 5aea313479b75a34574369a9731bff916d8a9352 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 09:36:15 +0200 Subject: [PATCH 10/34] Added drawConex and drawConez methods But they're not used yet --- .../java/carpet/commands/DrawCommand.java | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index a17123d3..b23a0d81 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -325,4 +325,128 @@ public class DrawCommand { return 1; } + + private static int drawConex(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, BlockStateArgument block, + Predicate replacement) { + return (int) drawConex(source, pos, radius, height, block, replacement, pointup, false); + } + + private static int drawConex(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, + Predicate replacement, boolean pointup, boolean solid) { + int affected = 0; + int offset = 0; + if(pointup){ + offset=height-1; + } + BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); + + List list = Lists.newArrayList(); + + ServerWorld world = source.getWorld(); + + CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; + + for (int x = -offset; x <= height-offset-1; ++x) { + + for (int y = -radius; y <= radius; ++y) { + + for (int z = -radius; z <= radius; ++z) { + + if (!(y*y+z*z<=(radius/height*x)*(radius/height*x))) { + continue; + } + + mbpos.set(pos.getX() + x+ offset, pos.getY() + y, pos.getZ() + z); + if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { + BlockEntity tileentity = world.getBlockEntity(mbpos); + + if (tileentity instanceof Inventory) { + ((Inventory) tileentity).clear(); + } + + if (block.setBlockState(world, mbpos, 2)) { + list.add(mbpos.toImmutable()); + ++affected; + } + } + } + } + } + + CarpetSettings.impendingFillSkipUpdates = false; + + if (CarpetSettings.fillUpdates) { + + for (BlockPos blockpos1 : list) { + Block blokc = world.getBlockState(blockpos1).getBlock(); + world.updateNeighbors(blockpos1, blokc); + } + } + + Messenger.m(source, "gi Filled " + affected + " blocks"); + + return 1; + } + + private static int drawConez(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, BlockStateArgument block, + Predicate replacement) { + return (int) drawConez(source, pos, radius, height, block, replacement, pointup, false); + } + + private static int drawConez(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, + Predicate replacement, boolean pointup, boolean solid) { + int affected = 0; + int offset = 0; + if(pointup){ + offset=height-1; + } + BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); + + List list = Lists.newArrayList(); + + ServerWorld world = source.getWorld(); + + CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; + + for (int z = -offset; z <= height-offset-1; ++z) { + + for (int y = -radius; y <= radius; ++y) { + + for (int x = -radius; x <= radius; ++x) { + + if (!(x*x+y*y<=(radius/height*z)*(radius/height*z))) { + continue; + } + + mbpos.set(pos.getX() + x, pos.getY() + y, pos.getZ() + z + offset); + if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { + BlockEntity tileentity = world.getBlockEntity(mbpos); + + if (tileentity instanceof Inventory) { + ((Inventory) tileentity).clear(); + } + + if (block.setBlockState(world, mbpos, 2)) { + list.add(mbpos.toImmutable()); + ++affected; + } + } + } + } + } + + CarpetSettings.impendingFillSkipUpdates = false; + + if (CarpetSettings.fillUpdates) { + + for (BlockPos blockpos1 : list) { + Block blokc = world.getBlockState(blockpos1).getBlock(); + world.updateNeighbors(blockpos1, blokc); + } + } + + Messenger.m(source, "gi Filled " + affected + " blocks"); + + return 1; + } } 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 11/34] 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; From 771fc8a437746874c21611f263879c14c0ccd1fd Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 10:03:11 +0200 Subject: [PATCH 12/34] added specific return statements I dont even know why --- src/main/java/carpet/commands/DrawCommand.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 6d5ce171..4bd83166 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -272,22 +272,27 @@ public class DrawCommand { private static int selectCone(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, String direction, BlockStateArgument block, Predicate replacement){ + int succeeded=0; + if(direction=="x"){ drawConex(source, pos, radius, height, pointup, block, replacement); + succeeded=1; } if(direction=="y"){ drawConey(source, pos, radius, height, pointup, block, replacement); + succeeded=1; } if(direction=="z"){ drawConez(source, pos, radius, height, pointup, block, replacement); + succeeded=1; } if(direction!="x" && direction!="y" && direction!="z"){ Messenger.m(source,"Invalid direction, must be \"x\",\"y\" or \"z\""); } - return(1); + return succeeded; } private static int drawConey(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, BlockStateArgument block, From b16c0abc54ccd5e6bac66b8e7ff4a65a9622ff91 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 10:23:53 +0200 Subject: [PATCH 13/34] I tried this way But it wont detect strings ofr some reason!? --- src/main/java/carpet/commands/DrawCommand.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 4bd83166..2d270c9e 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -93,8 +93,8 @@ public class DrawCommand { IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"), StringArgumentType.getString(c,"which direction?"), - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") ) ) ) @@ -274,6 +274,8 @@ public class DrawCommand { Predicate replacement){ int succeeded=0; + direction=direction.toLowerCase().replaceAll("\\s",""); + if(direction=="x"){ drawConex(source, pos, radius, height, pointup, block, replacement); succeeded=1; @@ -290,7 +292,8 @@ public class DrawCommand { } if(direction!="x" && direction!="y" && direction!="z"){ - Messenger.m(source,"Invalid direction, must be \"x\",\"y\" or \"z\""); + Messenger.m(source,"gi "+direction+" is an invalid direction, must be x, y or z"); + System.out.println(direction); } return succeeded; } From 4a02bb1572e998278a90f1d98308cab6722ad56c Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 10:33:42 +0200 Subject: [PATCH 14/34] The stupid way At least it works --- .../java/carpet/commands/DrawCommand.java | 85 +++++++++++-------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 2d270c9e..f40e7d42 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -8,7 +8,6 @@ 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; @@ -75,24 +74,70 @@ public class DrawCommand { .then(argument("radius", IntegerArgumentType.integer(1)) .then(argument("height",IntegerArgumentType.integer(1)) .then(argument("pointing up?",BoolArgumentType.bool()) - .then(argument("which direction?", StringArgumentType.string()) + .then(literal("x") .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> selectCone(c.getSource(), + .executes((c) -> drawConex(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(), + .executes((c) -> drawConex(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(literal("y") + .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(literal("z") + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawConez(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) -> drawConez(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") ) @@ -270,34 +315,6 @@ 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){ - int succeeded=0; - - direction=direction.toLowerCase().replaceAll("\\s",""); - - if(direction=="x"){ - drawConex(source, pos, radius, height, pointup, block, replacement); - succeeded=1; - } - - if(direction=="y"){ - drawConey(source, pos, radius, height, pointup, block, replacement); - succeeded=1; - } - - if(direction=="z"){ - drawConez(source, pos, radius, height, pointup, block, replacement); - succeeded=1; - } - - if(direction!="x" && direction!="y" && direction!="z"){ - Messenger.m(source,"gi "+direction+" is an invalid direction, must be x, y or z"); - System.out.println(direction); - } - return succeeded; - } - 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); From 571e5722a812be4973baea35e8087a70ee0d7029 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 19 Apr 2020 10:51:15 +0200 Subject: [PATCH 15/34] added wiki definition to ingame definition cos y not --- src/main/java/carpet/CarpetSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index cb9a3598..9f55f8d4 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -299,7 +299,7 @@ public class CarpetSettings ) public static String commandPerimeterInfo = "true"; - @Rule(desc = "Enables /draw commands", extra = "... allows for drawing simple shapes", category = COMMAND) + @Rule(desc = "Enables /draw commands", extra = "... allows for drawing simple shapes or other shapes which are sorta difficult to do normally", category = COMMAND) public static String commandDraw = "true"; @Rule( From 7783f60f6474a8e6bf0353711c21da2d9604062e Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 11:52:07 +0200 Subject: [PATCH 16/34] This should be about 300% faster I completely revamped it, only iterate over necessary blocks, and it returns correct value --- .../java/carpet/commands/DrawCommand.java | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index f40e7d42..ba2fd8ef 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -6,6 +6,7 @@ import carpet.utils.Messenger; import com.google.common.collect.Lists; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; + import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; @@ -251,8 +252,23 @@ public class DrawCommand { return (x * x) + (y * y) + (z * z); } - private static int manhattan(int x1, int y1, int z1, int x2, int y2, int z2) { - return Math.abs(x1 - x2) + Math.abs(y1 - y2) + Math.abs(z1 - z2); + private static int blockset(ServerCommandSource source, int x, int y, int z, Predicate replacement, List list, + BlockPos.Mutable mbpos, BlockStateArgument block){ + ServerWorld world = source.getWorld(); + mbpos.set(x, y, z); + int success=0; + if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { + BlockEntity tileentity = world.getBlockEntity(mbpos); + if (tileentity instanceof Inventory) { + ((Inventory) tileentity).clear(); + } + if (block.setBlockState(world, mbpos, 2)) { + list.add(mbpos.toImmutable()); + ++success; + } + } + + return success; } private static int drawDiamond(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, @@ -262,44 +278,30 @@ public class DrawCommand { private static int drawDiamond(ServerCommandSource source, BlockPos pos, int radius,BlockStateArgument block, Predicate replacement, boolean solid) { - int affected = 0; + int affected=0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); - List list = Lists.newArrayList(); ServerWorld world = source.getWorld(); CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; + int skipped=0;//testing-delete afterwards + for (int r = 0; r < radius; ++r) { + int y=r-radius+1; + for (int x = -r; x <= r; ++x) { + int z=r-Math.abs(x); - for (int x = -radius; x <= radius; ++x) { - - for (int y = -radius; y <= radius; ++y) { - - for (int z = -radius; z <= radius; ++z) { - - if (manhattan(0, 0, 0, x, y, z) != radius) { - continue; - } - - mbpos.set(pos.getX() + x, pos.getY() + y, pos.getZ() + z); - - if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { - BlockEntity tileentity = world.getBlockEntity(mbpos); - - if (tileentity instanceof Inventory) { - ((Inventory) tileentity).clear(); - } - - if (block.setBlockState(world, mbpos, 2)) { - list.add(mbpos.toImmutable()); - ++affected; - } - } - } + affected+=blockset(source, pos.getX()+x, pos.getY()-y, pos.getZ()+z, replacement, list, mbpos, block); + affected+=blockset(source, pos.getX()+x, pos.getY()-y, pos.getZ()-z, replacement, list, mbpos, block); + affected+=blockset(source, pos.getX()+x, pos.getY()+y, pos.getZ()+z, replacement, list, mbpos, block); + affected+=blockset(source, pos.getX()+x, pos.getY()+y, pos.getZ()-z, replacement, list, mbpos, block); } } + + System.out.println("Skipped: "+skipped);//testing-delete afterwards + CarpetSettings.impendingFillSkipUpdates = false; if (CarpetSettings.fillUpdates) { From aa94ec0ebc3df106db1b6f1d649c4e6fae1debd1 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 11:54:52 +0200 Subject: [PATCH 17/34] forgot to remove testing stuff I knew this would happen --- src/main/java/carpet/commands/DrawCommand.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index ba2fd8ef..8f5a9858 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -286,7 +286,7 @@ public class DrawCommand { ServerWorld world = source.getWorld(); CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; - int skipped=0;//testing-delete afterwards + for (int r = 0; r < radius; ++r) { int y=r-radius+1; for (int x = -r; x <= r; ++x) { @@ -299,9 +299,6 @@ public class DrawCommand { } } - - System.out.println("Skipped: "+skipped);//testing-delete afterwards - CarpetSettings.impendingFillSkipUpdates = false; if (CarpetSettings.fillUpdates) { From fe0ecccd4f079efb24dc99938f747a5c8c8fb6c7 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 13:44:49 +0200 Subject: [PATCH 18/34] Made drawCone WAY more fficient and code WAY less messy --- .../java/carpet/commands/DrawCommand.java | 214 +++++------------- 1 file changed, 57 insertions(+), 157 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 8f5a9858..9c0efe4c 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -36,13 +36,13 @@ public class DrawCommand { .then(literal("sphere").then(argument("center", BlockPosArgumentType.blockPos()) .then(argument("radius", IntegerArgumentType.integer(1)) .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawCircle(c.getSource(), + .executes((c) -> drawSphere(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), BlockStateArgumentType.getBlockState(c, "block"), null)) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawCircle(c.getSource(), + .executes((c) -> drawSphere(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), BlockStateArgumentType.getBlockState(c, "block"), @@ -77,20 +77,20 @@ public class DrawCommand { .then(argument("pointing up?",BoolArgumentType.bool()) .then(literal("x") .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawConex(c.getSource(), + .executes((c) -> drawCone(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"), + BoolArgumentType.getBool(c,"pointing up?"),"x", BlockStateArgumentType.getBlockState(c, "block"), null) ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawConex(c.getSource(), + .executes((c) -> drawCone(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"), + BoolArgumentType.getBool(c,"pointing up?"),"x", BlockStateArgumentType.getBlockState(c, "block"), BlockPredicateArgumentType.getBlockPredicate(c,"filter") ) @@ -101,20 +101,20 @@ public class DrawCommand { ) .then(literal("y") .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawConey(c.getSource(), + .executes((c) -> drawCone(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"), + BoolArgumentType.getBool(c,"pointing up?"),"y", BlockStateArgumentType.getBlockState(c, "block"), null) ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawConey(c.getSource(), + .executes((c) -> drawCone(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"), + BoolArgumentType.getBool(c,"pointing up?"),"y", BlockStateArgumentType.getBlockState(c, "block"), BlockPredicateArgumentType.getBlockPredicate(c,"filter") ) @@ -125,20 +125,20 @@ public class DrawCommand { ) .then(literal("z") .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawConez(c.getSource(), + .executes((c) -> drawCone(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"), + BoolArgumentType.getBool(c,"pointing up?"),"z", BlockStateArgumentType.getBlockState(c, "block"), null) ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawConez(c.getSource(), + .executes((c) -> drawCone(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"), + BoolArgumentType.getBool(c,"pointing up?"),"z", BlockStateArgumentType.getBlockState(c, "block"), BlockPredicateArgumentType.getBlockPredicate(c,"filter") ) @@ -155,12 +155,12 @@ public class DrawCommand { dispatcher.register(command); } - private static int drawCircle(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, + private static int drawSphere(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, Predicate replacement) { - return drawCircle(source, pos, (double) radius, (double) radius, (double) radius, block, replacement, false); + return drawSphere(source, pos, (double) radius, (double) radius, (double) radius, block, replacement, false); } - private static int drawCircle(ServerCommandSource source, BlockPos pos, double radiusX, double radiusY, + private static int drawSphere(ServerCommandSource source, BlockPos pos, double radiusX, double radiusY, double radiusZ, BlockStateArgument block, Predicate replacement, boolean solid) { int affected = 0; ServerWorld world = source.getWorld(); @@ -314,80 +314,56 @@ public class DrawCommand { 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 drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius, int height, boolean pointup, BlockStateArgument block, String orientation, + Predicate replacement, List list, BlockPos.Mutable mbpos){ + + if(orientation=="x"){ + for(int y=-radius;y<=radius;++y){ - 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; - if(pointup){ - offset=height-1; - } - BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); + for(int z=-radius;z<=radius;++z){ - List list = Lists.newArrayList(); - - ServerWorld world = source.getWorld(); - - CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; - - for (int x = -radius; x <= radius; ++x) { - - for (int y = -offset; y <= height-offset-1; ++y) { - - for (int z = -radius; z <= radius; ++z) { - - if (!(x*x+z*z<=(radius/height*y)*(radius/height*y))) { - continue; - } - - mbpos.set(pos.getX() + x, pos.getY() + y + offset, pos.getZ() + z); - if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { - BlockEntity tileentity = world.getBlockEntity(mbpos); - - if (tileentity instanceof Inventory) { - ((Inventory) tileentity).clear(); - } - - if (block.setBlockState(world, mbpos, 2)) { - list.add(mbpos.toImmutable()); - ++affected; - } + if(y*y+z*z<=radius*radius){ + blockset(source, pos.getX()+offset, pos.getY()+y, pos.getZ()+z, replacement, list, mbpos, block); } } } } - CarpetSettings.impendingFillSkipUpdates = false; + if(orientation=="y"){ + for(int x=-radius;x<=radius;++x){ - if (CarpetSettings.fillUpdates) { + for(int z=-radius;z<=radius;++z){ - for (BlockPos blockpos1 : list) { - Block blokc = world.getBlockState(blockpos1).getBlock(); - world.updateNeighbors(blockpos1, blokc); + if(x*x+z*z<=radius*radius){ + blockset(source, pos.getX()+x, pos.getY()+offset, pos.getZ()+z, replacement, list, mbpos, block); + } + } } } - Messenger.m(source, "gi Filled " + affected + " blocks"); + if(orientation=="z"){ + for(int y=-radius;y<=radius;++y){ + + for(int x=-radius;x<=radius;++x){ + + if(y*y+x*x<=radius*radius){ + blockset(source, pos.getX()+x, pos.getY()+y, pos.getZ()+offset, replacement, list, mbpos, block); + } + } + } + } return 1; } - - private static int drawConex(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, BlockStateArgument block, + + private static int drawCone(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, String orientation, BlockStateArgument block, Predicate replacement) { - return (int) drawConex(source, pos, radius, height, block, replacement, pointup, false); + return (int) drawCone(source, pos, radius, height, block, replacement, pointup, orientation, false); } - private static int drawConex(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, - Predicate replacement, boolean pointup, boolean solid) { + private static double drawCone(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, + Predicate replacement, boolean pointup, String orientation, boolean solid) { int affected = 0; - int offset = 0; - if(pointup){ - offset=height-1; - } BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); List list = Lists.newArrayList(); @@ -396,95 +372,19 @@ public class DrawCommand { CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; - for (int x = -offset; x <= height-offset-1; ++x) { + int r = radius; - for (int y = -radius; y <= radius; ++y) { - - for (int z = -radius; z <= radius; ++z) { - - if (!(y*y+z*z<=(radius/height*x)*(radius/height*x))) { - continue; - } - - mbpos.set(pos.getX() + x+ offset, pos.getY() + y, pos.getZ() + z); - if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { - BlockEntity tileentity = world.getBlockEntity(mbpos); - - if (tileentity instanceof Inventory) { - ((Inventory) tileentity).clear(); - } - - if (block.setBlockState(world, mbpos, 2)) { - list.add(mbpos.toImmutable()); - ++affected; - } - } - } + for(int i =0; i replacement) { - return (int) drawConez(source, pos, radius, height, block, replacement, pointup, false); - } - - private static int drawConez(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, - Predicate replacement, boolean pointup, boolean solid) { - int affected = 0; - int offset = 0; - if(pointup){ - offset=height-1; - } - BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); - - List list = Lists.newArrayList(); - - ServerWorld world = source.getWorld(); - - CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; - - for (int z = -offset; z <= height-offset-1; ++z) { - - for (int y = -radius; y <= radius; ++y) { - - for (int x = -radius; x <= radius; ++x) { - - if (!(x*x+y*y<=(radius/height*z)*(radius/height*z))) { - continue; - } - - mbpos.set(pos.getX() + x, pos.getY() + y, pos.getZ() + z + offset); - if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { - BlockEntity tileentity = world.getBlockEntity(mbpos); - - if (tileentity instanceof Inventory) { - ((Inventory) tileentity).clear(); - } - - if (block.setBlockState(world, mbpos, 2)) { - list.add(mbpos.toImmutable()); - ++affected; - } - } - } - } - } - + CarpetSettings.impendingFillSkipUpdates = false; if (CarpetSettings.fillUpdates) { From e0828513fa93c5d65289a5223606ac1f879e3ea6 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 17:00:51 +0200 Subject: [PATCH 19/34] Added pyramid literal FIrst step towards adding other shape pyramids --- .../java/carpet/commands/DrawCommand.java | 125 +++++++++--------- 1 file changed, 64 insertions(+), 61 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 9c0efe4c..853b8e6f 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -70,77 +70,79 @@ public class DrawCommand { ) ) ) - .then(literal("cone") - .then(argument("center", BlockPosArgumentType.blockPos()) - .then(argument("radius", IntegerArgumentType.integer(1)) - .then(argument("height",IntegerArgumentType.integer(1)) - .then(argument("pointing up?",BoolArgumentType.bool()) - .then(literal("x") - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawCone(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"x", - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawCone(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"x", - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") + .then(literal("pyramid") + .then(literal("cone") + .then(argument("center", BlockPosArgumentType.blockPos()) + .then(argument("radius", IntegerArgumentType.integer(1)) + .then(argument("height",IntegerArgumentType.integer(1)) + .then(argument("pointing up?",BoolArgumentType.bool()) + .then(literal("x") + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawCone(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"x", + BlockStateArgumentType.getBlockState(c, "block"), null) + ) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawCone(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"x", + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) ) ) ) ) ) - ) - .then(literal("y") - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawCone(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"y", - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawCone(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"y", - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") + .then(literal("y") + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawCone(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"y", + BlockStateArgumentType.getBlockState(c, "block"), null) + ) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawCone(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"y", + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) ) ) ) ) ) - ) - .then(literal("z") - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawCone(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"z", - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawCone(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"z", - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") + .then(literal("z") + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawCone(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"z", + BlockStateArgumentType.getBlockState(c, "block"), null) + ) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawCone(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"z", + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) ) ) ) @@ -151,6 +153,7 @@ public class DrawCommand { ) ) ) + ); dispatcher.register(command); } From 94a0f5584046f6986bb1850d1dc64497fcf4ac0c Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 17:20:15 +0200 Subject: [PATCH 20/34] undid eqyptian braces I hope you're happy now https://github.com/gnembon/fabric-carpet/pull/232#discussion_r411022932 --- .../java/carpet/commands/DrawCommand.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 853b8e6f..0dd280ff 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -159,12 +159,14 @@ public class DrawCommand { } private static int drawSphere(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block, - Predicate replacement) { + Predicate replacement) + { return drawSphere(source, pos, (double) radius, (double) radius, (double) radius, block, replacement, false); } private static int drawSphere(ServerCommandSource source, BlockPos pos, double radiusX, double radiusY, - double radiusZ, BlockStateArgument block, Predicate replacement, boolean solid) { + double radiusZ, BlockStateArgument block, Predicate replacement, boolean solid) + { int affected = 0; ServerWorld world = source.getWorld(); @@ -209,25 +211,30 @@ public class DrawCommand { } if (!solid) { - if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 - && lengthSq(xn, yn, nextZn) <= 1) { + if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) + { continue; } } CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; - for (int xmod = -1; xmod < 2; xmod += 2) { - for (int ymod = -1; ymod < 2; ymod += 2) { - for (int zmod = -1; zmod < 2; zmod += 2) { + for (int xmod = -1; xmod < 2; xmod += 2) + { + for (int ymod = -1; ymod < 2; ymod += 2) + { + for (int zmod = -1; zmod < 2; zmod += 2) + { mbpos.set(pos.getX() + xmod * x, pos.getY() + ymod * y, pos.getZ() + zmod * z); if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true))) { BlockEntity tileentity = world.getBlockEntity(mbpos); - if (tileentity instanceof Inventory) { + if (tileentity instanceof Inventory) + { ((Inventory) tileentity).clear(); } - if (block.setBlockState(world, mbpos, 2)) { + if (block.setBlockState(world, mbpos, 2)) + { list.add(mbpos.toImmutable()); ++affected; } From 36797a79e22c98cc271f2126d9563688d6f1f4d9 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 17:22:56 +0200 Subject: [PATCH 21/34] Made cone actually return affected blocks I forgot for some reason --- src/main/java/carpet/commands/DrawCommand.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 0dd280ff..34ae1c06 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -326,14 +326,14 @@ public class DrawCommand { private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius, int height, boolean pointup, BlockStateArgument block, String orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ - + int successes=0; if(orientation=="x"){ for(int y=-radius;y<=radius;++y){ for(int z=-radius;z<=radius;++z){ if(y*y+z*z<=radius*radius){ - blockset(source, pos.getX()+offset, pos.getY()+y, pos.getZ()+z, replacement, list, mbpos, block); + successes+=blockset(source, pos.getX()+offset, pos.getY()+y, pos.getZ()+z, replacement, list, mbpos, block); } } } @@ -345,7 +345,7 @@ public class DrawCommand { for(int z=-radius;z<=radius;++z){ if(x*x+z*z<=radius*radius){ - blockset(source, pos.getX()+x, pos.getY()+offset, pos.getZ()+z, replacement, list, mbpos, block); + successes+=blockset(source, pos.getX()+x, pos.getY()+offset, pos.getZ()+z, replacement, list, mbpos, block); } } } @@ -357,13 +357,13 @@ public class DrawCommand { for(int x=-radius;x<=radius;++x){ if(y*y+x*x<=radius*radius){ - blockset(source, pos.getX()+x, pos.getY()+y, pos.getZ()+offset, replacement, list, mbpos, block); + successes+=blockset(source, pos.getX()+x, pos.getY()+y, pos.getZ()+offset, replacement, list, mbpos, block); } } } } - return 1; + return successes; } private static int drawCone(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, String orientation, BlockStateArgument block, @@ -391,7 +391,7 @@ public class DrawCommand { if(pointup==false){ r=radius*i/height; } - drawCircle(source, pos, i, (int) Math.round(r), height, pointup, block, orientation, replacement, list, mbpos); + affected=drawCircle(source, pos, i, (int) Math.round(r), height, pointup, block, orientation, replacement, list, mbpos); //circle(cx+_,cy,cz,'x',ceil(r),block) in scarpet implementation, _ is i here, and is added in offset parameter } From 582f39b98d4778b34509991f98682f23f1e3038d Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 17:41:21 +0200 Subject: [PATCH 22/34] Renamed drawCone and added further steps toward pyramids --- .../java/carpet/commands/DrawCommand.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 34ae1c06..94b55f0e 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -78,8 +78,9 @@ public class DrawCommand { .then(argument("pointing up?",BoolArgumentType.bool()) .then(literal("x") .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawCone(c.getSource(), + .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), + "circle", IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"),"x", @@ -87,8 +88,9 @@ public class DrawCommand { ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawCone(c.getSource(), + .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), + "circle", IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"),"x", @@ -102,8 +104,9 @@ public class DrawCommand { ) .then(literal("y") .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawCone(c.getSource(), + .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), + "circle", IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"),"y", @@ -111,8 +114,9 @@ public class DrawCommand { ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawCone(c.getSource(), + .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), + "circle", IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"),"y", @@ -126,8 +130,9 @@ public class DrawCommand { ) .then(literal("z") .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawCone(c.getSource(), + .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), + "circle", IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"),"z", @@ -135,8 +140,9 @@ public class DrawCommand { ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawCone(c.getSource(), + .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), + "circle", IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"),"z", @@ -366,13 +372,13 @@ public class DrawCommand { return successes; } - private static int drawCone(ServerCommandSource source, BlockPos pos, int radius, int height, boolean pointup, String orientation, BlockStateArgument block, + private static int drawPyramid(ServerCommandSource source, BlockPos pos, String shape, int radius, int height, boolean pointup, String orientation, BlockStateArgument block, Predicate replacement) { - return (int) drawCone(source, pos, radius, height, block, replacement, pointup, orientation, false); + return (int) drawPyramid(source, pos, radius, height, block, replacement, pointup, orientation, false, shape); } - private static double drawCone(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, - Predicate replacement, boolean pointup, String orientation, boolean solid) { + private static double drawPyramid(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, + Predicate replacement, boolean pointup, String orientation, boolean solid, String shape) { int affected = 0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); From 2f780688753070996531d2aeebf16573d91bcb19 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 17:41:45 +0200 Subject: [PATCH 23/34] figured out why it wasnt showing proper affected blocks --- src/main/java/carpet/commands/DrawCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 94b55f0e..9dd11be3 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -397,7 +397,7 @@ public class DrawCommand { if(pointup==false){ r=radius*i/height; } - affected=drawCircle(source, pos, i, (int) Math.round(r), height, pointup, block, orientation, replacement, list, mbpos); + affected+=drawCircle(source, pos, i, (int) Math.round(r), height, pointup, block, orientation, replacement, list, mbpos); //circle(cx+_,cy,cz,'x',ceil(r),block) in scarpet implementation, _ is i here, and is added in offset parameter } From fcf2a6775c416e7675d39202aa4fb186ca9736f1 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 20 Apr 2020 21:29:19 +0200 Subject: [PATCH 24/34] Added square based pyramid also edited command tree to make it more understandable. Cones are, after all, simply circular-based pyramids. I may or may not add octagons in the future. --- .../java/carpet/commands/DrawCommand.java | 125 +++++++++++++++++- 1 file changed, 120 insertions(+), 5 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 9dd11be3..fe25bc44 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -71,7 +71,7 @@ public class DrawCommand { ) ) .then(literal("pyramid") - .then(literal("cone") + .then(literal("circular") .then(argument("center", BlockPosArgumentType.blockPos()) .then(argument("radius", IntegerArgumentType.integer(1)) .then(argument("height",IntegerArgumentType.integer(1)) @@ -159,6 +159,94 @@ public class DrawCommand { ) ) ) + .then(literal("square") + .then(argument("center", BlockPosArgumentType.blockPos()) + .then(argument("radius", IntegerArgumentType.integer(1)) + .then(argument("height",IntegerArgumentType.integer(1)) + .then(argument("pointing up?",BoolArgumentType.bool()) + .then(literal("x") + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawPyramid(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + "square", + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"x", + BlockStateArgumentType.getBlockState(c, "block"), null) + ) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawPyramid(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + "square", + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"x", + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) + ) + ) + ) + ) + ) + .then(literal("y") + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawPyramid(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + "square", + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"y", + BlockStateArgumentType.getBlockState(c, "block"), null) + ) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawPyramid(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + "square", + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"y", + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) + ) + ) + ) + ) + ) + .then(literal("z") + .then(argument("block", BlockStateArgumentType.blockState()) + .executes((c) -> drawPyramid(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + "square", + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"z", + BlockStateArgumentType.getBlockState(c, "block"), null) + ) + .then(literal("replace") + .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) + .executes((c) -> drawPyramid(c.getSource(), + BlockPosArgumentType.getBlockPos(c, "center"), + "square", + IntegerArgumentType.getInteger(c, "radius"), + IntegerArgumentType.getInteger(c, "height"), + BoolArgumentType.getBool(c,"pointing up?"),"z", + BlockStateArgumentType.getBlockState(c, "block"), + BlockPredicateArgumentType.getBlockPredicate(c,"filter") + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) ); dispatcher.register(command); @@ -330,7 +418,7 @@ public class DrawCommand { return 1; } - private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius, int height, boolean pointup, BlockStateArgument block, String orientation, + private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius,BlockStateArgument block, String orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ int successes=0; if(orientation=="x"){ @@ -371,13 +459,35 @@ public class DrawCommand { return successes; } + + private static int drawSquare(ServerCommandSource source, BlockPos pos, int offset, int radius, BlockStateArgument block, String orientation, + Predicate replacement, List list, BlockPos.Mutable mbpos){ + int success=0; + + for(int axis1=-radius;axis1<=radius;++axis1){ + + for(int axis2=-radius;axis2<=radius;++axis2){ + if(orientation=="x"){ + success+=blockset(source, pos.getX()+offset, pos.getY()+axis1, pos.getZ()+axis2,replacement, list, mbpos, block); + } + if(orientation=="y"){ + success+=blockset(source, pos.getX()+axis1, pos.getY()+offset, pos.getZ()+axis2,replacement, list, mbpos, block); + } + if(orientation=="z"){ + success+=blockset(source, pos.getX()+axis2, pos.getY()+axis1, pos.getZ()+offset,replacement, list, mbpos, block); + } + } + } + + return success; + } private static int drawPyramid(ServerCommandSource source, BlockPos pos, String shape, int radius, int height, boolean pointup, String orientation, BlockStateArgument block, Predicate replacement) { return (int) drawPyramid(source, pos, radius, height, block, replacement, pointup, orientation, false, shape); } - private static double drawPyramid(ServerCommandSource source, BlockPos pos, int radius, int height,BlockStateArgument block, + private static double drawPyramid(ServerCommandSource source, BlockPos pos, int radius, int height, BlockStateArgument block, Predicate replacement, boolean pointup, String orientation, boolean solid, String shape) { int affected = 0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); @@ -397,8 +507,13 @@ public class DrawCommand { if(pointup==false){ r=radius*i/height; } - affected+=drawCircle(source, pos, i, (int) Math.round(r), height, pointup, block, orientation, replacement, list, mbpos); - //circle(cx+_,cy,cz,'x',ceil(r),block) in scarpet implementation, _ is i here, and is added in offset parameter + if(shape=="circle"){ + affected+=drawCircle(source, pos, i, (int) Math.round(r), block, orientation, replacement, list, mbpos); + //circle(cx+_,cy,cz,'x',ceil(r),block) in scarpet implementation, _ is i here, and is added in offset parameter + } + if(shape=="square"){ + affected+=drawSquare(source, pos, i, (int) Math.round(r), block, orientation, replacement, list, mbpos); + } } CarpetSettings.impendingFillSkipUpdates = false; From 8d41bfa167e42c4d75932e04fcbaea50244abfe3 Mon Sep 17 00:00:00 2001 From: Ghoulboy Date: Tue, 21 Apr 2020 11:15:55 +0200 Subject: [PATCH 25/34] Undid egyptian bracing cos gnembon hates egyptians --- .../java/carpet/commands/DrawCommand.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index fe25bc44..ee952072 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -29,14 +29,17 @@ import java.lang.Math; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; -public class DrawCommand { - public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder command = literal("draw") - .requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)) - .then(literal("sphere").then(argument("center", BlockPosArgumentType.blockPos()) - .then(argument("radius", IntegerArgumentType.integer(1)) - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawSphere(c.getSource(), +public class DrawCommand +{ + public static void register(CommandDispatcher dispatcher) + { + LiteralArgumentBuilder command = literal("draw"). + requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)). + then(literal("sphere"). + then(argument("center", BlockPosArgumentType.blockPos()). + then(argument("radius", IntegerArgumentType.integer(1)). + then(argument("block", BlockStateArgumentType.blockState()). + executes((c) -> drawSphere(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), IntegerArgumentType.getInteger(c, "radius"), BlockStateArgumentType.getBlockState(c, "block"), null)) From 699d0abc5247c48012b371266a5239ea7c1bf1b7 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Wed, 22 Apr 2020 09:54:49 +0200 Subject: [PATCH 26/34] broke into 2 lines --- src/main/java/carpet/CarpetSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index 9f55f8d4..5376a05b 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -299,7 +299,7 @@ public class CarpetSettings ) public static String commandPerimeterInfo = "true"; - @Rule(desc = "Enables /draw commands", extra = "... allows for drawing simple shapes or other shapes which are sorta difficult to do normally", category = COMMAND) + @Rule(desc = "Enables /draw commands", extra = {"... allows for drawing simple shapes or","other shapes which are sorta difficult to do normally"}, category = COMMAND) public static String commandDraw = "true"; @Rule( From e8c8e68333a030ac86dc6b6cf135b7dafa807d28 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Wed, 22 Apr 2020 10:34:42 +0200 Subject: [PATCH 27/34] moved it all to ints less intuitive but code syntax is much better! --- .../java/carpet/commands/DrawCommand.java | 196 +++--------------- 1 file changed, 28 insertions(+), 168 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index ee952072..ee57d491 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -6,7 +6,6 @@ import carpet.utils.Messenger; import com.google.common.collect.Lists; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; - import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; @@ -17,6 +16,7 @@ import net.minecraft.command.arguments.BlockPosArgumentType; import net.minecraft.command.arguments.BlockPredicateArgumentType; import net.minecraft.command.arguments.BlockStateArgument; import net.minecraft.command.arguments.BlockStateArgumentType; +import static net.minecraft.server.command.CommandSource.suggestMatching; import net.minecraft.inventory.Inventory; import net.minecraft.block.entity.BlockEntity; import net.minecraft.util.math.BlockPos; @@ -74,81 +74,33 @@ public class DrawCommand ) ) .then(literal("pyramid") - .then(literal("circular") - .then(argument("center", BlockPosArgumentType.blockPos()) - .then(argument("radius", IntegerArgumentType.integer(1)) - .then(argument("height",IntegerArgumentType.integer(1)) - .then(argument("pointing up?",BoolArgumentType.bool()) - .then(literal("x") + .then(argument("center", BlockPosArgumentType.blockPos()) + .then(argument("radius", IntegerArgumentType.integer(1)) + .then(argument("height",IntegerArgumentType.integer(1)) + .then(argument("pointing up?",BoolArgumentType.bool()) + .then(argument("type",IntegerArgumentType.integer(1)) + .suggests( (c, b) -> suggestMatching(new String[]{"square=0","circle=1"},b)) + .then(argument("orientation",IntegerArgumentType.integer(1)) + .suggests( (c, b) -> suggestMatching(new String[]{"x=0","y=1","z=2"},b)) .then(argument("block", BlockStateArgumentType.blockState()) .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), - "circle", + IntegerArgumentType.getInteger(c, "type"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"x", + BoolArgumentType.getBool(c,"pointing up?"), + IntegerArgumentType.getInteger(c,"orientation"), BlockStateArgumentType.getBlockState(c, "block"), null) ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), - "circle", + IntegerArgumentType.getInteger(c, "type"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"x", - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") - ) - ) - ) - ) - ) - ) - .then(literal("y") - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "circle", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"y", - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "circle", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"y", - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") - ) - ) - ) - ) - ) - ) - .then(literal("z") - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "circle", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"z", - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "circle", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"z", + BoolArgumentType.getBool(c,"pointing up?"), + IntegerArgumentType.getInteger(c,"orientation"), BlockStateArgumentType.getBlockState(c, "block"), BlockPredicateArgumentType.getBlockPredicate(c,"filter") ) @@ -162,95 +114,6 @@ public class DrawCommand ) ) ) - .then(literal("square") - .then(argument("center", BlockPosArgumentType.blockPos()) - .then(argument("radius", IntegerArgumentType.integer(1)) - .then(argument("height",IntegerArgumentType.integer(1)) - .then(argument("pointing up?",BoolArgumentType.bool()) - .then(literal("x") - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "square", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"x", - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "square", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"x", - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") - ) - ) - ) - ) - ) - ) - .then(literal("y") - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "square", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"y", - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "square", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"y", - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") - ) - ) - ) - ) - ) - ) - .then(literal("z") - .then(argument("block", BlockStateArgumentType.blockState()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "square", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"z", - BlockStateArgumentType.getBlockState(c, "block"), null) - ) - .then(literal("replace") - .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) - .executes((c) -> drawPyramid(c.getSource(), - BlockPosArgumentType.getBlockPos(c, "center"), - "square", - IntegerArgumentType.getInteger(c, "radius"), - IntegerArgumentType.getInteger(c, "height"), - BoolArgumentType.getBool(c,"pointing up?"),"z", - BlockStateArgumentType.getBlockState(c, "block"), - BlockPredicateArgumentType.getBlockPredicate(c,"filter") - ) - ) - ) - ) - ) - ) - ) - ) - ) - ) - ) - ); dispatcher.register(command); } @@ -421,10 +284,10 @@ public class DrawCommand return 1; } - private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius,BlockStateArgument block, String orientation, + private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius,BlockStateArgument block, int orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ int successes=0; - if(orientation=="x"){ + if(orientation==0){ for(int y=-radius;y<=radius;++y){ for(int z=-radius;z<=radius;++z){ @@ -436,7 +299,7 @@ public class DrawCommand } } - if(orientation=="y"){ + if(orientation==1){ for(int x=-radius;x<=radius;++x){ for(int z=-radius;z<=radius;++z){ @@ -448,7 +311,7 @@ public class DrawCommand } } - if(orientation=="z"){ + if(orientation==2){ for(int y=-radius;y<=radius;++y){ for(int x=-radius;x<=radius;++x){ @@ -463,20 +326,20 @@ public class DrawCommand return successes; } - private static int drawSquare(ServerCommandSource source, BlockPos pos, int offset, int radius, BlockStateArgument block, String orientation, + private static int drawSquare(ServerCommandSource source, BlockPos pos, int offset, int radius, BlockStateArgument block, int orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ int success=0; for(int axis1=-radius;axis1<=radius;++axis1){ for(int axis2=-radius;axis2<=radius;++axis2){ - if(orientation=="x"){ + if(orientation==0){ success+=blockset(source, pos.getX()+offset, pos.getY()+axis1, pos.getZ()+axis2,replacement, list, mbpos, block); } - if(orientation=="y"){ + if(orientation==1){ success+=blockset(source, pos.getX()+axis1, pos.getY()+offset, pos.getZ()+axis2,replacement, list, mbpos, block); } - if(orientation=="z"){ + if(orientation==2){ success+=blockset(source, pos.getX()+axis2, pos.getY()+axis1, pos.getZ()+offset,replacement, list, mbpos, block); } } @@ -485,13 +348,13 @@ public class DrawCommand return success; } - private static int drawPyramid(ServerCommandSource source, BlockPos pos, String shape, int radius, int height, boolean pointup, String orientation, BlockStateArgument block, + private static int drawPyramid(ServerCommandSource source, BlockPos pos, int shape, int radius, int height, boolean pointup, int orientation, BlockStateArgument block, Predicate replacement) { return (int) drawPyramid(source, pos, radius, height, block, replacement, pointup, orientation, false, shape); } private static double drawPyramid(ServerCommandSource source, BlockPos pos, int radius, int height, BlockStateArgument block, - Predicate replacement, boolean pointup, String orientation, boolean solid, String shape) { + Predicate replacement, boolean pointup, int orientation, boolean solid, int shape) { int affected = 0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); @@ -506,15 +369,12 @@ public class DrawCommand for(int i =0; i Date: Wed, 22 Apr 2020 10:38:07 +0200 Subject: [PATCH 28/34] undoingn egyptian braces seriously gnemobn, what do you have against them? --- src/main/java/carpet/commands/DrawCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index ee57d491..8cffb9ae 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -186,7 +186,8 @@ public class DrawCommand { mbpos.set(pos.getX() + xmod * x, pos.getY() + ymod * y, pos.getZ() + zmod * z); if (replacement == null - || replacement.test(new CachedBlockPosition(world, mbpos, true))) { + || replacement.test(new CachedBlockPosition(world, mbpos, true))) + { BlockEntity tileentity = world.getBlockEntity(mbpos); if (tileentity instanceof Inventory) { From 0ee96174b823577c1f17970bb9b1c44e8c2bef7f Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Wed, 22 Apr 2020 10:56:14 +0200 Subject: [PATCH 29/34] apparently you can't input 0 otherwise its fine --- src/main/java/carpet/commands/DrawCommand.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 8cffb9ae..fcc55d82 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -79,9 +79,9 @@ public class DrawCommand .then(argument("height",IntegerArgumentType.integer(1)) .then(argument("pointing up?",BoolArgumentType.bool()) .then(argument("type",IntegerArgumentType.integer(1)) - .suggests( (c, b) -> suggestMatching(new String[]{"square=0","circle=1"},b)) + .suggests( (c, b) -> suggestMatching(new String[]{"square=2","circle=1"},b)) .then(argument("orientation",IntegerArgumentType.integer(1)) - .suggests( (c, b) -> suggestMatching(new String[]{"x=0","y=1","z=2"},b)) + .suggests( (c, b) -> suggestMatching(new String[]{"x=1","y=2","z=3"},b)) .then(argument("block", BlockStateArgumentType.blockState()) .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), @@ -288,7 +288,7 @@ public class DrawCommand private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius,BlockStateArgument block, int orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ int successes=0; - if(orientation==0){ + if(orientation==1){ for(int y=-radius;y<=radius;++y){ for(int z=-radius;z<=radius;++z){ @@ -300,7 +300,7 @@ public class DrawCommand } } - if(orientation==1){ + if(orientation==2){ for(int x=-radius;x<=radius;++x){ for(int z=-radius;z<=radius;++z){ @@ -312,7 +312,7 @@ public class DrawCommand } } - if(orientation==2){ + if(orientation==3){ for(int y=-radius;y<=radius;++y){ for(int x=-radius;x<=radius;++x){ @@ -334,13 +334,13 @@ public class DrawCommand for(int axis1=-radius;axis1<=radius;++axis1){ for(int axis2=-radius;axis2<=radius;++axis2){ - if(orientation==0){ + if(orientation==1){ success+=blockset(source, pos.getX()+offset, pos.getY()+axis1, pos.getZ()+axis2,replacement, list, mbpos, block); } - if(orientation==1){ + if(orientation==2){ success+=blockset(source, pos.getX()+axis1, pos.getY()+offset, pos.getZ()+axis2,replacement, list, mbpos, block); } - if(orientation==2){ + if(orientation==3){ success+=blockset(source, pos.getX()+axis2, pos.getY()+axis1, pos.getZ()+offset,replacement, list, mbpos, block); } } @@ -375,7 +375,7 @@ public class DrawCommand } if(shape==1){ affected+=drawCircle(source, pos, i, (int) Math.round(r), block, orientation, replacement, list, mbpos); - }else if(shape==0){ + }else if(shape==2){ affected+=drawSquare(source, pos, i, (int) Math.round(r), block, orientation, replacement, list, mbpos); } } From 890617c8ba433a50c704517d8c542749f51909ab Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Wed, 22 Apr 2020 11:11:20 +0200 Subject: [PATCH 30/34] Added error messages cos no throw statements available --- src/main/java/carpet/commands/DrawCommand.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index fcc55d82..c37ad9b0 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -366,6 +366,11 @@ public class DrawCommand CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; int r = radius; + + if(orientation<1||orientation>3){ + Messenger.m(source,"gi Incorrect orientation, 1 for x, 2 for y and 3 for z"); + return 0; + } for(int i =0; i Date: Fri, 24 Apr 2020 11:12:26 +0200 Subject: [PATCH 31/34] improved definitions COs messing about --- src/main/java/carpet/commands/DrawCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index c37ad9b0..27655836 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -368,7 +368,7 @@ public class DrawCommand int r = radius; if(orientation<1||orientation>3){ - Messenger.m(source,"gi Incorrect orientation, 1 for x, 2 for y and 3 for z"); + Messenger.m(source,"gi Incorrect orientation, must be 1 for x,2 for y or 3 for z"); return 0; } From 6146ff8ed86335b40e8223bfacc42743eaf895e0 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Fri, 24 Apr 2020 13:36:41 +0200 Subject: [PATCH 32/34] Let's see if this works --- .../java/carpet/commands/DrawCommand.java | 65 ++++++++++--------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 27655836..5df76879 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -8,6 +8,7 @@ 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; @@ -78,29 +79,29 @@ public class DrawCommand .then(argument("radius", IntegerArgumentType.integer(1)) .then(argument("height",IntegerArgumentType.integer(1)) .then(argument("pointing up?",BoolArgumentType.bool()) - .then(argument("type",IntegerArgumentType.integer(1)) - .suggests( (c, b) -> suggestMatching(new String[]{"square=2","circle=1"},b)) - .then(argument("orientation",IntegerArgumentType.integer(1)) - .suggests( (c, b) -> suggestMatching(new String[]{"x=1","y=2","z=3"},b)) + .then(argument("type",StringArgumentType.string()) + .suggests( (c, b) -> suggestMatching(new String[]{"square","circle"},b)) + .then(argument("orientation",StringArgumentType.string()) + .suggests( (c, b) -> suggestMatching(new String[]{"x","y","z"},b)) .then(argument("block", BlockStateArgumentType.blockState()) .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "type"), + StringArgumentType.getString(c,"type"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"), - IntegerArgumentType.getInteger(c,"orientation"), + StringArgumentType.getString(c,"orientation"), BlockStateArgumentType.getBlockState(c, "block"), null) ) .then(literal("replace") .then(argument("filter", BlockPredicateArgumentType.blockPredicate()) .executes((c) -> drawPyramid(c.getSource(), BlockPosArgumentType.getBlockPos(c, "center"), - IntegerArgumentType.getInteger(c, "type"), + StringArgumentType.getString(c,"type"), IntegerArgumentType.getInteger(c, "radius"), IntegerArgumentType.getInteger(c, "height"), BoolArgumentType.getBool(c,"pointing up?"), - IntegerArgumentType.getInteger(c,"orientation"), + StringArgumentType.getString(c,"orientation"), BlockStateArgumentType.getBlockState(c, "block"), BlockPredicateArgumentType.getBlockPredicate(c,"filter") ) @@ -285,10 +286,10 @@ public class DrawCommand return 1; } - private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius,BlockStateArgument block, int orientation, + private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius,BlockStateArgument block, String orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ int successes=0; - if(orientation==1){ + if(orientation=="x"){ for(int y=-radius;y<=radius;++y){ for(int z=-radius;z<=radius;++z){ @@ -300,7 +301,7 @@ public class DrawCommand } } - if(orientation==2){ + if(orientation=="y"){ for(int x=-radius;x<=radius;++x){ for(int z=-radius;z<=radius;++z){ @@ -312,7 +313,7 @@ public class DrawCommand } } - if(orientation==3){ + if(orientation=="z"){ for(int y=-radius;y<=radius;++y){ for(int x=-radius;x<=radius;++x){ @@ -327,20 +328,20 @@ public class DrawCommand return successes; } - private static int drawSquare(ServerCommandSource source, BlockPos pos, int offset, int radius, BlockStateArgument block, int orientation, + private static int drawSquare(ServerCommandSource source, BlockPos pos, int offset, int radius, BlockStateArgument block, String orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ int success=0; for(int axis1=-radius;axis1<=radius;++axis1){ for(int axis2=-radius;axis2<=radius;++axis2){ - if(orientation==1){ + if(orientation=="x"){ success+=blockset(source, pos.getX()+offset, pos.getY()+axis1, pos.getZ()+axis2,replacement, list, mbpos, block); } - if(orientation==2){ + if(orientation=="y"){ success+=blockset(source, pos.getX()+axis1, pos.getY()+offset, pos.getZ()+axis2,replacement, list, mbpos, block); } - if(orientation==3){ + if(orientation=="z"){ success+=blockset(source, pos.getX()+axis2, pos.getY()+axis1, pos.getZ()+offset,replacement, list, mbpos, block); } } @@ -349,13 +350,13 @@ public class DrawCommand return success; } - private static int drawPyramid(ServerCommandSource source, BlockPos pos, int shape, int radius, int height, boolean pointup, int orientation, BlockStateArgument block, + private static int drawPyramid(ServerCommandSource source, BlockPos pos, String shape, int radius, int height, boolean pointup, String orientation, BlockStateArgument block, Predicate replacement) { return (int) drawPyramid(source, pos, radius, height, block, replacement, pointup, orientation, false, shape); } private static double drawPyramid(ServerCommandSource source, BlockPos pos, int radius, int height, BlockStateArgument block, - Predicate replacement, boolean pointup, int orientation, boolean solid, int shape) { + Predicate replacement, boolean pointup, String orientation, boolean solid, String shape) { int affected = 0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); @@ -367,24 +368,30 @@ public class DrawCommand int r = radius; - if(orientation<1||orientation>3){ - Messenger.m(source,"gi Incorrect orientation, must be 1 for x,2 for y or 3 for z"); - return 0; + switch (orientation){ + case "x":break; + case "y":break; + case "z":break; + default:{ + Messenger.m(source,"gi Invalid orientation, must be x,y or z"); + return 0; + } } - for(int i =0; i Date: Fri, 24 Apr 2020 14:12:59 +0200 Subject: [PATCH 33/34] I removed the ++i statement and like crashed the world! --- .../java/carpet/commands/DrawCommand.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 5df76879..4b21d68d 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -324,7 +324,6 @@ public class DrawCommand } } } - return successes; } @@ -379,19 +378,25 @@ public class DrawCommand } - for(int i =0; i Date: Fri, 24 Apr 2020 16:19:35 +0200 Subject: [PATCH 34/34] moved everything to switch statement It all works now --- .../java/carpet/commands/DrawCommand.java | 80 +++++-------------- 1 file changed, 19 insertions(+), 61 deletions(-) diff --git a/src/main/java/carpet/commands/DrawCommand.java b/src/main/java/carpet/commands/DrawCommand.java index 4b21d68d..e2ca0bb3 100644 --- a/src/main/java/carpet/commands/DrawCommand.java +++ b/src/main/java/carpet/commands/DrawCommand.java @@ -289,44 +289,22 @@ public class DrawCommand private static int drawCircle(ServerCommandSource source, BlockPos pos, int offset, int radius,BlockStateArgument block, String orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ int successes=0; - if(orientation=="x"){ - for(int y=-radius;y<=radius;++y){ + for(int axis1=-radius;axis1<=radius;++axis1){ - for(int z=-radius;z<=radius;++z){ + for(int axis2=-radius;axis2<=radius;++axis2){ - if(y*y+z*z<=radius*radius){ - successes+=blockset(source, pos.getX()+offset, pos.getY()+y, pos.getZ()+z, replacement, list, mbpos, block); - } - } - } - } - - if(orientation=="y"){ - for(int x=-radius;x<=radius;++x){ - - for(int z=-radius;z<=radius;++z){ - - if(x*x+z*z<=radius*radius){ - successes+=blockset(source, pos.getX()+x, pos.getY()+offset, pos.getZ()+z, replacement, list, mbpos, block); - } - } - } - } - - if(orientation=="z"){ - for(int y=-radius;y<=radius;++y){ - - for(int x=-radius;x<=radius;++x){ - - if(y*y+x*x<=radius*radius){ - successes+=blockset(source, pos.getX()+x, pos.getY()+y, pos.getZ()+offset, replacement, list, mbpos, block); + if(axis1*axis1+axis2*axis2<=radius*radius){ + switch (orientation){ + case "x":successes+=blockset(source, pos.getX()+offset, pos.getY()+axis1, pos.getZ()+axis2,replacement, list, mbpos, block);break; + case "y":successes+=blockset(source, pos.getX()+axis1, pos.getY()+offset, pos.getZ()+axis2,replacement, list, mbpos, block);break; + case "z":successes+=blockset(source, pos.getX()+axis2, pos.getY()+axis1, pos.getZ()+offset,replacement, list, mbpos, block);break; + default:Messenger.m(source,"gi Invalid orientation, must be x, y or z");return 0; } } } } return successes; } - private static int drawSquare(ServerCommandSource source, BlockPos pos, int offset, int radius, BlockStateArgument block, String orientation, Predicate replacement, List list, BlockPos.Mutable mbpos){ int success=0; @@ -334,14 +312,11 @@ public class DrawCommand for(int axis1=-radius;axis1<=radius;++axis1){ for(int axis2=-radius;axis2<=radius;++axis2){ - if(orientation=="x"){ - success+=blockset(source, pos.getX()+offset, pos.getY()+axis1, pos.getZ()+axis2,replacement, list, mbpos, block); - } - if(orientation=="y"){ - success+=blockset(source, pos.getX()+axis1, pos.getY()+offset, pos.getZ()+axis2,replacement, list, mbpos, block); - } - if(orientation=="z"){ - success+=blockset(source, pos.getX()+axis2, pos.getY()+axis1, pos.getZ()+offset,replacement, list, mbpos, block); + switch (orientation){ + case "x":success+=blockset(source, pos.getX()+offset, pos.getY()+axis1, pos.getZ()+axis2,replacement, list, mbpos, block);break; + case "y":success+=blockset(source, pos.getX()+axis1, pos.getY()+offset, pos.getZ()+axis2,replacement, list, mbpos, block);break; + case "z":success+=blockset(source, pos.getX()+axis2, pos.getY()+axis1, pos.getZ()+offset,replacement, list, mbpos, block);break; + default:Messenger.m(source,"gi Invalid orientation, must be x, y or z");return 0; } } } @@ -366,17 +341,6 @@ public class DrawCommand CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; int r = radius; - - switch (orientation){ - case "x":break; - case "y":break; - case "z":break; - default:{ - Messenger.m(source,"gi Invalid orientation, must be x,y or z"); - return 0; - } - } - for(int i =0; i