Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.earthcomputer.clientcommands.features.BrigadierRemover;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import org.slf4j.Logger;
Expand All @@ -25,7 +25,6 @@
import java.util.regex.Pattern;

import static com.mojang.brigadier.arguments.StringArgumentType.*;
import static net.earthcomputer.clientcommands.command.ClientCommandHelper.*;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.*;

public class AliasCommand {
Expand All @@ -47,26 +46,26 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
.then(literal("add")
.then(argument("key", string())
.then(argument("command", greedyString())
.executes(ctx -> addAlias(getString(ctx, "key"), getString(ctx, "command"))))))
.executes(ctx -> addAlias(ctx.getSource(), getString(ctx, "key"), getString(ctx, "command"))))))
.then(literal("list")
.executes(ctx -> listAliases()))
.executes(ctx -> listAliases(ctx.getSource())))
.then(literal("remove")
.then(argument("key", string())
.executes(ctx -> removeAlias(getString(ctx, "key"))))));
.executes(ctx -> removeAlias(ctx.getSource(), getString(ctx, "key"))))));

for (String key: aliasMap.keySet()) {
for (String key : aliasMap.keySet()) {
if (dispatcher.getRoot().getChildren().stream().map(CommandNode::getName).noneMatch(literal -> literal.equals(key))) {
dispatcher.register(literal(key)
.executes(ctx -> executeAliasCommand(key, null))
.executes(ctx -> executeAliasCommand(ctx.getSource(), key, null))
.then(argument("arguments", greedyString())
.executes(ctx -> executeAliasCommand(key, getString(ctx, "arguments")))));
.executes(ctx -> executeAliasCommand(ctx.getSource(), key, getString(ctx, "arguments")))));
} else {
LOGGER.error("Attempted to register alias /{}, but that command already exists", key);
}
}
}

private static int executeAliasCommand(String aliasKey, String arguments) throws CommandSyntaxException {
private static int executeAliasCommand(FabricClientCommandSource source, String aliasKey, String arguments) throws CommandSyntaxException {
String cmd = aliasMap.get(aliasKey);
if (cmd == null) {
throw NOT_FOUND_EXCEPTION.create(aliasKey);
Expand All @@ -87,13 +86,12 @@ private static int executeAliasCommand(String aliasKey, String arguments) throws
} else if (arguments != null){
cmd += " " + arguments;
}
assert MinecraftClient.getInstance().player != null;
MinecraftClient.getInstance().player.sendChatMessage(cmd);
source.getPlayer().sendChatMessage(cmd);

return 0;
}

private static int addAlias(String key, String command) throws CommandSyntaxException {
private static int addAlias(FabricClientCommandSource source, String key, String command) throws CommandSyntaxException {
if (aliasMap.containsKey(key)) {
throw ALIAS_EXISTS_EXCEPTION.create(key);
}
Expand All @@ -105,29 +103,29 @@ private static int addAlias(String key, String command) throws CommandSyntaxExce
}

DISPATCHER.register(literal(key)
.executes(ctx -> executeAliasCommand(key, null))
.executes(ctx -> executeAliasCommand(source, key, null))
.then(argument("arguments", greedyString())
.executes(ctx -> executeAliasCommand(key, getString(ctx, "arguments")))));
.executes(ctx -> executeAliasCommand(source, key, getString(ctx, "arguments")))));
aliasMap.put(key, command);

saveAliases();
sendFeedback(new TranslatableText("commands.calias.addAlias.success", key));
source.sendFeedback(new TranslatableText("commands.calias.addAlias.success", key));
return 0;
}

