diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-12 04:14:51 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-12 04:14:51 +0200 |
commit | e3f8ef1c7efe1e4f16aa960756ef1297d10192fa (patch) | |
tree | b30daa53cd9687757bcb9c0e93f72fb878726d1d /src/main/java | |
parent | 7f7ad4a745c584892b773732ab84557ca4596470 (diff) | |
download | skyhanni-e3f8ef1c7efe1e4f16aa960756ef1297d10192fa.tar.gz skyhanni-e3f8ef1c7efe1e4f16aa960756ef1297d10192fa.tar.bz2 skyhanni-e3f8ef1c7efe1e4f16aa960756ef1297d10192fa.zip |
Rename util methods
Diffstat (limited to 'src/main/java')
10 files changed, 74 insertions, 74 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt index 98c595a63..9db52fe7c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropSpeedMeter.kt @@ -5,6 +5,8 @@ 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.features.garden.CropType.Companion.getCropType +import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -22,9 +24,14 @@ class CropSpeedMeter { @SubscribeEvent fun onBlockBreak(event: BlockClickEvent) { if (!isEnabled()) return - val cropBroken = CropType.getByBlock(event.getBlockState) ?: return if (startCrops.isEmpty()) return + val blockState = event.getBlockState + val cropBroken = blockState.getCropType() ?: return + if (cropBroken.multiplier == 1) { + if (blockState.isBabyCrop()) return + } + if (currentCrop != cropBroken) { currentCrop = cropBroken currentBlocks = 0 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 11deea8d4..e5fe7a056 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt @@ -21,6 +21,8 @@ enum class CropType(val cropName: String, val toolName: String, val baseDrops: D val icon by lazy { iconSupplier() } + val multiplier by lazy { if (this == SUGAR_CANE || this == CACTUS) 2 else 1 } + companion object { fun getByName(cropName: String) = values().firstOrNull { it.cropName == cropName } @@ -35,8 +37,8 @@ enum class CropType(val cropName: String, val toolName: String, val baseDrops: D return getByName(itemName) } - fun getByBlock(blockState: IBlockState): CropType? { - return when (blockState.block) { + fun IBlockState.getCropType(): CropType? { + return when (block) { Blocks.wheat -> WHEAT Blocks.carrots -> CARROT Blocks.potatoes -> POTATO diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt index c7351b763..a838eecc5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt @@ -5,13 +5,16 @@ import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter import at.hannibal2.skyhanni.data.GardenCropUpgrades.Companion.getUpgradeLevel import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType import at.hannibal2.skyhanni.features.garden.CropType.Companion.getTurboCrop +import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.addCropIcon +import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getCropType import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems -import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCounter import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHoeCounter import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -45,14 +48,14 @@ class FarmingFortuneDisplay { @SubscribeEvent(priority = EventPriority.LOW) fun onInventoryUpdate(event: OwnInventorItemUpdateEvent) { if (!GardenAPI.inGarden()) return - if (GardenAPI.getCropTypeFromItem(event.itemStack) == null) return + if (event.itemStack.getCropType() == null) return updateToolFortune(event.itemStack) } @SubscribeEvent fun onBlockBreak(event: BlockClickEvent) { if (!GardenAPI.inGarden()) return - val cropBroken = CropType.getByBlock(event.getBlockState) ?: return + val cropBroken = event.getBlockState.getCropType() ?: return if (cropBroken != currentCrop) { currentCrop = cropBroken updateToolFortune(event.itemInHand) @@ -78,7 +81,7 @@ class FarmingFortuneDisplay { if (event.phase != TickEvent.Phase.START || ticks++ % 5 != 0) return val displayCrop = currentCrop ?: return val updatedDisplay = mutableListOf<Any>() - GardenAPI.addGardenCropToList(displayCrop, updatedDisplay) + updatedDisplay.addCropIcon(displayCrop) val recentlySwitchedTool = System.currentTimeMillis() < lastToolSwitch + 1000 val displayString = upgradeFortune?.let { "§6Farming Fortune§7: §e" + if (!recentlySwitchedTool) { @@ -91,11 +94,12 @@ class FarmingFortuneDisplay { } private fun updateToolFortune(tool: ItemStack?) { - val cropMatchesTool = currentCrop == GardenAPI.getCropTypeFromItem(tool) + val cropMatchesTool = currentCrop == tool?.getCropType() val toolCounterFortune = if (cropMatchesTool) { getToolFortune(tool) + getCounterFortune(tool) + getCollectionFortune(tool) } else 0.0 - toolFortune = toolCounterFortune + getTurboCropFortune(tool, currentCrop) + getDedicationFortune(tool, currentCrop) + toolFortune = + toolCounterFortune + getTurboCropFortune(tool, currentCrop) + getDedicationFortune(tool, currentCrop) } private fun isEnabled(): Boolean = GardenAPI.inGarden() && config.farmingFortuneDisplay @@ -131,7 +135,7 @@ class FarmingFortuneDisplay { } fun getCounterFortune(tool: ItemStack?): Double { - val counter = tool?.getCounter() ?: return 0.0 + val counter = tool?.getHoeCounter() ?: return 0.0 val digits = floor(log10(counter.toDouble())) return (16 * digits - 48).takeIf { it > 0.0 } ?: 0.0 } 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 c7df35877..8a882226d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -6,8 +6,8 @@ import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCounter -import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCultivatingCount +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCultivatingCounter +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHoeCounter import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack import net.minecraft.network.play.client.C09PacketHeldItemChange @@ -54,7 +54,7 @@ class GardenAPI { private fun checkItemInHand() { val toolItem = Minecraft.getMinecraft().thePlayer.heldItem - val crop = getCropTypeFromItem(toolItem) + val crop = toolItem.getCropType() val newTool = getToolInHand(toolItem, crop) if (toolInHand != newTool) { toolInHand = newTool @@ -102,12 +102,12 @@ class GardenAPI { fun inGarden() = LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.GARDEN - fun getCropTypeFromItem(item: ItemStack?): CropType? { - val internalName = item?.getInternalName() ?: return null + fun ItemStack.getCropType(): CropType? { + val internalName = getInternalName() return CropType.values().firstOrNull { internalName.startsWith(it.toolName) } } - fun readCounter(itemStack: ItemStack): Int = itemStack.getCounter() ?: itemStack.getCultivatingCount() ?: -1 + fun readCounter(itemStack: ItemStack): Int = itemStack.getHoeCounter() ?: itemStack.getCultivatingCounter() ?: -1 fun CropType.getSpeed(): Int { val speed = cropsPerSecond[this] @@ -124,9 +124,9 @@ class GardenAPI { cropsPerSecond[this] = speed } - fun addGardenCropToList(crop: CropType, list: MutableList<Any>) { + fun MutableList<Any>.addCropIcon(crop: CropType) { try { - list.add(crop.icon) + add(crop.icon) } catch (e: NullPointerException) { e.printStackTrace() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt index 87666a1ed..db8cb6e07 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter +import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.addCropIcon import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getSpeed import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.sorted @@ -61,13 +62,13 @@ class GardenBestCropTime { val list = mutableListOf<Any>() list.add("§7$number# ") - GardenAPI.addGardenCropToList(crop, list) + list.addCropIcon(crop) val color = if (isCurrent) "§e" else "§7" val contestFormat = if (GardenNextJacobContest.isNextCrop(crop)) "§n" else "" val nextTier = GardenCropMilestones.getTierForCrops(crop.getCounter()) + 1 - val cropName = if (!config.cropMilestoneBestCompact) crop.cropName +" " else "" + val cropName = if (!config.cropMilestoneBestCompact) crop.cropName + " " else "" val cropNameDisplay = "$color$contestFormat$cropName$nextTier§r" list.add("$cropNameDisplay §b$duration") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt index ca118f665..18b408666 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt @@ -7,17 +7,18 @@ import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.setCounter import at.hannibal2.skyhanni.data.SendTitleHelper import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType +import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.addCropIcon +import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getCropType import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.setSpeed +import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SoundUtils.playSound import at.hannibal2.skyhanni.utils.TimeUtils -import net.minecraft.block.properties.PropertyInteger -import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.ISound import net.minecraft.client.audio.PositionedSound -import net.minecraft.init.Blocks import net.minecraft.item.ItemStack import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -123,7 +124,7 @@ class GardenCropMilestoneDisplay { val item = event.itemStack val counter = GardenAPI.readCounter(item) if (counter == -1) return - val crop = GardenAPI.getCropTypeFromItem(item) ?: return + val crop = item.getCropType() ?: return if (cultivatingData.containsKey(crop)) { val old = cultivatingData[crop]!! val addedCounter = counter - old @@ -156,45 +157,16 @@ class GardenCropMilestoneDisplay { @SubscribeEvent fun onBlockClick(event: BlockClickEvent) { if (!isEnabled()) return + if (event.clickType != ClickType.LEFT_CLICK) return - if (event.clickType == ClickType.LEFT_CLICK) { - val blockState = event.getBlockState - - val blocks = isFarmBlock(blockState) - if (blocks == 0) return - if (blocks == 1) { - for (property in blockState.block.blockState.properties) { - val name = property.name - if (name == "age") { - if (property is PropertyInteger) { - val value = blockState.getValue(property)!! - if (value == 0) return - } - } - } - } - blocksBroken += blocks - } - } + val blockState = event.getBlockState - private fun isFarmBlock(blockState: IBlockState): Int { - val block = blockState.block - if (block == Blocks.carrots) return 1 - if (block == Blocks.potatoes) return 1 - if (block == Blocks.wheat) return 1 - if (block == Blocks.cocoa) return 1 // Cocoa Beans - if (block == Blocks.red_mushroom) return 1 - if (block == Blocks.brown_mushroom) return 1 - if (block == Blocks.cactus) return 2 - if (block == Blocks.reeds) return 2 // Sugar Cane - if (block == Blocks.nether_wart) return 1 - if (block == Blocks.melon_block) return 1 - if (block == Blocks.pumpkin) return 1 - - if (block == Blocks.dirt) return 0 - if (block == Blocks.farmland) return 0 - - return 0 + val cropType = blockState.getCropType() ?: return + val multiplier = cropType.multiplier + if (multiplier == 1) { + if (blockState.isBabyCrop()) return + } + blocksBroken += multiplier } private var currentSpeed = 0 @@ -282,7 +254,7 @@ class GardenCropMilestoneDisplay { val nextTier = currentTier + 1 val list = mutableListOf<Any>() - GardenAPI.addGardenCropToList(crop, list) + list.addCropIcon(crop) list.add("§7" + crop.cropName + " Tier $nextTier") lineMap[1] = list @@ -375,11 +347,8 @@ class GardenCropMilestoneDisplay { val missing = need - have // We assume perfect 20 blocks per seconds - val blocksPerSecond = when (currentCrop) { - CropType.CACTUS, CropType.SUGAR_CANE -> 40 + val blocksPerSecond = 20 * (currentCrop?.multiplier ?: 1) - else -> 20 - } val missingTimeSeconds = missing / blocksPerSecond val millis = missingTimeSeconds * 1000 val duration = TimeUtils.formatDuration(millis) @@ -387,7 +356,7 @@ class GardenCropMilestoneDisplay { lineMap[0] = Collections.singletonList("§6Mooshroom Cow Perk") val list = mutableListOf<Any>() - GardenAPI.addGardenCropToList(CropType.MUSHROOM, list) + list.addCropIcon(CropType.MUSHROOM) list.add("§7Mushroom Tier $nextTier") lineMap[1] = list @@ -404,4 +373,4 @@ class GardenCropMilestoneDisplay { } private fun isEnabled() = GardenAPI.inGarden() && config.cropMilestoneProgress -}
\ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt index e22339edd..398b6818f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.addCropIcon import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils @@ -191,7 +192,7 @@ class GardenNextJacobContest { } for (crop in nextContest.crops) { list.add(" ") - GardenAPI.addGardenCropToList(crop, list) + list.addCropIcon(crop) nextContestCrops.add(crop) } val format = TimeUtils.formatDuration(duration) @@ -216,7 +217,7 @@ class GardenNextJacobContest { if (!config.nextJacobContestDisplay) return if (!inCalendar) return - if (!display.isEmpty()) { + if (display.isNotEmpty()) { config.nextJacobContestPos.renderSingleLineWithItems(display, posLabel = "Garden Next Jacob Contest") } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt index 7a60f7120..4c4553cb8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getCropType import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getFarmingForDummiesCount @@ -22,7 +23,7 @@ class ToolTooltipTweaks { @SubscribeEvent fun onTooltip(event: LorenzToolTipEvent) { if (!LorenzUtils.inSkyBlock) return - val crop = GardenAPI.getCropTypeFromItem(event.itemStack) ?: return + val crop = event.itemStack.getCropType() ?: return val toolFortune = FarmingFortuneDisplay.getToolFortune(event.itemStack) val counterFortune = FarmingFortuneDisplay.getCounterFortune(event.itemStack) val collectionFortune = FarmingFortuneDisplay.getCollectionFortune(event.itemStack) @@ -90,7 +91,7 @@ class ToolTooltipTweaks { if (counterStartLine.contains(line)) removingCounterDescription = true if (line == "§5§o§9Blessed Bonus") removingReforgeDescription = true - if (removingReforgeDescription ) { + if (removingReforgeDescription) { iterator.remove() removingReforgeDescription = !reforgeEndLine.contains(line) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt index 5138ebf35..e16df26e9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import net.minecraft.block.Block +import net.minecraft.block.properties.PropertyInteger import net.minecraft.block.state.IBlockState import net.minecraft.client.Minecraft import net.minecraft.tileentity.TileEntitySkull @@ -24,4 +25,18 @@ object BlockUtils { return serializeNBT.getCompoundTag("Owner").getCompoundTag("Properties") .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value") } + + fun IBlockState.isBabyCrop(): Boolean { + for (property in block.blockState.properties) { + val name = property.name + if (name != "age") continue + + if (property is PropertyInteger) { + val value = getValue(property)!! + if (value == 0) return true + } + } + + return false + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index 3ff2e54e6..bb1c8705e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -11,9 +11,9 @@ object SkyBlockItemModifierUtils { fun ItemStack.getFarmingForDummiesCount() = getAttributeInt("farming_for_dummies_count") - fun ItemStack.getCultivatingCount() = getAttributeInt("farmed_cultivating") + fun ItemStack.getCultivatingCounter() = getAttributeInt("farmed_cultivating") - fun ItemStack.getCounter() = getAttributeInt("mined_crops") + fun ItemStack.getHoeCounter() = getAttributeInt("mined_crops") fun ItemStack.getSilexCount(): Int? { val enchantments = getEnchantments() ?: return null |