Search in sources :

Example 6 with ClientCommandSource

use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.

the class ChestShopItemNames method registerCommand.

public LiteralArgumentBuilder<ClientCommandSource> registerCommand() {
    LiteralArgumentBuilder<ClientCommandSource> mapItemNames = literal("mapitemnames");
    mapItemNames.executes(c -> {
        sendModMessage("/datafetcher mapitemnames <start/check>");
        return 1;
    });
    mapItemNames.then(literal("start").executes(c -> {
        ClientPlayerEntity entityPlayer = PlayerUtils.getPlayer();
        if (nameLookupRunning) {
            sendModMessage("Mapping of item names already running!");
            return -1;
        }
        MessageIgnorer mi = EdenClient.getMod(MessageIgnorer.class);
        mi.enable(MessageIgnorer.Predefined.ITEM_INFO);
        boolean wasMessageIgnoringEnabled = mi.isEnabled();
        mi.setEnabled(true);
        DefaultedRegistry<Item> itemRegistry = Registry.ITEM;
        String[] minecraftIDs = itemRegistry.stream().map(itemRegistry::getId).map(Identifier::toString).map(itemName -> itemName.split(":")[1]).map(itemName -> itemName.replace('_', ' ')).map(String::toLowerCase).filter(Predicate.not(itemNameMap::containsValue)).toList().toArray(new String[0]);
        sendModMessage(ChatColor.GOLD + "Started Mapping. Mapping will take about " + ChatColor.AQUA + (minecraftIDs.length / 60 + 1) + " minutes");
        AtomicInteger index = new AtomicInteger();
        nameLookupRunning = true;
        Scheduler.get().scheduleSyncRepeating(() -> {
            int i = index.getAndIncrement();
            if (i >= minecraftIDs.length) {
                sendModMessage("Finished mapping of all items! Disconnect from the world now to save all items into the config properly! They will be loaded the next time you join the world.");
                Scheduler.get().scheduleSyncDelayed(() -> {
                    nameLookupRunning = false;
                    mi.disable(MessageIgnorer.Predefined.ITEM_INFO);
                    mi.setEnabled(wasMessageIgnoringEnabled);
                }, 50);
                return false;
            }
            String item = minecraftIDs[i];
            System.out.println("Mapping item:" + item);
            entityPlayer.sendChatMessage("/iteminfo " + item);
            if (i % 60 == 0) {
                sendModMessage(ChatColor.GOLD + "Mapped " + ChatColor.AQUA + i + ChatColor.GOLD + " items of " + ChatColor.AQUA + minecraftIDs.length + ChatColor.GOLD + " this far.");
            }
            return true;
        }, 20, 0);
        return 1;
    }));
    mapItemNames.then(literal("reset").executes(c -> {
        sendModMessage("Mapped item names cleared.");
        itemNameMap.clear();
        return 1;
    }));
    mapItemNames.then(literal("check").executes(c -> {
        sendModMessage(ChatColor.GOLD + "Amount of items mapped: " + ChatColor.AQUA + itemNameMap.size());
        return 1;
    }));
    return mapItemNames;
}
Also used : PerWorldConfig(at.haha007.edenclient.utils.config.PerWorldConfig) ChatColor(at.haha007.edenclient.utils.ChatColor) BiStringStringMap(at.haha007.edenclient.utils.config.wrappers.BiStringStringMap) Item(net.minecraft.item.Item) Predicate(java.util.function.Predicate) AddChatMessageCallback(at.haha007.edenclient.callbacks.AddChatMessageCallback) CommandManager.literal(at.haha007.edenclient.command.CommandManager.literal) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Registry(net.minecraft.util.registry.Registry) DefaultedRegistry(net.minecraft.util.registry.DefaultedRegistry) EdenClient(at.haha007.edenclient.EdenClient) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlayerUtils.sendModMessage(at.haha007.edenclient.utils.PlayerUtils.sendModMessage) ConfigSubscriber(at.haha007.edenclient.utils.config.ConfigSubscriber) LeaveWorldCallback(at.haha007.edenclient.callbacks.LeaveWorldCallback) MessageIgnorer(at.haha007.edenclient.mods.MessageIgnorer) Identifier(net.minecraft.util.Identifier) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) Pattern(java.util.regex.Pattern) Scheduler(at.haha007.edenclient.utils.Scheduler) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) PlayerUtils(at.haha007.edenclient.utils.PlayerUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) MessageIgnorer(at.haha007.edenclient.mods.MessageIgnorer) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) DefaultedRegistry(net.minecraft.util.registry.DefaultedRegistry)

