moved a bunch of stuff

This commit is contained in:
gnembon committed 2019-05-12 01:48:19 -03:00
1 parent 72c276f976
commit ecced620a4
30 files changed
+4450 -51

No files matched your search

@@ -0,0 +1,202 @@
package carpet.commands;
import carpet.CarpetSettings;
import carpet.CarpetSettings.CarpetSettingEntry;
import carpet.utils.Messenger;
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 net.minecraft.network.chat.BaseComponent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import static net.minecraft.server.command.CommandSource.suggestMatching;
public class CarpetCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("carpet").requires((player) ->
player.hasPermissionLevel(2) && !CarpetSettings.locked);
literalargumentbuilder.executes((context)->listAllSettings(context.getSource())).
then(literal("list").
executes( (c) -> listSettings(c.getSource(),
"All CarpetMod Settings",
CarpetSettings.findAll(null))).
then(literal("defaults").
executes( (c)-> listSettings(c.getSource(),
"Current CarpetMod Startup Settings from carpet.conf",
CarpetSettings.findStartupOverrides(c.getSource().getMinecraftServer())))).
then(argument("tag",StringArgumentType.word()).
suggests( (c, b)->suggestMatching(CarpetSettings.default_tags, b)).
executes( (c) -> listSettings(c.getSource(),
String.format("CarpetMod Settings matching \"%s\"", StringArgumentType.getString(c, "tag")),
CarpetSettings.findAll(StringArgumentType.getString(c, "tag"))))));
for (CarpetSettingEntry rule: CarpetSettings.getAllCarpetSettings())
{
literalargumentbuilder.then(literal(rule.getName()).executes( (context) ->
displayRuleMenu(context.getSource(),rule)));
literalargumentbuilder.then(literal("removeDefault").
then(literal(rule.getName()).executes((context) ->
removeDefault(context.getSource(), rule))));
literalargumentbuilder.then(literal(rule.getName()).
then(argument("value", StringArgumentType.word()).
suggests((c, b)-> suggestMatching(rule.getOptions(),b)).
executes((context) ->
setRule(context.getSource(), rule, StringArgumentType.getString(context, "value")))));
literalargumentbuilder.then(literal("setDefault").
then(literal(rule.getName()).
then(argument("value", StringArgumentType.word()).
suggests((c, b)-> suggestMatching(rule.getOptions(),b)).
executes((context) ->
setDefault(context.getSource(), rule, StringArgumentType.getString(context, "value"))))));
}
dispatcher.register(literalargumentbuilder);
}
private static int displayRuleMenu(ServerCommandSource source, CarpetSettingEntry rule)
{
PlayerEntity player;
try
{
player = source.getPlayer();
}
catch (CommandSyntaxException e)
{
Messenger.m(source, "w "+rule.getName() +" is set to: ","wb "+rule.getStringValue());
return 1;
}
Messenger.m(player, "");
Messenger.m(player, "wb "+rule.getName(),"!/carpet "+rule.getName(),"^g refresh");
Messenger.m(player, "w "+rule.getToast());
Arrays.stream(rule.getInfo()).forEach(s -> Messenger.m(player, "g "+s));
List<BaseComponent> tags = new ArrayList<>();
tags.add(Messenger.c("w Tags: "));
for (String t: rule.getTags())
{
tags.add(Messenger.c("c ["+t+"]", "^g list all "+t+" settings","!/carpet list "+t));
tags.add(Messenger.c("w , "));
}
tags.remove(tags.size()-1);
Messenger.m(player, tags.toArray(new Object[0]));
Messenger.m(player, "w Current value: ",String.format("%s %s (%s value)",rule.getBoolValue()?"lb":"nb", rule.getStringValue(),rule.isDefault()?"default":"modified"));
List<BaseComponent> options = new ArrayList<>();
options.add(Messenger.c("w Options: ", "y [ "));
for (String o: rule.getOptions())
{
options.add(Messenger.c(
String.format("%s%s %s",(o.equals(rule.getDefault()))?"u":"", (o.equals(rule.getStringValue()))?"bl":"y", o ),
"^g switch to "+o,
String.format("?/carpet %s %s",rule.getName(),o)));
options.add(Messenger.c("w "));
}
options.remove(options.size()-1);
options.add(Messenger.c("y ]"));
Messenger.m(player, options.toArray(new Object[0]));
return 1;
}
private static int setRule(ServerCommandSource source, CarpetSettingEntry rule, String newValue)
{
CarpetSettings.set(rule.getName(), newValue);
Messenger.m(source, "w "+rule.toString()+", ", "c [change permanently?]",
"^w Click to keep the settings in carpet.conf to save across restarts",
"?/carpet setDefault "+rule.getName()+" "+rule.getStringValue());
return 1;
}
private static int setDefault(ServerCommandSource source, CarpetSettingEntry rule, String defaultValue)
{
CarpetSettings.setDefaultRule(source.getMinecraftServer(), rule.getName(), defaultValue);
Messenger.m(source ,"gi rule "+ rule.getName()+" will now default to "+ defaultValue);
return 1;
}
private static int removeDefault(ServerCommandSource source, CarpetSettingEntry rule)
{
CarpetSettings.removeDefaultRule(source.getMinecraftServer(), rule.getName());
Messenger.m(source ,"gi rule "+ rule.getName()+" defaults to Vanilla");
return 1;
}
private static BaseComponent displayInteractiveSetting(CarpetSettingEntry e)
{
List<Object> args = new ArrayList<>();
args.add("w - "+e.getName()+" ");
args.add("!/carpet "+e.getName());
args.add("^y "+e.getToast());
for (String option: e.getOptions())
{
String style = e.isDefault()?"g":(option.equalsIgnoreCase(e.getDefault())?"y":"e");
if (option.equalsIgnoreCase(e.getDefault()))
style = style+"b";
else if (option.equalsIgnoreCase(e.getStringValue()))
style = style+"u";
args.add(style+" ["+option+"]");
if (!option.equalsIgnoreCase(e.getStringValue()))
{
args.add("!/carpet " + e.getName() + " " + option);
args.add("^w switch to " + option);
}
args.add("w ");
}
args.remove(args.size()-1);
return Messenger.c(args.toArray(new Object[0]));
}
private static int listSettings(ServerCommandSource source, String title, CarpetSettingEntry[] settings_list)
{
try
{
PlayerEntity player = source.getPlayer();
Messenger.m(player,String.format("wb %s:",title));
Arrays.stream(settings_list).forEach(e -> Messenger.m(player,displayInteractiveSetting(e)));
}
catch (CommandSyntaxException e)
{
Messenger.m(source, "w s:"+title);
Arrays.stream(settings_list).forEach(r -> Messenger.m(source, "w - "+ r.toString()));
}
return 1;
}
private static int listAllSettings(ServerCommandSource source)
{
listSettings(source, "Current CarpetMod Settings", CarpetSettings.find_nondefault(source.getMinecraftServer()));
Messenger.m(source, "Carpet Mod version: "+CarpetSettings.carpetVersion);
try
{
PlayerEntity player = source.getPlayer();
List<Object> tags = new ArrayList<>();
tags.add("w Browse Categories:\n");
for (String t : CarpetSettings.default_tags)
{
tags.add("c [" + t+"]");
tags.add("^g list all " + t + " settings");
tags.add("!/carpet list " + t);
tags.add("w ");
}
tags.remove(tags.size() - 1);
Messenger.m(player, tags.toArray(new Object[0]));
}
catch (CommandSyntaxException e)
{
}
return 1;
}
}
@@ -0,0 +1,78 @@
package carpet.commands;
import carpet.CarpetSettings;
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.network.chat.BaseComponent;
public class CounterCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("counter").executes((context)
-> listAllCounters(context.getSource(), false)).requires((player) ->
CarpetSettings.getBool("hopperCounters"));
literalargumentbuilder.
then((CommandManager.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) ->
resetCounter(context.getSource(), color))));
literalargumentbuilder.then(CommandManager.literal(color).
then(CommandManager.literal("realtime").executes((context) ->
displayCounter(context.getSource(), color, true))));
}
dispatcher.register(literalargumentbuilder);
}
private static int displayCounter(ServerCommandSource source, String color, boolean realtime)
{
HopperCounter counter = HopperCounter.getCounter(color);
if (counter == null) throw new CommandException(Messenger.s("Unknown wool color: "+color));
for (BaseComponent message: counter.format(source.getMinecraftServer(), realtime, false))
{
source.sendFeedback(message, false);
}
return 1;
}
private static int resetCounter(ServerCommandSource source, String color)
{
if (color == null)
{
HopperCounter.resetAll(source.getMinecraftServer());
Messenger.m(source, "w Restarted all counters");
}
else
{
HopperCounter counter = HopperCounter.getCounter(color);
if (counter == null) throw new CommandException(Messenger.s("Unknown wool color"));
counter.reset(source.getMinecraftServer());
Messenger.m(source, "w Restarted "+color+" counter");
}
return 1;
}
private static int listAllCounters(ServerCommandSource source, boolean realtime)
{
for (BaseComponent message: HopperCounter.formatAll(source.getMinecraftServer(), realtime))
{
source.sendFeedback(message, false);
}
return 1;
}
}
@@ -0,0 +1,75 @@
package carpet.commands;
import carpet.CarpetSettings;
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.EntityType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.command.arguments.BlockPosArgumentType;
import net.minecraft.command.arguments.EntitySummonArgumentType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
public class PerimeterInfoCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> command = literal("perimeterinfo").
requires((player) -> CarpetSettings.getBool("commandPerimeterInfo")).
executes( (c) -> perimeterDiagnose(
c.getSource(),
new BlockPos(c.getSource().getPosition()),
null)).
then(argument("center position", BlockPosArgumentType.create()).
executes( (c) -> perimeterDiagnose(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "center position"),
null)).
then(argument("mob",EntitySummonArgumentType.create()).
suggests(SuggestionProviders.SUMMONABLE_ENTITIES).
executes( (c) -> perimeterDiagnose(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "center position"),
EntitySummonArgumentType.getEntitySummon(c, "mob").toString()
))));
dispatcher.register(command);
}
private static int perimeterDiagnose(ServerCommandSource source, BlockPos pos, String mobId)
{
CompoundTag nbttagcompound = new CompoundTag();
MobEntity entityliving = null;
if (mobId != null)
{
nbttagcompound.putString("id", mobId);
entityliving = (MobEntity) EntityType.loadEntityWithPassengers(nbttagcompound, source.getWorld(), (entity_1x) -> {
entity_1x.setPositionAndAngles(pos.getX(), pos.getY(), pos.getZ(), entity_1x.yaw, entity_1x.pitch);
return !source.getWorld().method_18768(entity_1x) ? null : entity_1x;
});
if (entityliving == null)
{
Messenger.m(source, "r Failed to spawn test entity");
return 0;
}
}
PerimeterDiagnostics.Result res = PerimeterDiagnostics.countSpots(source.getWorld(), pos, entityliving);
Messenger.m(source, "w Spawning spaces around ",Messenger.tp("c",pos), "w :");
Messenger.m(source, "w potential in-liquid: ","wb "+res.liquid);
Messenger.m(source, "w potential on-ground: ","wb "+res.ground);
if (entityliving != null)
{
Messenger.m(source, "w ", entityliving.getDisplayName() ,"w : ","wb "+res.specific);
res.samples.forEach(bp -> Messenger.m(source, "w ", Messenger.tp("c", bp)));
entityliving.remove();
}
return 1;
}
}
@@ -0,0 +1,474 @@
package carpet.commands;
import carpet.CarpetSettings;
import carpet.patches.EntityPlayerMPFake;
import carpet.utils.Messenger;
import com.google.common.collect.Sets;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.suggestion.SuggestionProviders;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameType;
import net.minecraft.world.dimension.DimensionType;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
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.word;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
public class PlayerCommand
{
ServerPlayerEntity
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("player").
requires((player) -> CarpetSettings.getBool("commandPlayer")).
then(argument("player", word()).
suggests( (c, b) -> SuggestionProviders.suggest(getPlayers(c.getSource()), b)).
then(literal("stop").
executes(PlayerCommand::stop)).
then(literal("use").
executes(PlayerCommand::useOnce).
then(literal("once").
executes( PlayerCommand::useOnce)).
then(literal("continuous").
executes( PlayerCommand::useContinuous)).
then(literal("interval").
then(argument("ticks",integer(2)).
executes( PlayerCommand::useInterval)))).
then(literal("jump").
executes( PlayerCommand::jumpOnce).
then(literal("once").
executes( PlayerCommand::jumpOnce)).
then(literal("continuous").
executes( PlayerCommand::jumpContinuous)).
then(literal("interval").
then(argument("ticks",integer(2)).
executes( PlayerCommand::jumpInterval )))).
then(literal("attack").
executes(PlayerCommand::attackOnce).
then(literal("once").
executes(PlayerCommand::attackOnce)).
then(literal("continuous").
executes(PlayerCommand::attackContinuous)).
then(literal("interval").
then(argument("ticks",integer(2)).
executes(PlayerCommand::attackInterval)))).
then(literal("drop").
executes(PlayerCommand::dropItem)).
then(literal("swapHands").
executes(PlayerCommand::swapHands)).
then(literal("kill").
executes(PlayerCommand::kill)).
then(literal("shadow").
executes(PlayerCommand::shadow)).
then(literal("mount").
executes(PlayerCommand::mount)).
then(literal("dismount").
executes(PlayerCommand::dismount)).
then(literal("sneak").
executes(PlayerCommand::sneak)).
then(literal("sprint").
executes(PlayerCommand::sprint)).
then(literal("look").
then(literal("north").
executes(PlayerCommand::lookNorth)).
then(literal("south").
executes(PlayerCommand::lookSouth)).
then(literal("east").
executes(PlayerCommand::lookEast)).
then(literal("west").
executes(PlayerCommand::lookWest)).
then(literal("up").
executes(PlayerCommand::lookUp)).
then(literal("down").
executes(PlayerCommand::lookDown)).
then(argument("direction",RotationArgument.rotation()).
executes(PlayerCommand::lookAround))).
then(literal("turn").
then(literal("left").
executes(PlayerCommand::turnLeft)).
then(literal("right").
executes(PlayerCommand::turnRight)).
then(literal("back").
executes(PlayerCommand::turnBack)).
then(argument("direction",RotationArgument.rotation()).
executes(PlayerCommand::turn))).
then(literal("move").
then(literal("forward").
executes(PlayerCommand::moveForward)).
then(literal("backward").
executes(PlayerCommand::moveBackward)).
then(literal("left").
executes(PlayerCommand::strafeLeft)).
then(literal("right").
executes(PlayerCommand::strafeRight))).
then(literal("spawn").
executes(PlayerCommand::spawn).
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.getDimension()).
executes(PlayerCommand::spawn)))))))));
dispatcher.register(literalargumentbuilder);
}
private static Collection<String> getPlayers(ServerCommandSource source)
{
Set<String> players = Sets.newLinkedHashSet( Arrays.asList("Steve","Alex"));
players.addAll(source.getPlayerNames());
return players;
}
private static ServerPlayerEntityy getPlayer(CommandContext<ServerCommandSource> context)
{
String playerName = getString(context,"player");
MinecraftServer server = context.getSource().getServer();
return (ServerPlayerEntityy) server.getPlayerList().getPlayerByUsername(playerName);
}
private static boolean cantSpawn(CommandContext<ServerCommandSource> context)
{
String playerName = getString(context,"player");
PlayerEntity player = context.getSource().getServer().getPlayerList().getPlayerByUsername(playerName);
if (player != null)
{
Messenger.m(context.getSource(), "r Player ", "rb "+playerName, "r is already logged on");
return true;
}
return false;
}
private static boolean cantManipulate(CommandContext<ServerCommandSource> context)
{
PlayerEntity player = getPlayer(context);
if (player == null)
{
Messenger.m(context.getSource(),"r Can only manipulate existing players");
return true;
}
PlayerEntity sendingPlayer;
try
{
sendingPlayer = context.getSource().asPlayer();
}
catch (CommandSyntaxException e)
{
return false;
}
if (!(context.getSource().getServer().getPlayerList().canSendCommands(sendingPlayer.getGameProfile())))
{
if (!(sendingPlayer == player || player instanceof EntityPlayerMPFake))
{
Messenger.m(context.getSource(),"r Non OP players can't control other real players");
return true;
}
}
return false;
}
private static boolean cantShadow(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context))
return true;
PlayerEntity player = getPlayer(context);
if (player instanceof EntityPlayerMPFake)
{
Messenger.m(context.getSource(), "r Only real players can be shadowed");
return true;
}
return false;
}
private static boolean cantReMove(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context))
return true;
PlayerEntity player = getPlayer(context);
if (!(player instanceof EntityPlayerMPFake))
{
Messenger.m(context.getSource(), "r Only fake players can be moved or killed");
return true;
}
return false;
}
private static int stop(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.stop();
return 1;
}
private static int useOnce(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.useOnce();
return 1;
}
private static int useContinuous(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.setUseForever();
return 1;
}
private static int useInterval(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
int ticks = getInteger(context, "ticks");
getPlayer(context).actionPack.setUse(ticks, 0);
return 1;
}
private static int jumpOnce(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.jumpOnce();
return 1;
}
private static int jumpContinuous(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.setJumpForever();
return 1;
}
private static int jumpInterval(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
int ticks = getInteger(context, "ticks");
getPlayer(context).actionPack.setJump(ticks, 0);
return 1;
}
private static int attackOnce(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.attackOnce();
getPlayer(context).actionPack.resetBlockRemoving(true);
return 1;
}
private static int attackContinuous(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.setAttackForever();
return 1;
}
private static int attackInterval(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
int ticks = getInteger(context, "ticks");
getPlayer(context).actionPack.setAttack(ticks, 0);
return 1;
}
private static int dropItem(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.dropItem();
return 1;
}
private static int swapHands(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.swapHands();
return 1;
}
private static int kill(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).onKillCommand();
return 1;
}
private static int shadow(CommandContext<ServerCommandSource> context)
{
if (cantShadow(context)) return 0;
EntityPlayerMPFake.createShadow(
context.getSource().getServer(),
getPlayer(context));
return 1;
}
private static int mount(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.mount();
return 1;
}
private static int dismount(CommandContext<ServerCommandSource> context)
{
if (cantManipulate(context)) return 0;
getPlayer(context).actionPack.dismount();
return 1;
}
private static int sneak(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.setSneaking(true);
return 1;
}
private static int sprint(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.setSprinting(true);
return 1;
}
private static int lookNorth(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.look("north");
return 1;
}
private static int lookSouth(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.look("south");
return 1;
}
private static int lookEast(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.look("east");
return 1;
}
private static int lookWest(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.look("west");
return 1;
}
private static int lookUp(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.look("up");
return 1;
}
private static int lookDown(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.look("down");
return 1;
}
private static int lookAround(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
Vec2f vec2f = RotationArgument.getRotation(context, "direction").getRotation(context.getSource());
getPlayer(context).actionPack.look(vec2f.y,vec2f.x);
return 1;
}
private static int turnRight(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.turn("right");
return 1;
}
private static int turnLeft(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.turn("left");
return 1;
}
private static int turnBack(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.turn("back");
return 1;
}
private static int turn(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
Vec2f vec2f = RotationArgument.getRotation(context, "direction").getRotation(context.getSource());
getPlayer(context).actionPack.turn(vec2f.y,vec2f.x);
return 1;
}
private static int moveForward(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.setForward(1.0F);
return 1;
}
private static int moveBackward(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.setForward(-1.0F);
return 1;
}
private static int strafeLeft(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.setStrafing(-1.0F);
return 1;
}
private static int strafeRight(CommandContext<ServerCommandSource> context)
{
if (cantReMove(context)) return 0;
getPlayer(context).actionPack.setStrafing(1.0F);
return 1;
}
private static int spawn(CommandContext<ServerCommandSource> context) throws CommandSyntaxException
{
if (cantSpawn(context)) return 0;
Vec3d pos;
Vec2f facing;
DimensionType dim;
try
{
pos = Vec3Argument.getVec3(context, "position");
}
catch (IllegalArgumentException e)
{
pos = context.getSource().getPos();
}
try
{
facing = RotationArgument.getRotation(context, "direction").getRotation(context.getSource());
}
catch (IllegalArgumentException e)
{
facing = context.getSource().getRotation();
}
try
{
dim = DimensionArgument.func_212592_a(context, "dimension");
}
catch (IllegalArgumentException e)
{
dim = context.getSource().getWorld().dimension.getType();
}
GameType mode = GameType.CREATIVE;
try
{
ServerPlayerEntityy player = context.getSource().asPlayer();
mode = player.interactionManager.getGameType();
}
catch (CommandSyntaxException ignored)
{
}
PlayerEntity p = EntityPlayerMPFake.createFake(
getString(context,"player"),
context.getSource().getServer(),
pos.x, pos.y, pos.z,
facing.y, facing.x,
dim,
mode);
if (p == null)
{
Messenger.m(context.getSource(), "rb Player "+getString(context,"player")+" doesn't exist " +
"and cannot spawn in online mode. Turn the server offline to spawn non-existing players");
}
return 1;
}
}
@@ -0,0 +1,261 @@
package carpet.commands;
import carpet.CarpetSettings;
import carpet.helpers.HopperCounter;
import carpet.helpers.TickSpeed;
import carpet.utils.Messenger;
import carpet.utils.SpawnReporter;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.arguments.BlockPosArgumentType;
import net.minecraft.command.arguments.DimensionArgumentType;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.DyeColor;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.dimension.DimensionType;
import java.util.Arrays;
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.server.command.CommandSource.suggestMatching;
public class SpawnCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("spawn").
requires((player) -> CarpetSettings.getBool("commandSpawn"));
literalargumentbuilder.
then(literal("list").
then(argument("pos", BlockPosArgumentType.create()).
executes( (c) -> listSpawns(c.getSource(), BlockPosArgumentType.getBlockPos(c, "pos"))))).
then(literal("tracking").
executes( (c) -> printTrackingReport(c.getSource())).
then(literal("start").
executes( (c) -> startTracking(c.getSource(), null, null)).
then(argument("from", BlockPosArgumentType.create()).
then(argument("to", BlockPosArgumentType.create()).
executes( (c) -> startTracking(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "from"),
BlockPosArgumentType.getBlockPos(c, "to")))))).
then(literal("stop").
executes( (c) -> stopTracking(c.getSource()))).
then(argument("type", word()).
suggests( (c, b) -> suggestMatching(SpawnReporter.mob_groups,b)).
executes( (c) -> recentSpawnsForType(c.getSource(), getString(c, "type"))))).
then(literal("test").
executes( (c)-> runTest(c.getSource(), 72000, null)).
then(argument("ticks", integer(10,720000)).
executes( (c)-> runTest(
c.getSource(),
getInteger(c, "ticks"),
null)).
then(argument("counter", word()).
suggests( (c, b) -> suggestMatching(Arrays.stream(DyeColor.values()).map(DyeColor::toString),b)).
executes((c)-> runTest(
c.getSource(),
getInteger(c, "ticks"),
getString(c, "counter")))))).
then(literal("mocking").
then(argument("to do or not to do?", BoolArgumentType.bool()).
executes( (c) -> toggleMocking(c.getSource(), BoolArgumentType.getBool(c, "to do or not to do?"))))).
then(literal("rates").
executes( (c) -> generalMobcaps(c.getSource())).
then(literal("reset").
executes( (c) -> resetSpawnRates(c.getSource()))).
then(argument("type", word()).
suggests( (c, b) -> suggestMatching(SpawnReporter.mob_groups,b)).
then(argument("rounds", integer(0)).
suggests( (c, b) -> suggestMatching(new String[]{"1"},b)).
executes( (c) -> setSpawnRates(
c.getSource(),
getString(c, "type"),
getInteger(c, "rounds")))))).
then(literal("mobcaps").
executes( (c) -> generalMobcaps(c.getSource())).
then(literal("set").
then(argument("cap (hostile)", integer(1,1400)).
executes( (c) -> setMobcaps(c.getSource(), getInteger(c, "cap (hostile)"))))).
then(argument("dimension", DimensionArgumentType.create()).
executes( (c)-> mobcapsForDimension(c.getSource(), DimensionArgumentType.getDimensionArgument(c, "dimension"))))).
then(literal("entities").
executes( (c) -> generalMobcaps(c.getSource()) ).
then(argument("type", string()).
suggests( (c, b)->suggestMatching(SpawnReporter.mob_groups, b)).
executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type")))));
dispatcher.register(literalargumentbuilder);
}
private static int listSpawns(ServerCommandSource source, BlockPos pos)
{
Messenger.send(source, SpawnReporter.report(pos, source.getWorld()));
return 1;
}
private static int printTrackingReport(ServerCommandSource source)
{
Messenger.send(source, SpawnReporter.tracking_report(source.getWorld()));
return 1;
}
private static int startTracking(ServerCommandSource source, BlockPos a, BlockPos b)
{
if (SpawnReporter.track_spawns != 0L)
{
Messenger.m(source, "r You are already tracking spawning.");
return 0;
}
BlockPos lsl = null;
BlockPos usl = null;
if (a != null && b != null)
{
lsl = new BlockPos(
Math.min(a.getX(), b.getX()),
Math.min(a.getY(), b.getY()),
Math.min(a.getZ(), b.getZ()) );
usl = new BlockPos(
Math.max(a.getX(), b.getX()),
Math.max(a.getY(), b.getY()),
Math.max(a.getZ(), b.getZ()) );
}
SpawnReporter.reset_spawn_stats(false);
SpawnReporter.track_spawns = (long) source.getMinecraftServer().getTicks();
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)
{
Messenger.send(source, SpawnReporter.tracking_report(source.getWorld()));
SpawnReporter.reset_spawn_stats(false);
SpawnReporter.track_spawns = 0L;
SpawnReporter.lower_spawning_limit = null;
SpawnReporter.upper_spawning_limit = null;
Messenger.m(source, "gi Spawning tracking stopped.");
return 1;
}
private static int recentSpawnsForType(ServerCommandSource source, String mob_type)
{
if (!Arrays.asList(SpawnReporter.mob_groups).contains(mob_type))
{
Messenger.m(source, "r Wrong mob type: "+mob_type);
return 0;
}
Messenger.send(source, SpawnReporter.recent_spawns(source.getWorld(), mob_type));
return 1;
}
private static int runTest(ServerCommandSource source, int ticks, String counter)
{
//stop tracking
SpawnReporter.reset_spawn_stats(false);
//start tracking
SpawnReporter.track_spawns = (long) source.getMinecraftServer().getTicks();
//counter reset
if (counter == null)
{
HopperCounter.resetAll(source.getMinecraftServer());
}
else
{
HopperCounter hCounter = HopperCounter.getCounter(counter);
if (hCounter != null)
hCounter.reset(source.getMinecraftServer());
}
// tick warp 0
TickSpeed.tickrate_advance(null, 0, null, null);
// tick warp given player
ServerCommandSource csource = null;
PlayerEntity player = null;
try
{
player = source.getPlayer();
csource = source;
}
catch (CommandSyntaxException ignored)
{
}
TickSpeed.tickrate_advance(player, ticks, null, csource);
Messenger.m(source, String.format("gi Started spawn test for %d ticks", ticks));
return 1;
}
private static int toggleMocking(ServerCommandSource source, boolean domock)
{
if (domock)
{
SpawnReporter.initialize_mocking();
Messenger.m(source, "gi Mock spawns started, Spawn statistics reset");
}
else
{
SpawnReporter.stop_mocking();
Messenger.m(source, "gi Normal mob spawning, Spawn statistics reset");
}
return 1;
}
private static int generalMobcaps(ServerCommandSource source)
{
Messenger.send(source, SpawnReporter.printMobcapsForDimension(source.getWorld().getDimension().getType().getRawId()));
return 1;
}
private static int resetSpawnRates(ServerCommandSource source)
{
for (String s: SpawnReporter.spawn_tries.keySet())
{
SpawnReporter.spawn_tries.put(s,1);
}
Messenger.m(source, "gi Spawn rates brought to 1 round per tick for all groups.");
return 1;
}
private static int setSpawnRates(ServerCommandSource source, String mobtype, int rounds)
{
String code = SpawnReporter.get_creature_code_from_string(mobtype);
SpawnReporter.spawn_tries.put(code, 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)
{
double desired_ratio = (double)hostile_cap/ EntityCategory.MONSTER.getSpawnCap();
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, DimensionType dim)
{
Messenger.send(source, SpawnReporter.printMobcapsForDimension(dim.getRawId()));
return 1;
}
private static int listEntitiesOfType(ServerCommandSource source, String mobtype)
{
Messenger.send(source, SpawnReporter.printEntitiesByType(mobtype, source.getWorld()));
return 1;
}
}
@@ -0,0 +1,144 @@
package carpet.commands;
import carpet.CarpetSettings;
import carpet.helpers.TickSpeed;
import carpet.utils.CarpetProfiler;
import carpet.utils.Messenger;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.server.command.ServerCommandSource;
import static com.mojang.brigadier.arguments.FloatArgumentType.floatArg;
import static com.mojang.brigadier.arguments.FloatArgumentType.getFloat;
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.server.command.CommandSource.suggestMatching;
public class TickCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("tick").
requires((player) -> CarpetSettings.getBool("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)).
executes((c) -> setTps(c.getSource(), getFloat(c, "rate"))))).
then(literal("warp").
executes( (c)-> setWarp(c.getSource(), 0, null)).
then(argument("ticks", integer(0,4000000)).
suggests( (c, b) -> suggestMatching(new String[]{"3600","72000"},b)).
executes((c) -> setWarp(c.getSource(), getInteger(c,"ticks"), null)).
then(argument("tail command", greedyString()).
executes( (c) -> setWarp(
c.getSource(),
getInteger(c,"ticks"),
getString(c, "tail command")))))).
then(literal("freeze").executes( (c)-> toggleFreeze(c.getSource()))).
then(literal("step").
executes((c) -> step(1)).
then(argument("ticks", integer(1,72000)).
suggests( (c, b) -> suggestMatching(new String[]{"20"},b)).
executes((c) -> step(getInteger(c,"ticks"))))).
then(literal("superHot").executes( (c)-> toggleSuperHot(c.getSource()))).
then(literal("health").
executes( (c) -> healthReport(c.getSource(), 100)).
then(argument("ticks", integer(20,24000)).
executes( (c) -> healthReport(c.getSource(), getInteger(c, "ticks"))))).
then(literal("entities").
executes((c) -> healthEntities(c.getSource(), 100)).
then(argument("ticks", integer(20,24000)).
executes((c) -> healthEntities(c.getSource(), getInteger(c, "ticks")))));
dispatcher.register(literalargumentbuilder);
}
private static int setTps(ServerCommandSource source, float tps)
{
TickSpeed.tickrate(tps);
queryTps(source);
return (int)tps;
}
private static int queryTps(ServerCommandSource 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)
{
PlayerEntity player = null;
try
{
player = source.getPlayer();
}
catch (CommandSyntaxException ignored)
{
}
BaseComponent message = TickSpeed.tickrate_advance(player, advance, tail_command, source);
if (message != null)
{
source.sendFeedback(message, false);
}
return 1;
}
private static int toggleFreeze(ServerCommandSource source)
{
TickSpeed.is_paused = !TickSpeed.is_paused;
if (TickSpeed.is_paused)
{
Messenger.m(source, "gi Game is paused");
}
else
{
Messenger.m(source, "gi Game runs normally");
}
return 1;
}
private static int step(int advance)
{
TickSpeed.add_ticks_to_run_in_pause(advance);
return 1;
}
private static int toggleSuperHot(ServerCommandSource source)
{
TickSpeed.is_superHot = !TickSpeed.is_superHot;
if (TickSpeed.is_superHot)
{
Messenger.m(source,"gi Superhot enabled");
}
else
{
Messenger.m(source, "gi Superhot disabled");
}
return 1;
}
private static int healthReport(ServerCommandSource source, int ticks)
{
CarpetProfiler.prepare_tick_report(ticks);
return 1;
}
private static int healthEntities(ServerCommandSource source, int ticks)
{
CarpetProfiler.prepare_entity_report(ticks);
return 1;
}
}