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/at/hannibal2/skyhanni/features/garden | |
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/at/hannibal2/skyhanni/features/garden')
3 files changed, 68 insertions, 14 deletions
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 |