com.mojang.brigadier.arguments.IntegerArgumentType Java Examples

The following examples show how to use com.mojang.brigadier.arguments.IntegerArgumentType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerCommand.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static LiteralArgumentBuilder<ServerCommandSource> makeActionCommand(String actionName, EntityPlayerActionPack.ActionType type)
{
    return literal(actionName)
            .executes(c -> action(c, type, EntityPlayerActionPack.Action.once()))
            .then(literal("once").executes(c -> action(c, type, EntityPlayerActionPack.Action.once())))
            .then(literal("continuous").executes(c -> action(c, type, EntityPlayerActionPack.Action.continuous())))
            .then(literal("interval").then(argument("ticks", IntegerArgumentType.integer(2))
                    .executes(c -> action(c, type, EntityPlayerActionPack.Action.interval(IntegerArgumentType.getInteger(c, "ticks"))))));
}
 
Example #2
Source File: PlayerCommand.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static LiteralArgumentBuilder<ServerCommandSource> makeDropCommand(String actionName, boolean dropAll)
{
    return literal(actionName)
            .then(literal("all").executes(c ->manipulate(c, ap -> ap.drop(-2,dropAll))))
            .then(literal("mainhand").executes(c ->manipulate(c, ap -> ap.drop(-1,dropAll))))
            .then(literal("offhand").executes(c ->manipulate(c, ap -> ap.drop(40,dropAll))))
            .then(argument("slot", IntegerArgumentType.integer(0, 40)).
                    executes(c ->manipulate(c, ap -> ap.drop(
                            IntegerArgumentType.getInteger(c,"slot"),
                            dropAll
                    ))));
}
 
Example #3
Source File: IntegerArgument.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
/**
 * An integer argument with a minimum and maximum value
 * @param min The minimum value this argument can take (inclusive)
 * @param max The maximum value this argument can take (inclusive)
 */
public IntegerArgument(int min, int max) {
	super(IntegerArgumentType.integer(min, max));
	if(max < min) {
		throw new InvalidRangeException();
	}
}
 
Example #4
Source File: IntegerArgumentPropertySerializer.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public IntegerArgumentType deserialize(ByteBuf buf) {
  byte flags = buf.readByte();
  int minimum = (flags & HAS_MINIMUM) != 0 ? buf.readInt() : Integer.MIN_VALUE;
  int maximum = (flags & HAS_MAXIMUM) != 0 ? buf.readInt() : Integer.MAX_VALUE;
  return IntegerArgumentType.integer(minimum, maximum);
}
 
Example #5
Source File: IntegerArgumentPropertySerializer.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public void serialize(IntegerArgumentType object, ByteBuf buf) {
  boolean hasMinimum = object.getMinimum() != Integer.MIN_VALUE;
  boolean hasMaximum = object.getMaximum() != Integer.MAX_VALUE;
  byte flag = getFlags(hasMinimum, hasMaximum);

  buf.writeByte(flag);
  if (hasMinimum) {
    buf.writeInt(object.getMinimum());
  }
  if (hasMaximum) {
    buf.writeInt(object.getMaximum());
  }
}
 
Example #6
Source File: DrawCommand.java    From fabric-carpet with MIT License 4 votes vote down vote up
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> 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(drawShape(c -> DrawCommand.drawSphere(c, false)))))).
            then(literal("ball").
                    then(argument("center", BlockPosArgumentType.blockPos()).
                            then(argument("radius", IntegerArgumentType.integer(1)).
                                    then(drawShape(c -> DrawCommand.drawSphere(c, true)))))).
            then(literal("diamond").
                    then(argument("center", BlockPosArgumentType.blockPos()).
                            then(argument("radius", IntegerArgumentType.integer(1)).
                                    then(drawShape(c -> DrawCommand.drawDiamond(c, true)))))).
            then(literal("pyramid").
                    then(argument("center", BlockPosArgumentType.blockPos()).
                            then(argument("radius", IntegerArgumentType.integer(1)).
                                    then(argument("height",IntegerArgumentType.integer(1)).
                                            then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"up","down"},b)).
                                                    then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)).
                                                            then(drawShape(c -> DrawCommand.drawPyramid(c, "square", true))))))))).
            then(literal("cone").
                    then(argument("center", BlockPosArgumentType.blockPos()).
                            then(argument("radius", IntegerArgumentType.integer(1)).
                                    then(argument("height",IntegerArgumentType.integer(1)).
                                            then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"up","down"},b)).
                                                    then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b))
                                                            .then(drawShape(c -> DrawCommand.drawPyramid(c, "circle", true))))))))).
            then(literal("cylinder").
                    then(argument("center", BlockPosArgumentType.blockPos()).
                            then(argument("radius", IntegerArgumentType.integer(1)).
                                    then(argument("height",IntegerArgumentType.integer(1)).
                                                    then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b))
                                                            .then(drawShape(c -> DrawCommand.drawPrism(c, "circle")))))))).
            then(literal("cuboid").
                    then(argument("center", BlockPosArgumentType.blockPos()).
                            then(argument("radius", IntegerArgumentType.integer(1)).
                                    then(argument("height",IntegerArgumentType.integer(1)).
                                            then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b))
                                                    .then(drawShape(c -> DrawCommand.drawPrism(c, "square"))))))));
    dispatcher.register(command);
}
 
