forked from cookies-mod/mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dungeon-notifs
- Loading branch information
Showing
11 changed files
with
272 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/generated/.cache/cabcb80d088276cffde41e74584028f1c00b99b8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/codes/cookies/mod/features/dungeons/CroesusHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/main/java/codes/cookies/mod/features/dungeons/chests/CroesusChestHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters