From 87fca6d525c70c5e95122a3610916ad5f48cc4b8 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Thu, 3 Aug 2023 21:30:53 +0800 Subject: Refactor Scheduler#queueOpenScreen --- src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java | 4 ++-- src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java | 4 ++-- src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java index 29a6e687..040c8aed 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java @@ -1,7 +1,7 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon; -import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Scheduler; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.minecraft.client.MinecraftClient; @@ -56,6 +56,6 @@ public class DungeonMap { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") .then(ClientCommandManager.literal("hud") .then(ClientCommandManager.literal("dungeonmap") - .executes(context -> SkyblockerMod.getInstance().scheduler.queueOpenScreen(DungeonMapConfigScreen::new)))))); + .executes(Scheduler.queueOpenScreenCommand(DungeonMapConfigScreen::new)))))); } } \ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java index 7316577e..a52f288c 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -1,8 +1,8 @@ package me.xmrvizzy.skyblocker.skyblock.dwarven; -import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.CommsWidget; +import me.xmrvizzy.skyblocker.utils.Scheduler; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; @@ -45,7 +45,7 @@ public class DwarvenHud { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") .then(ClientCommandManager.literal("hud") .then(ClientCommandManager.literal("dwarven") - .executes(context -> SkyblockerMod.getInstance().scheduler.queueOpenScreen(DwarvenHudConfigScreen::new)))))); + .executes(Scheduler.queueOpenScreenCommand(DwarvenHudConfigScreen::new)))))); HudRenderCallback.EVENT.register((context, tickDelta) -> { if (!SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.enabled diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java index 44077b3e..36ff98c9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java @@ -7,6 +7,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Scheduler; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; @@ -179,7 +180,7 @@ public class Shortcuts { } return Command.SINGLE_SUCCESS; // Queue the screen or else the screen will be immediately closed after executing this command - })).then(literal("shortcuts").executes(context -> SkyblockerMod.getInstance().scheduler.queueOpenScreen(ShortcutsConfigScreen::new)))); + })).then(literal("shortcuts").executes(Scheduler.queueOpenScreenCommand(ShortcutsConfigScreen::new)))); } private static String modifyCommand(String command) { -- cgit From 43400f0a1bd0d4b2b0dd944d7a82019e37206c90 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:12:29 +0800 Subject: Refactor Trivia to use FairySouls --- .../xmrvizzy/skyblocker/skyblock/FairySouls.java | 9 ++++ .../skyblocker/skyblock/dungeon/Trivia.java | 55 ++++++++++++---------- 2 files changed, 38 insertions(+), 26 deletions(-) (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java index ccffdcca..dd8f20e7 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java @@ -20,6 +20,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.DyeColor; import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,6 +36,14 @@ public class FairySouls { private static final Map> fairySouls = new HashMap<>(); private static final Map>> foundFairies = new HashMap<>(); + public static CompletableFuture runAsyncAfterFairySoulsLoad(Runnable runnable) { + return fairySoulsLoaded.thenRunAsync(runnable); + } + + public static int getFairySoulsSize(@Nullable String location) { + return location == null ? fairySouls.values().stream().mapToInt(Set::size).sum() : fairySouls.get(location).size(); + } + public static void init() { fairySoulsLoaded = NEURepo.runAsyncAfterLoad(() -> { try { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java index f7598af5..9c7452ac 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java @@ -1,19 +1,18 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; - import me.xmrvizzy.skyblocker.chat.ChatFilterResult; import me.xmrvizzy.skyblocker.chat.ChatPatternListener; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.skyblock.FairySouls; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.regex.Matcher; public class Trivia extends ChatPatternListener { private static final Map answers; @@ -38,8 +37,7 @@ public class Trivia extends ChatPatternListener { MinecraftClient.getInstance().player.sendMessage(Text.of(" " + Formatting.GOLD + matcher.group(2) + Formatting.RED + " " + riddle), false); return player != null; } - } else - updateSolutions(matcher.group(0)); + } else updateSolutions(matcher.group(0)); return false; } @@ -56,7 +54,7 @@ public class Trivia extends ChatPatternListener { } static { - answers = new HashMap<>(); + answers = Collections.synchronizedMap(new HashMap<>()); answers.put("What is the status of The Watcher?", new String[]{"Stalker"}); answers.put("What is the status of Bonzo?", new String[]{"New Necromancer"}); answers.put("What is the status of Scarf?", new String[]{"Apprentice Necromancer"}); @@ -69,18 +67,6 @@ public class Trivia extends ChatPatternListener { answers.put("What is the status of Storm?", new String[]{"The Wither Lords"}); answers.put("What is the status of Necron?", new String[]{"The Wither Lords"}); answers.put("What is the status of Maxor, Storm, Goldor and Necron?", new String[]{"The Wither Lords"}); - answers.put("How many total Fairy Souls are there?", new String[]{"242 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Spider's Den?", new String[]{"19 Fairy Souls"}); - answers.put("How many Fairy Souls are there in The End?", new String[]{"12 Fairy Souls"}); - answers.put("How many Fairy Souls are there in The Farming Islands?", new String[]{"20 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Crimson Isle?", new String[]{"29 Fairy Souls"}); - answers.put("How many Fairy Souls are there in The Park?", new String[]{"11 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Jerry's Workshop?", new String[]{"5 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Hub?", new String[]{"79 Fairy Souls"}); - answers.put("How many Fairy Souls are there in The Hub?", new String[]{"79 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Deep Caverns?", new String[]{"21 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Gold Mine?", new String[]{"12 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Dungeon Hub?", new String[]{"7 Fairy Souls"}); answers.put("Which brother is on the Spider's Den?", new String[]{"Rick"}); answers.put("What is the name of Rick's brother?", new String[]{"Pat"}); answers.put("What is the name of the Painter in the Hub?", new String[]{"Marco"}); @@ -88,10 +74,27 @@ public class Trivia extends ChatPatternListener { answers.put("What is the name of the lady of the Nether?", new String[]{"Elle"}); answers.put("Which villager in the Village gives you a Rogue Sword?", new String[]{"Jamie"}); answers.put("How many unique minions are there?", new String[]{"59 Minions"}); - answers.put("Which of these enemies does not spawn in the Spider's Den?", new String[]{"Zombie Spider", "Cave Spider", "Wither Skeleton", - "Dashing Spooder", "Broodfather", "Night Spider"}); + answers.put("Which of these enemies does not spawn in the Spider's Den?", new String[]{"Zombie Spider", "Cave Spider", "Wither Skeleton", "Dashing Spooder", "Broodfather", "Night Spider"}); answers.put("Which of these monsters only spawns at night?", new String[]{"Zombie Villager", "Ghast"}); - answers.put("Which of these is not a dragon in The End?", new String[]{"Zoomer Dragon", "Weak Dragon", "Stonk Dragon", "Holy Dragon", "Boomer Dragon", - "Booger Dragon", "Older Dragon", "Elder Dragon", "Stable Dragon", "Professor Dragon"}); + answers.put("Which of these is not a dragon in The End?", new String[]{"Zoomer Dragon", "Weak Dragon", "Stonk Dragon", "Holy Dragon", "Boomer Dragon", "Booger Dragon", "Older Dragon", "Elder Dragon", "Stable Dragon", "Professor Dragon"}); + FairySouls.runAsyncAfterFairySoulsLoad(() -> { + answers.put("How many total Fairy Souls are there?", getFairySoulsSizeString(null)); + answers.put("How many Fairy Souls are there in Spider's Den?", getFairySoulsSizeString("combat_1")); + answers.put("How many Fairy Souls are there in The End?", getFairySoulsSizeString("combat_3")); + answers.put("How many Fairy Souls are there in The Farming Islands?", getFairySoulsSizeString("farming_1")); + answers.put("How many Fairy Souls are there in Crimson Isle?", getFairySoulsSizeString("crimson_isle")); + answers.put("How many Fairy Souls are there in The Park?", getFairySoulsSizeString("foraging_1")); + answers.put("How many Fairy Souls are there in Jerry's Workshop?", getFairySoulsSizeString("winter")); + answers.put("How many Fairy Souls are there in Hub?", getFairySoulsSizeString("hub")); + answers.put("How many Fairy Souls are there in The Hub?", getFairySoulsSizeString("hub")); + answers.put("How many Fairy Souls are there in Deep Caverns?", getFairySoulsSizeString("mining_2")); + answers.put("How many Fairy Souls are there in Gold Mine?", getFairySoulsSizeString("mining_1")); + answers.put("How many Fairy Souls are there in Dungeon Hub?", getFairySoulsSizeString("dungeon_hub")); + }); + } + + @NotNull + private static String[] getFairySoulsSizeString(@Nullable String location) { + return new String[]{"%d Fairy Souls".formatted(FairySouls.getFairySoulsSize(location))}; } } -- cgit From 0d0bd433af7f1250af27dd989b45aa7e5cab5223 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Mon, 7 Aug 2023 17:11:38 +0800 Subject: Fix TriviaTest --- src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java index dd8f20e7..2bdfa401 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java @@ -37,6 +37,10 @@ public class FairySouls { private static final Map>> foundFairies = new HashMap<>(); public static CompletableFuture runAsyncAfterFairySoulsLoad(Runnable runnable) { + if (fairySoulsLoaded == null) { + LOGGER.error("Fairy Souls have not being initialized yet! Please ensure the Fairy Souls module is initialized before modules calling this method in SkyblockerMod#onInitializeClient. This error can be safely ignore in a test environment."); + return CompletableFuture.completedFuture(null); + } return fairySoulsLoaded.thenRunAsync(runnable); } -- cgit From eeee6cc6aa9db5d2c9711bbfa10c67eccb5300df Mon Sep 17 00:00:00 2001 From: Yasin Date: Mon, 7 Aug 2023 21:04:48 +0200 Subject: update mod to 1.11.1 --- src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java index 2bdfa401..b7c4ff2f 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java @@ -33,6 +33,7 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit public class FairySouls { private static final Logger LOGGER = LoggerFactory.getLogger(FairySouls.class); private static CompletableFuture fairySoulsLoaded; + private static int maxSouls = 0; private static final Map> fairySouls = new HashMap<>(); private static final Map>> foundFairies = new HashMap<>(); @@ -45,7 +46,7 @@ public class FairySouls { } public static int getFairySoulsSize(@Nullable String location) { - return location == null ? fairySouls.values().stream().mapToInt(Set::size).sum() : fairySouls.get(location).size(); + return location == null ? maxSouls : fairySouls.get(location).size(); } public static void init() { @@ -54,6 +55,9 @@ public class FairySouls { BufferedReader reader = new BufferedReader(new FileReader(NEURepo.LOCAL_REPO_DIR.resolve("constants").resolve("fairy_souls.json").toFile())); for (Map.Entry fairySoulJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { if (fairySoulJson.getKey().equals("//") || fairySoulJson.getKey().equals("Max Souls")) { + if (fairySoulJson.getKey().equals("Max Souls")) { + maxSouls = fairySoulJson.getValue().getAsInt(); + } continue; } ImmutableSet.Builder fairySoulsForLocation = ImmutableSet.builder(); -- cgit From 506904b7a3a1d3d6024cf7c8193d02540b36e0f6 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Mon, 7 Aug 2023 16:18:46 -0400 Subject: Fix dungeons death counter in the tab hud --- .../xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDeathWidget.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDeathWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDeathWidget.java index 78e1aeae..05223211 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDeathWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/DungeonDeathWidget.java @@ -20,7 +20,7 @@ public class DungeonDeathWidget extends Widget { // match the deaths entry // group 1: amount of deaths - private static final Pattern DEATH_PATTERN = Pattern.compile("\\S*: \\((?\\d+)\\).*"); + private static final Pattern DEATH_PATTERN = Pattern.compile("Team Deaths: (?\\d+).*"); public DungeonDeathWidget() { super(TITLE, Formatting.DARK_PURPLE.getColorValue()); -- cgit From 79ba1ed6fc133bacf64ee8e3a5d1454d1eadde2f Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Tue, 8 Aug 2023 20:28:24 -0400 Subject: Add Item Renaming --- .../skyblocker/skyblock/item/ItemRenaming.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRenaming.java (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRenaming.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRenaming.java new file mode 100644 index 00000000..db672803 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRenaming.java @@ -0,0 +1,66 @@ +package me.xmrvizzy.skyblocker.skyblock.item; + +import java.util.Map; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; + +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.client.MinecraftClient; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.command.argument.TextArgumentType; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; + +public class ItemRenaming { + + public static void init() { + ClientCommandRegistrationCallback.EVENT.register(ItemRenaming::registerCommands); + } + + private static void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + dispatcher.register(ClientCommandManager.literal("skyblocker") + .then(ClientCommandManager.literal("renameItem") + .executes(context -> renameItem(context.getSource(), null)) + .then(ClientCommandManager.argument("textComponent", TextArgumentType.text()) + .executes(context -> renameItem(context.getSource(), context.getArgument("textComponent", Text.class)))))); + } + + private static int renameItem(FabricClientCommandSource source, Text text) { + MinecraftClient client = source.getClient(); + ItemStack heldItem = client.player.getMainHandStack(); + NbtCompound nbt = (heldItem != null) ? heldItem.getNbt() : null; + + if (Utils.isOnSkyblock() && nbt != null && nbt.contains("ExtraAttributes")) { + NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); + String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : null; + + if (itemUuid != null) { + Map customItemNames = SkyblockerConfig.get().general.customItemNames; + + if (text == null) { + //Remove custom item name when the text argument isn't passed + customItemNames.remove(itemUuid); + SkyblockerConfig.save(); + source.sendFeedback(Text.translatable("skyblocker.customItemNames.removed")); + } else { + //If the text is provided then set the item's custom name to it + customItemNames.put(itemUuid, text); + SkyblockerConfig.save(); + source.sendFeedback(Text.translatable("skyblocker.customItemNames.added")); + } + } else { + source.sendError(Text.translatable("skyblocker.customItemNames.noItemUuid")); + } + } else { + source.sendError(Text.translatable("skyblocker.customItemNames.unableToSetName")); + } + + return Command.SINGLE_SUCCESS; + } +} -- cgit From a629801cc3ffa5913bc07af173e8a01673a70681 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:01:18 -0400 Subject: Custom Armour Dye Colours --- .../skyblock/item/CustomArmorDyeColors.java | 87 ++++++++++++++++++++++ .../skyblocker/skyblock/item/CustomItemNames.java | 69 +++++++++++++++++ .../skyblocker/skyblock/item/ItemRenaming.java | 66 ---------------- 3 files changed, 156 insertions(+), 66 deletions(-) create mode 100644 src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomArmorDyeColors.java create mode 100644 src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomItemNames.java delete mode 100644 src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRenaming.java (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomArmorDyeColors.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomArmorDyeColors.java new file mode 100644 index 00000000..dd5614d1 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomArmorDyeColors.java @@ -0,0 +1,87 @@ +package me.xmrvizzy.skyblocker.skyblock.item; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; + +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.client.MinecraftClient; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.item.DyeableArmorItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; + +public class CustomArmorDyeColors { + + public static void init() { + ClientCommandRegistrationCallback.EVENT.register(CustomArmorDyeColors::registerCommands); + } + + private static void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + dispatcher.register(ClientCommandManager.literal("skyblocker") + .then(ClientCommandManager.literal("dyeColor") + .executes(context -> customizeDyeColor(context.getSource(), null)) + .then(ClientCommandManager.argument("hexCode", StringArgumentType.string()) + .executes(context -> customizeDyeColor(context.getSource(), StringArgumentType.getString(context, "hexCode")))))); + } + + private static int customizeDyeColor(FabricClientCommandSource source, String hex) { + MinecraftClient client = source.getClient(); + ItemStack heldItem = client.player.getMainHandStack(); + NbtCompound nbt = (heldItem != null) ? heldItem.getNbt() : null; + + if (hex != null && !isHexadecimalColor(hex)) { + source.sendError(Text.translatable("skyblocker.customDyeColors.invalidHex")); + return Command.SINGLE_SUCCESS; + } + + if (Utils.isOnSkyblock() && heldItem != null && heldItem.getItem() instanceof DyeableArmorItem) { + if (nbt != null && nbt.contains("ExtraAttributes")) { + NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); + String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : null; + + if (itemUuid != null) { + Object2IntOpenHashMap customDyeColors = SkyblockerConfig.get().general.customDyeColors; + + if (hex == null) { + if (customDyeColors.containsKey(itemUuid)) { + customDyeColors.removeInt(itemUuid); + SkyblockerConfig.save(); + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.removed")); + } else { + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.neverHad")); + } + } else { + customDyeColors.put(itemUuid, Integer.decode("0x" + hex.replace("#", "")).intValue()); + SkyblockerConfig.save(); + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.added")); + } + } else { + source.sendError(Text.translatable("skyblocker.customDyeColors.noItemUuid")); + } + } + } else { + if (!(heldItem.getItem() instanceof DyeableArmorItem)) { + source.sendError(Text.translatable("skyblocker.customDyeColors.notDyeable")); + return Command.SINGLE_SUCCESS; + } else { + source.sendError(Text.translatable("skyblocker.customDyeColors.unableToSetColor")); + } + } + + return Command.SINGLE_SUCCESS; + } + + private static boolean isHexadecimalColor(String s) { + s = s.replace("#", ""); + + return s.chars() + .allMatch(c -> "0123456789ABCDEFabcdef".indexOf(c) >= 0) && s.length() == 6; + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomItemNames.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomItemNames.java new file mode 100644 index 00000000..4ecff508 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomItemNames.java @@ -0,0 +1,69 @@ +package me.xmrvizzy.skyblocker.skyblock.item; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.client.MinecraftClient; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.command.argument.TextArgumentType; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; + +public class CustomItemNames { + + public static void init() { + ClientCommandRegistrationCallback.EVENT.register(CustomItemNames::registerCommands); + } + + private static void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + dispatcher.register(ClientCommandManager.literal("skyblocker") + .then(ClientCommandManager.literal("renameItem") + .executes(context -> renameItem(context.getSource(), null)) + .then(ClientCommandManager.argument("textComponent", TextArgumentType.text()) + .executes(context -> renameItem(context.getSource(), context.getArgument("textComponent", Text.class)))))); + } + + private static int renameItem(FabricClientCommandSource source, Text text) { + MinecraftClient client = source.getClient(); + ItemStack heldItem = client.player.getMainHandStack(); + NbtCompound nbt = (heldItem != null) ? heldItem.getNbt() : null; + + if (Utils.isOnSkyblock() && nbt != null && nbt.contains("ExtraAttributes")) { + NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); + String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : null; + + if (itemUuid != null) { + Object2ObjectOpenHashMap customItemNames = SkyblockerConfig.get().general.customItemNames; + + if (text == null) { + if (customItemNames.containsKey(itemUuid)) { + //Remove custom item name when the text argument isn't passed + customItemNames.remove(itemUuid); + SkyblockerConfig.save(); + source.sendFeedback(Text.translatable("skyblocker.customItemNames.removed")); + } else { + source.sendFeedback(Text.translatable("skyblocker.customItemNames.neverHad")); + } + } else { + //If the text is provided then set the item's custom name to it + customItemNames.put(itemUuid, text); + SkyblockerConfig.save(); + source.sendFeedback(Text.translatable("skyblocker.customItemNames.added")); + } + } else { + source.sendError(Text.translatable("skyblocker.customItemNames.noItemUuid")); + } + } else { + source.sendError(Text.translatable("skyblocker.customItemNames.unableToSetName")); + } + + return Command.SINGLE_SUCCESS; + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRenaming.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRenaming.java deleted file mode 100644 index db672803..00000000 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/ItemRenaming.java +++ /dev/null @@ -1,66 +0,0 @@ -package me.xmrvizzy.skyblocker.skyblock.item; - -import java.util.Map; - -import com.mojang.brigadier.Command; -import com.mojang.brigadier.CommandDispatcher; - -import me.xmrvizzy.skyblocker.config.SkyblockerConfig; -import me.xmrvizzy.skyblocker.utils.Utils; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; -import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.client.MinecraftClient; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.argument.TextArgumentType; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.Text; - -public class ItemRenaming { - - public static void init() { - ClientCommandRegistrationCallback.EVENT.register(ItemRenaming::registerCommands); - } - - private static void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { - dispatcher.register(ClientCommandManager.literal("skyblocker") - .then(ClientCommandManager.literal("renameItem") - .executes(context -> renameItem(context.getSource(), null)) - .then(ClientCommandManager.argument("textComponent", TextArgumentType.text()) - .executes(context -> renameItem(context.getSource(), context.getArgument("textComponent", Text.class)))))); - } - - private static int renameItem(FabricClientCommandSource source, Text text) { - MinecraftClient client = source.getClient(); - ItemStack heldItem = client.player.getMainHandStack(); - NbtCompound nbt = (heldItem != null) ? heldItem.getNbt() : null; - - if (Utils.isOnSkyblock() && nbt != null && nbt.contains("ExtraAttributes")) { - NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); - String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : null; - - if (itemUuid != null) { - Map customItemNames = SkyblockerConfig.get().general.customItemNames; - - if (text == null) { - //Remove custom item name when the text argument isn't passed - customItemNames.remove(itemUuid); - SkyblockerConfig.save(); - source.sendFeedback(Text.translatable("skyblocker.customItemNames.removed")); - } else { - //If the text is provided then set the item's custom name to it - customItemNames.put(itemUuid, text); - SkyblockerConfig.save(); - source.sendFeedback(Text.translatable("skyblocker.customItemNames.added")); - } - } else { - source.sendError(Text.translatable("skyblocker.customItemNames.noItemUuid")); - } - } else { - source.sendError(Text.translatable("skyblocker.customItemNames.unableToSetName")); - } - - return Command.SINGLE_SUCCESS; - } -} -- cgit From 16c6debb1cc90be5815cd188264b16ddf8b76f16 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Thu, 10 Aug 2023 10:55:45 +0800 Subject: Refactor CustomArmorDyeColors and CustomItemNames --- .../skyblock/item/CustomArmorDyeColors.java | 72 ++++++++++------------ .../skyblocker/skyblock/item/CustomItemNames.java | 21 +++---- 2 files changed, 42 insertions(+), 51 deletions(-) (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomArmorDyeColors.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomArmorDyeColors.java index dd5614d1..9385b4a1 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomArmorDyeColors.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomArmorDyeColors.java @@ -3,14 +3,12 @@ package me.xmrvizzy.skyblocker.skyblock.item; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; - import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.item.DyeableArmorItem; import net.minecraft.item.ItemStack; @@ -18,11 +16,10 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.text.Text; public class CustomArmorDyeColors { - public static void init() { ClientCommandRegistrationCallback.EVENT.register(CustomArmorDyeColors::registerCommands); } - + private static void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(ClientCommandManager.literal("skyblocker") .then(ClientCommandManager.literal("dyeColor") @@ -30,58 +27,55 @@ public class CustomArmorDyeColors { .then(ClientCommandManager.argument("hexCode", StringArgumentType.string()) .executes(context -> customizeDyeColor(context.getSource(), StringArgumentType.getString(context, "hexCode")))))); } - + + @SuppressWarnings("SameReturnValue") private static int customizeDyeColor(FabricClientCommandSource source, String hex) { - MinecraftClient client = source.getClient(); - ItemStack heldItem = client.player.getMainHandStack(); + ItemStack heldItem = source.getPlayer().getMainHandStack(); NbtCompound nbt = (heldItem != null) ? heldItem.getNbt() : null; - + if (hex != null && !isHexadecimalColor(hex)) { source.sendError(Text.translatable("skyblocker.customDyeColors.invalidHex")); return Command.SINGLE_SUCCESS; } - - if (Utils.isOnSkyblock() && heldItem != null && heldItem.getItem() instanceof DyeableArmorItem) { - if (nbt != null && nbt.contains("ExtraAttributes")) { - NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); - String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : null; - - if (itemUuid != null) { - Object2IntOpenHashMap customDyeColors = SkyblockerConfig.get().general.customDyeColors; - - if (hex == null) { - if (customDyeColors.containsKey(itemUuid)) { - customDyeColors.removeInt(itemUuid); - SkyblockerConfig.save(); - source.sendFeedback(Text.translatable("skyblocker.customDyeColors.removed")); + + if (Utils.isOnSkyblock() && heldItem != null) { + if (heldItem.getItem() instanceof DyeableArmorItem) { + if (nbt != null && nbt.contains("ExtraAttributes")) { + NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); + String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : null; + + if (itemUuid != null) { + Object2IntOpenHashMap customDyeColors = SkyblockerConfig.get().general.customDyeColors; + + if (hex == null) { + if (customDyeColors.containsKey(itemUuid)) { + customDyeColors.removeInt(itemUuid); + SkyblockerConfig.save(); + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.removed")); + } else { + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.neverHad")); + } } else { - source.sendFeedback(Text.translatable("skyblocker.customDyeColors.neverHad")); + customDyeColors.put(itemUuid, Integer.decode("0x" + hex.replace("#", "")).intValue()); + SkyblockerConfig.save(); + source.sendFeedback(Text.translatable("skyblocker.customDyeColors.added")); } } else { - customDyeColors.put(itemUuid, Integer.decode("0x" + hex.replace("#", "")).intValue()); - SkyblockerConfig.save(); - source.sendFeedback(Text.translatable("skyblocker.customDyeColors.added")); + source.sendError(Text.translatable("skyblocker.customDyeColors.noItemUuid")); } - } else { - source.sendError(Text.translatable("skyblocker.customDyeColors.noItemUuid")); } - } - } else { - if (!(heldItem.getItem() instanceof DyeableArmorItem)) { + } else { source.sendError(Text.translatable("skyblocker.customDyeColors.notDyeable")); return Command.SINGLE_SUCCESS; - } else { - source.sendError(Text.translatable("skyblocker.customDyeColors.unableToSetColor")); } + } else { + source.sendError(Text.translatable("skyblocker.customDyeColors.unableToSetColor")); } - + return Command.SINGLE_SUCCESS; } - + private static boolean isHexadecimalColor(String s) { - s = s.replace("#", ""); - - return s.chars() - .allMatch(c -> "0123456789ABCDEFabcdef".indexOf(c) >= 0) && s.length() == 6; + return s.replace("#", "").chars().allMatch(c -> "0123456789ABCDEFabcdef".indexOf(c) >= 0) && s.replace("#", "").length() == 6; } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomItemNames.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomItemNames.java index 4ecff508..5d410947 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomItemNames.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/CustomItemNames.java @@ -2,14 +2,12 @@ package me.xmrvizzy.skyblocker.skyblock.item; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; - import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.TextArgumentType; import net.minecraft.item.ItemStack; @@ -17,11 +15,10 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.text.Text; public class CustomItemNames { - public static void init() { ClientCommandRegistrationCallback.EVENT.register(CustomItemNames::registerCommands); } - + private static void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(ClientCommandManager.literal("skyblocker") .then(ClientCommandManager.literal("renameItem") @@ -29,19 +26,19 @@ public class CustomItemNames { .then(ClientCommandManager.argument("textComponent", TextArgumentType.text()) .executes(context -> renameItem(context.getSource(), context.getArgument("textComponent", Text.class)))))); } - + + @SuppressWarnings("SameReturnValue") private static int renameItem(FabricClientCommandSource source, Text text) { - MinecraftClient client = source.getClient(); - ItemStack heldItem = client.player.getMainHandStack(); + ItemStack heldItem = source.getPlayer().getMainHandStack(); NbtCompound nbt = (heldItem != null) ? heldItem.getNbt() : null; - + if (Utils.isOnSkyblock() && nbt != null && nbt.contains("ExtraAttributes")) { NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); - String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : null; - + String itemUuid = extraAttributes.contains("uuid") ? extraAttributes.getString("uuid") : null; + if (itemUuid != null) { Object2ObjectOpenHashMap customItemNames = SkyblockerConfig.get().general.customItemNames; - + if (text == null) { if (customItemNames.containsKey(itemUuid)) { //Remove custom item name when the text argument isn't passed @@ -63,7 +60,7 @@ public class CustomItemNames { } else { source.sendError(Text.translatable("skyblocker.customItemNames.unableToSetName")); } - + return Command.SINGLE_SUCCESS; } } -- cgit