Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> = NoBreakItem.entries.toMutableList()

@Expose
@Category(name = "Optimal Speed", desc = "Optimal Speed Settings")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

This file was deleted.

Loading