diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 7993b0b1..bbb16317 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -11,7 +11,7 @@ repositories { } dependencies { - implementation("org.eclipse.jgit:org.eclipse.jgit:7.0.0.202409031743-r") + implementation("org.eclipse.jgit:org.eclipse.jgit:7.1.0.202411261347-r") implementation("com.google.code.gson:gson:2.11.0") diff --git a/gradle.properties b/gradle.properties index 25c8813c..64dc3998 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.21.3+build.2 loader_version=0.16.9 # Mod Properties -mod_version=1.3.4-beta.4 +mod_version=1.3.4-beta.5 maven_group=cookiesmod archives_base_name=cookies-mod diff --git a/src/datagen/java/codes/cookies/mod/datagen/lang/EnglishLanguageProvider.java b/src/datagen/java/codes/cookies/mod/datagen/lang/EnglishLanguageProvider.java index 46de9ca2..fb2ba947 100644 --- a/src/datagen/java/codes/cookies/mod/datagen/lang/EnglishLanguageProvider.java +++ b/src/datagen/java/codes/cookies/mod/datagen/lang/EnglishLanguageProvider.java @@ -49,6 +49,9 @@ protected void generateLocals( translationBuilder.add(ITEM_SOURCE_BACKPACK, "Backpack"); translationBuilder.add("cookies.mod.keybinds", "Cookies Mod"); translationBuilder.add("cookies.mod.search", "Item Search"); + translationBuilder.add("cookies.mod.garden.keybind_switch", "Garden Keybinds Switcher"); + translationBuilder.add("cookies.mod.garden.keybinds.enabled", "Garden Keybinds Enabled"); + translationBuilder.add("cookies.mod.garden.keybinds.disabled", "Garden Keybinds Disabled"); this.addItemStats(translationBuilder); this.addMisc(translationBuilder); @@ -323,6 +326,19 @@ private void addFarmingConfig(CookiesTranslationBuilder translationBuilder) { "Highlight unclaimed", "Highlight unclaimed jacob contests in his inventory."); + translationBuilder.add(CONFIG_FARMING_RENDER, "Render"); + translationBuilder.addConfig( + CONFIG_FARMING_RENDER_HIGHLIGHT_GLOWING_MUSHROOMS, + "Highlight glowing mushrooms", + "Highlights glowing mushrooms by drawing an outline around them."); + + translationBuilder.add(CONFIG_FARMING_CATEGORIES_GARDEN_KEYBINDS, "Garden Keybinds"); + translationBuilder.addConfig(CONFIG_FARMING_OPEN_KEYBIND_MENU, "Open Keybind Menu", "Opens the garden keybind menu."); + + translationBuilder.add(CONFIG_FARMING_OPEN_KEYBIND_TEXT, "Click Here!"); + translationBuilder.add(CONFIG_FARMING_KEYBIND_MENU_TITLE, "Garden Keybinds"); + translationBuilder.addConfig(CONFIG_FARMING_GARDEN_KEYBIND_PREDICATE, "Predicate: ", "When to enable garden keybinds."); + translationBuilder.addConfig(CONFIG_MISC_NOTIFICATIONS_PEST, "Pest Warnings" ,"Warns you 10s before pests can spawn!"); translationBuilder.addConfig(CONFIG_MISC_NOTIFICATIONS_PEST_ORDER, "Pest timer", """ Changes what pest time to use for the notifications, @@ -398,6 +414,7 @@ private void addMiningConfig(CookiesTranslationBuilder translationBuilder) { CONFIG_MINING_MOD_CRYSTAL_HUD, "Crystal Hud", "Enables the crystal hud, shows information about current crystal status, parts available and tools available.\n\n§cRequires the crystal player list widget to be active!"); + translationBuilder.addConfig(CONFIG_MINING_GLOSSY_GEMSTONE_MESSAGE, "Glossy gemstone message", "Adds messages when you drop a glossy gemstone"); translationBuilder.addConfig(CONFIG_MINING_PUZZLER_SOLVER, "Puzzler solver", "Highlight the correct block for the puzzler."); @@ -497,6 +514,10 @@ private void addMiscConfig(CookiesTranslationBuilder translationBuilder) { translationBuilder.addConfig(CONFIG_MISC_SHOW_PET_RARITY_IN_LEVEL_TEXT, "Show rarity in level", "Shows the pet level in the color of the rarity"); + translationBuilder.addConfig( + CONFIG_MISC_SHOW_ITEM_UPGRADES, + "Show item stars", + "Shows the amount of stars that are applied to an item in the slot text."); translationBuilder.addConfig(CONFIG_MISC_SHOW_FORGE_RECIPE_STACK, "Show forge recipes", "Shows forge recipes in the recipe book"); diff --git a/src/main/generated/.cache/cabcb80d088276cffde41e74584028f1c00b99b8 b/src/main/generated/.cache/cabcb80d088276cffde41e74584028f1c00b99b8 index 8c37d588..0fa54e6f 100644 --- a/src/main/generated/.cache/cabcb80d088276cffde41e74584028f1c00b99b8 +++ b/src/main/generated/.cache/cabcb80d088276cffde41e74584028f1c00b99b8 @@ -1,2 +1,2 @@ // 1.21.3 2024-12-11T14:15:47.3017455 cookies-mod/Language (en_us) -b38b189b066d12ab0c2d533a84fa00f9718ed60c assets\cookies-mod\lang\en_us.json +b38b189b066d12ab0c2d533a84fa00f9718ed60c assets\cookies-mod\lang\en_us.json \ No newline at end of file diff --git a/src/main/generated/assets/cookies-mod/lang/en_us.json b/src/main/generated/assets/cookies-mod/lang/en_us.json index 50c605bf..57d8dfd9 100644 --- a/src/main/generated/assets/cookies-mod/lang/en_us.json +++ b/src/main/generated/assets/cookies-mod/lang/en_us.json @@ -187,17 +187,27 @@ "cookies.config.dungeon.use_features.name": "Enabled dungeon features", "cookies.config.dungeon.use_features.tooltip": "Enables or disables all dungeon features. This will not work for ongoing runs.", "cookies.config.farming.categories.compost": "Composter", + "cookies.config.farming.categories.garden_keybinds": "Garden Keybinds", "cookies.config.farming.categories.jacobs": "Jacob / Contests", "cookies.config.farming.categories.ranchers": "Rancher's Boots", + "cookies.config.farming.categories.render": "Render", "cookies.config.farming.categories.visitor": "Visitors", "cookies.config.farming.compost_sort_order.name": "Item sort", "cookies.config.farming.compost_sort_order.tooltip": "How the items should be sorted.", "cookies.config.farming.compost_sort_order.values.ascending": "Ascending", "cookies.config.farming.compost_sort_order.values.descending": "Descending", "cookies.config.farming.compost_sort_order.values.unsorted": "Unsorted", + "cookies.config.farming.garden_keybind_predicate.name": "Predicate: ", + "cookies.config.farming.garden_keybind_predicate.tooltip": "When to enable garden keybinds.", + "cookies.config.farming.highlight_glowing_mushrooms.name": "Highlight glowing mushrooms", + "cookies.config.farming.highlight_glowing_mushrooms.tooltip": "Highlights glowing mushrooms by drawing an outline around them.", "cookies.config.farming.highlight_unclaimed_jacobs_contents.name": "Highlight unclaimed", "cookies.config.farming.highlight_unclaimed_jacobs_contents.tooltip": "Highlight unclaimed jacob contests in his inventory.", + "cookies.config.farming.keybind_menu_title": "Garden Keybinds", "cookies.config.farming.name": "Farming Config", + "cookies.config.farming.open_keybind_menu.name": "Open Keybind Menu", + "cookies.config.farming.open_keybind_menu.text": "Click Here!", + "cookies.config.farming.open_keybind_menu.tooltip": "Opens the garden keybind menu.", "cookies.config.farming.show_compost_price_breakdown.name": "Compost upgrade price", "cookies.config.farming.show_compost_price_breakdown.tooltip": "Shows the amount of items required to max an upgrade.", "cookies.config.farming.show_rancher_optimal_speeds.name": "Show rancher overlay", @@ -246,6 +256,8 @@ "cookies.config.mining.categories.hotm": "HOTM", "cookies.config.mining.crystal_hud.name": "Crystal Hud", "cookies.config.mining.crystal_hud.tooltip": "Enables the crystal hud, shows information about current crystal status, parts available and tools available.\n\n§cRequires the crystal player list widget to be active!", + "cookies.config.mining.glossy_gemstone_message.name": "Glossy gemstone message", + "cookies.config.mining.glossy_gemstone_message.tooltip": "Adds messages when you drop a glossy gemstone", "cookies.config.mining.highlight_disabled_hotm_perks.name": "Highlight disabled", "cookies.config.mining.highlight_disabled_hotm_perks.tooltip": "Change disabled perks to redstone.", "cookies.config.mining.mod_helper.name": "Mod Helper", @@ -341,6 +353,8 @@ "cookies.config.misc.show_item_creation_date.tooltip": "Shows the creation dates of items.", "cookies.config.misc.show_item_npc_value.name": "NPC Value", "cookies.config.misc.show_item_npc_value.tooltip": "Show the npc value of items.", + "cookies.config.misc.show_item_upgrades.name": "Show item stars", + "cookies.config.misc.show_item_upgrades.tooltip": "Shows the amount of stars that are applied to an item in the slot text.", "cookies.config.misc.show_museum_armor_sets.name": "Show museum armor sets", "cookies.config.misc.show_museum_armor_sets.tooltip": "Shows the components of an armor set in the description.", "cookies.config.misc.show_pet_level.name": "Show pet level", @@ -410,6 +424,9 @@ "cookies.item_stats.value.obtained": "Obtained", "cookies.keybind": "Cookies Mod", "cookies.left_click_to_view": "Left-click to view", + "cookies.mod.garden.keybind_switch": "Garden Keybinds Switcher", + "cookies.mod.garden.keybinds.disabled": "Garden Keybinds Disabled", + "cookies.mod.garden.keybinds.enabled": "Garden Keybinds Enabled", "cookies.mod.keybinds": "Cookies Mod", "cookies.mod.search": "Item Search", "cookies.not_found": "Not Found", diff --git a/src/main/java/codes/cookies/mod/CookiesMod.java b/src/main/java/codes/cookies/mod/CookiesMod.java index 48460ee4..7d193a2d 100644 --- a/src/main/java/codes/cookies/mod/CookiesMod.java +++ b/src/main/java/codes/cookies/mod/CookiesMod.java @@ -9,9 +9,11 @@ import codes.cookies.mod.commands.system.CommandManager; import codes.cookies.mod.config.ConfigManager; import codes.cookies.mod.config.screen.ConfigScreen; +import codes.cookies.mod.data.cookiesmoddata.CookieDataManager; import codes.cookies.mod.data.profile.ProfileStorage; import codes.cookies.mod.events.EventLoader; import codes.cookies.mod.features.Features; +import codes.cookies.mod.features.farming.garden.keybinds.GardenKeybindPredicate; import codes.cookies.mod.render.hud.HudEditScreen; import codes.cookies.mod.render.hud.HudManager; import codes.cookies.mod.repository.Repository; @@ -23,6 +25,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import codes.cookies.mod.utils.cookies.CookiesUtils; +import codes.cookies.mod.utils.dev.DevUtils; +import codes.cookies.mod.utils.skyblock.LocationUtils; import codes.cookies.mod.utils.skyblock.MayorUtils; import codes.cookies.mod.utils.skyblock.playerlist.PlayerListUtils; import lombok.Getter; @@ -38,6 +43,8 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; +import net.minecraft.text.Text; + import org.lwjgl.glfw.GLFW; /** @@ -45,7 +52,7 @@ */ public class CookiesMod implements ClientModInitializer { public static KeyBinding chestSearch; - + private static KeyBinding useGardenKeybinds; @Getter private static final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(4); @@ -68,6 +75,7 @@ public static void openScreen(Screen screen) { @Override public void onInitializeClient() { CommandManager.initialize(); + CookieDataManager.load(); ProfileStorage.register(); Repository.loadRepository(); HypixelModAPI.getInstance().subscribeToEventPacket(ClientboundLocationPacket.class); @@ -82,6 +90,7 @@ public void onInitializeClient() { HudManager.load(); CrystalStatusService.register(); this.registerKeyBindings(); + DevUtils.registerDebugs(); } private void registerKeyBindings() { @@ -89,11 +98,23 @@ private void registerKeyBindings() { InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_O, "cookies.mod.keybinds")); + useGardenKeybinds = KeyBindingHelper.registerKeyBinding(new KeyBinding("cookies.mod.garden.keybind_switch", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_K, + "cookies.mod.keybinds")); ClientTickEvents.END_CLIENT_TICK.register(client -> { if (chestSearch.isPressed()) { openScreen(new ItemSearchScreen()); } + while(useGardenKeybinds.wasPressed() && LocationUtils.Island.GARDEN.isActive()) { + GardenKeybindPredicate.keyBindToggle = !GardenKeybindPredicate.keyBindToggle; + for (var keybind : KeyBinding.KEYS_BY_ID.values()) { + keybind.setPressed(false); + keybind.timesPressed = 0; + } + CookiesUtils.sendMessage(Text.translatable("cookies.mod.garden.keybinds." + (GardenKeybindPredicate.keyBindToggle ? "enabled" : "disabled")), false); + } }); } diff --git a/src/main/java/codes/cookies/mod/config/categories/FarmingConfig.java b/src/main/java/codes/cookies/mod/config/categories/FarmingConfig.java index 65c6c4fa..9fa7d137 100644 --- a/src/main/java/codes/cookies/mod/config/categories/FarmingConfig.java +++ b/src/main/java/codes/cookies/mod/config/categories/FarmingConfig.java @@ -11,12 +11,16 @@ import codes.cookies.mod.config.system.Parent; import codes.cookies.mod.config.system.Row; import codes.cookies.mod.config.system.options.BooleanOption; +import codes.cookies.mod.config.system.options.ButtonOption; import codes.cookies.mod.config.system.options.EnumCycleOption; import codes.cookies.mod.config.system.options.TextDisplayOption; +import codes.cookies.mod.features.farming.garden.keybinds.GardenKeybindPredicate; +import codes.cookies.mod.features.farming.garden.keybinds.GardenKeybindsScreen; import codes.cookies.mod.features.farming.garden.PestTimerHud; import codes.cookies.mod.features.misc.timer.NotificationManager; +import net.minecraft.client.MinecraftClient; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.text.Text; @@ -35,6 +39,15 @@ public class FarmingConfig extends Category { public PestFoldable pestFoldable = new PestFoldable(); + @Parent + public TextDisplayOption keybindsText = new TextDisplayOption(CONFIG_FARMING_CATEGORIES_GARDEN_KEYBINDS); + + public ButtonOption openKeybindMenu = new ButtonOption(CONFIG_FARMING_OPEN_KEYBIND_MENU, () -> MinecraftClient.getInstance().setScreen(new GardenKeybindsScreen(MinecraftClient.getInstance().currentScreen)), CONFIG_FARMING_OPEN_KEYBIND_TEXT); + + public EnumCycleOption gardenKeybindPredicate = new EnumCycleOption<>(CONFIG_FARMING_GARDEN_KEYBIND_PREDICATE, GardenKeybindPredicate.ON_GARDEN) + .withSupplier(value -> Text.literal(value.getName())); + + @Parent public TextDisplayOption ranchers = new TextDisplayOption(CONFIG_FARMING_CATEGORIES_RANCHERS); @@ -73,6 +86,11 @@ public class FarmingConfig extends Category { public BooleanOption highlightUnclaimedJacobContests = new BooleanOption(CONFIG_FARMING_HIGHLIGHT_UNCLAIMED_JACOB_CONTENTS, false); + @Parent + public TextDisplayOption renderText = new TextDisplayOption(CONFIG_FARMING_RENDER); + + public BooleanOption highlightGlowingMushrooms = new BooleanOption(CONFIG_FARMING_RENDER_HIGHLIGHT_GLOWING_MUSHROOMS, false); + public FarmingConfig() { super(new ItemStack(Items.WHEAT), CONFIG_FARMING); } diff --git a/src/main/java/codes/cookies/mod/config/categories/MiscConfig.java b/src/main/java/codes/cookies/mod/config/categories/MiscConfig.java index f450a62f..c3d505aa 100644 --- a/src/main/java/codes/cookies/mod/config/categories/MiscConfig.java +++ b/src/main/java/codes/cookies/mod/config/categories/MiscConfig.java @@ -102,6 +102,8 @@ public class MiscConfig extends Category { public BooleanOption showPetRarityInLevelText = new BooleanOption(CONFIG_MISC_SHOW_PET_RARITY_IN_LEVEL_TEXT, false).onlyIf(this.showPetLevelAsStackSize); + public BooleanOption showItemUpgrades = new BooleanOption(CONFIG_MISC_SHOW_ITEM_UPGRADES, false); + @Expose public BooleanOption showForgeRecipeStack = new BooleanOption(CONFIG_MISC_SHOW_FORGE_RECIPE_STACK, true); diff --git a/src/main/java/codes/cookies/mod/config/categories/mining/MiningConfig.java b/src/main/java/codes/cookies/mod/config/categories/mining/MiningConfig.java index 6a3c6c66..2f6465a8 100644 --- a/src/main/java/codes/cookies/mod/config/categories/mining/MiningConfig.java +++ b/src/main/java/codes/cookies/mod/config/categories/mining/MiningConfig.java @@ -34,6 +34,7 @@ public class MiningConfig extends Category { public PowderTrackerHudFoldable powderTrackerHud = new PowderTrackerHudFoldable(); @HudSetting(CrystalRunHud.class) public BooleanOption crystalHud = new BooleanOption(CONFIG_MINING_MOD_CRYSTAL_HUD, true); + public BooleanOption glossyGemstoneMessages = new BooleanOption(CONFIG_MINING_GLOSSY_GEMSTONE_MESSAGE, true); @Parent public TextDisplayOption hotmParentDisplay = new TextDisplayOption(CONFIG_MINING_CATEGORIES_HOTM); diff --git a/src/main/java/codes/cookies/mod/config/screen/ConfigScreen.java b/src/main/java/codes/cookies/mod/config/screen/ConfigScreen.java index 39190c63..370cc88b 100644 --- a/src/main/java/codes/cookies/mod/config/screen/ConfigScreen.java +++ b/src/main/java/codes/cookies/mod/config/screen/ConfigScreen.java @@ -160,7 +160,7 @@ public boolean keyPressed(final int keyCode, final int scanCode, final int modif if (hasBeenConsumed.get()) { return true; } - if (MinecraftClient.getInstance().options.inventoryKey.matchesKey(keyCode, scanCode)) { + if (!searchField.isFocused() && MinecraftClient.getInstance().options.inventoryKey.matchesKey(keyCode, scanCode)) { this.close(); return true; } diff --git a/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookieDataInstances.java b/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookieDataInstances.java new file mode 100644 index 00000000..ff70ec45 --- /dev/null +++ b/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookieDataInstances.java @@ -0,0 +1,7 @@ +package codes.cookies.mod.data.cookiesmoddata; + +import codes.cookies.mod.data.farming.GardenKeybindsData; + +public final class CookieDataInstances { + public static final GardenKeybindsData gardenKeybindsData = new GardenKeybindsData(); +} diff --git a/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookieDataManager.java b/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookieDataManager.java new file mode 100644 index 00000000..c4c339e6 --- /dev/null +++ b/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookieDataManager.java @@ -0,0 +1,80 @@ +package codes.cookies.mod.data.cookiesmoddata; + +import codes.cookies.mod.utils.exceptions.ExceptionHandler; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import lombok.SneakyThrows; + +import net.fabricmc.loader.api.FabricLoader; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; + +public class CookieDataManager { + public static final Path MOD_DATA_FOLDER = Path.of(FabricLoader.getInstance().getConfigDir().toString(), "cookiesmod/data"); + + public static void load() { + if(!Files.exists(MOD_DATA_FOLDER)) { + ExceptionHandler.tryCatch(() -> Files.createDirectories(MOD_DATA_FOLDER)); + } + + for (Field declaredField : CookieDataInstances.class.getDeclaredFields()) { + ExceptionHandler.tryCatch(() -> loadField(declaredField)); + } + } + + public static void save(CookiesModData modData) { + final Path dataLocation = MOD_DATA_FOLDER.resolve(modData.getFileLocation()); + final JsonElement jsonElement = modData.write(); + final byte[] content = jsonElement.toString().getBytes(StandardCharsets.UTF_8); + + ExceptionHandler.tryCatch(() -> { + saveFile(dataLocation, content); + }); + } + + private static void loadField(Field declaredField) { + declaredField.setAccessible(true); + + final Object instance; + try { + instance = declaredField.get(null); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + if (!(instance instanceof CookiesModData data)) { + return; + } + + final Path dataLocation = MOD_DATA_FOLDER.resolve(data.getFileLocation()); + if (!Files.exists(dataLocation)) { + return; + } + + final byte[] bytes; + try { + bytes = readFile(dataLocation); + } catch (IOException e) { + throw new RuntimeException(e); + } + + final String fileContent = new String(bytes, StandardCharsets.UTF_8); + final JsonElement fileElement = JsonParser.parseString(fileContent); + if(fileElement.isJsonObject()) + data.read(fileElement.getAsJsonObject()); + } + + private static byte[] readFile(Path filePath) throws IOException { + return Files.readAllBytes(filePath); + } + + @SneakyThrows + private static void saveFile(Path filePath, byte[] content) { + Files.write(filePath, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + } +} diff --git a/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookiesModData.java b/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookiesModData.java new file mode 100644 index 00000000..d9d87598 --- /dev/null +++ b/src/main/java/codes/cookies/mod/data/cookiesmoddata/CookiesModData.java @@ -0,0 +1,12 @@ +package codes.cookies.mod.data.cookiesmoddata; + +import codes.cookies.mod.utils.json.JsonSerializable; +import lombok.SneakyThrows; + +public interface CookiesModData extends JsonSerializable { + String getFileLocation(); + + default void save() { + CookieDataManager.save(this); + } +} diff --git a/src/main/java/codes/cookies/mod/data/farming/GardenKeybindsData.java b/src/main/java/codes/cookies/mod/data/farming/GardenKeybindsData.java new file mode 100644 index 00000000..998dd6bc --- /dev/null +++ b/src/main/java/codes/cookies/mod/data/farming/GardenKeybindsData.java @@ -0,0 +1,72 @@ +package codes.cookies.mod.data.farming; + +import codes.cookies.mod.data.cookiesmoddata.CookiesModData; +import codes.cookies.mod.utils.accessors.KeyBindingAccessor; +import codes.cookies.mod.utils.json.CodecJsonSerializable; +import codes.cookies.mod.utils.json.JsonUtils; +import com.google.common.reflect.TypeToken; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + + +import com.mojang.logging.LogUtils; + +import com.mojang.serialization.Codec; + +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; + +import org.slf4j.Logger; + +import java.util.HashMap; +import java.util.Map; + +public class GardenKeybindsData implements CookiesModData, CodecJsonSerializable> { + private static final Codec> CODEC = Codec.unboundedMap(Codec.STRING, GardenKeyBindOverride.CODEC); + + @Override + public String getFileLocation() { + return "garden_keybinds.json"; + } + + + @Override + public Codec> getCodec() { + return CODEC; + } + + @Override + public void load(Map value) { + for (var entry : value.entrySet()) { + if (entry.getValue() != null) { + var keyBinding = KeyBindingAccessor.toAccessor(KeyBinding.KEYS_BY_ID.get(entry.getKey())); + keyBinding.cookies$setGardenKey(entry.getValue()); + } + } + } + + @Override + public Map getValue() { + var gardenOverrides = new HashMap(); + + for (var keybind : KeyBinding.KEYS_BY_ID.values()) { + if (keybind instanceof KeyBindingAccessor gardenKeyBind && gardenKeyBind.cookies$getGardenKey() != null) { + gardenOverrides.put(keybind.getTranslationKey(), gardenKeyBind.cookies$getGardenKey()); + } + } + + return gardenOverrides; + } + + @Override + public Logger getLogger() { + return LogUtils.getLogger(); + } + + public record GardenKeyBindOverride(InputUtil.Key key) { + private static final Codec CODEC = Codec.STRING.xmap( + s -> new GardenKeyBindOverride(InputUtil.fromTranslationKey(s)), + gardenKeyBindOverride -> gardenKeyBindOverride.key.getTranslationKey()); + } + +} diff --git a/src/main/java/codes/cookies/mod/data/profile/sub/SackTracker.java b/src/main/java/codes/cookies/mod/data/profile/sub/SackTracker.java index 1ecd98ee..fd6b257a 100644 --- a/src/main/java/codes/cookies/mod/data/profile/sub/SackTracker.java +++ b/src/main/java/codes/cookies/mod/data/profile/sub/SackTracker.java @@ -1,5 +1,6 @@ package codes.cookies.mod.data.profile.sub; +import codes.cookies.mod.events.SackContentsChangeCallback; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import codes.cookies.mod.repository.RepositoryItem; @@ -38,9 +39,7 @@ public void read(@NotNull JsonElement jsonElement) { public @NotNull JsonElement write() { JsonObject jsonObject = new JsonObject(); - this.items.forEach((repositoryItem, integer) -> { - jsonObject.addProperty(repositoryItem.getInternalId(), integer); - }); + this.items.forEach((repositoryItem, integer) -> jsonObject.addProperty(repositoryItem.getInternalId(), integer)); return jsonObject; } @@ -52,7 +51,12 @@ public void read(@NotNull JsonElement jsonElement) { * @param value The amount of the item. */ public void set(RepositoryItem item, int value) { - items.put(item, value); + final Integer previous = items.get(item); + if (previous != null) { + SackContentsChangeCallback.DELTA_CALLBACK.invoker().accept(item, value - previous); + } + items.put(item, value); + SackContentsChangeCallback.CALLBACK.invoker().accept(item, value); } /** @@ -62,7 +66,9 @@ public void set(RepositoryItem item, int value) { * @param value The value. */ public void modify(RepositoryItem item, int value) { + SackContentsChangeCallback.DELTA_CALLBACK.invoker().accept(item, value); items.compute(item, (key, oldValue) -> Math.max(oldValue == null ? value : oldValue + value, 0)); + SackContentsChangeCallback.CALLBACK.invoker().accept(item, items.get(item)); } public void clear() { diff --git a/src/main/java/codes/cookies/mod/events/SackContentsChangeCallback.java b/src/main/java/codes/cookies/mod/events/SackContentsChangeCallback.java new file mode 100644 index 00000000..eb5443b3 --- /dev/null +++ b/src/main/java/codes/cookies/mod/events/SackContentsChangeCallback.java @@ -0,0 +1,16 @@ +package codes.cookies.mod.events; + +import codes.cookies.mod.repository.RepositoryItem; + +import codes.cookies.mod.utils.cookies.CookiesEventUtils; + +import net.fabricmc.fabric.api.event.Event; + +import java.util.function.BiConsumer; + +public interface SackContentsChangeCallback { + + Event> DELTA_CALLBACK = CookiesEventUtils.biConsumer(); + Event> CALLBACK = CookiesEventUtils.biConsumer(); + +} diff --git a/src/main/java/codes/cookies/mod/events/mixins/ParticleManager.java b/src/main/java/codes/cookies/mod/events/mixins/ParticleManager.java new file mode 100644 index 00000000..a2b6e5e2 --- /dev/null +++ b/src/main/java/codes/cookies/mod/events/mixins/ParticleManager.java @@ -0,0 +1,19 @@ +package codes.cookies.mod.events.mixins; + +import codes.cookies.mod.events.world.ParticleEmitEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.particle.Particle; + +@Mixin(net.minecraft.client.particle.ParticleManager.class) +public class ParticleManager { + + @Inject(method = "addParticle(Lnet/minecraft/client/particle/Particle;)V", at = @At(value = "INVOKE", target = "Ljava/util/Queue;add(Ljava/lang/Object;)Z")) + public void test(Particle particle, CallbackInfo ci) { + ParticleEmitEvent.EVENT.invoker().accept(particle); + } + +} diff --git a/src/main/java/codes/cookies/mod/events/world/ParticleEmitEvent.java b/src/main/java/codes/cookies/mod/events/world/ParticleEmitEvent.java new file mode 100644 index 00000000..7549e0a7 --- /dev/null +++ b/src/main/java/codes/cookies/mod/events/world/ParticleEmitEvent.java @@ -0,0 +1,16 @@ +package codes.cookies.mod.events.world; + +import codes.cookies.mod.utils.cookies.CookiesEventUtils; + +import net.minecraft.client.particle.Particle; + +import net.fabricmc.fabric.api.event.Event; + +import java.util.function.Consumer; + +public interface ParticleEmitEvent { + + Event> EVENT = CookiesEventUtils.consumer(); + + +} diff --git a/src/main/java/codes/cookies/mod/features/farming/garden/GardenFeatures.java b/src/main/java/codes/cookies/mod/features/farming/garden/GardenFeatures.java index ce092030..4baeff3d 100644 --- a/src/main/java/codes/cookies/mod/features/farming/garden/GardenFeatures.java +++ b/src/main/java/codes/cookies/mod/features/farming/garden/GardenFeatures.java @@ -13,5 +13,4 @@ public static void load() { Loader.load("CompostUpgrades", CompostUpgrades::new); //Loader.load("VisitorHelper", VisitorHelper::new); } - } diff --git a/src/main/java/codes/cookies/mod/features/farming/garden/keybinds/GardenKeybindPredicate.java b/src/main/java/codes/cookies/mod/features/farming/garden/keybinds/GardenKeybindPredicate.java new file mode 100644 index 00000000..e642edae --- /dev/null +++ b/src/main/java/codes/cookies/mod/features/farming/garden/keybinds/GardenKeybindPredicate.java @@ -0,0 +1,83 @@ +package codes.cookies.mod.features.farming.garden.keybinds; + +import codes.cookies.mod.utils.items.CookiesDataComponentTypes; +import codes.cookies.mod.utils.skyblock.LocationUtils; +import lombok.Getter; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.KeyBinding; + +import java.util.function.Supplier; + +@Getter +public enum GardenKeybindPredicate { + ON_GARDEN("On Garden", LocationUtils.Island.GARDEN::isActive), + IF_KEYBIND_ENABLED("If Keybind Pressed", null), + HOLDING_FARMING_TOOL("Holding Farming Tool", null), + ; + + private static boolean heldFarmingTool = false; + + public static boolean keyBindToggle = false; + + static { + IF_KEYBIND_ENABLED.shouldBeEnabled = () -> keyBindToggle && ON_GARDEN.shouldBeEnabled.get(); + HOLDING_FARMING_TOOL.shouldBeEnabled = () -> + { + var holdingFarmingTool = getHoldingFarmingTool(); + if(heldFarmingTool != holdingFarmingTool) { + for (var keybind : KeyBinding.KEYS_BY_ID.values()) { + keybind.setPressed(false); + keybind.timesPressed = 0; + } + } + heldFarmingTool = holdingFarmingTool; + return holdingFarmingTool; + }; + } + + + private final String name; + private Supplier shouldBeEnabled; + + GardenKeybindPredicate(String name, Supplier shouldBeEnabled) { + this.name = name; + this.shouldBeEnabled = shouldBeEnabled; + } + + private static Boolean getHoldingFarmingTool() { + if (!ON_GARDEN.shouldBeEnabled.get()) { + return false; + } + var player = MinecraftClient.getInstance().player; + if (player == null) { + return false; + } + + var mainHandStack = player.getMainHandStack(); + if (mainHandStack == null || mainHandStack.isEmpty()) { + return false; + } + + var skyblockId = mainHandStack.get(CookiesDataComponentTypes.SKYBLOCK_ID); + + if (skyblockId == null) { + return false; + } + var skyBlockIdLower = skyblockId.toLowerCase(); + + if (skyBlockIdLower.contains("hoe") || skyBlockIdLower.contains("chopper") || skyBlockIdLower.contains("dicer")) { + return true; + } + if (skyBlockIdLower.contains("daedalus")) { + return true; + } + + var enchantments = mainHandStack.get(CookiesDataComponentTypes.ENCHANTMENTS); + if (enchantments != null && enchantments.containsKey("cultivating")) { + return true; + } + + return false; + } +} diff --git a/src/main/java/codes/cookies/mod/features/farming/garden/keybinds/GardenKeybindsScreen.java b/src/main/java/codes/cookies/mod/features/farming/garden/keybinds/GardenKeybindsScreen.java new file mode 100644 index 00000000..53330fc7 --- /dev/null +++ b/src/main/java/codes/cookies/mod/features/farming/garden/keybinds/GardenKeybindsScreen.java @@ -0,0 +1,383 @@ +package codes.cookies.mod.features.farming.garden.keybinds; + +import codes.cookies.mod.data.cookiesmoddata.CookieDataInstances; +import codes.cookies.mod.data.farming.GardenKeybindsData; +import codes.cookies.mod.utils.accessors.KeyBindingAccessor; +import com.google.common.collect.ImmutableList; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.navigation.GuiNavigation; +import net.minecraft.client.gui.navigation.GuiNavigationPath; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; +import net.minecraft.client.gui.screen.narration.NarrationPart; +import net.minecraft.client.gui.tooltip.Tooltip; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.DirectionalLayoutWidget; +import net.minecraft.client.gui.widget.ElementListWidget; +import net.minecraft.client.gui.widget.OptionListWidget; +import net.minecraft.client.gui.widget.ThreePartsLayoutWidget; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; +import net.minecraft.screen.ScreenTexts; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; + +import codes.cookies.mod.translations.TranslationKeys; + +import net.minecraft.util.Colors; +import net.minecraft.util.Formatting; + +import org.apache.commons.lang3.ArrayUtils; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.glfw.GLFW; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public class GardenKeybindsScreen extends Screen implements TranslationKeys { + private final Screen parent; + public GardenKeybindsScreen(Screen parent) { + super(Text.empty()); + this.parent = parent; + this.title = Text.translatable(CONFIG_FARMING_KEYBIND_MENU_TITLE); + } + + @Nullable + public KeyBinding selectedKeyBinding; + private ControlsListWidget controlsList; + private ButtonWidget resetAllButton; + + protected void initBody() { + this.controlsList = this.layout.addBody(new GardenKeybindsScreen.ControlsListWidget(this, this.client)); + } + + protected void initFooter() { + this.resetAllButton = ButtonWidget.builder(Text.translatable("controls.resetAll"), button -> { + for (KeyBinding keyBinding : client.options.allKeys) { + KeyBindingAccessor.toAccessor(keyBinding).cookies$setGardenKey(null); + } + + this.controlsList.update(); + }).build(); + DirectionalLayoutWidget directionalLayoutWidget = this.layout.addFooter(DirectionalLayoutWidget.horizontal().spacing(8)); + directionalLayoutWidget.add(this.resetAllButton); + directionalLayoutWidget.add(ButtonWidget.builder(ScreenTexts.DONE, button -> this.close()).build()); + } + + protected void refreshWidgetPositions() { + this.layout.refreshPositions(); + this.controlsList.position(this.width, this.layout); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (this.selectedKeyBinding != null) { + var key = InputUtil.Type.MOUSE.createFromCode(button); + if(key == selectedKeyBinding.getDefaultKey()) { + KeyBindingAccessor.toAccessor(selectedKeyBinding).cookies$setGardenKey(null); + } else { + KeyBindingAccessor.toAccessor(selectedKeyBinding).cookies$setGardenKey(new GardenKeybindsData.GardenKeyBindOverride(key)); + } + this.selectedKeyBinding = null; + this.controlsList.update(); + return true; + } else { + return super.mouseClicked(mouseX, mouseY, button); + } + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (this.selectedKeyBinding != null) { + var key = keyCode == GLFW.GLFW_KEY_ESCAPE ? InputUtil.UNKNOWN_KEY : InputUtil.fromKeyCode(keyCode, scanCode); + if(key.equals(selectedKeyBinding.getDefaultKey())) { + KeyBindingAccessor.toAccessor(selectedKeyBinding).cookies$setGardenKey(null); + } else { + KeyBindingAccessor.toAccessor(selectedKeyBinding).cookies$setGardenKey(new GardenKeybindsData.GardenKeyBindOverride(key)); + } + + this.selectedKeyBinding = null; + this.controlsList.update(); + return true; + } else { + return super.keyPressed(keyCode, scanCode, modifiers); + } + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + super.render(context, mouseX, mouseY, delta); + boolean bl = false; + + for (KeyBinding keyBinding : this.client.options.allKeys) { + if (KeyBindingAccessor.toAccessor(keyBinding).cookies$getGardenKey() != null) { + bl = true; + break; + } + } + + this.resetAllButton.active = bl; + } + + protected OptionListWidget body; + public final ThreePartsLayoutWidget layout = new ThreePartsLayoutWidget(this); + + @Override + protected void init() { + this.initHeader(); + this.initBody(); + this.initFooter(); + this.layout.forEachChild(this::addDrawableChild); + this.refreshWidgetPositions(); + } + + protected void initHeader() { + this.layout.addHeader(this.title, this.textRenderer); + } + + @Override + public void removed() { + CookieDataInstances.gardenKeybindsData.save(); + } + + @Override + public void close() { + if (this.body != null) { + this.body.applyAllPendingValues(); + } + + this.client.setScreen(this.parent); + } + + @Environment(EnvType.CLIENT) + private class ControlsListWidget extends ElementListWidget { + final GardenKeybindsScreen parent; + private int maxKeyNameLength; + + public ControlsListWidget(GardenKeybindsScreen parent, MinecraftClient client) { + super(client, parent.width, parent.layout.getContentHeight(), parent.layout.getHeaderHeight(), 20); + this.parent = parent; + KeyBinding[] keyBindings = ArrayUtils.clone(client.options.allKeys); + Arrays.sort(keyBindings); + String string = null; + + for (KeyBinding keyBinding : keyBindings) { + String string2 = keyBinding.getCategory(); + if (!string2.equals(string)) { + string = string2; + this.addEntry(new CategoryEntry(Text.translatable(string2))); + } + + Text text = Text.translatable(keyBinding.getTranslationKey()); + int i = client.textRenderer.getWidth(text); + if (i > this.maxKeyNameLength) { + this.maxKeyNameLength = i; + } + + this.addEntry(new KeyBindingEntry(keyBinding, text)); + } + } + + public void update() { + this.updateChildren(); + } + + public void updateChildren() { + this.children().forEach(ControlsListWidget.Entry::update); + } + + @Override + public int getRowWidth() { + return 340; + } + + @Environment(EnvType.CLIENT) + public class CategoryEntry extends Entry { + final Text text; + private final int textWidth; + + public CategoryEntry(final Text text) { + this.text = text; + this.textWidth = client.textRenderer.getWidth(this.text); + } + + @Override + public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + context.drawText( + client.textRenderer, + this.text, + width / 2 - this.textWidth / 2, + y + entryHeight - 9 - 1, + Colors.WHITE, + false + ); + } + + @Nullable + @Override + public GuiNavigationPath getNavigationPath(GuiNavigation navigation) { + return null; + } + + @Override + public List children() { + return Collections.emptyList(); + } + + @Override + public List selectableChildren() { + return ImmutableList.of(new Selectable() { + @Override + public Selectable.SelectionType getType() { + return Selectable.SelectionType.HOVERED; + } + + @Override + public void appendNarrations(NarrationMessageBuilder builder) { + builder.put(NarrationPart.TITLE,CategoryEntry.this.text); + } + }); + } + + @Override + protected void update() { + } + } + + @Environment(EnvType.CLIENT) + public abstract static class Entry extends ElementListWidget.Entry { + abstract void update(); + } + + @Environment(EnvType.CLIENT) + public class KeyBindingEntry extends ControlsListWidget.Entry { + private static final Text RESET_TEXT = Text.translatable("controls.reset"); + private final KeyBinding binding; + private final Text bindingName; + private final ButtonWidget editButton; + private final ButtonWidget resetButton; + private boolean duplicate = false; + private final KeyBindingAccessor gardenKey; + + public KeyBindingEntry(final KeyBinding binding, final Text bindingName) { + this.binding = binding; + this.gardenKey = KeyBindingAccessor.toAccessor(binding); + this.bindingName = bindingName; + this.editButton = ButtonWidget.builder(bindingName, button -> { + parent.selectedKeyBinding = binding; + update(); + }) + .dimensions(0, 0, 75, 20) + .narrationSupplier( + textSupplier -> binding.isUnbound() + ? Text.translatable("narrator.controls.unbound", bindingName) + : Text.translatable("narrator.controls.bound", bindingName, textSupplier.get()) + ) + .build(); + this.resetButton = ButtonWidget.builder(RESET_TEXT, button -> { + this.gardenKey.cookies$setGardenKey(null); + ControlsListWidget.this.update(); + }).dimensions(0, 0, 50, 20).narrationSupplier(textSupplier -> Text.translatable("narrator.controls.reset", bindingName)).build(); + this.update(); + } + + @Override + public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + int i = getScrollbarX() - this.resetButton.getWidth() - 10; + int j = y - 2; + this.resetButton.setPosition(i, j); + this.resetButton.render(context, mouseX, mouseY, tickDelta); + int k = i - 5 - this.editButton.getWidth(); + this.editButton.setPosition(k, j); + this.editButton.render(context, mouseX, mouseY, tickDelta); + context.drawTextWithShadow(client.textRenderer, this.bindingName, x, y + entryHeight / 2 - 9 / 2, Colors.WHITE); + if (this.duplicate) { + int m = this.editButton.getX() - 6; + context.fill(m, y - 1, m + 3, y + entryHeight, -65536); + } + } + + @Override + public List children() { + return ImmutableList.of(this.editButton, this.resetButton); + } + + @Override + public List selectableChildren() { + return ImmutableList.of(this.editButton, this.resetButton); + } + + @Override + protected void update() { + KeyBinding.updateKeysByCode(); + Text message; + if (KeyBindingAccessor.toAccessor(this.binding).cookies$getGardenKey() != null) { + message = KeyBindingAccessor.toAccessor(this.binding).cookies$getGardenKey().key().getLocalizedText(); + } else { + message = this.binding.getBoundKeyLocalizedText(); + } + this.editButton.setMessage(message); + + this.resetButton.active = this.gardenKey.cookies$getGardenKey() != null; + + this.duplicate = false; + MutableText mutableText = Text.empty(); + + var thisKey = this.binding.boundKey; + if(this.gardenKey.cookies$getGardenKey() != null) + { + thisKey = this.gardenKey.cookies$getGardenKey().key(); + } + + if(!thisKey.equals(InputUtil.UNKNOWN_KEY)) { + for (KeyBinding keyBinding : ControlsListWidget.this.client.options.allKeys) { + var otherKey = keyBinding.boundKey; + + if (keyBinding.getTranslationKey().equals(this.binding.getTranslationKey())) { + continue; + } + + if (KeyBindingAccessor.toAccessor(keyBinding).cookies$getGardenKey() != null) { + otherKey = KeyBindingAccessor.toAccessor(keyBinding).cookies$getGardenKey().key(); + } + + if (otherKey.equals(thisKey)) { + if (this.duplicate) { + mutableText.append(", "); + } + + this.duplicate = true; + mutableText.append(Text.translatable(keyBinding.getTranslationKey())); + } + } + } + + if (this.duplicate) { + this.editButton.setMessage(Text.literal("[ ").append(this.editButton.getMessage().copy().formatted(Formatting.WHITE)).append(" ]").formatted(Formatting.RED)); + this.editButton.setTooltip(Tooltip.of(Text.translatable("controls.keybinds.duplicateKeybinds", mutableText))); + } else { + this.editButton.setTooltip(null); + } + + if (parent.selectedKeyBinding == this.binding) { + this.editButton + .setMessage( + Text.literal("> ") + .append(this.editButton.getMessage().copy().formatted(Formatting.WHITE, Formatting.UNDERLINE)) + .append(" <") + .formatted(Formatting.YELLOW) + ); + } + } + } + } +} diff --git a/src/main/java/codes/cookies/mod/features/mining/MiningFeatures.java b/src/main/java/codes/cookies/mod/features/mining/MiningFeatures.java index 45842c6f..6dad907b 100644 --- a/src/main/java/codes/cookies/mod/features/mining/MiningFeatures.java +++ b/src/main/java/codes/cookies/mod/features/mining/MiningFeatures.java @@ -7,6 +7,7 @@ import codes.cookies.mod.features.mining.shafts.CorpseWaypoints; import codes.cookies.mod.features.mining.shafts.MineshaftAnnouncements; import codes.cookies.mod.features.mining.shafts.ShaftFeatures; +import codes.cookies.mod.features.mining.utils.GlossyGemstoneMessage; import codes.cookies.mod.features.mining.utils.HotmUtils; /** @@ -27,6 +28,7 @@ static void load() { Loader.load("ShaftFeatures", ShaftFeatures::load); Loader.load("MineshaftCorpseMessages", MineshaftAnnouncements::register); Loader.load("CrystalRunHud", CrystalRunHud::new); + Loader.load("GlossyGemstoneMessage", GlossyGemstoneMessage::register); } } diff --git a/src/main/java/codes/cookies/mod/features/mining/utils/GlossyGemstoneMessage.java b/src/main/java/codes/cookies/mod/features/mining/utils/GlossyGemstoneMessage.java new file mode 100644 index 00000000..018a54a5 --- /dev/null +++ b/src/main/java/codes/cookies/mod/features/mining/utils/GlossyGemstoneMessage.java @@ -0,0 +1,34 @@ +package codes.cookies.mod.features.mining.utils; + +import codes.cookies.mod.config.categories.mining.MiningConfig; +import codes.cookies.mod.events.SackContentsChangeCallback; +import codes.cookies.mod.repository.RepositoryItem; +import codes.cookies.mod.utils.cookies.CookiesUtils; + +public class GlossyGemstoneMessage { + + public static void register() { + SackContentsChangeCallback.DELTA_CALLBACK.register(GlossyGemstoneMessage::update); + } + + public static void update(RepositoryItem repositoryItem, Integer integer) { + if (!MiningConfig.getInstance().glossyGemstoneMessages.getValue()) { + return; + } + + if (!repositoryItem.getInternalId().equals("GLOSSY_GEMSTONE")) { + return; + } + + if (integer == null) { + return; + } + + if (integer > 1) { + CookiesUtils.sendWhiteMessage("Found %s glossy gemstones!".formatted(integer)); + } else if (integer == 1) { + CookiesUtils.sendWhiteMessage("Found %s glossy gemstone!".formatted(integer)); + } + } + +} diff --git a/src/main/java/codes/cookies/mod/features/misc/MiscFeatures.java b/src/main/java/codes/cookies/mod/features/misc/MiscFeatures.java index ef11f119..3fa91364 100644 --- a/src/main/java/codes/cookies/mod/features/misc/MiscFeatures.java +++ b/src/main/java/codes/cookies/mod/features/misc/MiscFeatures.java @@ -3,6 +3,7 @@ import codes.cookies.mod.features.Loader; import codes.cookies.mod.features.misc.items.ItemFeatures; import codes.cookies.mod.features.misc.render.PingDisplay; +import codes.cookies.mod.features.misc.render.glowingmushroom.GlowingMushroomHighlights; import codes.cookies.mod.features.misc.timer.NotificationManager; import codes.cookies.mod.features.misc.utils.UtilsFeatures; @@ -17,6 +18,7 @@ static void load() { Loader.load("UtilityFeatures", UtilsFeatures::load); Loader.load("PingDisplay", PingDisplay::load); Loader.load("TimerFeatures", NotificationManager::register); + Loader.load("GlowingMushroomHighlight", GlowingMushroomHighlights::register); } diff --git a/src/main/java/codes/cookies/mod/features/misc/render/glowingmushroom/GlowingMushroomHighlights.java b/src/main/java/codes/cookies/mod/features/misc/render/glowingmushroom/GlowingMushroomHighlights.java new file mode 100644 index 00000000..da0033a6 --- /dev/null +++ b/src/main/java/codes/cookies/mod/features/misc/render/glowingmushroom/GlowingMushroomHighlights.java @@ -0,0 +1,60 @@ +package codes.cookies.mod.features.misc.render.glowingmushroom; + +import java.util.concurrent.TimeUnit; + +import codes.cookies.mod.config.ConfigManager; +import codes.cookies.mod.events.world.ParticleEmitEvent; +import codes.cookies.mod.render.WorldRender; +import codes.cookies.mod.render.types.Outlines; +import codes.cookies.mod.render.types.Timed; +import codes.cookies.mod.utils.SkyblockUtils; +import codes.cookies.mod.utils.cookies.CookiesUtils; +import codes.cookies.mod.utils.skyblock.LocationUtils; + +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.SpellParticle; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +public class GlowingMushroomHighlights { + + public static void register() { + ParticleEmitEvent.EVENT.register(GlowingMushroomHighlights::onParticle); + } + + private static void onParticle(Particle particle) { + if (!SkyblockUtils.isCurrentlyInSkyblock()) { + return; + } + + if (!LocationUtils.Island.MUSHROOM_DESERT.isActive()) { + return; + } + + if (!ConfigManager.getConfig().farmingConfig.highlightGlowingMushrooms.getValue()) { + return; + } + + if (particle instanceof SpellParticle spellParticle) { + final Vec3d center = spellParticle.getBoundingBox().getCenter(); + final BlockPos centerBlockPos = CookiesUtils.mapToBlockPos(center); + final BlockState blockState = spellParticle.world.getBlockState(centerBlockPos); + if (blockState.isOf(Blocks.BROWN_MUSHROOM) || blockState.isOf(Blocks.RED_MUSHROOM)) { + final net.minecraft.util.math.Box boundingBox = blockState.getOutlineShape( + particle.world, + centerBlockPos).getBoundingBox().offset(centerBlockPos); + WorldRender.addRenderable(new Timed( + new Outlines( + boundingBox.getMinPos(), + boundingBox.getMaxPos(), + blockState.isOf(Blocks.RED_MUSHROOM) ? Formatting.RED.getColorValue() : 0xFF9A7B4D, 5), + 1, + TimeUnit.SECONDS)); + } + } + } + +} diff --git a/src/main/java/codes/cookies/mod/features/misc/timer/PestTimer.java b/src/main/java/codes/cookies/mod/features/misc/timer/PestTimer.java index 78fbd359..d0592e1d 100644 --- a/src/main/java/codes/cookies/mod/features/misc/timer/PestTimer.java +++ b/src/main/java/codes/cookies/mod/features/misc/timer/PestTimer.java @@ -126,11 +126,15 @@ int getTimeBetweenPests() { } } } + + final double sprayedPlotReduction; if (MayorUtils.isPerkActive("pest_eradicator")) { if (stringBuilder != null) { stringBuilder.append("Finnegan perk (50%)"); } - baseTime *= 0.5; + sprayedPlotReduction = 0.25; + } else { + sprayedPlotReduction = 0.5; } final var value = ConfigManager.getConfig().farmingConfig.pestFoldable.timerType.getValue(); switch (value) { @@ -143,7 +147,7 @@ int getTimeBetweenPests() { if (stringBuilder != null) { stringBuilder.append("One plot sprayed (50%)\n"); } - baseTime *= 0.5; + baseTime *= sprayedPlotReduction; } } case CURRENT -> { @@ -159,7 +163,7 @@ int getTimeBetweenPests() { if (stringBuilder != null) { stringBuilder.append("Current plot sprayed (50%)\n"); } - baseTime *= 0.5; + baseTime *= sprayedPlotReduction; } } } diff --git a/src/main/java/codes/cookies/mod/mixins/KeybindingMixin.java b/src/main/java/codes/cookies/mod/mixins/KeybindingMixin.java new file mode 100644 index 00000000..a6d5fec3 --- /dev/null +++ b/src/main/java/codes/cookies/mod/mixins/KeybindingMixin.java @@ -0,0 +1,126 @@ +package codes.cookies.mod.mixins; + +import codes.cookies.mod.config.ConfigManager; +import codes.cookies.mod.config.categories.FarmingConfig; +import codes.cookies.mod.data.farming.GardenKeybindsData; +import codes.cookies.mod.utils.accessors.KeyBindingAccessor; +import codes.cookies.mod.utils.skyblock.LocationUtils; + +import com.mojang.logging.LogUtils; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.KeyBinding; + +import net.minecraft.client.util.InputUtil; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.HashMap; +import java.util.Map; + +@Mixin(value = KeyBinding.class) +public abstract class KeybindingMixin implements KeyBindingAccessor { + @Unique + private GardenKeybindsData.GardenKeyBindOverride cookies$gardenKey; + + @Unique + private static final Map GARDEN_KEY_TO_BINDINGS = new HashMap<>(); + + @Final + @Shadow + private static Map KEY_TO_BINDINGS; + + @Override + public GardenKeybindsData.GardenKeyBindOverride cookies$getGardenKey() { + return cookies$gardenKey; + } + + @Override + public void cookies$setGardenKey(GardenKeybindsData.GardenKeyBindOverride key) { + cookies$gardenKey = key; + if(key != null) { + GARDEN_KEY_TO_BINDINGS.put(key.key(), this); + } + } + + @Inject(method = "updateKeysByCode", at = @At("TAIL")) + private static void cookies$updateGardenKeysByCode(CallbackInfo ci) { + GARDEN_KEY_TO_BINDINGS.clear(); + for (KeyBinding keyBinding : KeyBinding.KEYS_BY_ID.values()) { + var gardenKey = KeyBindingAccessor.toAccessor(keyBinding).cookies$getGardenKey(); + if (gardenKey != null) { + GARDEN_KEY_TO_BINDINGS.put(gardenKey.key(), KeyBindingAccessor.toAccessor(keyBinding)); + } + } + } + + @Inject(method = "updatePressedStates", at = @At(value = "HEAD"), cancellable = true) + private static void cookies$updatePressedStates(CallbackInfo ci) { + if(ConfigManager.getConfig().farmingConfig.gardenKeybindPredicate.getValue().getShouldBeEnabled().get()) { + for (var keyBinding : GARDEN_KEY_TO_BINDINGS.values()) { + if (keyBinding.cookies$getGardenKey().key().getCategory() == InputUtil.Type.KEYSYM && keyBinding.cookies$getGardenKey().key().getCode() != InputUtil.UNKNOWN_KEY.getCode()) { + ((KeyBinding)keyBinding).setPressed(InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), keyBinding.cookies$getGardenKey().key().getCode())); + } + } + ci.cancel(); + } + } + + @Inject(method = "setKeyPressed", at = @At(value = "HEAD"), cancellable = true) + private static void cookies$setKeyPressed(InputUtil.Key key, boolean pressed, CallbackInfo ci) { + if(ConfigManager.getConfig().farmingConfig.gardenKeybindPredicate.getValue().getShouldBeEnabled().get()) { + if (GARDEN_KEY_TO_BINDINGS.get(key) instanceof KeyBindingAccessor accessor) { + if (accessor.cookies$getGardenKey() != null) { + ((KeyBinding) accessor).setPressed(pressed); + } + ci.cancel(); + } + if (KEY_TO_BINDINGS.get(key) instanceof KeyBindingAccessor accessor && accessor.cookies$getGardenKey() != null) { + ci.cancel(); + } + } + } + + @Inject(method = "onKeyPressed", at = @At(value = "HEAD"), cancellable = true) + private static void cookies$onKeyPressed(InputUtil.Key key, CallbackInfo ci) { + if(ConfigManager.getConfig().farmingConfig.gardenKeybindPredicate.getValue().getShouldBeEnabled().get()) { + if (GARDEN_KEY_TO_BINDINGS.get(key) instanceof KeyBindingAccessor accessor) { + if (accessor.cookies$getGardenKey() != null) { + ((KeyBinding) accessor).timesPressed++; + } + + ci.cancel(); + } + if(KEY_TO_BINDINGS.get(key) instanceof KeyBindingAccessor accessor && accessor.cookies$getGardenKey() != null) { + ci.cancel(); + } + } + } + + @Inject(method = "matchesKey", at = @At(value = "HEAD"), cancellable = true) + private void cookies$matchesKey(int keyCode, int scanCode, CallbackInfoReturnable cir) + { + if(ConfigManager.getConfig().farmingConfig.gardenKeybindPredicate.getValue().getShouldBeEnabled().get()) { + if (this.cookies$getGardenKey() != null) { + cir.setReturnValue(keyCode == InputUtil.UNKNOWN_KEY.getCode() + ? this.cookies$getGardenKey().key().getCategory() == InputUtil.Type.SCANCODE && this.cookies$getGardenKey().key().getCode() == scanCode + : this.cookies$getGardenKey().key().getCategory() == InputUtil.Type.KEYSYM && this.cookies$getGardenKey().key().getCode() == keyCode); + } + } + } + @Inject(method = "matchesMouse", at = @At(value = "HEAD"), cancellable = true) + public void matchesMouse(int code, CallbackInfoReturnable cir) { + if(ConfigManager.getConfig().farmingConfig.gardenKeybindPredicate.getValue().getShouldBeEnabled().get()) { + if (this.cookies$getGardenKey() != null) { + cir.setReturnValue(this.cookies$getGardenKey().key().getCategory() == InputUtil.Type.MOUSE && this.cookies$getGardenKey().key().getCode() == code); + } + } + } +} diff --git a/src/main/java/codes/cookies/mod/mixins/render/ArmorFeatureRenderMixin.java b/src/main/java/codes/cookies/mod/mixins/render/ArmorFeatureRenderMixin.java index d1ccd575..a620a78c 100644 --- a/src/main/java/codes/cookies/mod/mixins/render/ArmorFeatureRenderMixin.java +++ b/src/main/java/codes/cookies/mod/mixins/render/ArmorFeatureRenderMixin.java @@ -17,7 +17,6 @@ * Allows for cancellation of armor rendering. */ @Mixin(ArmorFeatureRenderer.class) -@Debug(export = true) public class ArmorFeatureRenderMixin { @Unique diff --git a/src/main/java/codes/cookies/mod/render/types/Outlines.java b/src/main/java/codes/cookies/mod/render/types/Outlines.java index dd4652bd..c327b197 100644 --- a/src/main/java/codes/cookies/mod/render/types/Outlines.java +++ b/src/main/java/codes/cookies/mod/render/types/Outlines.java @@ -1,5 +1,6 @@ package codes.cookies.mod.render.types; +import codes.cookies.mod.render.utils.RenderHelper; import com.mojang.blaze3d.systems.RenderSystem; import codes.cookies.mod.render.Renderable; import org.lwjgl.opengl.GL11; @@ -104,10 +105,10 @@ public Outlines( Vec3d start, Vec3d end, int color, int lineWidth, boolean throughWalls) { this( new Box(start.x, start.y, start.z, end.x, end.y, end.z), - (color & 0xFF) / 255f, - ((color >> 8) & 0xFF) / 255f, - ((color >> 16) & 0xFF) / 255f, - ((color >> 24) & 0xFF) / 255f, + RenderHelper.getRed(color) / 255f, + RenderHelper.getGreen(color) / 255f, + RenderHelper.getBlue(color) / 255f, + RenderHelper.getAlpha(color) / 255f, lineWidth, throughWalls); } diff --git a/src/main/java/codes/cookies/mod/translations/TranslationKeys.java b/src/main/java/codes/cookies/mod/translations/TranslationKeys.java index aec903e8..4e8431ff 100644 --- a/src/main/java/codes/cookies/mod/translations/TranslationKeys.java +++ b/src/main/java/codes/cookies/mod/translations/TranslationKeys.java @@ -251,6 +251,18 @@ public interface TranslationKeys { String CONFIG_FARMING_CATEGORIES_JACOBS = CONFIG_FARMING + CATEGORIES_PART + ".jacobs"; String CONFIG_FARMING_HIGHLIGHT_UNCLAIMED_JACOB_CONTENTS = CONFIG_FARMING + ".highlight_unclaimed_jacobs_contents"; + + String CONFIG_FARMING_RENDER = CONFIG_FARMING + CATEGORIES_PART + ".render"; + String CONFIG_FARMING_RENDER_HIGHLIGHT_GLOWING_MUSHROOMS = CONFIG_FARMING + ".highlight_glowing_mushrooms"; + + String CONFIG_FARMING_CATEGORIES_GARDEN_KEYBINDS = CONFIG_FARMING + CATEGORIES_PART + ".garden_keybinds"; + + String CONFIG_FARMING_OPEN_KEYBIND_MENU = CONFIG_FARMING + ".open_keybind_menu"; + String CONFIG_FARMING_OPEN_KEYBIND_TEXT = CONFIG_FARMING_OPEN_KEYBIND_MENU + ".text"; + String CONFIG_FARMING_KEYBIND_MENU_TITLE = CONFIG_FARMING + ".keybind_menu_title"; + + String CONFIG_FARMING_GARDEN_KEYBIND_PREDICATE = CONFIG_FARMING + ".garden_keybind_predicate"; + // // String CONFIG_HELPERS = CONFIG + ".helpers"; @@ -283,6 +295,7 @@ public interface TranslationKeys { String CONFIG_MINING_PUZZLER_SOLVER = CONFIG_MINING + ".puzzler_solver"; String CONFIG_MINING_MOD_HELPER = CONFIG_MINING + ".mod_helper"; String CONFIG_MINING_MOD_CRYSTAL_HUD = CONFIG_MINING + ".crystal_hud"; + String CONFIG_MINING_GLOSSY_GEMSTONE_MESSAGE = CONFIG_MINING + ".glossy_gemstone_message"; String CONFIG_MINING_CATEGORIES_HOTM = CONFIG_MINING + CATEGORIES_PART + ".hotm"; String CONFIG_MINING_SHOW_HOTM_PERK_LEVEL_AS_STACK_SIZE = CONFIG_MINING + ".show_hotm_perk_level_as_stack_size"; String CONFIG_MINING_HIGHLIGHT_DISABLED_HOTM_PERKS = CONFIG_MINING + ".highlight_disabled_hotm_perks"; @@ -334,6 +347,7 @@ public interface TranslationKeys { String CONFIG_MISC_CATEGORIES_RENDER_INVENTORY = CONFIG_MISC + CATEGORIES_PART + ".render_inventory"; String CONFIG_MISC_SHOW_PET_LEVEL = CONFIG_MISC + ".show_pet_level"; String CONFIG_MISC_SHOW_PET_RARITY_IN_LEVEL_TEXT = CONFIG_MISC + ".show_pet_rarity_in_level_text"; + String CONFIG_MISC_SHOW_ITEM_UPGRADES = CONFIG_MISC + ".show_item_upgrades"; String CONFIG_MISC_SHOW_FORGE_RECIPE_STACK = CONFIG_MISC + ".show_forge_recipe_stack"; String CONFIG_MISC_NOTIFICATIONS = CONFIG_MISC + ".notifications"; diff --git a/src/main/java/codes/cookies/mod/utils/accessors/KeyBindingAccessor.java b/src/main/java/codes/cookies/mod/utils/accessors/KeyBindingAccessor.java new file mode 100644 index 00000000..3a2fff63 --- /dev/null +++ b/src/main/java/codes/cookies/mod/utils/accessors/KeyBindingAccessor.java @@ -0,0 +1,14 @@ +package codes.cookies.mod.utils.accessors; + +import codes.cookies.mod.data.farming.GardenKeybindsData; + +import net.minecraft.client.option.KeyBinding; + +public interface KeyBindingAccessor { + GardenKeybindsData.GardenKeyBindOverride cookies$getGardenKey(); + void cookies$setGardenKey(GardenKeybindsData.GardenKeyBindOverride key); + + static KeyBindingAccessor toAccessor(KeyBinding keyBinding) { + return (KeyBindingAccessor) keyBinding; + } +} diff --git a/src/main/java/codes/cookies/mod/utils/cookies/CookiesUtils.java b/src/main/java/codes/cookies/mod/utils/cookies/CookiesUtils.java index 8038ce0c..5bda6213 100644 --- a/src/main/java/codes/cookies/mod/utils/cookies/CookiesUtils.java +++ b/src/main/java/codes/cookies/mod/utils/cookies/CookiesUtils.java @@ -6,6 +6,9 @@ import java.util.Random; import codes.cookies.mod.utils.ColorUtils; + +import net.minecraft.util.math.BlockPos; + import org.joml.Vector2i; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -237,4 +240,8 @@ public static void sendCommand(String command) { Optional.ofNullable(MinecraftClient.getInstance().player) .ifPresent(player -> player.networkHandler.sendCommand(command)); } + + public static BlockPos mapToBlockPos(Vec3d vec3d) { + return new BlockPos((int) Math.floor(vec3d.x), (int) Math.floor(vec3d.y), (int) Math.floor(vec3d.z)); + } } diff --git a/src/main/java/codes/cookies/mod/utils/dev/DevUtils.java b/src/main/java/codes/cookies/mod/utils/dev/DevUtils.java index 8c2cbb52..433e2906 100644 --- a/src/main/java/codes/cookies/mod/utils/dev/DevUtils.java +++ b/src/main/java/codes/cookies/mod/utils/dev/DevUtils.java @@ -9,6 +9,7 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; +import codes.cookies.mod.utils.dev.debug.ParticleDebugMode; import lombok.Getter; import net.fabricmc.loader.api.FabricLoader; @@ -36,6 +37,10 @@ public class DevUtils { @Getter private static final List enabledExtraLogging = new LinkedList<>(); + public static void registerDebugs() { + ParticleDebugMode.register(); + } + /** * Whether the mod is currently logging debug messages or not. * diff --git a/src/main/java/codes/cookies/mod/utils/dev/debug/ParticleDebugMode.java b/src/main/java/codes/cookies/mod/utils/dev/debug/ParticleDebugMode.java new file mode 100644 index 00000000..7e5ace02 --- /dev/null +++ b/src/main/java/codes/cookies/mod/utils/dev/debug/ParticleDebugMode.java @@ -0,0 +1,31 @@ +package codes.cookies.mod.utils.dev.debug; + +import codes.cookies.mod.events.world.ParticleEmitEvent; +import codes.cookies.mod.render.WorldRender; +import codes.cookies.mod.render.types.Timed; +import codes.cookies.mod.render.types.WorldText; +import codes.cookies.mod.utils.dev.DevUtils; + +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +import java.util.concurrent.TimeUnit; + +public interface ParticleDebugMode { + Identifier DEBUG_MODE = DevUtils.createIdentifier("particle_debug_mode"); + + static void register() { + ParticleEmitEvent.EVENT.register(particle -> { + if (DevUtils.isDisabled(DEBUG_MODE)) { + return; + } + + WorldRender.addRenderable(new Timed( + new WorldText( + particle.getBoundingBox().getCenter(), + Text.literal(particle.getClass().getSimpleName()), + false), 1, + TimeUnit.SECONDS)); + }); + } +} diff --git a/src/main/java/codes/cookies/mod/utils/items/CookiesDataComponentTypes.java b/src/main/java/codes/cookies/mod/utils/items/CookiesDataComponentTypes.java index 47621874..39ee5667 100644 --- a/src/main/java/codes/cookies/mod/utils/items/CookiesDataComponentTypes.java +++ b/src/main/java/codes/cookies/mod/utils/items/CookiesDataComponentTypes.java @@ -54,7 +54,7 @@ public class CookiesDataComponentTypes { public static final ComponentType RARITY_UPGRADES; @GenerateAccessor public static final ComponentType> RUNES; - @GenerateAccessor + @GenerateAccessor // stars public static final ComponentType UPGRADE_LEVEL; @GenerateAccessor public static final ComponentType STACKING_ENCHANT_XP; diff --git a/src/main/java/codes/cookies/mod/utils/json/CodecJsonSerializable.java b/src/main/java/codes/cookies/mod/utils/json/CodecJsonSerializable.java index 36c9c882..73d0d98f 100644 --- a/src/main/java/codes/cookies/mod/utils/json/CodecJsonSerializable.java +++ b/src/main/java/codes/cookies/mod/utils/json/CodecJsonSerializable.java @@ -37,7 +37,7 @@ default void read(@NotNull JsonElement jsonElement) { this.load(parse.getOrThrow()); } else { this.getLogger() - .warn("Failed to load island chest data, trying to load partial. {}", + .warn("Failed to load data from a CodecJsonSerializable, trying to load partial. {}", parse.error().get().message()); try { this.load(parse.getOrThrow()); diff --git a/src/main/java/codes/cookies/mod/utils/mixins/ItemStackMixin.java b/src/main/java/codes/cookies/mod/utils/mixins/ItemStackMixin.java index f0d11d5e..d4f24635 100644 --- a/src/main/java/codes/cookies/mod/utils/mixins/ItemStackMixin.java +++ b/src/main/java/codes/cookies/mod/utils/mixins/ItemStackMixin.java @@ -1,5 +1,6 @@ package codes.cookies.mod.utils.mixins; +import codes.cookies.mod.config.categories.MiscConfig; import codes.cookies.mod.utils.items.PetInfo; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -102,6 +103,7 @@ public void initializeItemStackWithComponents( } this.cookies$setPetLevel(nbtCompound, componentMapImpl); + this.cookies$setStars(); final LoreComponent loreComponent = componentMapImpl.get(DataComponentTypes.LORE); if (loreComponent == null || loreComponent.lines() == null || loreComponent.lines().isEmpty()) { @@ -128,7 +130,38 @@ public void initializeItemStackWithComponents( } } - @Unique + @Unique + private void cookies$setStars() { + if (!ConfigManager.getConfig().miscConfig.showItemUpgrades.getValue()) { + return; + } + + if (!contains(CookiesDataComponentTypes.UPGRADE_LEVEL)) { + return; + } + + final Integer i = get(CookiesDataComponentTypes.UPGRADE_LEVEL); + if (i == null) { + return; + } + + + final String slotText; + if (i == 10) { + slotText = "§4" + i; + } else if (i > 5) { + slotText = "§c" + i; + } else if (i == 5) { + slotText = "§6" + i; + } else if (i >= 1) { + slotText = "§e" + i; + } else { + return; + } + set(CookiesDataComponentTypes.CUSTOM_SLOT_TEXT, slotText); + } + + @Unique private void cookies$setComponents() { if (((CustomComponentMapAccessor) (Object) this.components).cookies$getMergedComponentMap() == null) { ((CustomComponentMapAccessor) (Object) this.components).cookies$setMergedComponentMap(new MergedComponentMap( @@ -180,7 +213,7 @@ public void initializeItemStackWithComponents( tier = Formatting.WHITE; } - set(CookiesDataComponentTypes.CUSTOM_SLOT_TEXT, tier.toString() + level); + set(CookiesDataComponentTypes.CUSTOM_SLOT_TEXT, tier.toString() + level.replaceAll("\\D", "")); } @Unique diff --git a/src/main/resources/cookies-mod.events.mixins.json b/src/main/resources/cookies-mod.events.mixins.json index 8a2eed0f..2ac909c8 100644 --- a/src/main/resources/cookies-mod.events.mixins.json +++ b/src/main/resources/cookies-mod.events.mixins.json @@ -1,11 +1,12 @@ { "package": "codes.cookies.mod.events.mixins", "client": [ + "AbstractSignEditScreenMixin", "InventoryContentUpdateMixin", "ItemBackgroundRenderMixin", + "ParticleManager", + "PlayerListMixin", "ScreenMixin", - "AbstractSignEditScreenMixin", - "TeamMixin", - "PlayerListMixin" + "TeamMixin" ] } diff --git a/src/main/resources/cookies-mod.mixins.json b/src/main/resources/cookies-mod.mixins.json index f86f6f64..dafbc80c 100644 --- a/src/main/resources/cookies-mod.mixins.json +++ b/src/main/resources/cookies-mod.mixins.json @@ -2,14 +2,15 @@ "package": "codes.cookies.mod.mixins", "compatibilityLevel": "JAVA_21", "client": [ + "KeybindingMixin", "render.ArmorFeatureRenderMixin", + "render.EntityRenderDispatcherMixin", "render.HeadFeatureRenderMixin", "render.HideLightningBoltMixin", - "render.EntityRenderDispatcherMixin", - "ui.PotionEffectMixin", + "render.TextFieldWidgetMixin", "ui.InGameHudMixin", "ui.ParentElementMixin", - "ui.ScrollableTooltipMixin", - "render.TextFieldWidgetMixin" + "ui.PotionEffectMixin", + "ui.ScrollableTooltipMixin" ] } diff --git a/src/main/resources/cookies.accesswidener b/src/main/resources/cookies.accesswidener index 4ecf67e6..8487a7c6 100644 --- a/src/main/resources/cookies.accesswidener +++ b/src/main/resources/cookies.accesswidener @@ -20,3 +20,8 @@ accessible field net/minecraft/client/gui/screen/ingame/HandledScreen SLOT_HIGHL accessible method net/minecraft/client/gui/DrawContext drawTooltip (Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;Lnet/minecraft/util/Identifier;)V accessible field net/minecraft/client/gui/hud/PlayerListHud footer Lnet/minecraft/text/Text; accessible field net/minecraft/client/gui/screen/Screen drawables Ljava/util/List; +mutable field net/minecraft/client/gui/screen/Screen title Lnet/minecraft/text/Text; +accessible field net/minecraft/client/option/KeyBinding boundKey Lnet/minecraft/client/util/InputUtil$Key; +accessible field net/minecraft/client/option/KeyBinding KEYS_BY_ID Ljava/util/Map; +accessible field net/minecraft/client/option/KeyBinding timesPressed I +accessible field net/minecraft/client/particle/Particle world Lnet/minecraft/client/world/ClientWorld;