Example 7 with ClientCommandSource

use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.

the class Nuker method removeCommand.

private ArgumentBuilder<ClientCommandSource, ?> removeCommand() {
    LiteralArgumentBuilder<ClientCommandSource> cmd = literal("remove");
    cmd.then(argument("type", StringArgumentType.word()).suggests((context, builder) -> {
        for (Block block : filter) {
            builder.suggest(Registry.BLOCK.getId(block).getPath());
        }
        return builder.buildFuture();
    }).executes(context -> {
        String name = context.getArgument("type", String.class);
        Identifier identifier = new Identifier(name);
        filter.remove(Registry.BLOCK.get(identifier));
        PlayerUtils.sendModMessage("Removed " + name);
        return 1;
    }));
    return cmd;
}
Also used : ServerCommandSource(net.minecraft.server.command.ServerCommandSource) PerWorldConfig(at.haha007.edenclient.utils.config.PerWorldConfig) ChatColor(at.haha007.edenclient.utils.ChatColor) PosArgument(net.minecraft.command.argument.PosArgument) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) Block(net.minecraft.block.Block) CommandManager(at.haha007.edenclient.command.CommandManager) PlayerTickCallback(at.haha007.edenclient.callbacks.PlayerTickCallback) BlockSet(at.haha007.edenclient.utils.config.wrappers.BlockSet) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) Hand(net.minecraft.util.Hand) BlockState(net.minecraft.block.BlockState) BlockPosArgumentType(net.minecraft.command.argument.BlockPosArgumentType) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket) net.minecraft.util.math(net.minecraft.util.math) ClientPlayerInteractionManager(net.minecraft.client.network.ClientPlayerInteractionManager) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Blocks(net.minecraft.block.Blocks) Registry(net.minecraft.util.registry.Registry) PlayerUtils.getHitDirectionForBlock(at.haha007.edenclient.utils.PlayerUtils.getHitDirectionForBlock) List(java.util.List) Stream(java.util.stream.Stream) ConfigSubscriber(at.haha007.edenclient.utils.config.ConfigSubscriber) DoubleArgumentType(com.mojang.brigadier.arguments.DoubleArgumentType) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) Comparator(java.util.Comparator) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) ArgumentBuilder(com.mojang.brigadier.builder.ArgumentBuilder) PlayerUtils(at.haha007.edenclient.utils.PlayerUtils) ClientWorld(net.minecraft.client.world.ClientWorld) Identifier(net.minecraft.util.Identifier) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) Block(net.minecraft.block.Block) PlayerUtils.getHitDirectionForBlock(at.haha007.edenclient.utils.PlayerUtils.getHitDirectionForBlock)

Example 8 with ClientCommandSource

use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.

the class Rainbowifier method registerCommand.

