Skip to content

Commit

Permalink
Merge branch 'master' into dungeon-notifs
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamKracker authored Jan 22, 2025
2 parents ac7f33f + f359c49 commit ed6b267
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@ private void addDungeonConfig(CookiesTranslationBuilder translationBuilder) {
Furthermore thank you to drek1984, Jade and bonsai
which where helping Desco1 with the original
and as well skytils for parts of the original solver.""");

translationBuilder.addConfig(CONFIG_DUNGEON_PARTY_CHAT_COMMANDS, "Chat Commands", "All of the party chat commands.");
translationBuilder.addConfig(CONFIG_DUNGEON_PARTY_CHAT_COMMANDS_PT_ME,
"Party Transfer",
Expand All @@ -716,5 +715,8 @@ private void addDungeonConfig(CookiesTranslationBuilder translationBuilder) {
translationBuilder.addConfig(CONFIG_DUNGEON_PARTY_CHAT_COMMANDS_COIN_FLIP,
"Coin flip",
"Enables the !cf command, allowing players to flip a coin, sends heads or tails to party chat.");
translationBuilder.addConfig(CONFIG_DUNGEON_CROESUS, "Croesus", "Adds features to the croesus npc.");
translationBuilder.addConfig(CONFIG_DUNGEON_CROESUS_HIGHLIGHT_UNCLAIMED, "Highlight unclaimed", "Highlights unclaimed chests in the croesus npc.");
translationBuilder.addConfig(CONFIG_DUNGEON_CROESUS_REPLACE_ITEM, "Replace chest item", "Replaces the chest item with the highest rarity item in the chest, this MAY not be the most valuable item in the chest.");
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.3 2024-12-24T02:43:54.214095 cookies-mod/Language (en_us)
221fcc1e2c7a96aab55552e72cd228815baa08ea assets\cookies-mod\lang\en_us.json
221fcc1e2c7a96aab55552e72cd228815baa08ea assets\cookies-mod\lang\en_us.json
6 changes: 6 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 @@ -93,6 +93,12 @@
"cookies.config.dungeon.announce_leap_coords.tooltip": "Announce the coords of the player you leap to as well.",
"cookies.config.dungeon.announce_leaps.name": "Announce leaps",
"cookies.config.dungeon.announce_leaps.tooltip": "Announce who you leap to and their coords when you leap to a player using the custom leap ui.",
"cookies.config.dungeon.croesus.highlight_unclaimed.name": "Highlight unclaimed",
"cookies.config.dungeon.croesus.highlight_unclaimed.tooltip": "Highlights unclaimed chests in the croesus npc.",
"cookies.config.dungeon.croesus.name": "Croesus",
"cookies.config.dungeon.croesus.replace_item.name": "Replace chest item",
"cookies.config.dungeon.croesus.replace_item.tooltip": "Replaces the chest item with the highest rarity item in the chest, this MAY not be the most valuable item in the chest.",
"cookies.config.dungeon.croesus.tooltip": "Adds features to the croesus npc.",
"cookies.config.dungeon.name": "Dungeon Config",
"cookies.config.dungeon.party_chat_commands.coin_flip.name": "Coin flip",
"cookies.config.dungeon.party_chat_commands.coin_flip.tooltip": "Enables the !cf command, allowing players to flip a coin, sends heads or tails to party chat.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public DungeonConfig() {
public SpiritLeapFoldable spiritLeapFoldable = new SpiritLeapFoldable();
public PuzzleFoldable puzzleFoldable = new PuzzleFoldable();
public ClassColorFoldable classColorFoldable = new ClassColorFoldable();
public CroesusFoldable croesusFoldable = new CroesusFoldable();
public BooleanOption glowClassColor = new BooleanOption(CONFIG_DUNGEON_GLOW_CLASS_COLOR, true);
public PartyChatCommandsFoldable partyChatCommandsFoldable = new PartyChatCommandsFoldable();

Expand Down Expand Up @@ -190,4 +191,14 @@ public String getName() {
return CONFIG_DUNGEON_PARTY_CHAT_COMMANDS;
}
}
public static class CroesusFoldable extends Foldable {

public BooleanOption highlightUnclaimedChests = new BooleanOption(CONFIG_DUNGEON_CROESUS_HIGHLIGHT_UNCLAIMED, false);
public BooleanOption replaceChestItemWithHighestRarityItem = new BooleanOption(CONFIG_DUNGEON_CROESUS_REPLACE_ITEM, false);

@Override
public String getName() {
return CONFIG_DUNGEON_CROESUS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ private void renderBackground(DrawContext context, Slot slot, CallbackInfo ci) {
if (stack == null) {
return;
}
if (stack.contains(CookiesDataComponentTypes.BACKGROUND_ITEM)) {
final ItemStack itemStack = stack.get(CookiesDataComponentTypes.BACKGROUND_ITEM);
context.getMatrices().push();
context.getMatrices().translate(0,0,-100);
context.drawItem(itemStack, slot.x, slot.y);
context.getMatrices().pop();
return;
}

final Integer data = ItemUtils.getData(stack, CookiesDataComponentTypes.ITEM_BACKGROUND_COLOR);
if (data == null) {
return;
Expand All @@ -64,6 +73,25 @@ private void renderBackground(DrawContext context, Slot slot, CallbackInfo ci) {
);
}

@Inject(
method = "drawSlot",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/DrawContext;drawItem(Lnet/minecraft/item/ItemStack;III)V",
shift = At.Shift.AFTER
)
)
private void renderForeground(DrawContext context, Slot slot, CallbackInfo ci) {
final ItemStack stack = slot.getStack();
if (stack == null) {
return;
}
if (stack.contains(CookiesDataComponentTypes.FOREGROUND_ITEM)) {
final ItemStack itemStack = stack.get(CookiesDataComponentTypes.FOREGROUND_ITEM);
context.drawItem(itemStack, slot.x, slot.y);
}
}

/**
* Called when a screen is opened or resized.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package codes.cookies.mod.features.dungeons;

import java.util.List;
import java.util.Optional;

import codes.cookies.mod.config.categories.DungeonConfig;
import codes.cookies.mod.events.InventoryEvents;
import codes.cookies.mod.events.api.InventoryContentUpdateEvent;
import codes.cookies.mod.utils.cookies.CookiesUtils;
import codes.cookies.mod.utils.items.CookiesDataComponentTypes;
import codes.cookies.mod.utils.items.ItemUtils;
import codes.cookies.mod.utils.skyblock.LocationUtils;
import com.google.common.base.Predicates;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.slot.Slot;

public class CroesusHelper {

public CroesusHelper(HandledScreen<?> handledScreen) {
InventoryContentUpdateEvent.registerSlot(handledScreen.getScreenHandler(), this::update);
}

public static void init() {
InventoryEvents.beforeInit(
"Croesus", Predicates.<HandledScreen<?>>alwaysTrue()
.and(o -> LocationUtils.Island.DUNGEON_HUB.isActive()),
CroesusHelper::open);
}

private static void open(HandledScreen<?> handledScreen) {
if (!DungeonConfig.getInstance().croesusFoldable.highlightUnclaimedChests.getValue()) {
return;
}
new CroesusHelper(handledScreen);
}

private void update(Slot slot) {
final ItemStack stack = slot.getStack();

if (!stack.isOf(Items.PLAYER_HEAD)) {
return;
}

final String literalStackName = CookiesUtils.stripColor(stack.getName().getString());
if (!this.isCatacombsOrMasterModeMame(literalStackName)) {
return;
}

final Optional<List<String>> optionalLore = ItemUtils.getLore(stack);
if (optionalLore.isEmpty()) {
return;
}

final List<String> lore = optionalLore.get().stream().map(String::trim).toList();
final boolean hasntOpenedChests = lore.contains("No Chests Opened!");

final Item backgroundStackItem;
if (hasntOpenedChests) {
backgroundStackItem = Items.LIME_STAINED_GLASS_PANE;
} else {
backgroundStackItem = Items.GRAY_STAINED_GLASS_PANE;
}

stack.set(CookiesDataComponentTypes.BACKGROUND_ITEM, new ItemStack(backgroundStackItem));
}

private boolean isCatacombsOrMasterModeMame(String name) {
return name.equalsIgnoreCase("Master Mode The Catacombs") || name.equalsIgnoreCase("The Catacombs");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package codes.cookies.mod.features.dungeons;

import codes.cookies.mod.features.dungeons.chests.CroesusChestHelper;
import codes.cookies.mod.features.dungeons.map.DungeonMapHud;
import codes.cookies.mod.features.dungeons.solver.terminals.MelodyTerminalSolver;
import codes.cookies.mod.render.hud.HudManager;
Expand Down Expand Up @@ -76,7 +77,8 @@ public DungeonFeatures() {
new ChangeAllToSameColorTerminalSolver();
new MelodyTerminalSolver();
SpiritLeapOverlay.init(this);

CroesusHelper.init();
CroesusChestHelper.init();
HudManager.register(DungeonMapHud.getInstance());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package codes.cookies.mod.features.dungeons.chests;

import codes.cookies.mod.config.categories.DungeonConfig;
import codes.cookies.mod.events.InventoryEvents;
import codes.cookies.mod.events.api.InventoryContentUpdateEvent;
import codes.cookies.mod.repository.RepositoryItem;
import codes.cookies.mod.utils.items.CookiesDataComponentTypes;
import codes.cookies.mod.utils.items.ItemUtils;
import codes.cookies.mod.utils.skyblock.LocationUtils;
import com.google.common.base.Predicates;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.slot.Slot;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class CroesusChestHelper {

private final List<String> chestsNames = List.of("Wood Chest", "Gold Chest", "Diamond Chest", "Emerald Chest", "Obsidian Chest", "Bedrock Chest");

public CroesusChestHelper(HandledScreen<?> handledScreen) {
InventoryContentUpdateEvent.registerSlot(handledScreen.getScreenHandler(), this::update);
}

private void update(Slot slot) {
final ItemStack stack = slot.getStack();

if (!stack.isOf(Items.PLAYER_HEAD)) {
return;
}

final String literalStackName = stack.getName().getString();

if (!isChestName(literalStackName)) {
return;
}

final Optional<ItemStack> stackForChest = this.getStackForChest(stack);
stackForChest.ifPresent(itemStack -> this.modifyItem(stack, itemStack));
}

private void modifyItem(ItemStack originalStack, @NotNull ItemStack overrideStack) {
ItemUtils.copy(DataComponentTypes.LORE, originalStack, overrideStack);
ItemUtils.copy(DataComponentTypes.CUSTOM_NAME, originalStack, overrideStack);
ItemUtils.copy(DataComponentTypes.ITEM_NAME, originalStack, overrideStack);

if (overrideStack.isOf(Items.PLAYER_HEAD)) {
originalStack.set(CookiesDataComponentTypes.FOREGROUND_ITEM, overrideStack);
} else {
originalStack.set(CookiesDataComponentTypes.OVERRIDE_RENDER_ITEM, overrideStack);
}
}

private boolean isChestName(String name) {
return chestsNames.contains(name);
}

public static void init() {
InventoryEvents.beforeInit(
"cookies-regex:Master Mode The Catacombs - F.*", Predicates.<HandledScreen<?>>alwaysTrue()
.and(o -> LocationUtils.Island.DUNGEON_HUB.isActive()),
CroesusChestHelper::open);
InventoryEvents.beforeInit(
"cookies-regex:The Catacombs - F.*", Predicates.<HandledScreen<?>>alwaysTrue()
.and(o -> LocationUtils.Island.DUNGEON_HUB.isActive()),
CroesusChestHelper::open);
}

private static void open(HandledScreen<?> handledScreen) {
if (!DungeonConfig.getInstance().croesusFoldable.replaceChestItemWithHighestRarityItem.getValue()) {
return;
}
new CroesusChestHelper(handledScreen);
}

private Optional<ItemStack> getStackForChest(ItemStack chest) {
final Optional<List<String>> optionalLore = ItemUtils.getLore(chest);

if (optionalLore.isEmpty()) {
return Optional.empty();
}

final List<String> lore = optionalLore.get();

final List<String> contents = lore.stream().skip(1).takeWhile(line -> !line.isEmpty()).collect(Collectors.toList());
contents.removeIf(string -> string.contains("Essence"));

final List<RepositoryItem> items = new ArrayList<>();
boolean containsEnchantedBooks = false;
for (String content : contents) {
if (content.startsWith("Enchanted Book")) {
containsEnchantedBooks = true;
}

RepositoryItem.ofName(content).ifPresent(items::add);
}

items.sort(Comparator.comparingInt(item -> item.getTier().ordinal()));

if (!items.isEmpty()) {
return Optional.ofNullable(items.getFirst().constructItemStack());
}

if (containsEnchantedBooks) {
return Optional.of(new ItemStack(Items.ENCHANTED_BOOK));
}

return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ public interface TranslationKeys {
String CONFIG_DUNGEON_PARTY_CHAT_COMMANDS_JOIN_INSTANCE = CONFIG_DUNGEON_PARTY_CHAT_COMMANDS + ".join_instance";
String CONFIG_DUNGEON_PARTY_CHAT_COMMANDS_DOWN_TIME = CONFIG_DUNGEON_PARTY_CHAT_COMMANDS + ".down_time";
String CONFIG_DUNGEON_PARTY_CHAT_COMMANDS_COIN_FLIP = CONFIG_DUNGEON_PARTY_CHAT_COMMANDS + ".coin_flip";

String CONFIG_DUNGEON_CROESUS = CONFIG_DUNGEON + ".croesus";
String CONFIG_DUNGEON_CROESUS_HIGHLIGHT_UNCLAIMED = CONFIG_DUNGEON_CROESUS + ".highlight_unclaimed";
String CONFIG_DUNGEON_CROESUS_REPLACE_ITEM = CONFIG_DUNGEON_CROESUS + ".replace_item";

//</editor-fold>
// internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class CookiesDataComponentTypes {
public static final ComponentType<Integer> ITEM_BACKGROUND_COLOR;
public static final ComponentType<List<Text>> CUSTOM_LORE;
public static final ComponentType<ItemTooltipComponent> LORE_ITEMS;
public static final ComponentType<ItemStack> BACKGROUND_ITEM;
public static final ComponentType<ItemStack> FOREGROUND_ITEM;

private static final List<ComponentType<?>> list = new ArrayList<>();
@Getter
Expand Down Expand Up @@ -216,6 +218,8 @@ public class CookiesDataComponentTypes {
ITEM_BACKGROUND_COLOR = new CookiesDataComponent<>(Identifier.of("cookies:item_background_color"));
CUSTOM_LORE = new CookiesDataComponent<>(Identifier.of("cookies:custom_lore"));
LORE_ITEMS = new CookiesDataComponent<>(Identifier.of("cookies:lore_items"));
BACKGROUND_ITEM = new CookiesDataComponent<>(Identifier.of("cookies:background_item"));
FOREGROUND_ITEM = new CookiesDataComponent<>(Identifier.of("cookies:foreground_item"));
ON_ITEM_CLICK_RUNNABLE = new CookiesDataComponent<>(Identifier.of("cookies:on_item_click_runnable"));
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/codes/cookies/mod/utils/items/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

import codes.cookies.mod.data.profile.items.Item;

import codes.cookies.mod.utils.cookies.CookiesUtils;

import net.minecraft.client.MinecraftClient;
import net.minecraft.component.ComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.LoreComponent;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Item related utility methods.
*/
Expand Down Expand Up @@ -81,4 +90,14 @@ public static String getId(Item<?> item) {
}
return item.itemStack().get(CookiesDataComponentTypes.SKYBLOCK_ID);
}

public static Optional<List<String>> getLore(ItemStack stack) {
return Optional.ofNullable(stack.get(DataComponentTypes.LORE))
.map(LoreComponent::lines)
.map(ItemUtils::mapTextListToString);
}

private static List<String> mapTextListToString(@NotNull List<Text> texts) {
return texts.stream().map(Text::getString).map(CookiesUtils::stripColor).collect(Collectors.toList());
}
}

0 comments on commit ed6b267

Please sign in to comment.