Skip to content

Commit

Permalink
feat: add stars in slot text (#214)
Browse files Browse the repository at this point in the history
fix: favorite pet slot text being bugged
  • Loading branch information
Morazzer authored Dec 7, 2024
1 parent 449b220 commit 245f56d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,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");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.3 2024-12-07T10:09:01.037834 cookies-mod/Language (en_us)
b9c2449b89671407032b10d0041a619b0acb13c7 assets/cookies-mod/lang/en_us.json
// 1.21.3 2024-12-07T10:30:22.914149 cookies-mod/Language (en_us)
e7b7bab76739a378cb9b6e48a0534029ba9d04d3 assets/cookies-mod/lang/en_us.json
2 changes: 2 additions & 0 deletions src/main/generated/assets/cookies-mod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class CookiesDataComponentTypes {
public static final ComponentType<Integer> RARITY_UPGRADES;
@GenerateAccessor
public static final ComponentType<Map<String, Integer>> RUNES;
@GenerateAccessor
@GenerateAccessor // stars
public static final ComponentType<Integer> UPGRADE_LEVEL;
@GenerateAccessor
public static final ComponentType<Integer> STACKING_ENCHANT_XP;
Expand Down
37 changes: 35 additions & 2 deletions src/main/java/codes/cookies/mod/utils/mixins/ItemStackMixin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 245f56d

Please sign in to comment.