private static int listAliases() {
private static int listAliases(FabricClientCommandSource source) {
if (aliasMap.isEmpty()) {
sendFeedback(new TranslatableText("commands.calias.listAliases.noAliasesRegistered"));
source.sendFeedback(new TranslatableText("commands.calias.listAliases.noAliasesRegistered"));
} else {
sendFeedback("commands.calias.listAliases.success", aliasMap.size());
for (String key: aliasMap.keySet()) {
sendFeedback(Formatting.BOLD + key + Formatting.RESET+ ": "+ aliasMap.get(key).replace("%","%%"));
source.sendFeedback(new TranslatableText("commands.calias.listAliases.success", aliasMap.size()));
for (String key : aliasMap.keySet()) {
source.sendFeedback(Text.of(Formatting.BOLD + key + Formatting.RESET + ": " + aliasMap.get(key).replace("%","%%")));
}
}
return 0;
}

private static int removeAlias(String key) throws CommandSyntaxException {
private static int removeAlias(FabricClientCommandSource source, String key) throws CommandSyntaxException {
if (aliasMap.containsKey(key)) {
BrigadierRemover.of(DISPATCHER).get(key).remove();
aliasMap.remove(key);
Expand All @@ -136,7 +134,7 @@ private static int removeAlias(String key) throws CommandSyntaxException {
}

saveAliases();
sendFeedback(new TranslatableText("commands.calias.removeAlias.success", key));
source.sendFeedback(new TranslatableText("commands.calias.removeAlias.success", key));
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.earthcomputer.clientcommands.render.RenderQueue;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.BlockPos;
Expand All @@ -16,7 +15,6 @@
import net.minecraft.world.chunk.WorldChunk;

import static dev.xpple.clientarguments.arguments.CBlockPosArgumentType.*;
import static net.earthcomputer.clientcommands.command.ClientCommandHelper.*;
import static net.earthcomputer.clientcommands.command.arguments.ListArgumentType.*;
import static net.earthcomputer.clientcommands.command.arguments.ClientBlockPredicateArgumentType.*;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.*;
Expand All @@ -38,7 +36,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
}

private static int areaStats(FabricClientCommandSource source, BlockPos pos1, BlockPos pos2, ClientBlockPredicate blockPredicate) throws CommandSyntaxException {
final ClientWorld world = MinecraftClient.getInstance().world;
final ClientWorld world = source.getWorld();
chunkManager = world.getChunkManager();
assertChunkIsLoaded(pos1.getX() >> 4, pos1.getZ() >> 4);
assertChunkIsLoaded(pos2.getX() >> 4, pos2.getZ() >> 4);
Expand Down Expand Up @@ -164,9 +162,9 @@ private static int areaStats(FabricClientCommandSource source, BlockPos pos1, Bl

long endTime = System.nanoTime();

sendFeedback("commands.careastats.output.chunksScanned", chunks, endTime - startTime, (endTime - startTime) / 1000000);
sendFeedback("commands.careastats.output.blocksMatched", blocks, (maxX - minX + 1) * (maxY - minY + 1) * (maxZ - minZ + 1));
sendFeedback("commands.careastats.output.entitiesFound", entities);
source.sendFeedback(new TranslatableText("commands.careastats.output.chunksScanned", chunks, endTime - startTime, (endTime - startTime) / 1000000));
source.sendFeedback(new TranslatableText("commands.careastats.output.blocksMatched", blocks, (maxX - minX + 1) * (maxY - minY + 1) * (maxZ - minZ + 1)));
source.sendFeedback(new TranslatableText("commands.careastats.output.entitiesFound", entities));

return blocks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import net.earthcomputer.multiconnect.api.MultiConnectAPI;
import net.earthcomputer.multiconnect.api.Protocols;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
Expand All @@ -28,7 +26,6 @@

import static com.mojang.brigadier.arguments.IntegerArgumentType.*;
import static com.mojang.brigadier.arguments.LongArgumentType.*;
import static net.earthcomputer.clientcommands.command.ClientCommandHelper.*;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.*;

public class BookCommand {
Expand Down Expand Up @@ -73,8 +70,8 @@ private static IntStream ascii(Random rand) {
return rand.ints(0x20, 0x7f);
}

private static int fillBook(CommandSource source, IntStream characterGenerator, int limit) throws CommandSyntaxException {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
private static int fillBook(FabricClientCommandSource source, IntStream characterGenerator, int limit) throws CommandSyntaxException {
ClientPlayerEntity player = source.getPlayer();
assert player != null;

ItemStack heldItem = player.getMainHandStack();
Expand Down Expand Up @@ -102,7 +99,7 @@ private static int fillBook(CommandSource source, IntStream characterGenerator,
heldItem.setSubNbt("pages", pagesNbt);
player.networkHandler.sendPacket(new BookUpdateC2SPacket(slot, pages, Optional.empty()));

sendFeedback("commands.cbook.success");
source.sendFeedback(new TranslatableText("commands.cbook.success"));

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ private static int cenchant(FabricClientCommandSource source, ItemAndEnchantment
.formatted(Formatting.RED)
.append(" ")
.append(getCommandTextComponent("commands.client.enable", "/ctemprule set enchantingPrediction true"));
sendFeedback(text);
source.sendFeedback(text);
return 0;
}
if (!TempRules.playerCrackState.knowsSeed() && TempRules.enchCrackState != EnchantmentCracker.CrackState.CRACKED) {
Text text = new TranslatableText("commands.cenchant.uncracked")
.formatted(Formatting.RED)
.append(" ")
.append(getCommandTextComponent("commands.client.crack", "/ccrackrng"));
sendFeedback(text);
source.sendFeedback(text);
return 0;
}

Expand All @@ -53,29 +53,25 @@ private static int cenchant(FabricClientCommandSource source, ItemAndEnchantment
simulate
);
if (result == null) {
sendFeedback("commands.cenchant.failed");
return 0;
source.sendFeedback(new TranslatableText("commands.cenchant.failed"));
} else {

if (simulate) {
if (result.itemThrows() < 0) {
sendFeedback("enchCrack.insn.itemThrows.noDummy");
source.sendFeedback(new TranslatableText("enchCrack.insn.itemThrows.noDummy"));
} else {
sendFeedback(new TranslatableText("enchCrack.insn.itemThrows", result.itemThrows(), (float)result.itemThrows() / 20f));
source.sendFeedback(new TranslatableText("enchCrack.insn.itemThrows", result.itemThrows(), (float)result.itemThrows() / 20f));
}
sendFeedback(new TranslatableText("enchCrack.insn.bookshelves", result.bookshelves()));
sendFeedback(new TranslatableText("enchCrack.insn.slot", result.slot() + 1));
sendFeedback("enchCrack.insn.enchantments");
source.sendFeedback(new TranslatableText("enchCrack.insn.bookshelves", result.bookshelves()));
source.sendFeedback(new TranslatableText("enchCrack.insn.slot", result.slot() + 1));
source.sendFeedback(new TranslatableText("enchCrack.insn.enchantments"));
for (EnchantmentLevelEntry ench : result.enchantments()) {
sendFeedback(new LiteralText("- ").append(ench.enchantment.getName(ench.level)));
source.sendFeedback(new LiteralText("- ").append(ench.enchantment.getName(ench.level)));
}
return 0;

} else {
sendFeedback("commands.cenchant.success");
return 0;
source.sendFeedback(new TranslatableText("commands.cenchant.success"));
}
}
return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.argument.ItemStackArgument;
import net.minecraft.item.ItemStack;
import net.minecraft.text.TranslatableText;

import static com.mojang.brigadier.arguments.IntegerArgumentType.*;
import static dev.xpple.clientarguments.arguments.CItemStackArgumentType.*;
import static net.earthcomputer.clientcommands.command.ClientCommandHelper.*;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.*;

public class CGiveCommand {
Expand All @@ -27,16 +25,15 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
}

private static int give(FabricClientCommandSource source, ItemStackArgument itemArgument, int count) throws CommandSyntaxException {
final MinecraftClient client = MinecraftClient.getInstance();
if (!client.player.getAbilities().creativeMode) {
if (!source.getPlayer().getAbilities().creativeMode) {
throw NOT_CREATIVE_EXCEPTION.create();
}

ItemStack stack = itemArgument.createStack(Math.min(count, itemArgument.getItem().getMaxCount()), false);
client.interactionManager.clickCreativeStack(stack, 36 + client.player.getInventory().selectedSlot);
client.player.playerScreenHandler.sendContentUpdates();
source.getClient().interactionManager.clickCreativeStack(stack, 36 + source.getPlayer().getInventory().selectedSlot);
source.getPlayer().playerScreenHandler.sendContentUpdates();

sendFeedback(new TranslatableText("commands.cgive.success", count, stack.toHoverableText()));
source.sendFeedback(new TranslatableText("commands.cgive.success", count, stack.toHoverableText()));
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.text.TranslatableText;
Expand All @@ -17,19 +16,16 @@
import static com.mojang.brigadier.arguments.IntegerArgumentType.*;
import static dev.xpple.clientarguments.arguments.CParticleEffectArgumentType.*;
import static dev.xpple.clientarguments.arguments.CVec3ArgumentType.*;
import static net.earthcomputer.clientcommands.command.ClientCommandHelper.*;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.*;

public class CParticleCommand {

private static final SimpleCommandExceptionType UNSUITABLE_PARTICLE_OPTION_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.cparticle.unsuitableParticleOption"));

private static final MinecraftClient client = MinecraftClient.getInstance();

public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(literal("cparticle")
.then(argument("name", particleEffect())
.executes(ctx -> spawnParticle(ctx.getSource(), getCParticle(ctx, "name"), client.player.getPos(), Vec3d.ZERO, 1, 1, false))
.executes(ctx -> spawnParticle(ctx.getSource(), getCParticle(ctx, "name"), ctx.getSource().getPlayer().getPos(), Vec3d.ZERO, 1, 1, false))
.then(argument("pos", vec3())
.executes(ctx -> spawnParticle(ctx.getSource(), getCParticle(ctx, "name"), getCVec3(ctx, "pos"), Vec3d.ZERO, 1, 1, false))
.then(argument("delta", vec3(false))
Expand All @@ -45,7 +41,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
}

private static int spawnParticle(FabricClientCommandSource source, ParticleEffect parameters, Vec3d pos, Vec3d delta, float speed, int count, boolean force) throws CommandSyntaxException {
switch (client.options.particles) {
switch (source.getClient().options.particles) {
case MINIMAL:
if (!force) {
throw UNSUITABLE_PARTICLE_OPTION_EXCEPTION.create();
Expand All @@ -56,14 +52,14 @@ private static int spawnParticle(FabricClientCommandSource source, ParticleEffec
}
default:
if (count == 0) {
client.world.addParticle(parameters, force, pos.x, pos.y, pos.z, delta.x * speed, delta.y * speed, delta.z * speed);
source.getWorld().addParticle(parameters, force, pos.x, pos.y, pos.z, delta.x * speed, delta.y * speed, delta.z * speed);
} else {
final Random random = client.getNetworkHandler().getWorld().random;
final Random random = source.getClient().getNetworkHandler().getWorld().random;
for (int i = 0; i < count; i++) {
client.world.addParticle(parameters, force, pos.x + delta.x * random.nextGaussian(), pos.y + delta.y * random.nextGaussian(), pos.z + delta.z * random.nextGaussian(), speed * random.nextGaussian(), speed * random.nextGaussian(), speed * random.nextGaussian());
source.getWorld().addParticle(parameters, force, pos.x + delta.x * random.nextGaussian(), pos.y + delta.y * random.nextGaussian(), pos.z + delta.z * random.nextGaussian(), speed * random.nextGaussian(), speed * random.nextGaussian(), speed * random.nextGaussian());
}
}
sendFeedback(new TranslatableText("commands.cparticle.success", Registry.PARTICLE_TYPE.getId(parameters.getType()).toString()));
source.sendFeedback(new TranslatableText("commands.cparticle.success", Registry.PARTICLE_TYPE.getId(parameters.getType()).toString()));
return 0;
}
}
Expand Down
Loading