Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions src/main/java/meteordevelopment/meteorclient/MeteorClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import meteordevelopment.meteorclient.utils.misc.Version;
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
import meteordevelopment.meteorclient.utils.misc.input.KeyBinds;
import meteordevelopment.meteorclient.utils.misc.text.MeteorTranslatableTextComponent;
import meteordevelopment.meteorclient.utils.network.OnlinePlayers;
import meteordevelopment.orbit.EventBus;
import meteordevelopment.orbit.EventHandler;
Expand All @@ -37,6 +38,7 @@
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.text.MutableText;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -197,4 +199,12 @@ private void onOpenScreen(OpenScreenEvent event) {
public static Identifier identifier(String path) {
return Identifier.of(MeteorClient.MOD_ID, path);
}

public static MutableText translatable(String key, Object... args) {
return MutableText.of(new MeteorTranslatableTextComponent(key, args));
}

public static MutableText translatable(String key, String fallback, Object... args) {
return MutableText.of(new MeteorTranslatableTextComponent(key, fallback, args));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public String getCommit() {

ModMetadata metadata = FabricLoader.getInstance().getModContainer(MeteorClient.MOD_ID).get().getMetadata();

MeteorClient.ADDON.id = metadata.getId();
MeteorClient.ADDON.name = metadata.getName();
MeteorClient.ADDON.authors = new String[metadata.getAuthors().size()];
if (metadata.containsCustomValue(MeteorClient.MOD_ID + ":color")) {
Expand All @@ -72,6 +73,7 @@ public String getCommit() {
throw new RuntimeException("Exception during addon init \"%s\".".formatted(metadata.getName()), throwable);
}

addon.id = metadata.getId();
addon.name = metadata.getName();

if (metadata.getAuthors().isEmpty()) throw new RuntimeException("Addon \"%s\" requires at least 1 author to be defined in it's fabric.mod.json. See https://fabricmc.net/wiki/documentation:fabric_mod_json_spec".formatted(addon.name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import meteordevelopment.meteorclient.utils.render.color.Color;

public abstract class MeteorAddon {
/** This field is automatically assigned from fabric.mod.json file.
* @since 1.21.11 */ // todo replace with exact version when released
public String id;

/** This field is automatically assigned from fabric.mod.json file. */
public String name;

Expand Down
33 changes: 24 additions & 9 deletions src/main/java/meteordevelopment/meteorclient/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.misc.MeteorTranslations;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import net.minecraft.registry.BuiltinRegistries;
import net.minecraft.server.command.CommandManager;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;

import java.util.List;
Expand All @@ -29,14 +31,23 @@ public abstract class Command {

private final String name;
private final String title;
private final String description;
private final List<String> aliases;
public final String translationKey;

// todo remove the description parameter in the next minecraft version update
@Deprecated(forRemoval = true)
public Command(String name, String description, String... aliases) {
this.name = name;
this.title = Utils.nameToTitle(name);
this.description = description;
this.aliases = List.of(aliases);
this.translationKey = "meteor.command." + name;
}

public Command(String name) {
this.name = name;
this.title = Utils.nameToTitle(name);
this.aliases = List.of();
this.translationKey = "meteor.command." + name;
}

// Helper methods to painlessly infer the CommandSource generic type argument
Expand Down Expand Up @@ -65,10 +76,6 @@ public String getName() {
return name;
}

public String getDescription() {
return description;
}

public List<String> getAliases() {
return aliases;
}
Expand All @@ -90,16 +97,24 @@ public void info(Text message) {

public void info(String message, Object... args) {
ChatUtils.forceNextPrefixClass(getClass());
ChatUtils.infoPrefix(title, message, args);
ChatUtils.infoPrefix(title, MeteorTranslations.translate(translationKey + ".info." + message, message, args));
}

public void warning(String message, Object... args) {
ChatUtils.forceNextPrefixClass(getClass());
ChatUtils.warningPrefix(title, message, args);
ChatUtils.warningPrefix(title, MeteorTranslations.translate(translationKey + ".warning." + message, message, args));
}

public void error(String message, Object... args) {
ChatUtils.forceNextPrefixClass(getClass());
ChatUtils.errorPrefix(title, message, args);
ChatUtils.errorPrefix(title, MeteorTranslations.translate(translationKey + ".error." + message, message, args));
}

public MutableText translatable(String string, Object... args) {
return MeteorClient.translatable(translationKey + "." + string, args);
}

public MutableText translatable(String string, String fallback, Object... args) {
return MeteorClient.translatable(translationKey + "." + string, fallback, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class BindCommand extends Command {
public BindCommand() {
super("bind", "Binds a specified module to the next pressed key.");
super("bind");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class BindsCommand extends Command {
public BindsCommand() {
super("binds", "List of all bound modules.");
super("binds");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private MutableText getCommandText(Command command) {
}
tooltip.append(aliases.formatted(Formatting.GRAY)).append("\n\n");

tooltip.append(Text.literal(command.getDescription()).formatted(Formatting.WHITE));
tooltip.append(command.translatable("description")).formatted(Formatting.WHITE);

// Text
MutableText text = Text.literal(Utils.nameToTitle(command.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public DisconnectCommand() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(Text.literal("%s[%sDisconnectCommand%s] Disconnected by user.".formatted(Formatting.GRAY, Formatting.BLUE, Formatting.GRAY))));
mc.player.networkHandler.onDisconnect(new DisconnectS2CPacket(translatable("disconnection_message", Formatting.GRAY, Formatting.BLUE, Formatting.GRAY)));
return SINGLE_SUCCESS;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class DismountCommand extends Command {
public DismountCommand() {
super("dismount", "Dismounts you from entity you are riding.");
super("dismount");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import net.minecraft.client.network.ClientPlayerEntity;
Expand All @@ -19,14 +20,13 @@
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;

public class DropCommand extends Command {
private static final SimpleCommandExceptionType NOT_SPECTATOR = new SimpleCommandExceptionType(Text.literal("Can't drop items while in spectator."));
private static final SimpleCommandExceptionType NO_SUCH_ITEM = new SimpleCommandExceptionType(Text.literal("Could not find an item with that name!"));
private static final SimpleCommandExceptionType NOT_SPECTATOR = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.drop.exception.not_spectator"));
private static final SimpleCommandExceptionType NO_SUCH_ITEM = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.drop.exception.no_such_item"));

public DropCommand() {
super("drop", "Automatically drops specified items.");
super("drop");
}

@Override
Expand Down Expand Up @@ -70,9 +70,9 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {

// Specific item
builder.then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS))
.executes(context -> drop(player -> {
dropItem(player, context, Integer.MAX_VALUE);
}))
.executes(context -> drop(player ->
dropItem(player, context, Integer.MAX_VALUE)
))
.then(argument("amount", IntegerArgumentType.integer(1))
.executes(context -> drop(player -> {
int amount = IntegerArgumentType.getInteger(context, "amount");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.commands.arguments.RegistryEntryReferenceArgumentType;
import meteordevelopment.meteorclient.utils.Utils;
Expand All @@ -19,16 +20,15 @@
import net.minecraft.item.ItemStack;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.text.Text;

import java.util.function.ToIntFunction;

public class EnchantCommand extends Command {
private static final SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(Text.literal("You must be in creative mode to use this."));
private static final SimpleCommandExceptionType NOT_HOLDING_ITEM = new SimpleCommandExceptionType(Text.literal("You need to hold some item to enchant."));
private static final SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.enchant.exception.not_in_creative"));
private static final SimpleCommandExceptionType NOT_HOLDING_ITEM = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.enchant.exception.not_holding_item"));

public EnchantCommand() {
super("enchant", "Enchants the item in your hand. REQUIRES Creative mode.");
super("enchant");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
import meteordevelopment.meteorclient.systems.modules.player.FakePlayer;
import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerEntity;
import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerManager;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import net.minecraft.command.CommandSource;

public class FakePlayerCommand extends Command {
public FakePlayerCommand() {
super("fake-player", "Manages fake players that you can use for testing.");
super("fake-player");
}

@Override
Expand All @@ -43,12 +42,12 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
.executes(context -> {
FakePlayerEntity fp = FakePlayerArgumentType.get(context);
if (fp == null || !FakePlayerManager.contains(fp)) {
error("Couldn't find a Fake Player with that name.");
error("not_found");
return SINGLE_SUCCESS;
}

FakePlayerManager.remove(fp);
info("Removed Fake Player %s.".formatted(fp.getName().getString()));
info("removed", fp.getName().getString());

return SINGLE_SUCCESS;
})
Expand All @@ -65,7 +64,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("list")
.executes(context -> {
info("--- Fake Players ((highlight)%s(default)) ---", FakePlayerManager.count());
FakePlayerManager.forEach(fp -> ChatUtils.info("(highlight)%s".formatted(fp.getName().getString())));
FakePlayerManager.forEach(fp -> info("(highlight)%s".formatted(fp.getName().getString())));
return SINGLE_SUCCESS;
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class FovCommand extends Command {
public FovCommand() {
super("fov", "Changes your fov.");
super("fov");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class FriendsCommand extends Command {
public FriendsCommand() {
super("friends", "Manages friends.");
super("friends");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.utils.player.FindItemResult;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.minecraft.text.Text;

public class GiveCommand extends Command {
private final static SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(Text.literal("You must be in creative mode to use this."));
private final static SimpleCommandExceptionType NO_SPACE = new SimpleCommandExceptionType(Text.literal("No space in hotbar."));
private final static SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.give.exception.not_in_creative"));
private final static SimpleCommandExceptionType NO_SPACE = new SimpleCommandExceptionType(MeteorClient.translatable("meteor.command.give.exception.no_space"));

public GiveCommand() {
super("give", "Gives you any item.");
super("give");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class HClipCommand extends Command {
public HClipCommand() {
super("hclip", "Lets you clip through blocks horizontally.");
super("hclip");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class InputCommand extends Command {
);

public InputCommand() {
super("input", "Keyboard input simulation.");
super("input");
}

@Override
Expand Down Expand Up @@ -76,32 +76,32 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
}

builder.then(literal("clear").executes(ctx -> {
if (activeHandlers.isEmpty()) warning("No active keypress handlers.");
if (activeHandlers.isEmpty()) warning("no_handlers");
else {
info("Cleared all keypress handlers.");
info("cleared_handlers");
activeHandlers.forEach(MeteorClient.EVENT_BUS::unsubscribe);
activeHandlers.clear();
}
return SINGLE_SUCCESS;
}));

builder.then(literal("list").executes(ctx -> {
if (activeHandlers.isEmpty()) warning("No active keypress handlers.");
if (activeHandlers.isEmpty()) warning("no_handlers");
else {
info("Active keypress handlers: ");
info("");
for (int i = 0; i < activeHandlers.size(); i++) {
KeypressHandler handler = activeHandlers.get(i);
info("(highlight)%d(default) - (highlight)%s %d(default) ticks left out of (highlight)%d(default).", i, I18n.translate(handler.key.getId()), handler.ticks, handler.totalTicks);
info("keypress_handler", i, I18n.translate(handler.key.getId()), handler.ticks, handler.totalTicks);
}
}
return SINGLE_SUCCESS;
}));

builder.then(literal("remove").then(argument("index", IntegerArgumentType.integer(0)).executes(ctx -> {
int index = IntegerArgumentType.getInteger(ctx, "index");
if (index >= activeHandlers.size()) warning("Index out of range.");
if (index >= activeHandlers.size()) warning("out_of_range");
else {
info("Removed keypress handler.");
info("removed_handler");
MeteorClient.EVENT_BUS.unsubscribe(activeHandlers.get(index));
activeHandlers.remove(index);
}
Expand Down
Loading