Example #7
Source File: DrawCommand.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static int drawSphere(CommandContext<ServerCommandSource> ctx, boolean solid) throws CommandSyntaxException
{
    BlockPos pos;
    int radius;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled ignored) { return 0; }

    int affected = 0;
    ServerWorld world = ctx.getSource().getWorld();

    double radiusX = radius+0.5;
    double radiusY = radius+0.5;
    double radiusZ = radius+0.5;

    final double invRadiusX = 1 / radiusX;
    final double invRadiusY = 1 / radiusY;
    final double invRadiusZ = 1 / radiusZ;

    final int ceilRadiusX = (int) Math.ceil(radiusX);
    final int ceilRadiusY = (int) Math.ceil(radiusY);
    final int ceilRadiusZ = (int) Math.ceil(radiusZ);

    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);
    List<BlockPos> list = Lists.newArrayList();

    double nextXn = 0;

    forX: for (int x = 0; x <= ceilRadiusX; ++x)
    {
        final double xn = nextXn;
        nextXn = (x + 1) * invRadiusX;
        double nextYn = 0;
        forY: for (int y = 0; y <= ceilRadiusY; ++y)
        {
            final double yn = nextYn;
            nextYn = (y + 1) * invRadiusY;
            double nextZn = 0;
            forZ: for (int z = 0; z <= ceilRadiusZ; ++z)
            {
                final double zn = nextZn;
                nextZn = (z + 1) * invRadiusZ;

                double distanceSq = lengthSq(xn, yn, zn);
                if (distanceSq > 1)
                {
                    if (z == 0)
                    {
                        if (y == 0)
                        {
                            break forX;
                        }
                        break forY;
                    }
                    break forZ;
                }

                if (!solid && 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)
                        {
                            affected+= setBlock(world, mbpos,
                                    pos.getX() + xmod * x, pos.getY() + ymod * y, pos.getZ() + zmod * z,
                                    block, replacement, list
                            );
                        }
                    }
                }
                CarpetSettings.impendingFillSkipUpdates = false;
            }
        }
    }
    if (CarpetSettings.fillUpdates)
    {
        list.forEach(blockpos1 -> world.updateNeighbors(blockpos1, world.getBlockState(blockpos1).getBlock()));
    }
    Messenger.m(ctx.getSource(), "gi Filled " + affected + " blocks");
    return affected;
}
 
Example #8
Source File: DrawCommand.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static int drawDiamond(CommandContext<ServerCommandSource> ctx, boolean solid) throws CommandSyntaxException
{
    BlockPos pos;
    int radius;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled ignored) { return 0; }

    ServerCommandSource source = ctx.getSource();

    int affected=0;

    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);
    List<BlockPos> list = Lists.newArrayList();

    ServerWorld world = source.getWorld();

    CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;

    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);

            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()-y, pos.getZ()+z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()-y, pos.getZ()-z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()+y, pos.getZ()+z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()+y, pos.getZ()-z, block, replacement, list);
        }
    }

    CarpetSettings.impendingFillSkipUpdates = false;

    if (CarpetSettings.fillUpdates)
    {
        list.forEach(p -> world.updateNeighbors(p, world.getBlockState(p).getBlock()));
    }

    Messenger.m(source, "gi Filled " + affected + " blocks");

    return affected;
}
 
Example #9
Source File: DrawCommand.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static int drawPyramid(CommandContext<ServerCommandSource> ctx, String base, boolean solid) throws CommandSyntaxException
{
    BlockPos pos;
    double radius;
    int height;
    boolean pointup;
    String orientation;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius")+0.5D;
        height = getArg(ctx, IntegerArgumentType::getInteger, "height");
        pointup = getArg(ctx, StringArgumentType::getString, "pointing").equalsIgnoreCase("up");
        orientation = getArg(ctx, StringArgumentType::getString,"orientation");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled ignored) { return 0; }

    ServerCommandSource source = ctx.getSource();

    int affected = 0;
    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);

    List<BlockPos> list = Lists.newArrayList();

    ServerWorld world = source.getWorld();

    CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;

    boolean isSquare = base.equalsIgnoreCase("square");

    for(int i =0; i<height;++i)
    {
        double r = pointup ? radius - radius * i / height - 1 : radius * i / height;
        affected+= fillFlat(world, pos, i, r, isSquare, orientation, block, replacement, list, mbpos);
    }
    
    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 affected;
}
 
Example #10
Source File: DrawCommand.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static int drawPrism(CommandContext<ServerCommandSource> ctx, String base){
    BlockPos pos;
    double radius;
    int height;
    String orientation;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius")+0.5D;
        height = getArg(ctx, IntegerArgumentType::getInteger, "height");
        orientation = getArg(ctx, StringArgumentType::getString,"orientation");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled | CommandSyntaxException ignored) { return 0; }

    ServerCommandSource source = ctx.getSource();

    int affected = 0;
    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);

    List<BlockPos> list = Lists.newArrayList();

    ServerWorld world = source.getWorld();

    CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;

    boolean isSquare = base.equalsIgnoreCase("square");

    for(int i =0; i<height;++i)
    {
        affected+= fillFlat(world, pos, i, radius, isSquare, orientation, block, replacement, list, mbpos);
    }

    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 affected;
}
 
Example #11
Source File: IntegerArgument.java    From 1.13-Command-API with Apache License 2.0 4 votes vote down vote up
/**
 * An integer argument
 */
public IntegerArgument() {
	super(IntegerArgumentType.integer());
}
 
Example #12
Source File: IntegerArgument.java    From 1.13-Command-API with Apache License 2.0 2 votes vote down vote up
/**
 * An integer argument with a minimum value
 * @param min The minimum value this argument can take (inclusive)
 */
public IntegerArgument(int min) {
	super(IntegerArgumentType.integer(min));
}