use of net.minecraft.util.registry.DefaultedRegistry 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;
}
use of net.minecraft.util.registry.DefaultedRegistry 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.");
}
Aggregations