Migrate the Carpet codebase to Mojang Mappings

This commit is contained in:
altrisi committed 2022-01-24 20:33:16 +01:00
1 parent a1a2488bc3
commit 06af9ce8b1
346 files changed
+8353 -8492

No files matched your search

@@ -5,11 +5,11 @@ import carpet.helpers.HopperCounter;
import carpet.utils.Messenger;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.CommandException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.command.CommandManager;
import net.minecraft.util.DyeColor;
import net.minecraft.text.BaseText;
import net.minecraft.commands.CommandRuntimeException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.world.item.DyeColor;
/**
* Class for the /counter command which allows to use hoppers pointing into wool
@@ -20,25 +20,25 @@ public class CounterCommand
/**
* The method used to register the command and make it available for the players to use.
*/
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("counter").executes((context)
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = Commands.literal("counter").executes((context)
-> listAllCounters(context.getSource(), false)).requires((player) ->
CarpetSettings.hopperCounters);
literalargumentbuilder.
then((CommandManager.literal("reset").executes( (p_198489_1_)->
then((Commands.literal("reset").executes( (p_198489_1_)->
resetCounter(p_198489_1_.getSource(), null))));
for (DyeColor enumDyeColor: DyeColor.values())
{
String color = enumDyeColor.toString();
literalargumentbuilder.
then((CommandManager.literal(color).executes( (p_198489_1_)-> displayCounter(p_198489_1_.getSource(), color, false))));
literalargumentbuilder.then(CommandManager.literal(color).
then(CommandManager.literal("reset").executes((context) ->
then((Commands.literal(color).executes( (p_198489_1_)-> displayCounter(p_198489_1_.getSource(), color, false))));
literalargumentbuilder.then(Commands.literal(color).
then(Commands.literal("reset").executes((context) ->
resetCounter(context.getSource(), color))));
literalargumentbuilder.then(CommandManager.literal(color).
then(CommandManager.literal("realtime").executes((context) ->
literalargumentbuilder.then(Commands.literal(color).
then(Commands.literal("realtime").executes((context) ->
displayCounter(context.getSource(), color, true))));
}
dispatcher.register(literalargumentbuilder);
@@ -51,14 +51,14 @@ public class CounterCommand
* would make it slower than IRL
*/
private static int displayCounter(ServerCommandSource source, String color, boolean realtime)
private static int displayCounter(CommandSourceStack source, String color, boolean realtime)
{
HopperCounter counter = HopperCounter.getCounter(color);
if (counter == null) throw new CommandException(Messenger.s("Unknown wool color: "+color));
if (counter == null) throw new CommandRuntimeException(Messenger.s("Unknown wool color: "+color));
for (BaseText message: counter.format(source.getServer(), realtime, false))
for (BaseComponent message: counter.format(source.getServer(), realtime, false))
{
source.sendFeedback(message, false);
source.sendSuccess(message, false);
}
return 1;
}
@@ -68,7 +68,7 @@ public class CounterCommand
* it will reset all counters.
* @param color The counter whose contents we want to reset
*/
private static int resetCounter(ServerCommandSource source, String color)
private static int resetCounter(CommandSourceStack source, String color)
{
if (color == null)
{
@@ -78,7 +78,7 @@ public class CounterCommand
else
{
HopperCounter counter = HopperCounter.getCounter(color);
if (counter == null) throw new CommandException(Messenger.s("Unknown wool color"));
if (counter == null) throw new CommandRuntimeException(Messenger.s("Unknown wool color"));
counter.reset(source.getServer());
Messenger.m(source, "w Restarted "+color+" counter");
}
@@ -90,11 +90,11 @@ public class CounterCommand
* @param realtime Whether or not to display it as in-game time or IRL time, which accounts for less than 20TPS which
* would make it slower than IRL
*/
private static int listAllCounters(ServerCommandSource source, boolean realtime)
private static int listAllCounters(CommandSourceStack source, boolean realtime)
{
for (BaseText message: HopperCounter.formatAll(source.getServer(), realtime))
for (BaseComponent message: HopperCounter.formatAll(source.getServer(), realtime))
{
source.sendFeedback(message, false);
source.sendSuccess(message, false);
}
return 1;
}
@@ -5,39 +5,39 @@ import carpet.settings.SettingsManager;
import carpet.utils.DistanceCalculator;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.command.argument.Vec3ArgumentType;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
public class DistanceCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> command = literal("distance").
LiteralArgumentBuilder<CommandSourceStack> command = literal("distance").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDistance)).
then(literal("from").
executes( (c) -> DistanceCalculator.setStart(c.getSource(), c.getSource().getPosition())).
then(argument("from", Vec3ArgumentType.vec3()).
then(argument("from", Vec3Argument.vec3()).
executes( (c) -> DistanceCalculator.setStart(
c.getSource(),
Vec3ArgumentType.getVec3(c, "from"))).
Vec3Argument.getVec3(c, "from"))).
then(literal("to").
executes((c) -> DistanceCalculator.distance(
c.getSource(),
Vec3ArgumentType.getVec3(c, "from"),
Vec3Argument.getVec3(c, "from"),
c.getSource().getPosition())).
then(argument("to", Vec3ArgumentType.vec3()).
then(argument("to", Vec3Argument.vec3()).
executes( (c) -> DistanceCalculator.distance(
c.getSource(),
Vec3ArgumentType.getVec3(c, "from"),
Vec3ArgumentType.getVec3(c, "to")
Vec3Argument.getVec3(c, "from"),
Vec3Argument.getVec3(c, "to")
)))))).
then(literal("to").
executes( (c) -> DistanceCalculator.setEnd(c.getSource(), c.getSource().getPosition()) ).
then(argument("to", Vec3ArgumentType.vec3()).
executes( (c) -> DistanceCalculator.setEnd(c.getSource(), Vec3ArgumentType.getVec3(c, "to")))));
then(argument("to", Vec3Argument.vec3()).
executes( (c) -> DistanceCalculator.setEnd(c.getSource(), Vec3Argument.getVec3(c, "to")))));
dispatcher.register(command);
}
}
+87 -88
View File
@@ -12,70 +12,69 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.Block;
import net.minecraft.block.pattern.CachedBlockPosition;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.BlockPredicateArgumentType;
import net.minecraft.command.argument.BlockStateArgument;
import net.minecraft.command.argument.BlockStateArgumentType;
import net.minecraft.inventory.Inventory;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.MathHelper;
import java.util.List;
import java.util.function.Predicate;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.blocks.BlockInput;
import net.minecraft.commands.arguments.blocks.BlockPredicateArgument;
import net.minecraft.commands.arguments.blocks.BlockStateArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.Container;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
import java.lang.Math;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.command.CommandSource.suggestMatching;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
public class DrawCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> command = literal("draw").
LiteralArgumentBuilder<CommandSourceStack> command = literal("draw").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)).
then(literal("sphere").
then(argument("center", BlockPosArgumentType.blockPos()).
then(argument("center", BlockPosArgument.blockPos()).
then(argument("radius", IntegerArgumentType.integer(1)).
then(drawShape(c -> DrawCommand.drawSphere(c, false)))))).
then(literal("ball").
then(argument("center", BlockPosArgumentType.blockPos()).
then(argument("center", BlockPosArgument.blockPos()).
then(argument("radius", IntegerArgumentType.integer(1)).
then(drawShape(c -> DrawCommand.drawSphere(c, true)))))).
then(literal("diamond").
then(argument("center", BlockPosArgumentType.blockPos()).
then(argument("center", BlockPosArgument.blockPos()).
then(argument("radius", IntegerArgumentType.integer(1)).
then(drawShape(c -> DrawCommand.drawDiamond(c, true)))))).
then(literal("pyramid").
then(argument("center", BlockPosArgumentType.blockPos()).
then(argument("center", BlockPosArgument.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(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"up","down"},b)).
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b)).
then(drawShape(c -> DrawCommand.drawPyramid(c, "square", true))))))))).
then(literal("cone").
then(argument("center", BlockPosArgumentType.blockPos()).
then(argument("center", BlockPosArgument.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(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"up","down"},b)).
then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
.then(drawShape(c -> DrawCommand.drawPyramid(c, "circle", true))))))))).
then(literal("cylinder").
then(argument("center", BlockPosArgumentType.blockPos()).
then(argument("center", BlockPosArgument.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(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
.then(drawShape(c -> DrawCommand.drawPrism(c, "circle")))))))).
then(literal("cuboid").
then(argument("center", BlockPosArgumentType.blockPos()).
then(argument("center", BlockPosArgument.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(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggest(new String[]{"y","x","z"},b))
.then(drawShape(c -> DrawCommand.drawPrism(c, "square"))))))));
dispatcher.register(command);
}
@@ -83,33 +82,33 @@ public class DrawCommand
@FunctionalInterface
private interface OptionalBlockSelector
{
Integer apply(final CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException;
Integer apply(final CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException;
}
@FunctionalInterface
private interface ArgumentExtractor<T>
{
T apply(final CommandContext<ServerCommandSource> ctx, final String argName) throws CommandSyntaxException;
T apply(final CommandContext<CommandSourceStack> ctx, final String argName) throws CommandSyntaxException;
}
private static RequiredArgumentBuilder<ServerCommandSource, BlockStateArgument>
private static RequiredArgumentBuilder<CommandSourceStack, BlockInput>
drawShape(OptionalBlockSelector drawer)
{
return argument("block", BlockStateArgumentType.blockState()).
return argument("block", BlockStateArgument.block()).
executes(drawer::apply)
.then(literal("replace")
.then(argument("filter", BlockPredicateArgumentType.blockPredicate())
.then(argument("filter", BlockPredicateArgument.blockPredicate())
.executes(drawer::apply)));
}
private static class ErrorHandled extends RuntimeException {}
private static <T> T getArg(CommandContext<ServerCommandSource> ctx, ArgumentExtractor<T> extract, String hwat) throws CommandSyntaxException
private static <T> T getArg(CommandContext<CommandSourceStack> ctx, ArgumentExtractor<T> extract, String hwat) throws CommandSyntaxException
{
return getArg(ctx, extract, hwat, false);
}
private static <T> T getArg(CommandContext<ServerCommandSource> ctx, ArgumentExtractor<T> extract, String hwat, boolean optional) throws CommandSyntaxException
private static <T> T getArg(CommandContext<CommandSourceStack> ctx, ArgumentExtractor<T> extract, String hwat, boolean optional) throws CommandSyntaxException
{
T arg = null;
try
@@ -131,23 +130,23 @@ public class DrawCommand
}
private static int setBlock(
ServerWorld world, BlockPos.Mutable mbpos, int x, int y, int z,
BlockStateArgument block, Predicate<CachedBlockPosition> replacement,
ServerLevel world, BlockPos.MutableBlockPos mbpos, int x, int y, int z,
BlockInput block, Predicate<BlockInWorld> replacement,
List<BlockPos> list
)
{
mbpos.set(x, y, z);
int success=0;
if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true)))
if (replacement == null || replacement.test(new BlockInWorld(world, mbpos, true)))
{
BlockEntity tileentity = world.getBlockEntity(mbpos);
if (tileentity instanceof Inventory)
if (tileentity instanceof Container)
{
((Inventory) tileentity).clear();
((Container) tileentity).clearContent();
}
if (block.setBlockState(world, mbpos, 2))
if (block.place(world, mbpos, 2))
{
list.add(mbpos.toImmutable());
list.add(mbpos.immutable());
++success;
}
}
@@ -155,23 +154,23 @@ public class DrawCommand
return success;
}
private static int drawSphere(CommandContext<ServerCommandSource> ctx, boolean solid) throws CommandSyntaxException
private static int drawSphere(CommandContext<CommandSourceStack> ctx, boolean solid) throws CommandSyntaxException
{
BlockPos pos;
int radius;
BlockStateArgument block;
Predicate<CachedBlockPosition> replacement;
BlockInput block;
Predicate<BlockInWorld> replacement;
try
{
pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
pos = getArg(ctx, BlockPosArgument::getSpawnablePos, "center");
radius = getArg(ctx, IntegerArgumentType::getInteger, "radius");
block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
block = getArg(ctx, BlockStateArgument::getBlock, "block");
replacement = getArg(ctx, BlockPredicateArgument::getBlockPredicate, "filter", true);
}
catch (ErrorHandled ignored) { return 0; }
int affected = 0;
ServerWorld world = ctx.getSource().getWorld();
ServerLevel world = ctx.getSource().getLevel();
double radiusX = radius+0.5;
double radiusY = radius+0.5;
@@ -185,7 +184,7 @@ public class DrawCommand
final int ceilRadiusY = (int) Math.ceil(radiusY);
final int ceilRadiusZ = (int) Math.ceil(radiusZ);
BlockPos.Mutable mbpos = pos.mutableCopy();
BlockPos.MutableBlockPos mbpos = pos.mutable();
List<BlockPos> list = Lists.newArrayList();
double nextXn = 0;
@@ -244,35 +243,35 @@ public class DrawCommand
}
if (CarpetSettings.fillUpdates)
{
list.forEach(blockpos1 -> world.updateNeighbors(blockpos1, world.getBlockState(blockpos1).getBlock()));
list.forEach(blockpos1 -> world.blockUpdated(blockpos1, world.getBlockState(blockpos1).getBlock()));
}
Messenger.m(ctx.getSource(), "gi Filled " + affected + " blocks");
return affected;
}
private static int drawDiamond(CommandContext<ServerCommandSource> ctx, boolean solid) throws CommandSyntaxException
private static int drawDiamond(CommandContext<CommandSourceStack> ctx, boolean solid) throws CommandSyntaxException
{
BlockPos pos;
int radius;
BlockStateArgument block;
Predicate<CachedBlockPosition> replacement;
BlockInput block;
Predicate<BlockInWorld> replacement;
try
{
pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
pos = getArg(ctx, BlockPosArgument::getSpawnablePos, "center");
radius = getArg(ctx, IntegerArgumentType::getInteger, "radius");
block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
block = getArg(ctx, BlockStateArgument::getBlock, "block");
replacement = getArg(ctx, BlockPredicateArgument::getBlockPredicate, "filter", true);
}
catch (ErrorHandled ignored) { return 0; }
ServerCommandSource source = ctx.getSource();
CommandSourceStack source = ctx.getSource();
int affected=0;
BlockPos.Mutable mbpos = pos.mutableCopy();
BlockPos.MutableBlockPos mbpos = pos.mutable();
List<BlockPos> list = Lists.newArrayList();
ServerWorld world = source.getWorld();
ServerLevel world = source.getLevel();
CarpetSettings.impendingFillSkipUpdates.set(!CarpetSettings.fillUpdates);
@@ -294,7 +293,7 @@ public class DrawCommand
if (CarpetSettings.fillUpdates)
{
list.forEach(p -> world.updateNeighbors(p, world.getBlockState(p).getBlock()));
list.forEach(p -> world.blockUpdated(p, world.getBlockState(p).getBlock()));
}
Messenger.m(source, "gi Filled " + affected + " blocks");
@@ -303,13 +302,13 @@ public class DrawCommand
}
private static int fillFlat(
ServerWorld world, BlockPos pos, int offset, double dr, boolean rectangle, String orientation,
BlockStateArgument block, Predicate<CachedBlockPosition> replacement,
List<BlockPos> list, BlockPos.Mutable mbpos
ServerLevel world, BlockPos pos, int offset, double dr, boolean rectangle, String orientation,
BlockInput block, Predicate<BlockInWorld> replacement,
List<BlockPos> list, BlockPos.MutableBlockPos mbpos
)
{
int successes=0;
int r = MathHelper.floor(dr);
int r = Mth.floor(dr);
double drsq = dr*dr;
if (orientation.equalsIgnoreCase("x"))
{
@@ -347,35 +346,35 @@ public class DrawCommand
return 0;
}
private static int drawPyramid(CommandContext<ServerCommandSource> ctx, String base, boolean solid) throws CommandSyntaxException
private static int drawPyramid(CommandContext<CommandSourceStack> ctx, String base, boolean solid) throws CommandSyntaxException
{
BlockPos pos;
double radius;
int height;
boolean pointup;
String orientation;
BlockStateArgument block;
Predicate<CachedBlockPosition> replacement;
BlockInput block;
Predicate<BlockInWorld> replacement;
try
{
pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
pos = getArg(ctx, BlockPosArgument::getSpawnablePos, "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);
block = getArg(ctx, BlockStateArgument::getBlock, "block");
replacement = getArg(ctx, BlockPredicateArgument::getBlockPredicate, "filter", true);
}
catch (ErrorHandled ignored) { return 0; }
ServerCommandSource source = ctx.getSource();
CommandSourceStack source = ctx.getSource();
int affected = 0;
BlockPos.Mutable mbpos = pos.mutableCopy();
BlockPos.MutableBlockPos mbpos = pos.mutable();
List<BlockPos> list = Lists.newArrayList();
ServerWorld world = source.getWorld();
ServerLevel world = source.getLevel();
CarpetSettings.impendingFillSkipUpdates.set(!CarpetSettings.fillUpdates);
@@ -393,7 +392,7 @@ public class DrawCommand
for (BlockPos blockpos1 : list) {
Block blokc = world.getBlockState(blockpos1).getBlock();
world.updateNeighbors(blockpos1, blokc);
world.blockUpdated(blockpos1, blokc);
}
}
@@ -402,32 +401,32 @@ public class DrawCommand
return affected;
}
private static int drawPrism(CommandContext<ServerCommandSource> ctx, String base){
private static int drawPrism(CommandContext<CommandSourceStack> ctx, String base){
BlockPos pos;
double radius;
int height;
String orientation;
BlockStateArgument block;
Predicate<CachedBlockPosition> replacement;
BlockInput block;
Predicate<BlockInWorld> replacement;
try
{
pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
pos = getArg(ctx, BlockPosArgument::getSpawnablePos, "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);
block = getArg(ctx, BlockStateArgument::getBlock, "block");
replacement = getArg(ctx, BlockPredicateArgument::getBlockPredicate, "filter", true);
}
catch (ErrorHandled | CommandSyntaxException ignored) { return 0; }
ServerCommandSource source = ctx.getSource();
CommandSourceStack source = ctx.getSource();
int affected = 0;
BlockPos.Mutable mbpos = pos.mutableCopy();
BlockPos.MutableBlockPos mbpos = pos.mutable();
List<BlockPos> list = Lists.newArrayList();
ServerWorld world = source.getWorld();
ServerLevel world = source.getLevel();
CarpetSettings.impendingFillSkipUpdates.set(!CarpetSettings.fillUpdates);
@@ -444,7 +443,7 @@ public class DrawCommand
for (BlockPos blockpos1 : list) {
Block blokc = world.getBlockState(blockpos1).getBlock();
world.updateNeighbors(blockpos1, blokc);
world.blockUpdated(blockpos1, blokc);
}
}
+15 -16
View File
@@ -6,42 +6,41 @@ import carpet.utils.BlockInfo;
import carpet.utils.Messenger;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.text.BaseText;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.util.math.BlockPos;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.BaseComponent;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
public class InfoCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> command = literal("info").
LiteralArgumentBuilder<CommandSourceStack> command = literal("info").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandInfo)).
then(literal("block").
then(argument("block position", BlockPosArgumentType.blockPos()).
then(argument("block position", BlockPosArgument.blockPos()).
executes( (c) -> infoBlock(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "block position"), null)).
BlockPosArgument.getSpawnablePos(c, "block position"), null)).
then(literal("grep").
then(argument("regexp",greedyString()).
executes( (c) -> infoBlock(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "block position"),
BlockPosArgument.getSpawnablePos(c, "block position"),
getString(c, "regexp")))))));
dispatcher.register(command);
}
public static void printBlock(List<BaseText> messages, ServerCommandSource source, String grep)
public static void printBlock(List<BaseComponent> messages, CommandSourceStack source, String grep)
{
Messenger.m(source, "");
if (grep != null)
@@ -50,7 +49,7 @@ public class InfoCommand
Messenger.m(source, messages.get(0));
for (int i = 1; i<messages.size(); i++)
{
BaseText line = messages.get(i);
BaseComponent line = messages.get(i);
Matcher m = p.matcher(line.getString());
if (m.find())
{
@@ -64,9 +63,9 @@ public class InfoCommand
}
}
private static int infoBlock(ServerCommandSource source, BlockPos pos, String grep)
private static int infoBlock(CommandSourceStack source, BlockPos pos, String grep)
{
printBlock(BlockInfo.blockInfo(pos, source.getWorld()),source, grep);
printBlock(BlockInfo.blockInfo(pos, source.getLevel()),source, grep);
return 1;
}
+32 -33
View File
@@ -9,54 +9,53 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.command.CommandManager;
import net.minecraft.entity.player.PlayerEntity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.world.entity.player.Player;
import java.util.Arrays;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static net.minecraft.command.CommandSource.suggestMatching;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
public class LogCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("log").
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = Commands.literal("log").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandLog)).
executes((context) -> listLogs(context.getSource())).
then(CommandManager.literal("clear").
executes( (c) -> unsubFromAll(c.getSource(), c.getSource().getName())).
then(CommandManager.argument("player", StringArgumentType.word()).
suggests( (c, b)-> suggestMatching(c.getSource().getPlayerNames(),b)).
then(Commands.literal("clear").
executes( (c) -> unsubFromAll(c.getSource(), c.getSource().getTextName())).
then(Commands.argument("player", StringArgumentType.word()).
suggests( (c, b)-> suggest(c.getSource().getOnlinePlayerNames(),b)).
executes( (c) -> unsubFromAll(c.getSource(), getString(c, "player")))));
literalargumentbuilder.then(CommandManager.argument("log name",StringArgumentType.word()).
suggests( (c, b)-> suggestMatching(LoggerRegistry.getLoggerNames(),b)).
executes( (c)-> toggleSubscription(c.getSource(), c.getSource().getName(), getString(c, "log name"))).
then(CommandManager.literal("clear").
literalargumentbuilder.then(Commands.argument("log name",StringArgumentType.word()).
suggests( (c, b)-> suggest(LoggerRegistry.getLoggerNames(),b)).
executes( (c)-> toggleSubscription(c.getSource(), c.getSource().getTextName(), getString(c, "log name"))).
then(Commands.literal("clear").
executes( (c) -> unsubFromLogger(
c.getSource(),
c.getSource().getName(),
c.getSource().getTextName(),
getString(c, "log name")))).
then(CommandManager.argument("option", StringArgumentType.string()).
suggests( (c, b) -> suggestMatching(
then(Commands.argument("option", StringArgumentType.string()).
suggests( (c, b) -> suggest(
(LoggerRegistry.getLogger(getString(c, "log name"))==null
?new String[]{}
:LoggerRegistry.getLogger(getString(c, "log name")).getOptions()),
b)).
executes( (c) -> subscribePlayer(
c.getSource(),
c.getSource().getName(),
c.getSource().getTextName(),
getString(c, "log name"),
getString(c, "option"))).
then(CommandManager.argument("player", StringArgumentType.word()).
suggests( (c, b) -> suggestMatching(c.getSource().getPlayerNames(),b)).
then(Commands.argument("player", StringArgumentType.word()).
suggests( (c, b) -> suggest(c.getSource().getOnlinePlayerNames(),b)).
executes( (c) -> subscribePlayer(
c.getSource(),
getString(c, "player"),
@@ -65,19 +64,19 @@ public class LogCommand
dispatcher.register(literalargumentbuilder);
}
private static int listLogs(ServerCommandSource source)
private static int listLogs(CommandSourceStack source)
{
PlayerEntity player;
Player player;
try
{
player = source.getPlayer();
player = source.getPlayerOrException();
}
catch (CommandSyntaxException e)
{
Messenger.m(source, "For players only");
return 0;
}
Map<String,String> subs = LoggerRegistry.getPlayerSubscriptions(source.getName());
Map<String,String> subs = LoggerRegistry.getPlayerSubscriptions(source.getTextName());
if (subs == null)
{
subs = new HashMap<>();
@@ -132,9 +131,9 @@ public class LogCommand
}
return 1;
}
private static int unsubFromAll(ServerCommandSource source, String player_name)
private static int unsubFromAll(CommandSourceStack source, String player_name)
{
PlayerEntity player = source.getServer().getPlayerManager().getPlayer(player_name);
Player player = source.getServer().getPlayerList().getPlayerByName(player_name);
if (player == null)
{
Messenger.m(source, "r No player specified");
@@ -147,9 +146,9 @@ public class LogCommand
Messenger.m(source, "gi Unsubscribed from all logs");
return 1;
}
private static int unsubFromLogger(ServerCommandSource source, String player_name, String logname)
private static int unsubFromLogger(CommandSourceStack source, String player_name, String logname)
{
PlayerEntity player = source.getServer().getPlayerManager().getPlayer(player_name);
Player player = source.getServer().getPlayerList().getPlayerByName(player_name);
if (player == null)
{
Messenger.m(source, "r No player specified");
@@ -165,9 +164,9 @@ public class LogCommand
return 1;
}
private static int toggleSubscription(ServerCommandSource source, String player_name, String logName)
private static int toggleSubscription(CommandSourceStack source, String player_name, String logName)
{
PlayerEntity player = source.getServer().getPlayerManager().getPlayer(player_name);
Player player = source.getServer().getPlayerList().getPlayerByName(player_name);
if (player == null)
{
Messenger.m(source, "r No player specified");
@@ -189,9 +188,9 @@ public class LogCommand
}
return 1;
}
private static int subscribePlayer(ServerCommandSource source, String player_name, String logname, String option)
private static int subscribePlayer(CommandSourceStack source, String player_name, String logname, String option)
{
PlayerEntity player = source.getServer().getPlayerManager().getPlayer(player_name);
Player player = source.getServer().getPlayerList().getPlayerByName(player_name);
if (player == null)
{
Messenger.m(source, "r No player specified");
+13 -13
View File
@@ -6,34 +6,34 @@ import carpet.utils.MobAI;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.argument.EntitySummonArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.registry.Registry;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntitySummonArgument;
import net.minecraft.core.Registry;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.command.CommandSource.suggestMatching;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
public class MobAICommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> command = literal("track").
LiteralArgumentBuilder<CommandSourceStack> command = literal("track").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTrackAI)).
then(argument("entity type", EntitySummonArgumentType.entitySummon()).
then(argument("entity type", EntitySummonArgument.id()).
suggests( (c, b) -> suggestMatching(MobAI.availbleTypes(), b)).
suggests( (c, b) -> suggest(MobAI.availbleTypes(), b)).
then(literal("clear").executes( (c) ->
{
MobAI.clearTracking(Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type")));
MobAI.clearTracking(Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(c, "entity type")));
return 1;
}
)).
then(argument("aspect", StringArgumentType.word()).
suggests( (c, b) -> suggestMatching(MobAI.availableFor(Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type"))),b)).
suggests( (c, b) -> suggest(MobAI.availableFor(Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(c, "entity type"))),b)).
executes( (c) -> {
MobAI.startTracking(
Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type")),
Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(c, "entity type")),
MobAI.TrackingType.byName(StringArgumentType.getString(c, "aspect"))
);
return 1;
@@ -6,64 +6,64 @@ import carpet.utils.Messenger;
import carpet.utils.PerimeterDiagnostics;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.suggestion.SuggestionProviders;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.EntitySummonArgumentType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.EntitySummonArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.commands.synchronization.SuggestionProviders;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
public class PerimeterInfoCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> command = literal("perimeterinfo").
LiteralArgumentBuilder<CommandSourceStack> command = literal("perimeterinfo").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPerimeterInfo)).
executes( (c) -> perimeterDiagnose(
c.getSource(),
new BlockPos(c.getSource().getPosition()),
null)).
then(argument("center position", BlockPosArgumentType.blockPos()).
then(argument("center position", BlockPosArgument.blockPos()).
executes( (c) -> perimeterDiagnose(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "center position"),
BlockPosArgument.getSpawnablePos(c, "center position"),
null)).
then(argument("mob",EntitySummonArgumentType.entitySummon()).
then(argument("mob",EntitySummonArgument.id()).
suggests(SuggestionProviders.SUMMONABLE_ENTITIES).
executes( (c) -> perimeterDiagnose(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "center position"),
EntitySummonArgumentType.getEntitySummon(c, "mob").toString()
BlockPosArgument.getSpawnablePos(c, "center position"),
EntitySummonArgument.getSummonableEntity(c, "mob").toString()
))));
dispatcher.register(command);
}
private static int perimeterDiagnose(ServerCommandSource source, BlockPos pos, String mobId)
private static int perimeterDiagnose(CommandSourceStack source, BlockPos pos, String mobId)
{
NbtCompound nbttagcompound = new NbtCompound();
MobEntity entityliving = null;
CompoundTag nbttagcompound = new CompoundTag();
Mob entityliving = null;
if (mobId != null)
{
nbttagcompound.putString("id", mobId);
Entity baseEntity = EntityType.loadEntityWithPassengers(nbttagcompound, source.getWorld(), (entity_1x) -> {
entity_1x.refreshPositionAndAngles(new BlockPos(pos.getX(), source.getWorld().getBottomY()-10, pos.getZ()), entity_1x.getYaw(), entity_1x. getPitch());
return !source.getWorld().tryLoadEntity(entity_1x) ? null : entity_1x;
Entity baseEntity = EntityType.loadEntityRecursive(nbttagcompound, source.getLevel(), (entity_1x) -> {
entity_1x.moveTo(new BlockPos(pos.getX(), source.getLevel().getMinBuildHeight()-10, pos.getZ()), entity_1x.getYRot(), entity_1x. getXRot());
return !source.getLevel().addWithUUID(entity_1x) ? null : entity_1x;
});
if (!(baseEntity instanceof MobEntity))
if (!(baseEntity instanceof Mob))
{
Messenger.m(source, "r /perimeterinfo requires a mob entity to test agains.");
if (baseEntity != null) baseEntity.discard();
return 0;
}
entityliving = (MobEntity) baseEntity;
entityliving = (Mob) baseEntity;
}
PerimeterDiagnostics.Result res = PerimeterDiagnostics.countSpots(source.getWorld(), pos, entityliving);
PerimeterDiagnostics.Result res = PerimeterDiagnostics.countSpots(source.getLevel(), pos, entityliving);
Messenger.m(source, "w Spawning spaces around ",Messenger.tp("c",pos), "w :");
Messenger.m(source, "w potential in-liquid: ","wb "+res.liquid);
@@ -15,46 +15,45 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.argument.DimensionArgumentType;
import net.minecraft.command.argument.RotationArgumentType;
import net.minecraft.command.argument.Vec3ArgumentType;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.commands.arguments.coordinates.RotationArgument;
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.command.CommandSource.suggestMatching;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
public class PlayerCommand
{
// TODO: allow any order like execute
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
final String[] gamemodeStrings = Arrays.stream(GameMode.values())
.map(GameMode::getName)
final String[] gamemodeStrings = Arrays.stream(GameType.values())
.map(GameType::getName)
.collect(Collectors.toList())
.toArray(new String[]{});
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("player")
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("player")
.requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPlayer))
.then(argument("player", StringArgumentType.word())
.suggests( (c, b) -> suggestMatching(getPlayers(c.getSource()), b))
.suggests( (c, b) -> suggest(getPlayers(c.getSource()), b))
.then(literal("stop").executes(PlayerCommand::stop))
.then(makeActionCommand("use", EntityPlayerActionPack.ActionType.USE))
.then(makeActionCommand("jump", EntityPlayerActionPack.ActionType.JUMP))
@@ -83,30 +82,30 @@ public class PlayerCommand
.then(literal("west").executes(manipulation(ap -> ap.look(Direction.WEST))))
.then(literal("up").executes(manipulation(ap -> ap.look(Direction.UP))))
.then(literal("down").executes(manipulation(ap -> ap.look(Direction.DOWN))))
.then(literal("at").then(argument("position", Vec3ArgumentType.vec3()).executes(PlayerCommand::lookAt)))
.then(argument("direction", RotationArgumentType.rotation())
.executes(c -> manipulate(c, ap -> ap.look(RotationArgumentType.getRotation(c, "direction").toAbsoluteRotation(c.getSource())))))
.then(literal("at").then(argument("position", Vec3Argument.vec3()).executes(PlayerCommand::lookAt)))
.then(argument("direction", RotationArgument.rotation())
.executes(c -> manipulate(c, ap -> ap.look(RotationArgument.getRotation(c, "direction").getRotation(c.getSource())))))
).then(literal("turn")
.then(literal("left").executes(c -> manipulate(c, ap -> ap.turn(-90, 0))))
.then(literal("right").executes(c -> manipulate(c, ap -> ap.turn(90, 0))))
.then(literal("back").executes(c -> manipulate(c, ap -> ap.turn(180, 0))))
.then(argument("rotation", RotationArgumentType.rotation())
.executes(c -> manipulate(c, ap -> ap.turn(RotationArgumentType.getRotation(c, "rotation").toAbsoluteRotation(c.getSource())))))
.then(argument("rotation", RotationArgument.rotation())
.executes(c -> manipulate(c, ap -> ap.turn(RotationArgument.getRotation(c, "rotation").getRotation(c.getSource())))))
).then(literal("move").executes(c -> manipulate(c, EntityPlayerActionPack::stopMovement))
.then(literal("forward").executes(c -> manipulate(c, ap -> ap.setForward(1))))
.then(literal("backward").executes(c -> manipulate(c, ap -> ap.setForward(-1))))
.then(literal("left").executes(c -> manipulate(c, ap -> ap.setStrafing(1))))
.then(literal("right").executes(c -> manipulate(c, ap -> ap.setStrafing(-1))))
).then(literal("spawn").executes(PlayerCommand::spawn)
.then(literal("in").requires((player) -> player.hasPermissionLevel(2))
.then(literal("in").requires((player) -> player.hasPermission(2))
.then(argument("gamemode", StringArgumentType.word())
.suggests( (c, b) -> suggestMatching(gamemodeStrings, b))
.suggests( (c, b) -> suggest(gamemodeStrings, b))
.executes(PlayerCommand::spawn)))
.then(literal("at").then(argument("position", Vec3ArgumentType.vec3()).executes(PlayerCommand::spawn)
.then(literal("facing").then(argument("direction", RotationArgumentType.rotation()).executes(PlayerCommand::spawn)
.then(literal("in").then(argument("dimension", DimensionArgumentType.dimension()).executes(PlayerCommand::spawn)
.then(literal("in").requires((player) -> player.hasPermissionLevel(2))
.then(argument("gamemode", StringArgumentType.word()).suggests( (c, b) -> suggestMatching(gamemodeStrings, b))
.then(literal("at").then(argument("position", Vec3Argument.vec3()).executes(PlayerCommand::spawn)
.then(literal("facing").then(argument("direction", RotationArgument.rotation()).executes(PlayerCommand::spawn)
.then(literal("in").then(argument("dimension", DimensionArgument.dimension()).executes(PlayerCommand::spawn)
.then(literal("in").requires((player) -> player.hasPermission(2))
.then(argument("gamemode", StringArgumentType.word()).suggests( (c, b) -> suggest(gamemodeStrings, b))
.executes(PlayerCommand::spawn)
)))
)))
@@ -116,7 +115,7 @@ public class PlayerCommand
dispatcher.register(literalargumentbuilder);
}
private static LiteralArgumentBuilder<ServerCommandSource> makeActionCommand(String actionName, EntityPlayerActionPack.ActionType type)
private static LiteralArgumentBuilder<CommandSourceStack> makeActionCommand(String actionName, EntityPlayerActionPack.ActionType type)
{
return literal(actionName)
.executes(c -> action(c, type, EntityPlayerActionPack.Action.once()))
@@ -126,7 +125,7 @@ public class PlayerCommand
.executes(c -> action(c, type, EntityPlayerActionPack.Action.interval(IntegerArgumentType.getInteger(c, "ticks"))))));
}
private static LiteralArgumentBuilder<ServerCommandSource> makeDropCommand(String actionName, boolean dropAll)
private static LiteralArgumentBuilder<CommandSourceStack> makeDropCommand(String actionName, boolean dropAll)
{
return literal(actionName)
.then(literal("all").executes(c ->manipulate(c, ap -> ap.drop(-2,dropAll))))
@@ -139,39 +138,39 @@ public class PlayerCommand
))));
}
private static Collection<String> getPlayers(ServerCommandSource source)
private static Collection<String> getPlayers(CommandSourceStack source)
{
Set<String> players = Sets.newLinkedHashSet(Arrays.asList("Steve", "Alex"));
players.addAll(source.getPlayerNames());
players.addAll(source.getOnlinePlayerNames());
return players;
}
private static ServerPlayerEntity getPlayer(CommandContext<ServerCommandSource> context)
private static ServerPlayer getPlayer(CommandContext<CommandSourceStack> context)
{
String playerName = StringArgumentType.getString(context, "player");
MinecraftServer server = context.getSource().getServer();
return server.getPlayerManager().getPlayer(playerName);
return server.getPlayerList().getPlayerByName(playerName);
}
private static boolean cantManipulate(CommandContext<ServerCommandSource> context)
private static boolean cantManipulate(CommandContext<CommandSourceStack> context)
{
PlayerEntity player = getPlayer(context);
Player player = getPlayer(context);
if (player == null)
{
Messenger.m(context.getSource(), "r Can only manipulate existing players");
return true;
}
PlayerEntity sendingPlayer;
Player sendingPlayer;
try
{
sendingPlayer = context.getSource().getPlayer();
sendingPlayer = context.getSource().getPlayerOrException();
}
catch (CommandSyntaxException e)
{
return false;
}
if (!context.getSource().getServer().getPlayerManager().isOperator(sendingPlayer.getGameProfile()))
if (!context.getSource().getServer().getPlayerList().isOp(sendingPlayer.getGameProfile()))
{
if (sendingPlayer != player && !(player instanceof EntityPlayerMPFake))
{
@@ -182,27 +181,27 @@ public class PlayerCommand
return false;
}
private static boolean cantReMove(CommandContext<ServerCommandSource> context)
private static boolean cantReMove(CommandContext<CommandSourceStack> context)
{
if (cantManipulate(context)) return true;
PlayerEntity player = getPlayer(context);
Player player = getPlayer(context);
if (player instanceof EntityPlayerMPFake) return false;
Messenger.m(context.getSource(), "r Only fake players can be moved or killed");
return true;
}
private static boolean cantSpawn(CommandContext<ServerCommandSource> context)
private static boolean cantSpawn(CommandContext<CommandSourceStack> context)
{
String playerName = StringArgumentType.getString(context, "player");
MinecraftServer server = context.getSource().getServer();
PlayerManager manager = server.getPlayerManager();
PlayerEntity player = manager.getPlayer(playerName);
PlayerList manager = server.getPlayerList();
Player player = manager.getPlayerByName(playerName);
if (player != null)
{
Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is already logged on");
return true;
}
GameProfile profile = server.getUserCache().findByName(playerName).orElse(null);
GameProfile profile = server.getProfileCache().get(playerName).orElse(null);
if (profile == null)
{
if (!CarpetSettings.allowSpawningOfflinePlayers)
@@ -211,15 +210,15 @@ public class PlayerCommand
"Banned players can only be summoned in Singleplayer and in servers in off-line mode.");
return true;
} else {
profile = new GameProfile(PlayerEntity.getOfflinePlayerUuid(playerName), playerName);
profile = new GameProfile(Player.createPlayerUUID(playerName), playerName);
}
}
if (manager.getUserBanList().contains(profile))
if (manager.getBans().isBanned(profile))
{
Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is banned on this server");
return true;
}
if (manager.isWhitelistEnabled() && manager.isWhitelisted(profile) && !context.getSource().hasPermissionLevel(2))
if (manager.isUsingWhitelist() && manager.isWhiteListed(profile) && !context.getSource().hasPermission(2))
{
Messenger.m(context.getSource(), "r Whitelisted players can only be spawned by operators");
return true;
@@ -227,18 +226,18 @@ public class PlayerCommand
return false;
}
private static int kill(CommandContext<ServerCommandSource> context)
private static int kill(CommandContext<CommandSourceStack> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).kill();
return 1;
}
private static int lookAt(CommandContext<ServerCommandSource> context)
private static int lookAt(CommandContext<CommandSourceStack> context)
{
return manipulate(context, ap -> {
//try {
ap.lookAt(Vec3ArgumentType.getVec3(context, "position"));
ap.lookAt(Vec3Argument.getVec3(context, "position"));
//} catch (CommandSyntaxException ignored) {}
});
}
@@ -261,45 +260,45 @@ public class PlayerCommand
}
}
private static int spawn(CommandContext<ServerCommandSource> context) throws CommandSyntaxException
private static int spawn(CommandContext<CommandSourceStack> context) throws CommandSyntaxException
{
if (cantSpawn(context)) return 0;
ServerCommandSource source = context.getSource();
Vec3d pos = tryGetArg(
() -> Vec3ArgumentType.getVec3(context, "position"),
CommandSourceStack source = context.getSource();
Vec3 pos = tryGetArg(
() -> Vec3Argument.getVec3(context, "position"),
source::getPosition
);
Vec2f facing = tryGetArg(
() -> RotationArgumentType.getRotation(context, "direction").toAbsoluteRotation(context.getSource()),
Vec2 facing = tryGetArg(
() -> RotationArgument.getRotation(context, "direction").getRotation(context.getSource()),
source::getRotation
);
RegistryKey<World> dimType = tryGetArg(
() -> DimensionArgumentType.getDimensionArgument(context, "dimension").getRegistryKey(),
() -> source.getWorld().getRegistryKey() // dimension.getType()
ResourceKey<Level> dimType = tryGetArg(
() -> DimensionArgument.getDimension(context, "dimension").dimension(),
() -> source.getLevel().dimension() // dimension.getType()
);
GameMode mode = GameMode.CREATIVE;
GameType mode = GameType.CREATIVE;
boolean flying = false;
try
{
ServerPlayerEntity player = context.getSource().getPlayer();
mode = player.interactionManager.getGameMode();
ServerPlayer player = context.getSource().getPlayerOrException();
mode = player.gameMode.getGameModeForPlayer();
flying = player.getAbilities().flying;
}
catch (CommandSyntaxException ignored) {}
try {
String opGameMode = StringArgumentType.getString(context, "gamemode");
mode = GameMode.byName(opGameMode, null);
mode = GameType.byName(opGameMode, null);
if(mode == null)
{
Messenger.m(context.getSource(), "rb Invalid game mode: "+opGameMode+".");
return 0;
}
} catch (IllegalArgumentException ignored) {}
if(mode == GameMode.SPECTATOR)
if(mode == GameType.SPECTATOR)
{
// Force override flying to true for spectator players, or they will fell out of the world.
flying = true;
} else if(mode.isSurvivalLike()){
} else if(mode.isSurvival()){
// Force override flying to false for survival-like players, or they will fly too
flying = false;
}
@@ -311,12 +310,12 @@ public class PlayerCommand
}
MinecraftServer server = source.getServer();
if (!World.isValid(new BlockPos(pos.x, pos.y, pos.z)))
if (!Level.isInSpawnableBounds(new BlockPos(pos.x, pos.y, pos.z)))
{
Messenger.m(context.getSource(), "rb Player "+playerName+" cannot be placed outside of the world");
return 0;
}
PlayerEntity player = EntityPlayerMPFake.createFake(playerName, server, pos.x, pos.y, pos.z, facing.y, facing.x, dimType, mode, flying);
Player player = EntityPlayerMPFake.createFake(playerName, server, pos.x, pos.y, pos.z, facing.y, facing.x, dimType, mode, flying);
if (player == null)
{
Messenger.m(context.getSource(), "rb Player " + StringArgumentType.getString(context, "player") + " doesn't exist " +
@@ -328,47 +327,47 @@ public class PlayerCommand
private static int maxPlayerLength(MinecraftServer server)
{
return server.getServerPort() >= 0 ? 16 : 40;
return server.getPort() >= 0 ? 16 : 40;
}
private static int stop(CommandContext<ServerCommandSource> context)
private static int stop(CommandContext<CommandSourceStack> context)
{
if (cantManipulate(context)) return 0;
ServerPlayerEntity player = getPlayer(context);
ServerPlayer player = getPlayer(context);
((ServerPlayerEntityInterface) player).getActionPack().stopAll();
return 1;
}
private static int manipulate(CommandContext<ServerCommandSource> context, Consumer<EntityPlayerActionPack> action)
private static int manipulate(CommandContext<CommandSourceStack> context, Consumer<EntityPlayerActionPack> action)
{
if (cantManipulate(context)) return 0;
ServerPlayerEntity player = getPlayer(context);
ServerPlayer player = getPlayer(context);
action.accept(((ServerPlayerEntityInterface) player).getActionPack());
return 1;
}
private static Command<ServerCommandSource> manipulation(Consumer<EntityPlayerActionPack> action)
private static Command<CommandSourceStack> manipulation(Consumer<EntityPlayerActionPack> action)
{
return c -> manipulate(c, action);
}
private static int action(CommandContext<ServerCommandSource> context, EntityPlayerActionPack.ActionType type, EntityPlayerActionPack.Action action)
private static int action(CommandContext<CommandSourceStack> context, EntityPlayerActionPack.ActionType type, EntityPlayerActionPack.Action action)
{
return manipulate(context, ap -> ap.start(type, action));
}
private static int shadow(CommandContext<ServerCommandSource> context)
private static int shadow(CommandContext<CommandSourceStack> context)
{
ServerPlayerEntity player = getPlayer(context);
ServerPlayer player = getPlayer(context);
if (player instanceof EntityPlayerMPFake)
{
Messenger.m(context.getSource(), "r Cannot shadow fake players");
return 0;
}
ServerPlayerEntity sendingPlayer = null;
ServerPlayer sendingPlayer = null;
try
{
sendingPlayer = context.getSource().getPlayer();
sendingPlayer = context.getSource().getPlayerOrException();
}
catch (CommandSyntaxException ignored) { }
@@ -4,20 +4,20 @@ import carpet.CarpetSettings;
import carpet.settings.SettingsManager;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.commands.CommandSourceStack;
import static carpet.commands.TickCommand.healthEntities;
import static carpet.commands.TickCommand.healthReport;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
public class ProfileCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("profile").
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("profile").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandProfile)).
executes( (c) -> healthReport(c.getSource(), 100)).
then(literal("health").
+129 -129
View File
@@ -23,18 +23,6 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.pattern.CachedBlockPosition;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.BlockPredicateArgumentType;
import net.minecraft.command.argument.BlockStateArgument;
import net.minecraft.command.argument.BlockStateArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Clearable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockBox;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
@@ -49,10 +37,22 @@ import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.blocks.BlockInput;
import net.minecraft.commands.arguments.blocks.BlockPredicateArgument;
import net.minecraft.commands.arguments.blocks.BlockStateArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Clearable;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.command.CommandSource.suggestMatching;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
public class ScriptCommand
{
@@ -86,7 +86,7 @@ public class ScriptCommand
}
private static CompletableFuture<Suggestions> suggestCode(
CommandContext<ServerCommandSource> context,
CommandContext<CommandSourceStack> context,
SuggestionsBuilder suggestionsBuilder
) throws CommandSyntaxException
{
@@ -112,7 +112,7 @@ public class ScriptCommand
* variable.
*/
private static CompletableFuture<Suggestions> suggestDownloadableApps(
CommandContext<ServerCommandSource> context,
CommandContext<CommandSourceStack> context,
SuggestionsBuilder suggestionsBuilder
) throws CommandSyntaxException {
@@ -129,23 +129,23 @@ public class ScriptCommand
});
}
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> b = literal("globals").
LiteralArgumentBuilder<CommandSourceStack> b = literal("globals").
executes(context -> listGlobals(context, false)).
then(literal("all").executes(context -> listGlobals(context, true)));
LiteralArgumentBuilder<ServerCommandSource> o = literal("stop").
LiteralArgumentBuilder<CommandSourceStack> o = literal("stop").
executes( (cc) -> { CarpetServer.scriptServer.stopAll = true; return 1;});
LiteralArgumentBuilder<ServerCommandSource> u = literal("resume").
LiteralArgumentBuilder<CommandSourceStack> u = literal("resume").
executes( (cc) -> { CarpetServer.scriptServer.stopAll = false; return 1;});
LiteralArgumentBuilder<ServerCommandSource> l = literal("run").
LiteralArgumentBuilder<CommandSourceStack> l = literal("run").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE)).
then(argument("expr", StringArgumentType.greedyString()).suggests(ScriptCommand::suggestCode).
executes((cc) -> compute(
cc,
StringArgumentType.getString(cc, "expr"))));
LiteralArgumentBuilder<ServerCommandSource> s = literal("invoke").
then(argument("call", StringArgumentType.word()).suggests( (cc, bb)->suggestMatching(suggestFunctionCalls(cc),bb)).
LiteralArgumentBuilder<CommandSourceStack> s = literal("invoke").
then(argument("call", StringArgumentType.word()).suggests( (cc, bb)->suggest(suggestFunctionCalls(cc),bb)).
executes( (cc) -> invoke(
cc,
StringArgumentType.getString(cc, "call"),
@@ -161,13 +161,13 @@ public class ScriptCommand
null,
StringArgumentType.getString(cc, "arguments")
))));
LiteralArgumentBuilder<ServerCommandSource> c = literal("invokepoint").
then(argument("call", StringArgumentType.word()).suggests( (cc, bb)->suggestMatching(suggestFunctionCalls(cc),bb)).
then(argument("origin", BlockPosArgumentType.blockPos()).
LiteralArgumentBuilder<CommandSourceStack> c = literal("invokepoint").
then(argument("call", StringArgumentType.word()).suggests( (cc, bb)->suggest(suggestFunctionCalls(cc),bb)).
then(argument("origin", BlockPosArgument.blockPos()).
executes( (cc) -> invoke(
cc,
StringArgumentType.getString(cc, "call"),
BlockPosArgumentType.getBlockPos(cc, "origin"),
BlockPosArgument.getSpawnablePos(cc, "origin"),
null,
""
)).
@@ -175,99 +175,99 @@ public class ScriptCommand
executes( (cc) -> invoke(
cc,
StringArgumentType.getString(cc, "call"),
BlockPosArgumentType.getBlockPos(cc, "origin"),
BlockPosArgument.getSpawnablePos(cc, "origin"),
null,
StringArgumentType.getString(cc, "arguments")
)))));
LiteralArgumentBuilder<ServerCommandSource> h = literal("invokearea").
then(argument("call", StringArgumentType.word()).suggests( (cc, bb)->suggestMatching(suggestFunctionCalls(cc),bb)).
then(argument("from", BlockPosArgumentType.blockPos()).
then(argument("to", BlockPosArgumentType.blockPos()).
LiteralArgumentBuilder<CommandSourceStack> h = literal("invokearea").
then(argument("call", StringArgumentType.word()).suggests( (cc, bb)->suggest(suggestFunctionCalls(cc),bb)).
then(argument("from", BlockPosArgument.blockPos()).
then(argument("to", BlockPosArgument.blockPos()).
executes( (cc) -> invoke(
cc,
StringArgumentType.getString(cc, "call"),
BlockPosArgumentType.getBlockPos(cc, "from"),
BlockPosArgumentType.getBlockPos(cc, "to"),
BlockPosArgument.getSpawnablePos(cc, "from"),
BlockPosArgument.getSpawnablePos(cc, "to"),
""
)).
then(argument("arguments", StringArgumentType.greedyString()).
executes( (cc) -> invoke(
cc,
StringArgumentType.getString(cc, "call"),
BlockPosArgumentType.getBlockPos(cc, "from"),
BlockPosArgumentType.getBlockPos(cc, "to"),
BlockPosArgument.getSpawnablePos(cc, "from"),
BlockPosArgument.getSpawnablePos(cc, "to"),
StringArgumentType.getString(cc, "arguments")
))))));
LiteralArgumentBuilder<ServerCommandSource> i = literal("scan").requires((player) -> player.hasPermissionLevel(2)).
then(argument("origin", BlockPosArgumentType.blockPos()).
then(argument("from", BlockPosArgumentType.blockPos()).
then(argument("to", BlockPosArgumentType.blockPos()).
LiteralArgumentBuilder<CommandSourceStack> i = literal("scan").requires((player) -> player.hasPermission(2)).
then(argument("origin", BlockPosArgument.blockPos()).
then(argument("from", BlockPosArgument.blockPos()).
then(argument("to", BlockPosArgument.blockPos()).
then(argument("expr", StringArgumentType.greedyString()).
suggests(ScriptCommand::suggestCode).
executes( (cc) -> scriptScan(
cc,
BlockPosArgumentType.getBlockPos(cc, "origin"),
BlockPosArgumentType.getBlockPos(cc, "from"),
BlockPosArgumentType.getBlockPos(cc, "to"),
BlockPosArgument.getSpawnablePos(cc, "origin"),
BlockPosArgument.getSpawnablePos(cc, "from"),
BlockPosArgument.getSpawnablePos(cc, "to"),
StringArgumentType.getString(cc, "expr")
))))));
LiteralArgumentBuilder<ServerCommandSource> e = literal("fill").requires((player) -> player.hasPermissionLevel(2)).
then(argument("origin", BlockPosArgumentType.blockPos()).
then(argument("from", BlockPosArgumentType.blockPos()).
then(argument("to", BlockPosArgumentType.blockPos()).
LiteralArgumentBuilder<CommandSourceStack> e = literal("fill").requires((player) -> player.hasPermission(2)).
then(argument("origin", BlockPosArgument.blockPos()).
then(argument("from", BlockPosArgument.blockPos()).
then(argument("to", BlockPosArgument.blockPos()).
then(argument("expr", StringArgumentType.string()).
then(argument("block", BlockStateArgumentType.blockState()).
then(argument("block", BlockStateArgument.block()).
executes((cc) -> scriptFill(
cc,
BlockPosArgumentType.getBlockPos(cc, "origin"),
BlockPosArgumentType.getBlockPos(cc, "from"),
BlockPosArgumentType.getBlockPos(cc, "to"),
BlockPosArgument.getSpawnablePos(cc, "origin"),
BlockPosArgument.getSpawnablePos(cc, "from"),
BlockPosArgument.getSpawnablePos(cc, "to"),
StringArgumentType.getString(cc, "expr"),
BlockStateArgumentType.getBlockState(cc, "block"),
BlockStateArgument.getBlock(cc, "block"),
null, "solid"
)).
then(literal("replace").
then(argument("filter", BlockPredicateArgumentType.blockPredicate())
then(argument("filter", BlockPredicateArgument.blockPredicate())
.executes((cc) -> scriptFill(
cc,
BlockPosArgumentType.getBlockPos(cc, "origin"),
BlockPosArgumentType.getBlockPos(cc, "from"),
BlockPosArgumentType.getBlockPos(cc, "to"),
BlockPosArgument.getSpawnablePos(cc, "origin"),
BlockPosArgument.getSpawnablePos(cc, "from"),
BlockPosArgument.getSpawnablePos(cc, "to"),
StringArgumentType.getString(cc, "expr"),
BlockStateArgumentType.getBlockState(cc, "block"),
BlockPredicateArgumentType.getBlockPredicate(cc, "filter"),
BlockStateArgument.getBlock(cc, "block"),
BlockPredicateArgument.getBlockPredicate(cc, "filter"),
"solid"
)))))))));
LiteralArgumentBuilder<ServerCommandSource> t = literal("outline").requires((player) -> player.hasPermissionLevel(2)).
then(argument("origin", BlockPosArgumentType.blockPos()).
then(argument("from", BlockPosArgumentType.blockPos()).
then(argument("to", BlockPosArgumentType.blockPos()).
LiteralArgumentBuilder<CommandSourceStack> t = literal("outline").requires((player) -> player.hasPermission(2)).
then(argument("origin", BlockPosArgument.blockPos()).
then(argument("from", BlockPosArgument.blockPos()).
then(argument("to", BlockPosArgument.blockPos()).
then(argument("expr", StringArgumentType.string()).
then(argument("block", BlockStateArgumentType.blockState()).
then(argument("block", BlockStateArgument.block()).
executes((cc) -> scriptFill(
cc,
BlockPosArgumentType.getBlockPos(cc, "origin"),
BlockPosArgumentType.getBlockPos(cc, "from"),
BlockPosArgumentType.getBlockPos(cc, "to"),
BlockPosArgument.getSpawnablePos(cc, "origin"),
BlockPosArgument.getSpawnablePos(cc, "from"),
BlockPosArgument.getSpawnablePos(cc, "to"),
StringArgumentType.getString(cc, "expr"),
BlockStateArgumentType.getBlockState(cc, "block"),
BlockStateArgument.getBlock(cc, "block"),
null, "outline"
)).
then(literal("replace").
then(argument("filter", BlockPredicateArgumentType.blockPredicate())
then(argument("filter", BlockPredicateArgument.blockPredicate())
.executes((cc) -> scriptFill(
cc,
BlockPosArgumentType.getBlockPos(cc, "origin"),
BlockPosArgumentType.getBlockPos(cc, "from"),
BlockPosArgumentType.getBlockPos(cc, "to"),
BlockPosArgument.getSpawnablePos(cc, "origin"),
BlockPosArgument.getSpawnablePos(cc, "from"),
BlockPosArgument.getSpawnablePos(cc, "to"),
StringArgumentType.getString(cc, "expr"),
BlockStateArgumentType.getBlockState(cc, "block"),
BlockPredicateArgumentType.getBlockPredicate(cc, "filter"),
BlockStateArgument.getBlock(cc, "block"),
BlockPredicateArgument.getBlockPredicate(cc, "filter"),
"outline"
)))))))));
LiteralArgumentBuilder<ServerCommandSource> a = literal("load").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
LiteralArgumentBuilder<CommandSourceStack> a = literal("load").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
then(argument("app", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.listAvailableModules(true),bb)).
suggests( (cc, bb) -> suggest(CarpetServer.scriptServer.listAvailableModules(true),bb)).
executes((cc) ->
{
boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "app"), null, true, false, false, null);
@@ -282,22 +282,22 @@ public class ScriptCommand
)
)
);
LiteralArgumentBuilder<ServerCommandSource> f = literal("unload").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
LiteralArgumentBuilder<CommandSourceStack> f = literal("unload").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
then(argument("app", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.unloadableModules,bb)).
suggests( (cc, bb) -> suggest(CarpetServer.scriptServer.unloadableModules,bb)).
executes((cc) ->
{
boolean success =CarpetServer.scriptServer.removeScriptHost(cc.getSource(), StringArgumentType.getString(cc, "app"), true, false);
return success?1:0;
}));
LiteralArgumentBuilder<ServerCommandSource> q = literal("event").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
LiteralArgumentBuilder<CommandSourceStack> q = literal("event").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
executes( (cc) -> listEvents(cc.getSource())).
then(literal("add_to").
then(argument("event", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetEventServer.Event.publicEvents(CarpetServer.scriptServer).stream().map(ev -> ev.name).collect(Collectors.toList()),bb)).
suggests( (cc, bb) -> suggest(CarpetEventServer.Event.publicEvents(CarpetServer.scriptServer).stream().map(ev -> ev.name).collect(Collectors.toList()),bb)).
then(argument("call", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(suggestFunctionCalls(cc), bb)).
suggests( (cc, bb) -> suggest(suggestFunctionCalls(cc), bb)).
executes( (cc) -> CarpetServer.scriptServer.events.addEventFromCommand(
cc.getSource(),
StringArgumentType.getString(cc, "event"),
@@ -306,9 +306,9 @@ public class ScriptCommand
)?1:0)).
then(literal("from").
then(argument("app", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.modules.keySet(), bb)).
suggests( (cc, bb) -> suggest(CarpetServer.scriptServer.modules.keySet(), bb)).
then(argument("call", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(suggestFunctionCalls(cc), bb)).
suggests( (cc, bb) -> suggest(suggestFunctionCalls(cc), bb)).
executes( (cc) -> CarpetServer.scriptServer.events.addEventFromCommand(
cc.getSource(),
StringArgumentType.getString(cc, "event"),
@@ -317,22 +317,22 @@ public class ScriptCommand
)?1:0)))))).
then(literal("remove_from").
then(argument("event", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetEventServer.Event.publicEvents(CarpetServer.scriptServer).stream().filter(CarpetEventServer.Event::isNeeded).map(ev -> ev.name).collect(Collectors.toList()) ,bb)).
suggests( (cc, bb) -> suggest(CarpetEventServer.Event.publicEvents(CarpetServer.scriptServer).stream().filter(CarpetEventServer.Event::isNeeded).map(ev -> ev.name).collect(Collectors.toList()) ,bb)).
then(argument("call", StringArgumentType.greedyString()).
suggests( (cc, bb) -> suggestMatching(CarpetEventServer.Event.getEvent(StringArgumentType.getString(cc, "event"), CarpetServer.scriptServer).handler.inspectCurrentCalls().stream().map(CarpetEventServer.Callback::toString), bb)).
suggests( (cc, bb) -> suggest(CarpetEventServer.Event.getEvent(StringArgumentType.getString(cc, "event"), CarpetServer.scriptServer).handler.inspectCurrentCalls().stream().map(CarpetEventServer.Callback::toString), bb)).
executes( (cc) -> CarpetServer.scriptServer.events.removeEventFromCommand(
cc.getSource(),
StringArgumentType.getString(cc, "event"),
StringArgumentType.getString(cc, "call")
)?1:0))));
LiteralArgumentBuilder<ServerCommandSource> d = literal("download").requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE)).
LiteralArgumentBuilder<CommandSourceStack> d = literal("download").requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE)).
then(argument("path", StringArgumentType.greedyString()).
suggests(ScriptCommand::suggestDownloadableApps).
executes(cc-> AppStoreManager.downloadScript(cc.getSource(), StringArgumentType.getString(cc,"path"))));
LiteralArgumentBuilder<ServerCommandSource> r = literal("remove").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
LiteralArgumentBuilder<CommandSourceStack> r = literal("remove").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
then(argument("app", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.unloadableModules,bb)).
suggests( (cc, bb) -> suggest(CarpetServer.scriptServer.unloadableModules,bb)).
executes((cc) ->
{
boolean success =CarpetServer.scriptServer.uninstallApp(cc.getSource(), StringArgumentType.getString(cc, "app"));
@@ -346,10 +346,10 @@ public class ScriptCommand
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
then(literal("in").
then(argument("app", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.modules.keySet(), bb)).
suggests( (cc, bb) -> suggest(CarpetServer.scriptServer.modules.keySet(), bb)).
then(b).then(u).then(o).then(l).then(s).then(c).then(h).then(i).then(e).then(t))));
}
private static CarpetScriptHost getHost(CommandContext<ServerCommandSource> context) throws CommandSyntaxException
private static CarpetScriptHost getHost(CommandContext<CommandSourceStack> context) throws CommandSyntaxException
{
CarpetScriptHost host;
try
@@ -365,12 +365,12 @@ public class ScriptCommand
host.setChatErrorSnooper(context.getSource());
return host;
}
private static Collection<String> suggestFunctionCalls(CommandContext<ServerCommandSource> c) throws CommandSyntaxException
private static Collection<String> suggestFunctionCalls(CommandContext<CommandSourceStack> c) throws CommandSyntaxException
{
CarpetScriptHost host = getHost(c);
return host.globalFunctionNames(host.main, s -> !s.startsWith("_")).sorted().collect(Collectors.toList());
}
private static int listEvents(ServerCommandSource source)
private static int listEvents(CommandSourceStack source)
{
Messenger.m(source, "w Lists ALL event handlers:");
for (CarpetEventServer.Event event: CarpetEventServer.Event.getAllEvents(CarpetServer.scriptServer, null))
@@ -388,10 +388,10 @@ public class ScriptCommand
}
return 1;
}
private static int listGlobals(CommandContext<ServerCommandSource> context, boolean all) throws CommandSyntaxException
private static int listGlobals(CommandContext<CommandSourceStack> context, boolean all) throws CommandSyntaxException
{
CarpetScriptHost host = getHost(context);
ServerCommandSource source = context.getSource();
CommandSourceStack source = context.getSource();
Messenger.m(source, "lb Stored functions"+((host == CarpetServer.scriptServer.globalHost)?":":" in "+host.getName()+":"));
host.globalFunctionNames(host.main, (str) -> all || !str.startsWith("__")).sorted().forEach( (s) -> {
@@ -429,7 +429,7 @@ public class ScriptCommand
return 1;
}
public static int handleCall(ServerCommandSource source, CarpetScriptHost host, Supplier<Value> call)
public static int handleCall(CommandSourceStack source, CarpetScriptHost host, Supplier<Value> call)
{
try
{
@@ -470,9 +470,9 @@ public class ScriptCommand
//host.resetErrorSnooper(); // lets say no need to reset the snooper in case something happens on the way
}
private static int invoke(CommandContext<ServerCommandSource> context, String call, BlockPos pos1, BlockPos pos2, String args) throws CommandSyntaxException
private static int invoke(CommandContext<CommandSourceStack> context, String call, BlockPos pos1, BlockPos pos2, String args) throws CommandSyntaxException
{
ServerCommandSource source = context.getSource();
CommandSourceStack source = context.getSource();
CarpetScriptHost host = getHost(context);
if (call.startsWith("__"))
{
@@ -498,9 +498,9 @@ public class ScriptCommand
}
private static int compute(CommandContext<ServerCommandSource> context, String expr) throws CommandSyntaxException
private static int compute(CommandContext<CommandSourceStack> context, String expr) throws CommandSyntaxException
{
ServerCommandSource source = context.getSource();
CommandSourceStack source = context.getSource();
CarpetScriptHost host = getHost(context);
return handleCall(source, host, () -> {
CarpetExpression ex = new CarpetExpression(host.main, expr, source, new BlockPos(0, 0, 0));
@@ -508,13 +508,13 @@ public class ScriptCommand
});
}
private static int scriptScan(CommandContext<ServerCommandSource> context, BlockPos origin, BlockPos a, BlockPos b, String expr) throws CommandSyntaxException
private static int scriptScan(CommandContext<CommandSourceStack> context, BlockPos origin, BlockPos a, BlockPos b, String expr) throws CommandSyntaxException
{
ServerCommandSource source = context.getSource();
CommandSourceStack source = context.getSource();
CarpetScriptHost host = getHost(context);
BlockBox area = BlockBox.create(a, b);
BoundingBox area = BoundingBox.fromCorners(a, b);
CarpetExpression cexpr = new CarpetExpression(host.main, expr, source, origin);
int int_1 = area.getBlockCountX() * area.getBlockCountY() * area.getBlockCountZ(); // X Y Z
int int_1 = area.getXSpan() * area.getYSpan() * area.getZSpan(); // X Y Z
if (int_1 > CarpetSettings.fillLimit)
{
Messenger.m(source, "r too many blocks to evaluate: " + int_1);
@@ -524,11 +524,11 @@ public class ScriptCommand
CarpetSettings.impendingFillSkipUpdates.set(!CarpetSettings.fillUpdates);
try
{
for (int x = area.getMinX(); x <= area.getMaxX(); x++)
for (int x = area.minX(); x <= area.maxX(); x++)
{
for (int y = area.getMinY(); y <= area.getMaxY(); y++)
for (int y = area.minY(); y <= area.maxY(); y++)
{
for (int z = area.getMinZ(); z <= area.getMaxZ(); z++)
for (int z = area.minZ(); z <= area.maxZ(); z++)
{
try
{
@@ -556,36 +556,36 @@ public class ScriptCommand
}
private static int scriptFill(CommandContext<ServerCommandSource> context, BlockPos origin, BlockPos a, BlockPos b, String expr,
BlockStateArgument block, Predicate<CachedBlockPosition> replacement, String mode) throws CommandSyntaxException
private static int scriptFill(CommandContext<CommandSourceStack> context, BlockPos origin, BlockPos a, BlockPos b, String expr,
BlockInput block, Predicate<BlockInWorld> replacement, String mode) throws CommandSyntaxException
{
ServerCommandSource source = context.getSource();
CommandSourceStack source = context.getSource();
CarpetScriptHost host = getHost(context);
BlockBox area = BlockBox.create(a, b);
BoundingBox area = BoundingBox.fromCorners(a, b);
CarpetExpression cexpr = new CarpetExpression(host.main, expr, source, origin);
int int_1 = area.getBlockCountX() * area.getBlockCountY() * area.getBlockCountZ();
int int_1 = area.getXSpan() * area.getYSpan() * area.getZSpan();
if (int_1 > CarpetSettings.fillLimit)
{
Messenger.m(source, "r too many blocks to evaluate: "+ int_1);
return 1;
}
boolean[][][] volume = new boolean[area.getBlockCountX()][area.getBlockCountY()][area.getBlockCountZ()]; //X then Y then Z got messedup
boolean[][][] volume = new boolean[area.getXSpan()][area.getYSpan()][area.getZSpan()]; //X then Y then Z got messedup
BlockPos.Mutable mbpos = origin.mutableCopy();
ServerWorld world = source.getWorld();
BlockPos.MutableBlockPos mbpos = origin.mutable();
ServerLevel world = source.getLevel();
for (int x = area.getMinX(); x <= area.getMaxX(); x++)
for (int x = area.minX(); x <= area.maxX(); x++)
{
for (int y = area.getMinY(); y <= area.getMaxY(); y++)
for (int y = area.minY(); y <= area.maxY(); y++)
{
for (int z = area.getMinZ(); z <= area.getMaxZ(); z++)
for (int z = area.minZ(); z <= area.maxZ(); z++)
{
try
{
if (cexpr.fillAndScanCommand(host, x, y, z))
{
volume[x-area.getMinX()][y-area.getMinY()][z-area.getMinZ()]=true;
volume[x-area.minX()][y-area.minY()][z-area.minZ()]=true;
}
}
catch (CarpetExpressionException e)
@@ -599,12 +599,12 @@ public class ScriptCommand
}
}
}
final int maxx = area.getBlockCountX()-1;
final int maxy = area.getBlockCountY()-1;
final int maxz = area.getBlockCountZ()-1;
final int maxx = area.getXSpan()-1;
final int maxy = area.getYSpan()-1;
final int maxz = area.getZSpan()-1;
if ("outline".equalsIgnoreCase(mode))
{
boolean[][][] newVolume = new boolean[area.getBlockCountX()][area.getBlockCountY()][area.getBlockCountZ()];
boolean[][][] newVolume = new boolean[area.getXSpan()][area.getYSpan()][area.getZSpan()];
for (int x = 0; x <= maxx; x++)
{
for (int y = 0; y <= maxy; y++)
@@ -640,14 +640,14 @@ public class ScriptCommand
{
if (volume[x][y][z])
{
mbpos.set(x+area.getMinX(), y+area.getMinY(), z+area.getMinZ());
mbpos.set(x+area.minX(), y+area.minY(), z+area.minZ());
if (replacement == null || replacement.test(
new CachedBlockPosition( world, mbpos, true)))
new BlockInWorld( world, mbpos, true)))
{
BlockEntity tileentity = world.getBlockEntity(mbpos);
Clearable.clear(tileentity);
Clearable.tryClear(tileentity);
if (block.setBlockState(world, mbpos,2))
if (block.place(world, mbpos,2))
{
++affected;
}
@@ -668,15 +668,15 @@ public class ScriptCommand
{
if (volume[x][y][z])
{
mbpos.set(x+area.getMinX(), y+area.getMinY(), z+area.getMinZ());
mbpos.set(x+area.minX(), y+area.minY(), z+area.minZ());
Block blokc = world.getBlockState(mbpos).getBlock();
world.updateNeighbors(mbpos, blokc);
world.blockUpdated(mbpos, blokc);
}
}
}
}
}
Messenger.m(source, "gi Affected "+affected+" blocks in "+area.getBlockCountX() * area.getBlockCountY() * area.getBlockCountZ()+" block volume");
Messenger.m(source, "gi Affected "+affected+" blocks in "+area.getXSpan() * area.getYSpan() * area.getZSpan()+" block volume");
return 1;
}
}
+59 -60
View File
@@ -12,54 +12,53 @@ import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.DimensionArgumentType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;
import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Collectors;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.item.DyeColor;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.string;
import static com.mojang.brigadier.arguments.StringArgumentType.word;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.command.CommandSource.suggestMatching;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
public class SpawnCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("spawn").
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("spawn").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandSpawn));
literalargumentbuilder.
then(literal("list").
then(argument("pos", BlockPosArgumentType.blockPos()).
executes( (c) -> listSpawns(c.getSource(), BlockPosArgumentType.getBlockPos(c, "pos"))))).
then(argument("pos", BlockPosArgument.blockPos()).
executes( (c) -> listSpawns(c.getSource(), BlockPosArgument.getSpawnablePos(c, "pos"))))).
then(literal("tracking").
executes( (c) -> printTrackingReport(c.getSource())).
then(literal("start").
executes( (c) -> startTracking(c.getSource(), null, null)).
then(argument("from", BlockPosArgumentType.blockPos()).
then(argument("to", BlockPosArgumentType.blockPos()).
then(argument("from", BlockPosArgument.blockPos()).
then(argument("to", BlockPosArgument.blockPos()).
executes( (c) -> startTracking(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "from"),
BlockPosArgumentType.getBlockPos(c, "to")))))).
BlockPosArgument.getSpawnablePos(c, "from"),
BlockPosArgument.getSpawnablePos(c, "to")))))).
then(literal("stop").
executes( (c) -> stopTracking(c.getSource()))).
then(argument("type", word()).
suggests( (c, b) -> suggestMatching(Arrays.stream(SpawnGroup.values()).map(SpawnGroup::getName),b)).
suggests( (c, b) -> suggest(Arrays.stream(MobCategory.values()).map(MobCategory::getName),b)).
executes( (c) -> recentSpawnsForType(c.getSource(), getString(c, "type"))))).
then(literal("test").
executes( (c)-> runTest(c.getSource(), 72000, null)).
@@ -69,7 +68,7 @@ public class SpawnCommand
getInteger(c, "ticks"),
null)).
then(argument("counter", word()).
suggests( (c, b) -> suggestMatching(Arrays.stream(DyeColor.values()).map(DyeColor::toString),b)).
suggests( (c, b) -> suggest(Arrays.stream(DyeColor.values()).map(DyeColor::toString),b)).
executes((c)-> runTest(
c.getSource(),
getInteger(c, "ticks"),
@@ -82,9 +81,9 @@ public class SpawnCommand
then(literal("reset").
executes( (c) -> resetSpawnRates(c.getSource()))).
then(argument("type", word()).
suggests( (c, b) -> suggestMatching(Arrays.stream(SpawnGroup.values()).map(SpawnGroup::getName),b)).
suggests( (c, b) -> suggest(Arrays.stream(MobCategory.values()).map(MobCategory::getName),b)).
then(argument("rounds", integer(0)).
suggests( (c, b) -> suggestMatching(new String[]{"1"},b)).
suggests( (c, b) -> suggest(new String[]{"1"},b)).
executes( (c) -> setSpawnRates(
c.getSource(),
getString(c, "type"),
@@ -94,41 +93,41 @@ public class SpawnCommand
then(literal("set").
then(argument("cap (hostile)", integer(1,1400)).
executes( (c) -> setMobcaps(c.getSource(), getInteger(c, "cap (hostile)"))))).
then(argument("dimension", DimensionArgumentType.dimension()).
executes( (c)-> mobcapsForDimension(c.getSource(), DimensionArgumentType.getDimensionArgument(c, "dimension"))))).
then(argument("dimension", DimensionArgument.dimension()).
executes( (c)-> mobcapsForDimension(c.getSource(), DimensionArgument.getDimension(c, "dimension"))))).
then(literal("entities").
executes( (c) -> generalMobcaps(c.getSource()) ).
then(argument("type", string()).
suggests( (c, b)->suggestMatching(Arrays.stream(SpawnGroup.values()).map(SpawnGroup::getName), b)).
suggests( (c, b)->suggest(Arrays.stream(MobCategory.values()).map(MobCategory::getName), b)).
executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type"), false)).
then(literal("all").executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type"), true)))));
dispatcher.register(literalargumentbuilder);
}
private static SpawnGroup getCategory(String string) throws CommandSyntaxException
private static MobCategory getCategory(String string) throws CommandSyntaxException
{
if (!Arrays.stream(SpawnGroup.values()).map(SpawnGroup::getName).collect(Collectors.toSet()).contains(string))
if (!Arrays.stream(MobCategory.values()).map(MobCategory::getName).collect(Collectors.toSet()).contains(string))
{
throw new SimpleCommandExceptionType(Messenger.c("r Wrong mob type: "+string+" should be "+ Arrays.stream(SpawnGroup.values()).map(SpawnGroup::getName).collect(Collectors.joining(", ")))).create();
throw new SimpleCommandExceptionType(Messenger.c("r Wrong mob type: "+string+" should be "+ Arrays.stream(MobCategory.values()).map(MobCategory::getName).collect(Collectors.joining(", ")))).create();
}
return SpawnGroup.byName(string.toLowerCase(Locale.ROOT));
return MobCategory.byName(string.toLowerCase(Locale.ROOT));
}
private static int listSpawns(ServerCommandSource source, BlockPos pos)
private static int listSpawns(CommandSourceStack source, BlockPos pos)
{
Messenger.send(source, SpawnReporter.report(pos, source.getWorld()));
Messenger.send(source, SpawnReporter.report(pos, source.getLevel()));
return 1;
}
private static int printTrackingReport(ServerCommandSource source)
private static int printTrackingReport(CommandSourceStack source)
{
Messenger.send(source, SpawnReporter.tracking_report(source.getWorld()));
Messenger.send(source, SpawnReporter.tracking_report(source.getLevel()));
return 1;
}
private static int startTracking(ServerCommandSource source, BlockPos a, BlockPos b)
private static int startTracking(CommandSourceStack source, BlockPos a, BlockPos b)
{
if (SpawnReporter.track_spawns != 0L)
{
@@ -149,16 +148,16 @@ public class SpawnCommand
Math.max(a.getZ(), b.getZ()) );
}
SpawnReporter.reset_spawn_stats(source.getServer(), false);
SpawnReporter.track_spawns = (long) source.getServer().getTicks();
SpawnReporter.track_spawns = (long) source.getServer().getTickCount();
SpawnReporter.lower_spawning_limit = lsl;
SpawnReporter.upper_spawning_limit = usl;
Messenger.m(source, "gi Spawning tracking started.");
return 1;
}
private static int stopTracking(ServerCommandSource source)
private static int stopTracking(CommandSourceStack source)
{
Messenger.send(source, SpawnReporter.tracking_report(source.getWorld()));
Messenger.send(source, SpawnReporter.tracking_report(source.getLevel()));
SpawnReporter.reset_spawn_stats(source.getServer(),false);
SpawnReporter.track_spawns = 0L;
SpawnReporter.lower_spawning_limit = null;
@@ -167,19 +166,19 @@ public class SpawnCommand
return 1;
}
private static int recentSpawnsForType(ServerCommandSource source, String mob_type) throws CommandSyntaxException
private static int recentSpawnsForType(CommandSourceStack source, String mob_type) throws CommandSyntaxException
{
SpawnGroup cat = getCategory(mob_type);
Messenger.send(source, SpawnReporter.recent_spawns(source.getWorld(), cat));
MobCategory cat = getCategory(mob_type);
Messenger.send(source, SpawnReporter.recent_spawns(source.getLevel(), cat));
return 1;
}
private static int runTest(ServerCommandSource source, int ticks, String counter)
private static int runTest(CommandSourceStack source, int ticks, String counter)
{
//stop tracking
SpawnReporter.reset_spawn_stats(source.getServer(),false);
//start tracking
SpawnReporter.track_spawns = (long) source.getServer().getTicks();
SpawnReporter.track_spawns = (long) source.getServer().getTickCount();
//counter reset
if (counter == null)
{
@@ -196,11 +195,11 @@ public class SpawnCommand
// tick warp 0
TickSpeed.tickrate_advance(null, 0, null, null);
// tick warp given player
ServerCommandSource csource = null;
ServerPlayerEntity player = null;
CommandSourceStack csource = null;
ServerPlayer player = null;
try
{
player = source.getPlayer();
player = source.getPlayerOrException();
csource = source;
}
catch (CommandSyntaxException ignored)
@@ -211,7 +210,7 @@ public class SpawnCommand
return 1;
}
private static int toggleMocking(ServerCommandSource source, boolean domock)
private static int toggleMocking(CommandSourceStack source, boolean domock)
{
if (domock)
{
@@ -226,15 +225,15 @@ public class SpawnCommand
return 1;
}
private static int generalMobcaps(ServerCommandSource source)
private static int generalMobcaps(CommandSourceStack source)
{
Messenger.send(source, SpawnReporter.printMobcapsForDimension(source.getWorld(), true));
Messenger.send(source, SpawnReporter.printMobcapsForDimension(source.getLevel(), true));
return 1;
}
private static int resetSpawnRates(ServerCommandSource source)
private static int resetSpawnRates(CommandSourceStack source)
{
for (SpawnGroup s: SpawnReporter.spawn_tries.keySet())
for (MobCategory s: SpawnReporter.spawn_tries.keySet())
{
SpawnReporter.spawn_tries.put(s,1);
}
@@ -243,32 +242,32 @@ public class SpawnCommand
return 1;
}
private static int setSpawnRates(ServerCommandSource source, String mobtype, int rounds) throws CommandSyntaxException
private static int setSpawnRates(CommandSourceStack source, String mobtype, int rounds) throws CommandSyntaxException
{
SpawnGroup cat = getCategory(mobtype);
MobCategory cat = getCategory(mobtype);
SpawnReporter.spawn_tries.put(cat, rounds);
Messenger.m(source, "gi "+mobtype+" mobs will now spawn "+rounds+" times per tick");
return 1;
}
private static int setMobcaps(ServerCommandSource source, int hostile_cap)
private static int setMobcaps(CommandSourceStack source, int hostile_cap)
{
double desired_ratio = (double)hostile_cap/ ((SpawnGroupInterface)(Object)SpawnGroup.MONSTER).getInitialSpawnCap();
double desired_ratio = (double)hostile_cap/ ((SpawnGroupInterface)(Object)MobCategory.MONSTER).getInitialSpawnCap();
SpawnReporter.mobcap_exponent = 4.0*Math.log(desired_ratio)/Math.log(2.0);
Messenger.m(source, String.format("gi Mobcaps for hostile mobs changed to %d, other groups will follow", hostile_cap));
return 1;
}
private static int mobcapsForDimension(ServerCommandSource source, ServerWorld world)
private static int mobcapsForDimension(CommandSourceStack source, ServerLevel world)
{
Messenger.send(source, SpawnReporter.printMobcapsForDimension(world, true));
return 1;
}
private static int listEntitiesOfType(ServerCommandSource source, String mobtype, boolean all) throws CommandSyntaxException
private static int listEntitiesOfType(CommandSourceStack source, String mobtype, boolean all) throws CommandSyntaxException
{
SpawnGroup cat = getCategory(mobtype);
Messenger.send(source, SpawnReporter.printEntitiesByType(cat, source.getWorld(), all));
MobCategory cat = getCategory(mobtype);
Messenger.send(source, SpawnReporter.printEntitiesByType(cat, source.getLevel(), all));
return 1;
}
}
@@ -4,16 +4,16 @@ import carpet.CarpetServer;
import carpet.utils.Messenger;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.commands.CommandSourceStack;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.word;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
public class TestCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(literal("testcarpet").
then(literal("dump").
@@ -26,7 +26,7 @@ public class TestCommand
executes( (c)-> test(c, getString(c, "second")+" 2"))));
}
private static int test(CommandContext<ServerCommandSource> c, String term)
private static int test(CommandContext<CommandSourceStack> c, String term)
{
Messenger.m(c.getSource(),term.substring(0,1)+" "+term+": how did you get here?");
return 1;
+25 -25
View File
@@ -9,9 +9,9 @@ import carpet.utils.Messenger;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.server.level.ServerPlayer;
import static com.mojang.brigadier.arguments.FloatArgumentType.floatArg;
import static com.mojang.brigadier.arguments.FloatArgumentType.getFloat;
@@ -19,25 +19,25 @@ import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.command.CommandSource.suggestMatching;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
public class TickCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("tick").
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("tick").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTick)).
then(literal("rate").
executes((c) -> queryTps(c.getSource())).
then(argument("rate", floatArg(0.1F, 500.0F)).
suggests( (c, b) -> suggestMatching(new String[]{"20.0"},b)).
suggests( (c, b) -> suggest(new String[]{"20.0"},b)).
executes((c) -> setTps(c.getSource(), getFloat(c, "rate"))))).
then(literal("warp").
executes( (c)-> setWarp(c.getSource(), 0, null)).
then(argument("ticks", integer(0)).
suggests( (c, b) -> suggestMatching(new String[]{"3600","72000"},b)).
suggests( (c, b) -> suggest(new String[]{"3600","72000"},b)).
executes((c) -> setWarp(c.getSource(), getInteger(c,"ticks"), null)).
then(argument("tail command", greedyString()).
executes( (c) -> setWarp(
@@ -53,7 +53,7 @@ public class TickCommand
then(literal("step").
executes((c) -> step(c.getSource(), 1)).
then(argument("ticks", integer(1,72000)).
suggests( (c, b) -> suggestMatching(new String[]{"20"},b)).
suggests( (c, b) -> suggest(new String[]{"20"},b)).
executes((c) -> step(c.getSource(), getInteger(c,"ticks"))))).
then(literal("superHot").executes( (c)-> toggleSuperHot(c.getSource()))).
then(literal("health").
@@ -70,35 +70,35 @@ public class TickCommand
}
private static int setTps(ServerCommandSource source, float tps)
private static int setTps(CommandSourceStack source, float tps)
{
TickSpeed.tickrate(tps, true);
queryTps(source);
return (int)tps;
}
private static int queryTps(ServerCommandSource source)
private static int queryTps(CommandSourceStack source)
{
Messenger.m(source, "w Current tps is: ",String.format("wb %.1f", TickSpeed.tickrate));
return (int)TickSpeed.tickrate;
}
private static int setWarp(ServerCommandSource source, int advance, String tail_command)
private static int setWarp(CommandSourceStack source, int advance, String tail_command)
{
ServerPlayerEntity player = null;
ServerPlayer player = null;
try
{
player = source.getPlayer();
player = source.getPlayerOrException();
}
catch (CommandSyntaxException ignored)
{
}
BaseText message = TickSpeed.tickrate_advance(player, advance, tail_command, source);
source.sendFeedback(message, false);
BaseComponent message = TickSpeed.tickrate_advance(player, advance, tail_command, source);
source.sendSuccess(message, false);
return 1;
}
private static int freezeStatus(ServerCommandSource source)
private static int freezeStatus(CommandSourceStack source)
{
if(TickSpeed.isPaused())
{
@@ -111,7 +111,7 @@ public class TickCommand
return 1;
}
private static int setFreeze(ServerCommandSource source, boolean isDeep, boolean freeze)
private static int setFreeze(CommandSourceStack source, boolean isDeep, boolean freeze)
{
TickSpeed.setFrozenState(freeze, isDeep);
if (TickSpeed.isPaused())
@@ -125,19 +125,19 @@ public class TickCommand
return 1;
}
private static int toggleFreeze(ServerCommandSource source, boolean isDeep)
private static int toggleFreeze(CommandSourceStack source, boolean isDeep)
{
return setFreeze(source, isDeep, !TickSpeed.isPaused());
}
private static int step(ServerCommandSource source, int advance)
private static int step(CommandSourceStack source, int advance)
{
TickSpeed.add_ticks_to_run_in_pause(advance);
Messenger.m(source, "gi Stepping " + advance + " tick" + (advance != 1 ? "s" : ""));
return 1;
}
private static int toggleSuperHot(ServerCommandSource source)
private static int toggleSuperHot(CommandSourceStack source)
{
TickSpeed.is_superHot = !TickSpeed.is_superHot;
ServerNetworkHandler.updateSuperHotStateToConnectedPlayers();
@@ -152,13 +152,13 @@ public class TickCommand
return 1;
}
public static int healthReport(ServerCommandSource source, int ticks)
public static int healthReport(CommandSourceStack source, int ticks)
{
CarpetProfiler.prepare_tick_report(source, ticks);
return 1;
}
public static int healthEntities(ServerCommandSource source, int ticks)
public static int healthEntities(CommandSourceStack source, int ticks)
{
CarpetProfiler.prepare_entity_report(source, ticks);
return 1;