FIxed some stuff
Still borken asf, but im not sure how to fix
This commit is contained in:
1 parent
67e3ed3229
commit
dab41bb0ce
1 file changed
+75
-106
@@ -21,79 +21,55 @@ import net.minecraft.server.world.ServerWorld;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
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.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
|
||||||
public class DrawCommand
|
public class DrawCommand {
|
||||||
{
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
LiteralArgumentBuilder<ServerCommandSource> command = literal("draw")
|
||||||
{
|
.requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw))
|
||||||
LiteralArgumentBuilder<ServerCommandSource> command = literal("draw").
|
.then(literal("sphere").then(argument("center", BlockPosArgumentType.blockPos())
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)).
|
.then(argument("radius", IntegerArgumentType.integer(1))
|
||||||
then(literal("sphere").
|
.then(argument("block", BlockStateArgumentType.blockState())
|
||||||
then(argument("center",BlockPosArgumentType.blockPos()).
|
.executes((c) -> drawCircle(c.getSource(),
|
||||||
then(argument("radius",IntegerArgumentType.integer(1)).
|
BlockPosArgumentType.getBlockPos(c, "center"),
|
||||||
then(argument("block",BlockStateArgumentType.blockState()).
|
IntegerArgumentType.getInteger(c, "radius"),
|
||||||
executes((c)-> drawCircle(
|
BlockStateArgumentType.getBlockState(c, "block"), null))
|
||||||
c.getSource(),
|
.then(literal("replace")
|
||||||
BlockPosArgumentType.getBlockPos(c, "center"),
|
.then(argument("filter", BlockPredicateArgumentType.blockPredicate())
|
||||||
IntegerArgumentType.getInteger(c, "radius"),
|
.executes((c) -> drawCircle(c.getSource(),
|
||||||
BlockStateArgumentType.getBlockState (c,"block"),
|
BlockPosArgumentType.getBlockPos(c, "center"),
|
||||||
null
|
IntegerArgumentType.getInteger(c, "radius"),
|
||||||
)
|
BlockStateArgumentType.getBlockState(c, "block"),
|
||||||
).
|
BlockPredicateArgumentType.getBlockPredicate(c,
|
||||||
then(literal("replace").
|
"filter")))))))))
|
||||||
then(argument("filter",BlockPredicateArgumentType.blockPredicate())
|
.then(literal("diamond").then(argument("centre", BlockPosArgumentType.blockPos())
|
||||||
.executes((c)-> drawCircle(
|
.then(argument("radius", IntegerArgumentType.integer(1)).then(
|
||||||
c.getSource(),
|
argument("block", BlockStateArgumentType.blockState()).executes((c) -> drawDiamond(
|
||||||
BlockPosArgumentType.getBlockPos(c, "center"),
|
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"),
|
IntegerArgumentType.getInteger(c, "radius"),
|
||||||
BlockStateArgumentType.getBlockState(c,"block"),
|
BlockStateArgumentType.getBlockState(c,
|
||||||
|
"block"),
|
||||||
BlockPredicateArgumentType.getBlockPredicate(c,
|
BlockPredicateArgumentType.getBlockPredicate(c,
|
||||||
"filter")
|
"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);
|
dispatcher.register(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static int drawCircle(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block,
|
private static int drawCircle(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block,
|
||||||
Predicate<CachedBlockPosition> replacement)
|
Predicate<CachedBlockPosition> replacement) {
|
||||||
{
|
return drawCircle(source, pos, (double) radius, (double) radius, (double) radius, block, replacement, false);
|
||||||
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<CachedBlockPosition> replacement, boolean solid)
|
private static int drawCircle(ServerCommandSource source, BlockPos pos, double radiusX, double radiusY,
|
||||||
{
|
double radiusZ, BlockStateArgument block, Predicate<CachedBlockPosition> replacement, boolean solid) {
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
ServerWorld world = source.getWorld();
|
ServerWorld world = source.getWorld();
|
||||||
|
|
||||||
@@ -138,30 +114,25 @@ public class DrawCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!solid) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;
|
CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;
|
||||||
for (int xmod = -1; xmod < 2; xmod+= 2)
|
for (int xmod = -1; xmod < 2; xmod += 2) {
|
||||||
{
|
for (int ymod = -1; ymod < 2; ymod += 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);
|
||||||
for (int zmod = -1; zmod < 2; zmod += 2)
|
if (replacement == null
|
||||||
{
|
|| replacement.test(new CachedBlockPosition(world, mbpos, true))) {
|
||||||
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);
|
BlockEntity tileentity = world.getBlockEntity(mbpos);
|
||||||
if (tileentity instanceof Inventory)
|
if (tileentity instanceof Inventory) {
|
||||||
{
|
((Inventory) tileentity).clear();
|
||||||
((Inventory)tileentity).clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block.setBlockState(world, mbpos,2))
|
if (block.setBlockState(world, mbpos, 2)) {
|
||||||
{
|
|
||||||
list.add(mbpos.toImmutable());
|
list.add(mbpos.toImmutable());
|
||||||
++affected;
|
++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();
|
Block blokc = world.getBlockState(blockpos1).getBlock();
|
||||||
world.updateNeighbors(blockpos1, blokc); // or always version????
|
world.updateNeighbors(blockpos1, blokc); // or always version????
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Messenger.m(source, "gi Filled "+affected+" blocks");
|
Messenger.m(source, "gi Filled " + affected + " blocks");
|
||||||
|
|
||||||
return 1;
|
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);
|
return (x * x) + (y * y) + (z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int manhattan(int x1, int y1, int z1, int x2, int y2, int z2){
|
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)
|
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,
|
private static int drawDiamond(ServerCommandSource source, BlockPos pos, int radius, BlockStateArgument block,
|
||||||
Predicate<CachedBlockPosition> replacement){
|
Predicate<CachedBlockPosition> replacement) {
|
||||||
int affected =0;
|
int affected = 0;
|
||||||
|
|
||||||
BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);
|
BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);
|
||||||
|
|
||||||
List<BlockPos> list = Lists.newArrayList();
|
List<BlockPos> list = Lists.newArrayList();
|
||||||
|
|
||||||
ServerWorld world=source.getWorld();
|
ServerWorld world = source.getWorld();
|
||||||
|
|
||||||
CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;
|
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);
|
BlockEntity tileentity = world.getBlockEntity(mbpos);
|
||||||
|
|
||||||
if (tileentity instanceof Inventory){
|
if (tileentity instanceof Inventory) {
|
||||||
((Inventory)tileentity).clear();
|
((Inventory) tileentity).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block.setBlockState(world, mbpos,2)){
|
if (block.setBlockState(world, mbpos, 2)) {
|
||||||
list.add(mbpos.toImmutable());
|
list.add(mbpos.toImmutable());
|
||||||
++affected;
|
++affected;
|
||||||
}
|
}
|
||||||
@@ -235,17 +206,15 @@ public class DrawCommand
|
|||||||
|
|
||||||
CarpetSettings.impendingFillSkipUpdates = false;
|
CarpetSettings.impendingFillSkipUpdates = false;
|
||||||
|
|
||||||
if (CarpetSettings.fillUpdates)
|
if (CarpetSettings.fillUpdates) {
|
||||||
{
|
|
||||||
|
|
||||||
for (BlockPos blockpos1 : list)
|
for (BlockPos blockpos1 : list) {
|
||||||
{
|
|
||||||
Block blokc = world.getBlockState(blockpos1).getBlock();
|
Block blokc = world.getBlockState(blockpos1).getBlock();
|
||||||
world.updateNeighbors(blockpos1, blokc);
|
world.updateNeighbors(blockpos1, blokc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Messenger.m(source, "gi Filled "+affected+" blocks");
|
Messenger.m(source, "gi Filled " + affected + " blocks");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user