diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index cd40fe9b0a4c..636df03e849b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -13,7 +13,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = SkyHanniLogger("ConfigMigration") - const val CONFIG_VERSION = 129 + const val CONFIG_VERSION = 130 fun JsonElement.at(chain: List, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.kt b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.kt index 40f11d29e6ad..fe99b3f32bc2 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.kt @@ -13,10 +13,12 @@ import at.hannibal2.skyhanni.config.features.garden.optimalAngles.OptimalAnglesC import at.hannibal2.skyhanni.config.features.garden.optimalspeed.OptimalSpeedConfig import at.hannibal2.skyhanni.config.features.garden.pests.PestsConfig import at.hannibal2.skyhanni.config.features.garden.visitor.VisitorConfig +import at.hannibal2.skyhanni.features.garden.farming.NoBreak.NoBreakItem import com.google.gson.annotations.Expose import io.github.notenoughupdates.moulconfig.annotations.Accordion import io.github.notenoughupdates.moulconfig.annotations.Category import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind import io.github.notenoughupdates.moulconfig.annotations.ConfigLink @@ -55,12 +57,11 @@ class GardenConfig { @Expose @ConfigOption( - name = "Prevent Breaking with Rod", - desc = "Stops you from breaking blocks while holding a fishing rod.", + name = "Prevent Breaking Crops", + desc = "Stops you from breaking crops while holding certain items.", ) - @ConfigEditorBoolean - @FeatureToggle - var noRodBreak: Boolean = true + @ConfigEditorDraggableList + val noBreakItems: MutableList = NoBreakItem.entries.toMutableList() @Expose @Category(name = "Optimal Speed", desc = "Optimal Speed Settings") 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 a40f97853ab9..390aa5a9e8fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.garden +import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.utils.ItemUtils.overrideId import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzVec @@ -166,6 +167,9 @@ enum class CropType( } } + fun BlockClickEvent.getCropType(): CropType? = + getBlockState.getCropType(position) + fun getTimeFlower(): CropType { val time = ServerTime.dayTime % 24000 // pretty sure great spook will break this 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 6f73a9ccb058..ee6509d77134 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenApi.kt @@ -223,8 +223,8 @@ object GardenApi { @HandleEvent(onlyOnIsland = IslandType.GARDEN) fun onBlockClick(event: BlockClickEvent) { + val cropBroken = event.getCropType() ?: return val blockState = event.getBlockState - val cropBroken = blockState.getCropType(event.position) ?: return if (cropBroken.multiplier == 1 && blockState.isBabyCrop()) return val position = event.position diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/NoBreak.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/NoBreak.kt new file mode 100644 index 000000000000..6767eb8976fe --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/NoBreak.kt @@ -0,0 +1,58 @@ +package at.hannibal2.skyhanni.features.garden.farming + +import at.hannibal2.skyhanni.api.event.HandleEvent +import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.data.ClickType +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.BlockClickEvent +import at.hannibal2.skyhanni.features.fishing.FishingApi.isFishingRod +import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType +import at.hannibal2.skyhanni.features.garden.GardenApi +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.NeuInternalName +import at.hannibal2.skyhanni.utils.NeuInternalName.Companion.toInternalName +import com.google.gson.JsonArray + +@SkyHanniModule +object NoBreak { + + private val SPRAYONATOR_ITEM = "SPRAYONATOR".toInternalName() + + private val config get() = GardenApi.config + + @HandleEvent(onlyOnIsland = IslandType.GARDEN) + fun onBlockClick(event: BlockClickEvent) { + if (event.clickType != ClickType.LEFT_CLICK) return + // TODO make this work with CropClickEvent + if (event.getCropType() == null) return + + val heldItem = InventoryUtils.itemInHandId + if (config.noBreakItems.any { it.predicate(heldItem) }) { + event.cancel() + } + } + + @HandleEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(130, "garden.noRodBreak", "garden.noBreakItems") { element -> + if (element.asBoolean) { + ConfigManager.gson.toJsonTree(NoBreakItem.entries) + } else { + JsonArray() + } + } + } + + enum class NoBreakItem( + val displayName: String, + val predicate: (NeuInternalName) -> Boolean, + ) { + FISHING_ROD("Fishing Rod", { it.isFishingRod() }), + SPRAYONATOR("Sprayonator", { it == SPRAYONATOR_ITEM }), + ; + + override fun toString() = displayName + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/NoRodBreak.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/NoRodBreak.kt deleted file mode 100644 index d11a0b2d34fd..000000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/NoRodBreak.kt +++ /dev/null @@ -1,26 +0,0 @@ -package at.hannibal2.skyhanni.features.garden.farming - -import at.hannibal2.skyhanni.api.event.HandleEvent -import at.hannibal2.skyhanni.data.ClickType -import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.events.BlockClickEvent -import at.hannibal2.skyhanni.features.fishing.FishingApi.isFishingRod -import at.hannibal2.skyhanni.features.garden.GardenApi -import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.utils.InventoryUtils - -@SkyHanniModule -object NoRodBreak { - - private val config get() = GardenApi.config - - @HandleEvent(onlyOnIsland = IslandType.GARDEN) - fun onBlockClick(event: BlockClickEvent) { - if (!config.noRodBreak) return - if (event.clickType != ClickType.LEFT_CLICK) return - - if (InventoryUtils.getItemInHand()?.isFishingRod() == true) { - event.cancel() - } - } -}