diff options
Diffstat (limited to 'src/main/java')
5 files changed, 260 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index ab1641d5e..3d1f90a3f 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -219,6 +219,7 @@ public class SkyHanniMod { loadModule(new GardenLevelDisplay()); loadModule(new EliteFarmingWeight()); loadModule(new DicerRngDropCounter()); + loadModule(new CropMoneyDisplay()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index f0f80a66a..b30659e8d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -218,6 +218,11 @@ public class Features extends Config { editOverlay(activeConfigCategory, 200, 16, garden.dicerCounterPos); return; } + + if (runnableId.equals("moneyPerHour")) { + editOverlay(activeConfigCategory, 200, 16, garden.moneyPerHourPos); + return; + } } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index 69a2235f7..a1272c452 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -364,6 +364,43 @@ public class Garden { public Position dicerCounterPos = new Position(16, -232, false, true); @Expose + @ConfigOption(name = "Money per Hour", desc = "") + @ConfigEditorAccordion(id = 13) + public boolean moneyPerHour = false; + + @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.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 13) + public boolean moneyPerHourDisplay = true; + + // TODO moulconfig runnable support + @Expose + @ConfigOption(name = "Only show top", desc = "Only show the best # items.") + @ConfigEditorSlider( + minValue = 1, + maxValue = 25, + minStep = 1 + ) + @ConfigAccordionId(id = 13) + public int moneyPerHourShowOnlyBest = 5; + + // TODO moulconfig runnable support + @Expose + @ConfigOption( + name = "Always On", + desc = "Show the money/hour Display always while on the garden.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 13) + public boolean moneyPerHourAlwaysOn = false; + + @Expose + @ConfigOption(name = "Dicer Counter Position", desc = "") + @ConfigEditorButton(runnableId = "moneyPerHour", buttonText = "Edit") + @ConfigAccordionId(id = 13) + public Position moneyPerHourPos = new Position(16, -232, false, true); + + @Expose @ConfigOption(name = "Plot Price", desc = "Show the price of the plot in coins when inside the Configure Plots inventory.") @ConfigEditorBoolean public boolean plotPrice = true; diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt new file mode 100644 index 000000000..0c8e45ff3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt @@ -0,0 +1,210 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GardenToolChangeEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import kotlinx.coroutines.launch +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import java.util.* + +class CropMoneyDisplay { + private val display = mutableListOf<List<Any>>() + private val config get() = SkyHanniMod.feature.garden + private var tick = 0 + private var loaded = false + private var ready = false + private val multipliers = mutableMapOf<String, Int>() + private val cropNames = mutableMapOf<String, String>() // internalName -> cropName + private var hasCropInHand = false + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + + config.moneyPerHourPos.renderStringsAndItems(display) + } + + @SubscribeEvent + fun onGardenToolChange(event: GardenToolChangeEvent) { + val crop = if (event.isRealCrop) event.crop else null + hasCropInHand = crop != null + update() + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!isEnabled()) return + + if (tick++ % (20 * 5) != 0) return + + if (!hasCropInHand && !config.moneyPerHourAlwaysOn) return + update() + } + + private fun update() { + init() + + if (ready) { + val newDisplay = drawNewDisplay() + display.clear() + display.addAll(newDisplay) + } + } + + private fun drawNewDisplay(): MutableList<List<Any>> { + val newDisplay = mutableListOf<List<Any>>() + + if (!hasCropInHand && !config.moneyPerHourAlwaysOn) return newDisplay + + newDisplay.add(Collections.singletonList("§7Money per hour when selling:")) + + var number = 0 + for ((internalName, moneyPerHour) in calculateMoneyPerHour().sortedDesc()) { + number++ + val cropName = cropNames[internalName] + val isCurrent = cropName == GardenAPI.cropInHand + if (number > config.moneyPerHourShowOnlyBest && !isCurrent) continue + + val list = mutableListOf<Any>() + list.add("§7$number# ") + + try { + val itemStack = NEUItems.getItemStack(internalName) + list.add(itemStack) + } catch (e: NullPointerException) { + e.printStackTrace() + } + val format = LorenzUtils.formatInteger(moneyPerHour.toLong()) + val itemName = NEUItems.getItemStack(internalName).name?.removeColor() ?: continue + val color = if (isCurrent) "§e" else "§7" + list.add("$color$itemName§7: §6$format") + + newDisplay.add(list) + } + + return newDisplay + } + + private fun calculateMoneyPerHour(): MutableMap<String, Double> { + val moneyPerHours = mutableMapOf<String, Double>() + for ((internalName, amount) in multipliers) { + val price = NEUItems.getPrice(internalName) + val cropName = cropNames[internalName]!! + val speed = GardenAPI.getCropsPerSecond(cropName) + + // No speed data for item in hand + if (speed == -1) continue + + // Price not found + if (price == -1.0) continue + + val speedPerHr = speed.toDouble() * 60 * 60 + val blocksPerHour = speedPerHr / amount.toDouble() + val moneyPerHour = price * blocksPerHour + moneyPerHours[internalName] = moneyPerHour + } + return moneyPerHours + } + + private fun init() { + if (loaded) return + loaded = true + + SkyHanniMod.coroutineScope.launch { + val crops = listOf( + "Wheat", + "Carrot", + "Potato", + "Pumpkin", + "Sugar Cane", + "Melon", + "Cactus", + "Cocoa Beans", + "Mushroom", + "Nether Wart", + ) + + val ignoreCheapCraftedItems = listOf( + "BREAD", + "BUILDER_BROWN_MUSHROOM", + "BUILDER_CACTUS", + "BUILDER_MELON", + "CACTUS_BOOTS", + "CACTUS_CHESTPLATE", + "CACTUS_HELMET", + "CACTUS_LEGGINGS", + "FARM_SUIT_BOOTS", + "FARM_SUIT_CHESTPLATE", + "FARM_SUIT_HELMET", + "FARM_SUIT_LEGGINGS", + "MUSHROOM_BOOTS", + "MUSHROOM_CHESTPLATE", + "MUSHROOM_HELMET", + "MUSHROOM_LEGGINGS", + "PAPER", + "POTION_AFFINITY_TALISMAN", + "PUMPKIN_BOOTS", + "PUMPKIN_CHESTPLATE", + "PUMPKIN_HELMET", + "PUMPKIN_LEGGINGS", + "SIMPLE_CARROT_CANDY", + "SPEED_TALISMAN", + ) + + val ignoreCheapItems = listOf( + "BROWN_MUSHROOM", + "CACTUS", + "CARROT_ITEM", + "ENCHANTED_BREAD", + "HAY_BLOCK", + "HUGE_MUSHROOM_1", + "HUGE_MUSHROOM_2", + "INK_SACK-3", + "MELON", + "MELON_BLOCK", + "NETHER_STALK", + "POTATO_ITEM", + "PUMPKIN", + "RED_MUSHROOM", + "SUGAR_CANE", + "WHEAT", + ) + + for ((internalName, _) in NotEnoughUpdates.INSTANCE.manager.itemInformation) { + if (ignoreCheapCraftedItems.contains(internalName)) continue + if (ignoreCheapItems.contains(internalName)) continue + // filter craftable items + if (internalName.endsWith("_BOOTS") || + internalName.endsWith("_HELMET") || + internalName.endsWith("_LEGGINGS") || + internalName.endsWith("_CHESTPLATE") || + internalName == "ENCHANTED_PAPER" + ) { + continue + } + + val (newId, amount) = NEUItems.getMultiplier(internalName) + val itemName = NEUItems.getItemStack(newId).name?.removeColor() ?: continue + val cropName = GardenAPI.itemNameToCropName(itemName) + if (crops.contains(cropName)) { + multipliers[internalName] = amount + cropNames[internalName] = cropName + } + } + + + ready = true + update() + } + } + + private fun isEnabled() = GardenAPI.inGarden() && config.moneyPerHourDisplay +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index e5c6b72ca..71ebe5ea9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -113,7 +113,13 @@ class GardenAPI { } fun getCropsPerSecond(itemName: String): Int { - return cropsPerSecond[itemNameToCropName(itemName)]!! + val name = itemNameToCropName(itemName) + val result = cropsPerSecond[name] + if (result == null) { + println("getCropsPerSecond is null for '$name'") + return -1 + } + return result } fun itemNameToCropName(itemName: String): String { |