diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2023-09-27 19:48:40 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-27 11:48:40 +0200 |
commit | 26031387bb9408e20ad9aaf375300a400119e03c (patch) | |
tree | c70a306a5e7be746530edf9795628c49200dbd5b /src/main/java | |
parent | 9d19d31b90abc55fd6eb538c73b6a3378f092710 (diff) | |
download | skyhanni-26031387bb9408e20ad9aaf375300a400119e03c.tar.gz skyhanni-26031387bb9408e20ad9aaf375300a400119e03c.tar.bz2 skyhanni-26031387bb9408e20ad9aaf375300a400119e03c.zip |
Feature: Armor drops to $/hr (#427)
Added Armor Drops to Money per Hour display. #427
Diffstat (limited to 'src/main/java')
6 files changed, 98 insertions, 19 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java index 0e3ccc3c5..af2de3bdc 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java @@ -862,8 +862,8 @@ public class GardenConfig { @Expose @ConfigOption(name = "Show money per Hour", - desc = "Displays the money per hour YOU get with YOUR crop/minute value when selling the item to Bazaar. " + - "Supports Bountiful, Mooshroom Cow Perk and Dicer drops. Their toggles are below.") + desc = "Displays the money per hour YOU get with YOUR crop/minute value when selling the item to bazaar. " + + "Supports Bountiful, Mushroom Cow Perk, Armor Crops and Dicer Drops. Their toggles are below.") @ConfigEditorBoolean @ConfigAccordionId(id = 13) @FeatureToggle @@ -960,6 +960,14 @@ public class GardenConfig { @Expose @ConfigOption( + name = "Include Armor Drops", + desc = "Includes the average coins/hr from your armor.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 13) + public boolean moneyPerHourArmor = true; + + @Expose + @ConfigOption( name = "Include Dicer Drops", desc = "Includes the average coins/hr from your melon or pumpkin dicer.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt index 3bb3534e3..f8a837984 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt @@ -9,23 +9,24 @@ import net.minecraft.item.ItemStack enum class CropType( val cropName: String, val toolName: String, + val specialDropType: String, val baseDrops: Double, iconSupplier: () -> ItemStack, val replenish: Boolean = false, ) { - WHEAT("Wheat", "THEORETICAL_HOE_WHEAT", 1.0, { ItemStack(Items.wheat) }), - CARROT("Carrot", "THEORETICAL_HOE_CARROT", 3.0, { ItemStack(Items.carrot) }, replenish = true), - POTATO("Potato", "THEORETICAL_HOE_POTATO", 3.0, { ItemStack(Items.potato) }, replenish = true), - NETHER_WART("Nether Wart", "THEORETICAL_HOE_WARTS", 2.5, { ItemStack(Items.nether_wart) }, replenish = true), - PUMPKIN("Pumpkin", "PUMPKIN_DICER", 1.0, { ItemStack(Blocks.pumpkin) }), - MELON("Melon", "MELON_DICER", 5.0, { ItemStack(Items.melon) }), + WHEAT("Wheat", "THEORETICAL_HOE_WHEAT", "CROPIE", 1.0, { ItemStack(Items.wheat) }), + CARROT("Carrot", "THEORETICAL_HOE_CARROT", "CROPIE", 3.0, { ItemStack(Items.carrot) }, replenish = true), + POTATO("Potato", "THEORETICAL_HOE_POTATO", "CROPIE", 3.0, { ItemStack(Items.potato) }, replenish = true), + NETHER_WART("Nether Wart", "FERMENTO", "THEORETICAL_HOE_WARTS", 2.5, { ItemStack(Items.nether_wart) }, replenish = true), + PUMPKIN("Pumpkin", "PUMPKIN_DICER", "SQUASH", 1.0, { ItemStack(Blocks.pumpkin) }), + MELON("Melon", "MELON_DICER", "SQUASH", 5.0, { ItemStack(Items.melon) }), COCOA_BEANS( - "Cocoa Beans", "COCO_CHOPPER", + "Cocoa Beans", "COCO_CHOPPER", "SQUASH", 3.0, { ItemStack(Items.dye, 1, EnumDyeColor.BROWN.dyeDamage) }, replenish = true ), - SUGAR_CANE("Sugar Cane", "THEORETICAL_HOE_CANE", 2.0, { ItemStack(Items.reeds) }), - CACTUS("Cactus", "CACTUS_KNIFE", 2.0, { ItemStack(Blocks.cactus) }), - MUSHROOM("Mushroom", "FUNGI_CUTTER", 1.0, { ItemStack(Blocks.red_mushroom_block) }), + SUGAR_CANE("Sugar Cane", "THEORETICAL_HOE_CANE", "FERMENTO", 2.0, { ItemStack(Items.reeds) }), + CACTUS("Cactus", "CACTUS_KNIFE", "FERMENTO", 2.0, { ItemStack(Blocks.cactus) }), + MUSHROOM("Mushroom", "FUNGI_CUTTER", "FERMENTO", 1.0, { ItemStack(Blocks.red_mushroom_block) }), ; val icon by lazy { iconSupplier() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index 3e1fb1e62..11ee9635d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -116,6 +116,7 @@ object CropMoneyDisplay { var extraMushroomCowPerkCoins = 0.0 var extraDicerCoins = 0.0 + var extraArmorCoins = 0.0 GardenAPI.getCurrentlyFarmedCrop()?.let { val reforgeName = InventoryUtils.getItemInHand()?.getReforgeName() toolHasBountiful?.put(it, reforgeName == "bountiful") @@ -150,6 +151,12 @@ object CropMoneyDisplay { if (LorenzUtils.noTradeMode || bazaarData == null) internalName.getNpcPrice() / 160 else (bazaarData.sellPrice + bazaarData.buyPrice) / 320 extraDicerCoins = 60 * 60 * GardenCropSpeed.getRecentBPS() * dicerDrops * price } + + if (config.moneyPerHourArmor) { + val amountPerHour = + it.multiplier * GardenCropSpeed.getRecentBPS() * FarmingArmorDrops.getDropsPerHour(it) + extraArmorCoins = amountPerHour * it.specialDropType.asInternalName().getNpcPrice() + } } val moneyPerHourData = calculateMoneyPerHour(newDisplay) @@ -186,13 +193,13 @@ object CropMoneyDisplay { try { if (isSeeds(internalName)) { - list.add(NEUItems.getItemStack("BOX_OF_SEEDS", true)) + list.add(getItemStack("BOX_OF_SEEDS", true)) } else { list.add(internalName.getItemStack()) } if (cropNames[internalName] == CropType.WHEAT && config.moneyPerHourMergeSeeds) { - list.add(NEUItems.getItemStack("BOX_OF_SEEDS", true)) + list.add(getItemStack("BOX_OF_SEEDS", true)) } } catch (e: NullPointerException) { e.printStackTrace() @@ -209,12 +216,13 @@ object CropMoneyDisplay { val moneyArray = moneyPerHourData[internalName]!! for (price in moneyArray) { - val finalPrice = price + extraMushroomCowPerkCoins + extraDicerCoins + val finalPrice = price + extraMushroomCowPerkCoins + extraDicerCoins + extraArmorCoins val format = format(finalPrice) if (debug) { newDisplay.addAsSingletonList(" price: ${price.addSeparators()}") newDisplay.addAsSingletonList(" extraMushroomCowPerkCoins: ${extraMushroomCowPerkCoins.addSeparators()}") - newDisplay.addAsSingletonList(" existing extraDicerCoins: ${extraDicerCoins.addSeparators()}") + newDisplay.addAsSingletonList(" extraArmorCoins: ${extraArmorCoins.addSeparators()}") + newDisplay.addAsSingletonList(" extraDicerCoins: ${extraDicerCoins.addSeparators()}") newDisplay.addAsSingletonList(" finalPrice: ${finalPrice.addSeparators()}") } list.add("$coinsColor$format") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt index b0cb0176e..9fb9be0b0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt @@ -6,13 +6,19 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.PreProfileSwitchEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.jsonobjects.ArmorDropsJson import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds class FarmingArmorDrops { private var display = emptyList<String>() @@ -97,4 +103,43 @@ class FarmingArmorDrops { .count { armorPattern.matcher(it).matches() } hasArmor = armorPieces > 1 } + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + try { + val data = event.getConstant<ArmorDropsJson>("ArmorDrops") ?: error("ArmorDrops not found in repo") + armorDropInfo = data.special_crops + } catch (e: Exception) { + e.printStackTrace() + LorenzUtils.error("error in RepositoryReloadEvent") + } + } + + companion object { + var armorDropInfo = mapOf<String, ArmorDropsJson.DropInfo>() + private var currentArmorDropChance = 0.0 + private var lastCalculationTime = SimpleTimeMark.farPast() + + fun getDropsPerHour(crop: CropType?): Double { + if (crop == null) return 0.0 + + if (lastCalculationTime.passedSince() > 5.seconds) { + lastCalculationTime = SimpleTimeMark.now() + + val armorDropName = crop.specialDropType + val armorName = armorDropInfo[armorDropName]?.armor_type ?: return 0.0 + val pieceCount = InventoryUtils.getArmor() + .mapNotNull { it?.getInternalName_old() } + .count { it.contains(armorName) || it.contains("FERMENTO") } + + val dropRates = armorDropInfo[armorDropName]?.chance ?: return 0.0 + var dropRate = 0.0 + if (pieceCount > 0 && dropRates.size >= pieceCount) { + dropRate = dropRates[pieceCount - 1] + } + currentArmorDropChance = (dropRate * 60 * 60.0) / 100 + } + return currentArmorDropChance + } + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt index 1cd9abdc8..8aefe5a2e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt @@ -10,7 +10,6 @@ object InventoryUtils { var itemInHandId = NEUInternalName.NONE var recentItemsInHand = mutableMapOf<Long, NEUInternalName>() var latestItemInHand: ItemStack? = null - fun getItemsInOpenChest() = buildList<Slot> { val guiChest = Minecraft.getMinecraft().currentScreen as? GuiChest ?: return emptyList<Slot>() val inventorySlots = guiChest.inventorySlots.inventorySlots @@ -40,8 +39,6 @@ object InventoryUtils { fun countItemsInLowerInventory(predicate: (ItemStack) -> Boolean) = getItemsInOwnInventory().filter { predicate(it) }.sumOf { it.stackSize } - fun getArmor(): Array<ItemStack?> = Minecraft.getMinecraft().thePlayer.inventory.armorInventory - fun inStorage() = openInventoryName().let { (it.contains("Storage") && !it.contains("Rift Storage")) || it.contains("Ender Chest") || it.contains( @@ -50,4 +47,6 @@ object InventoryUtils { } fun getItemInHand(): ItemStack? = Minecraft.getMinecraft().thePlayer.heldItem + + fun getArmor(): Array<ItemStack?> = Minecraft.getMinecraft().thePlayer.inventory.armorInventory }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ArmorDropsJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ArmorDropsJson.java new file mode 100644 index 000000000..5815e54ad --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ArmorDropsJson.java @@ -0,0 +1,18 @@ +package at.hannibal2.skyhanni.utils.jsonobjects; + +import com.google.gson.annotations.Expose; + +import java.util.List; +import java.util.Map; + +public class ArmorDropsJson { + @Expose + public Map<String, DropInfo> special_crops; + + public static class DropInfo { + @Expose + public String armor_type; + @Expose + public List<Double> chance; + } +}
\ No newline at end of file |