aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-26 20:17:14 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-26 20:17:14 +0200
commit1bd223a7a026a2810c28f55e205d9bd92c183fba (patch)
treee0c80754f6744fe2e8d7b7a43d5e86bf940e8fd4 /src/main/java
parentd5078e7c8625f1cfca46fddad3a3c1c51d5dd5e1 (diff)
downloadskyhanni-1bd223a7a026a2810c28f55e205d9bd92c183fba.tar.gz
skyhanni-1bd223a7a026a2810c28f55e205d9bd92c183fba.tar.bz2
skyhanni-1bd223a7a026a2810c28f55e205d9bd92c183fba.zip
Added City Project Features
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Misc.java21
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/CityProjectMaterialHelper.kt146
3 files changed, 168 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 9fa6c5d8f..b2e6427a8 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -279,6 +279,7 @@ class SkyHanniMod {
loadModule(GardenStartLocation)
loadModule(PetCandyUsedDisplay())
loadModule(ServerRestartTitle())
+ loadModule(CityProjectMaterialHelper())
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java
index 5643892ca..28d7093c0 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java
@@ -364,6 +364,27 @@ public class Misc {
public boolean inventoryNumbers = false;
}
+ @ConfigOption(name = "City Project", desc = "")
+ @Accordion
+ @Expose
+ public CityProject cityProject = new CityProject();
+
+ public static class CityProject {
+
+ @Expose
+ @ConfigOption(name = "Show Materials", desc = "Show materials needed for contributing to the City Project.")
+ @ConfigEditorBoolean
+ public boolean showMaterials = true;
+
+ @Expose
+ @ConfigOption(name = "Show Ready", desc = "Mark Contributions that are ready to participate.")
+ @ConfigEditorBoolean
+ public boolean showReady = true;
+
+ @Expose
+ public Position pos = new Position(394, 124, false, true);
+ }
+
@Expose
@ConfigOption(name = "Exp Bottles", desc = "Hides all the experience orbs lying on the ground.")
@ConfigEditorBoolean
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CityProjectMaterialHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CityProjectMaterialHelper.kt
new file mode 100644
index 000000000..869154ec1
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CityProjectMaterialHelper.kt
@@ -0,0 +1,146 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.InventoryOpenEvent
+import at.hannibal2.skyhanni.features.garden.AnitaMedalProfit
+import at.hannibal2.skyhanni.utils.*
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraft.client.gui.inventory.GuiEditSign
+import net.minecraft.inventory.ContainerChest
+import net.minecraft.item.ItemStack
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class CityProjectMaterialHelper {
+ private val config get() = SkyHanniMod.feature.misc.cityProject
+ private var display = listOf<List<Any>>()
+ private var inCityProjectInventory = false
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ AnitaMedalProfit.inInventory = false
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryOpenEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.showMaterials) return
+
+ val lore = event.inventoryItems[4]?.getLore() ?: return
+ if (lore.isEmpty()) return
+ if (lore[0] != "§8City Project") return
+ inCityProjectInventory = true
+
+ // internal name -> amount
+ val materials = mutableMapOf<String, Int>()
+ for ((_, item) in event.inventoryItems) {
+ val itemName = item.name ?: continue
+ if (itemName != "§eContribute this component!") continue
+ fetchMaterials(item, materials)
+ }
+
+ println("materials: $materials")
+
+ display = buildList(materials)
+ }
+
+ private fun buildList(materials: MutableMap<String, Int>) = buildList<List<Any>> {
+ addAsSingletonList("§7City Project Materials")
+
+ if (materials.isEmpty()) {
+ addAsSingletonList("§cNo Materials to contribute.")
+ return@buildList
+ }
+
+ for ((internalName, amount) in materials) {
+ val stack = NEUItems.getItemStack(internalName)
+ val name = stack.name ?: continue
+ val list = mutableListOf<Any>()
+ list.add(" §7- ")
+ list.add(stack)
+
+ list.add(Renderable.optionalLink("$name §ex${amount.addSeparators()}", {
+ if (Minecraft.getMinecraft().currentScreen is GuiEditSign) {
+ LorenzUtils.setTextIntoSign("$amount")
+ } else if (!NEUItems.neuHasFocus() && !LorenzUtils.noTradeMode) {
+ LorenzUtils.sendCommandToServer("bz ${name.removeColor()}")
+ OSUtils.copyToClipboard("$amount")
+ }
+ }) { inCityProjectInventory && !NEUItems.neuHasFocus() })
+
+ val price = NEUItems.getPrice(internalName) * amount
+ val format = NumberUtil.format(price)
+ list.add(" §7(§6$format§7)")
+ add(list)
+ }
+ }
+
+ private fun fetchMaterials(item: ItemStack, materials: MutableMap<String, Int>) {
+ var next = false
+ for (line in item.getLore()) {
+ if (line == "§7Cost") {
+ next = true
+ continue
+ }
+ if (!next) continue
+ if (line == "") break
+ if (line.contains("Bits")) break
+
+ println(" ")
+ println("line: '$line'")
+ val (name, amount) = ItemUtils.readItemAmount(line)
+ if (name != null) {
+ val internalName = NEUItems.getInternalName(name)
+ println("internalName: $internalName")
+ println("amount: $amount")
+ val old = materials.getOrPut(internalName) { 0 }
+ materials[internalName] = old + amount
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDraw(event: GuiRenderEvent.ChestBackgroundRenderEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.showMaterials) return
+ if (!inCityProjectInventory) return
+
+ config.pos.renderStringsAndItems(display, posLabel = "City Project Materials")
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.showReady) return
+ if (!inCityProjectInventory) return
+
+
+ if (event.gui !is GuiChest) return
+ val guiChest = event.gui
+ val chest = guiChest.inventorySlots as ContainerChest
+
+ for (slot in chest.inventorySlots) {
+ if (slot == null) continue
+ if (slot.slotNumber != slot.slotIndex) continue
+ val stack = slot.stack ?: continue
+ val lore = stack.getLore()
+ if (lore.isEmpty()) continue
+ val last = lore.last()
+ if (last == "§eClick to contribute!") {
+ slot highlight LorenzColor.YELLOW
+ }
+ }
+ }
+
+}