Search in sources :

Example 1 with MessageIgnorer

use of at.haha007.edenclient.mods.MessageIgnorer 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)

Aggregations

EdenClient (at.haha007.edenclient.EdenClient)1 AddChatMessageCallback (at.haha007.edenclient.callbacks.AddChatMessageCallback)1 LeaveWorldCallback (at.haha007.edenclient.callbacks.LeaveWorldCallback)1 CommandManager.literal (at.haha007.edenclient.command.CommandManager.literal)1 MessageIgnorer (at.haha007.edenclient.mods.MessageIgnorer)1 ChatColor (at.haha007.edenclient.utils.ChatColor)1 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)1 PlayerUtils.sendModMessage (at.haha007.edenclient.utils.PlayerUtils.sendModMessage)1 Scheduler (at.haha007.edenclient.utils.Scheduler)1 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)1 PerWorldConfig (at.haha007.edenclient.utils.config.PerWorldConfig)1 BiStringStringMap (at.haha007.edenclient.utils.config.wrappers.BiStringStringMap)1 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Predicate (java.util.function.Predicate)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ClientCommandSource (net.minecraft.client.network.ClientCommandSource)1 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 Item (net.minecraft.item.Item)1