diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-12 02:06:44 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-12 02:06:44 +0200 |
commit | b8ff120faff344de82e6b4b956de968a01a92433 (patch) | |
tree | c098a1fbc2746a83049fec46aaaa73f3974e9ac6 /src/main/java | |
parent | 1c3d1c70e3491ed6d02c73376f83dfdadc47ea09 (diff) | |
download | skyhanni-b8ff120faff344de82e6b4b956de968a01a92433.tar.gz skyhanni-b8ff120faff344de82e6b4b956de968a01a92433.tar.bz2 skyhanni-b8ff120faff344de82e6b4b956de968a01a92433.zip |
Added command /shcropspeedmeter - Helps calculate the real farming fortune with the formula crops broken per block
Diffstat (limited to 'src/main/java')
5 files changed, 151 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 20359056d..3392e83c7 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -247,6 +247,7 @@ public class SkyHanniMod { loadModule(new ComposterInventoryNumbers()); loadModule(new FarmingFortuneDisplay()); loadModule(new ToolTooltipTweaks()); + loadModule(new CropSpeedMeter()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index b808c4b31..f45c8a035 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.features.bazaar.BazaarDataGrabber import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper +import at.hannibal2.skyhanni.features.garden.CropSpeedMeter import at.hannibal2.skyhanni.features.misc.CollectionCounter import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.test.LorenzTest @@ -55,6 +56,7 @@ object Commands { registerCommand("shtestgardenvisitors") { LorenzTest.testGardenVisitors() } registerCommand("shresetitemnames") { BazaarDataGrabber.resetItemNames() } registerCommand("shtogglehypixelapierrors") { APIUtil.toggleApiErrorMessages() } + registerCommand("shcropspeedmeter") { CropSpeedMeter.toggle() } } private fun registerCommand(name: String, function: (Array<String>) -> Unit) { 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 1e01135ce..fcacb9ddb 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -822,4 +822,7 @@ public class Garden { @ConfigOption(name = "Fungi Cutter Warning", desc = "Warn when breaking mushroom with the wrong Fungi Cutter mode.") @ConfigEditorBoolean public boolean fungiCutterWarn = true; + + @Expose + public Position cropSpeedMeterPos = new Position(278, -236, false, true); } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt new file mode 100644 index 000000000..98c595a63 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt @@ -0,0 +1,134 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter +import at.hannibal2.skyhanni.events.BlockClickEvent +import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent + +class CropSpeedMeter { + private var display = listOf<String>() + private var currentCrop: CropType? = null + private var currentBlocks = 0 + private var tick = 0 + private var snapshot = listOf<String>() + + @SubscribeEvent + fun onBlockBreak(event: BlockClickEvent) { + if (!isEnabled()) return + val cropBroken = CropType.getByBlock(event.getBlockState) ?: return + if (startCrops.isEmpty()) return + + if (currentCrop != cropBroken) { + currentCrop = cropBroken + currentBlocks = 0 + snapshot = emptyList() + } + breakBlock() + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!isEnabled()) return + if (tick++ % 30 != 0) return + + updateDisplay() + } + + private fun updateDisplay() { + display = renderDisplay() + } + + private fun renderDisplay(): MutableList<String> { + val list = mutableListOf<String>() + list.add("§7Crop Speed Meter") + if (startCrops.isEmpty()) { + list.add("§cOpen §e/cropmilestones §cto start!") + return list + } + + if (currentCrop == null) { + list.add("§cStart breaking blocks!") + return list + } + currentCrop?.let { + list.add(" §7Current ${it.cropName} counter: §e${currentBlocks.addSeparators()}") + } + + if (snapshot.isNotEmpty()) { + list += snapshot + } else { + list.add("§cOpen §e/cropmilestones §cagain to calculate!") + } + + return list + } + + @SubscribeEvent + fun onCropMilestoneUpdate(event: CropMilestoneUpdateEvent) { + if (!isEnabled()) return + val counters = mutableMapOf<CropType, Long>() + for (cropType in CropType.values()) { + counters[cropType] = cropType.getCounter() + } + if (startCrops.isEmpty()) { + startCrops = counters + currentCrop = null + snapshot = emptyList() + } else { + currentCrop?.let { + val crops = it.getCounter() - startCrops[it]!! + val blocks = currentBlocks + val cropsPerBlocks = (crops.toDouble() / blocks.toDouble()).round(3) + + val list = mutableListOf<String>() + list.add("") + list.add("§6Calculation results") + list.add(" §7Crops collected: " + crops.addSeparators()) + list.add(" §7Blocks broken: " + blocks.addSeparators()) + list.add(" §7Crops per Block: " + cropsPerBlocks.addSeparators()) + + val baseDrops = it.baseDrops + val farmingFortune = (cropsPerBlocks * 100 / baseDrops).round(3) + + + list.add(" §7Calculated farming Fortune: §e" + farmingFortune.addSeparators()) + list.add("§cOpen /cropmilestones again to recalculate!") + + snapshot = list + updateDisplay() + } + } + } + + private fun breakBlock() { + currentBlocks++ + } + + companion object { + var enabled = false + private var startCrops = mapOf<CropType, Long>() + + fun toggle() { + enabled = !enabled + LorenzUtils.chat("§e[SkyHanni] Crop Speed Meter " + if (enabled) "§aEnabled" else "§cDisabled") + startCrops = emptyMap() + + } + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + + SkyHanniMod.feature.garden.cropSpeedMeterPos.renderStrings(display, posLabel = "Crop Speed Meter") + } + + fun isEnabled() = enabled && GardenAPI.inGarden() +}
\ No newline at end of file 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 d8c05dff0..11deea8d4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt @@ -6,17 +6,17 @@ import net.minecraft.init.Items import net.minecraft.item.EnumDyeColor import net.minecraft.item.ItemStack -enum class CropType(val cropName: String, val toolName: String, iconSupplier: () -> ItemStack) { - WHEAT("Wheat", "THEORETICAL_HOE_WHEAT", { ItemStack(Items.wheat) }), - CARROT("Carrot", "THEORETICAL_HOE_CARROT", { ItemStack(Items.carrot) }), - POTATO("Potato", "THEORETICAL_HOE_POTATO", { ItemStack(Items.potato) }), - NETHER_WART("Nether Wart", "THEORETICAL_HOE_WARTS", { ItemStack(Items.nether_wart) }), - PUMPKIN("Pumpkin", "PUMPKIN_DICER", { ItemStack(Blocks.pumpkin) }), - MELON("Melon", "MELON_DICER", { ItemStack(Items.melon) }), - COCOA_BEANS("Cocoa Beans", "COCO_CHOPPER", { ItemStack(Items.dye, 1, EnumDyeColor.BROWN.dyeDamage) }), - SUGAR_CANE("Sugar Cane", "THEORETICAL_HOE_CANE", { ItemStack(Items.reeds) }), - CACTUS("Cactus", "CACTUS_KNIFE", { ItemStack(Blocks.cactus) }), - MUSHROOM("Mushroom", "FUNGI_CUTTER", { ItemStack(Blocks.red_mushroom_block) }), +enum class CropType(val cropName: String, val toolName: String, val baseDrops: Double, iconSupplier: () -> ItemStack) { + WHEAT("Wheat", "THEORETICAL_HOE_WHEAT", 1.0, { ItemStack(Items.wheat) }), + CARROT("Carrot", "THEORETICAL_HOE_CARROT", 3.0, { ItemStack(Items.carrot) }), + POTATO("Potato", "THEORETICAL_HOE_POTATO", 3.0, { ItemStack(Items.potato) }), + NETHER_WART("Nether Wart", "THEORETICAL_HOE_WARTS", 2.5, { ItemStack(Items.nether_wart) }), + PUMPKIN("Pumpkin", "PUMPKIN_DICER", 1.0, { ItemStack(Blocks.pumpkin) }), + MELON("Melon", "MELON_DICER", 5.0, { ItemStack(Items.melon) }), + COCOA_BEANS("Cocoa Beans", "COCO_CHOPPER", 3.0, { ItemStack(Items.dye, 1, EnumDyeColor.BROWN.dyeDamage) }), + 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) }), ; val icon by lazy { iconSupplier() } |