private void registerCommand() {
    LiteralArgumentBuilder<ClientCommandSource> node = literal("erainbowify");
    node.then(literal("fancy").then(argument("input", StringArgumentType.greedyString()).executes(c -> {
        String input = c.getArgument("input", String.class);
        String message = rainbowifyMessageFancy(input);
        if (message.length() >= 256) {
            sendModMessage(ChatColor.GOLD + "Your message is too long.");
            return 0;
        }
        ClientPlayerEntity entityPlayer = PlayerUtils.getPlayer();
        entityPlayer.sendChatMessage(rainbowifyMessageFancy(input));
        return 1;
    })));
    node.then(literal("simple").then(argument("input", StringArgumentType.greedyString()).executes(c -> {
        String input = c.getArgument("input", String.class);
        String message = rainbowifyMessageSimple(input);
        if (message.length() >= 256) {
            sendModMessage(ChatColor.GOLD + "Your message is too long.");
            return 0;
        }
        ClientPlayerEntity entityPlayer = PlayerUtils.getPlayer();
        entityPlayer.sendChatMessage(rainbowifyMessageSimple(input));
        return 1;
    })));
    node.then(literal("msg").then(argument("player", StringArgumentType.word()).then(argument("message", StringArgumentType.greedyString()).executes(c -> {
        String player = c.getArgument("player", String.class);
        String originalMessage = c.getArgument("message", String.class);
        String message = "/msg " + player + " " + rainbowifyMessageFancy(originalMessage);
        if (message.length() >= 256) {
            message = "/msg " + player + " " + rainbowifyMessageSimple(originalMessage);
            if (message.length() >= 256) {
                sendModMessage(ChatColor.GOLD + "Your message is too long.");
                return 0;
            }
        }
        ClientPlayerEntity entityPlayer = PlayerUtils.getPlayer();
        entityPlayer.sendChatMessage(message);
        return 1;
    }))));
    node.then(literal("auto").then(argument("input", StringArgumentType.greedyString()).executes(c -> {
        String input = c.getArgument("input", String.class);
        String message = rainbowifyMessageFancy(input);
        if (message.length() >= 256) {
            message = rainbowifyMessageSimple(input);
            if (message.length() >= 256) {
                sendModMessage(ChatColor.GOLD + "Your message is too long.");
                return 0;
            }
        }
        ClientPlayerEntity entityPlayer = PlayerUtils.getPlayer();
        entityPlayer.sendChatMessage(message);
        return 1;
    })));
    node.then(literal("freq").then(argument("frequency", DoubleArgumentType.doubleArg(0.1, 1.0)).executes(c -> {
        this.freq = c.getArgument("frequency", Double.class);
        sendModMessage(ChatColor.GOLD + "Frequency updated to " + ChatColor.AQUA + freq);
        return 1;
    })));
    node.executes(c -> {
        sendDebugMessage();
        return 1;
    });
    register(node, "Rainbowifier enables you to send rainbow-colored messages into either the global chat or directly as a private message.");
}
Also used : StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) List(java.util.List) PerWorldConfig(at.haha007.edenclient.utils.config.PerWorldConfig) CommandManager(at.haha007.edenclient.command.CommandManager) PlayerUtils.sendModMessage(at.haha007.edenclient.utils.PlayerUtils.sendModMessage) ChatColor(at.haha007.edenclient.utils.ChatColor) ConfigSubscriber(at.haha007.edenclient.utils.config.ConfigSubscriber) DoubleArgumentType(com.mojang.brigadier.arguments.DoubleArgumentType) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) PlayerUtils(at.haha007.edenclient.utils.PlayerUtils) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Example 9 with ClientCommandSource

use of net.minecraft.client.network.ClientCommandSource in project EdenClient by HahaOO7.

the class AutoSell method registerCommand.

private void registerCommand(String cmd) {
    LiteralArgumentBuilder<ClientCommandSource> node = literal(cmd);
    node.then(literal("toggle").executes(c -> {
        enabled = !enabled;
        sendModMessage(enabled ? "AutoSell enabled" : "AutoSell disabled");
        return 1;
    }));
    node.then(literal("clear").executes(c -> {
        autoSellItems.clear();
        sendModMessage("Removed all entries");
        return 1;
    }));
    node.then(literal("list").executes(c -> {
        sendModMessage(autoSellItems.toString());
        return 1;
    }));
    DefaultedRegistry<Item> registry = Registry.ITEM;
    for (Item item : registry) {
        node.then(literal("add").then(literal(registry.getId(item).toString().replace("minecraft:", "")).executes(c -> {
            autoSellItems.add(item);
            sendModMessage("Added /sell " + item.getName().getString());
            return 1;
        })));
    }
    node.then(literal("remove").then(argument("item", StringArgumentType.greedyString()).suggests(this::suggestRemoveItems).executes(c -> {
        Optional<Item> opt = Registry.ITEM.getOrEmpty(new Identifier(c.getArgument("item", String.class).replace(" ", "_")));
        if (opt.isEmpty()) {
            sendModMessage("No item with this name exists.");
            return 1;
        }
        if (autoSellItems.remove(opt.get()))
            sendModMessage("Removed /sell " + opt.get().getName().getString());
        else {
            sendModMessage("Couldn't remove /sell " + opt.get().getName().getString() + " because it wasn't in your sell list.");
        }
        return 1;
    })));
    node.then(literal("stats").executes(c -> {
        ClientPlayerEntity entityPlayer = PlayerUtils.getPlayer();
        entityPlayer.sendChatMessage("/esellstatstracker global");
        return 1;
    }));
    node.executes(c -> {
        sendModMessage("/autosell clear");
        sendModMessage("/autosell list");
        sendModMessage("/autosell toggle");
        sendModMessage("/autosell add");
        sendModMessage("/autosell remove");
        return 1;
    });
    register(node, "AutoSell allows for automatic selling of items in any kind of command-accessible public server shop.", "It will always toggle when your inventory is full and execute the sell-command. You can select the items you want to sell yourself.");
}
Also used : PlayerInventory(net.minecraft.entity.player.PlayerInventory) Suggestions(com.mojang.brigadier.suggestion.Suggestions) PerWorldConfig(at.haha007.edenclient.utils.config.PerWorldConfig) CommandContext(com.mojang.brigadier.context.CommandContext) Item(net.minecraft.item.Item) CompletableFuture(java.util.concurrent.CompletableFuture) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Registry(net.minecraft.util.registry.Registry) DefaultedRegistry(net.minecraft.util.registry.DefaultedRegistry) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) CommandManager(at.haha007.edenclient.command.CommandManager) PlayerUtils.sendModMessage(at.haha007.edenclient.utils.PlayerUtils.sendModMessage) ConfigSubscriber(at.haha007.edenclient.utils.config.ConfigSubscriber) ItemSet(at.haha007.edenclient.utils.config.wrappers.ItemSet) Identifier(net.minecraft.util.Identifier) Optional(java.util.Optional) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) Comparator(java.util.Comparator) PlayerInvChangeCallback(at.haha007.edenclient.callbacks.PlayerInvChangeCallback) Collections(java.util.Collections) SuggestionsBuilder(com.mojang.brigadier.suggestion.SuggestionsBuilder) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) PlayerUtils(at.haha007.edenclient.utils.PlayerUtils) Item(net.minecraft.item.Item) Identifier(net.minecraft.util.Identifier) ClientCommandSource(net.minecraft.client.network.ClientCommandSource) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Aggregations

ClientCommandSource (net.minecraft.client.network.ClientCommandSource)9 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)8 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)8 PerWorldConfig (at.haha007.edenclient.utils.config.PerWorldConfig)8 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)8 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)8 CommandManager (at.haha007.edenclient.command.CommandManager)7 ChatColor (at.haha007.edenclient.utils.ChatColor)7 PlayerUtils.sendModMessage (at.haha007.edenclient.utils.PlayerUtils.sendModMessage)7 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)7 CommandContext (com.mojang.brigadier.context.CommandContext)5 Suggestions (com.mojang.brigadier.suggestion.Suggestions)5 SuggestionsBuilder (com.mojang.brigadier.suggestion.SuggestionsBuilder)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 EdenClient (at.haha007.edenclient.EdenClient)4 PlayerTickCallback (at.haha007.edenclient.callbacks.PlayerTickCallback)4 Collectors (java.util.stream.Collectors)4 GetTo (at.haha007.edenclient.mods.GetTo)3 ChestShopItemNames (at.haha007.edenclient.mods.datafetcher.ChestShopItemNames)3