-
-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Optimal Angles Overlay for Squeaky Mousemat #2999
base: beta
Are you sure you want to change the base?
Changes from all commits
cd4f122
3e61b03
5c8632a
0a63ca0
efcf5ac
845ff5d
da305b0
8fe4ac6
ec0366b
43de886
c56cca4
fed8b8d
8140fd1
29c913b
49f2d62
d0c759e
1934772
df06c91
02ad94a
de1c1b9
fe2799e
c273058
dc93775
6489b39
651b165
f0b0dda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package at.hannibal2.skyhanni.config.features.garden.optimalAngles | ||
|
||
import com.google.gson.annotations.Expose | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption | ||
import io.github.notenoughupdates.moulconfig.observer.Property | ||
|
||
class CustomAnglesConfig { | ||
|
||
// Cactus | ||
@Expose | ||
@ConfigOption(name = "Cactus Yaw", desc = "Set Yaw for cactus farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var cactusYaw: Property<Float> = Property.of(-90f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Cactus Pitch", desc = "Set Pitch for cactus farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var cactusPitch: Property<Float> = Property.of(0f) | ||
|
||
// Carrot | ||
@Expose | ||
@ConfigOption(name = "Carrot Yaw", desc = "Set Yaw for carrot farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var carrotYaw: Property<Float> = Property.of(-90f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Carrot Pitch", desc = "Set Pitch for carrot farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var carrotPitch: Property<Float> = Property.of(2.8f) | ||
|
||
// Cocoa Beans | ||
@Expose | ||
@ConfigOption(name = "Cocoa Beans Yaw", desc = "Set Yaw for cocoa bean farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var cocoaBeansYaw: Property<Float> = Property.of(180f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Cocoa Beans Pitch", desc = "Set Pitch for cocoa bean farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var cocoaBeansPitch: Property<Float> = Property.of(-45f) | ||
|
||
// Melon | ||
@Expose | ||
@ConfigOption(name = "Melon Yaw", desc = "Set Yaw for melon farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var melonYaw: Property<Float> = Property.of(90f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Melon Pitch", desc = "Set Pitch for melon farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var melonPitch: Property<Float> = Property.of(-58.5f) | ||
|
||
// Mushroom | ||
@Expose | ||
@ConfigOption(name = "Mushroom Yaw", desc = "Set Yaw for mushroom farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var mushroomYaw: Property<Float> = Property.of(116.5f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Mushroom Pitch", desc = "Set Pitch for mushroom farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var mushroomPitch: Property<Float> = Property.of(0f) | ||
|
||
// Nether Wart | ||
@Expose | ||
@ConfigOption(name = "Nether Wart Yaw", desc = "Set Yaw for nether wart farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var netherWartYaw: Property<Float> = Property.of(90f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Nether Wart Pitch", desc = "Set Pitch for nether wart farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var netherWartPitch: Property<Float> = Property.of(0f) | ||
|
||
// Potato | ||
@Expose | ||
@ConfigOption(name = "Potato Yaw", desc = "Set Yaw for potato farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var potatoYaw: Property<Float> = Property.of(-90f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Potato Pitch", desc = "Set Pitch for potato farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var potatoPitch: Property<Float> = Property.of(2.8f) | ||
|
||
// Pumpkin | ||
@Expose | ||
@ConfigOption(name = "Pumpkin Yaw", desc = "Set Yaw for pumpkin farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var pumpkinYaw: Property<Float> = Property.of(90f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Pumpkin Pitch", desc = "Set Pitch for pumpkin farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var pumpkinPitch: Property<Float> = Property.of(-58.5f) | ||
|
||
// Sugar Cane | ||
@Expose | ||
@ConfigOption(name = "Sugar Cane Yaw", desc = "Set Yaw for sugar cane farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var sugarCaneYaw: Property<Float> = Property.of(-135f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Sugar Cane Pitch", desc = "Set Pitch for sugar cane farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var sugarCanePitch: Property<Float> = Property.of(0f) | ||
|
||
// Wheat | ||
@Expose | ||
@ConfigOption(name = "Wheat Yaw", desc = "Set Yaw for wheat farming.") | ||
@ConfigEditorSlider(minValue = -180f, maxValue = 180f, minStep = 0.1f) | ||
var wheatYaw: Property<Float> = Property.of(90f) | ||
|
||
@Expose | ||
@ConfigOption(name = "Wheat Pitch", desc = "Set Pitch for wheat farming.") | ||
@ConfigEditorSlider(minValue = -90f, maxValue = 90f, minStep = 0.1f) | ||
var wheatPitch: Property<Float> = Property.of(0f) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package at.hannibal2.skyhanni.config.features.garden.optimalAngles | ||
|
||
import at.hannibal2.skyhanni.config.FeatureToggle | ||
import at.hannibal2.skyhanni.config.core.config.Position | ||
import com.google.gson.annotations.Expose | ||
import io.github.notenoughupdates.moulconfig.annotations.Accordion | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption | ||
|
||
class OptimalAnglesConfig { | ||
@Expose | ||
@ConfigOption( | ||
name = "Squeaky Mousemat", | ||
desc = "Set the optimal angles (pitch & yaw) in the Squeaky Mousemat overlay by clicking on the presets." | ||
) | ||
@ConfigEditorBoolean | ||
@FeatureToggle | ||
var signEnabled: Boolean = true | ||
|
||
@Expose | ||
@ConfigOption(name = "Compact GUI", desc = "Compact the Squeaky Mousemat GUI only showing crop icons.") | ||
@ConfigEditorBoolean | ||
var compactMousematGui: Boolean = false | ||
|
||
@Expose | ||
@ConfigLink(owner = OptimalAnglesConfig::class, field = "signEnabled") | ||
var signPosition: Position = Position(20, -195, false, true) | ||
|
||
@Expose | ||
@ConfigOption(name = "Custom Speed", desc = "Change the exact speed for every single crop.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update the name/desc |
||
@Accordion | ||
var customAngles: CustomAnglesConfig = CustomAnglesConfig() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package at.hannibal2.skyhanni.features.garden | ||
|
||
import at.hannibal2.skyhanni.api.event.HandleEvent | ||
import at.hannibal2.skyhanni.events.GardenToolChangeEvent | ||
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule | ||
import at.hannibal2.skyhanni.utils.LorenzColor | ||
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables | ||
import at.hannibal2.skyhanni.utils.SignUtils | ||
import at.hannibal2.skyhanni.utils.SignUtils.isMousematSign | ||
import at.hannibal2.skyhanni.utils.renderables.Renderable | ||
import io.github.notenoughupdates.moulconfig.observer.Property | ||
import net.minecraft.client.gui.inventory.GuiEditSign | ||
import net.minecraftforge.client.event.GuiOpenEvent | ||
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
|
||
@SkyHanniModule | ||
object GardenOptimalAngles { | ||
|
||
private val config get() = GardenApi.config.optimalAngles | ||
|
||
private val configCustomAngles get() = config.customAngles | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is only used once it can be inlined |
||
|
||
private var cropInHand: CropType? = null | ||
private var lastCrop: CropType? = null | ||
private var display = listOf<Renderable>() | ||
|
||
@SubscribeEvent | ||
fun onGuiOpen(event: GuiOpenEvent) { | ||
if (!isSqueakyMousematEnabled()) return | ||
val gui = event.gui as? GuiEditSign ?: return | ||
if (!gui.isMousematSign()) return | ||
|
||
val crops = CropType.entries.map { it to it.getAngles() } | ||
|
||
display = if (config.compactMousematGui) { | ||
crops.groupBy({ it.second }, { it.first }).map { (angles, crops) -> | ||
val color = if (lastCrop in crops) LorenzColor.GOLD else LorenzColor.WHITE | ||
val renderable = Renderable.horizontalContainer( | ||
listOf( | ||
Renderable.horizontalContainer(crops.map { Renderable.itemStack(it.icon) }), | ||
Renderable.string("${color.getChatColor()} - ${angles.first}/${angles.second}"), | ||
), | ||
spacing = 2, | ||
) | ||
Renderable.link(renderable, underlineColor = color.toColor(), onClick = { setAngles(angles) }) | ||
} | ||
} else { | ||
crops.map { (crop, angles) -> | ||
val color = if (lastCrop == crop) LorenzColor.GOLD else LorenzColor.WHITE | ||
val renderable = Renderable.horizontalContainer( | ||
listOf( | ||
Renderable.itemStack(crop.icon), | ||
Renderable.string("${color.getChatColor()}${crop.cropName} - ${angles.first}/${angles.second}"), | ||
), | ||
spacing = 2, | ||
) | ||
Renderable.link(renderable, underlineColor = color.toColor(), onClick = { setAngles(angles) }) | ||
} | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
fun onGuiRender(event: DrawScreenEvent.Post) { | ||
if (!isSqueakyMousematEnabled()) return | ||
val gui = event.gui as? GuiEditSign ?: return | ||
if (!gui.isMousematSign()) return | ||
config.signPosition.renderRenderables( | ||
display, | ||
posLabel = "Optimal Angles Mousemat Overlay", | ||
) | ||
} | ||
|
||
@HandleEvent | ||
fun onGardenToolChange(event: GardenToolChangeEvent) { | ||
cropInHand = event.crop | ||
event.crop?.let { lastCrop = it } | ||
} | ||
|
||
private fun setAngles(angles: Pair<Float, Float>) { | ||
SignUtils.setTextIntoSign("${angles.first}", 0) | ||
SignUtils.setTextIntoSign("${angles.second}", 3) | ||
} | ||
|
||
private fun CropType.getAngles() = getConfig().let { Pair(it.first.get(), it.second.get()) } | ||
|
||
private fun CropType.getConfig(): Pair<Property<Float>, Property<Float>> = with(configCustomAngles) { | ||
when (this@getConfig) { | ||
CropType.CACTUS -> Pair(cactusYaw, cactusPitch) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of |
||
CropType.WHEAT -> Pair(wheatYaw, wheatPitch) | ||
CropType.CARROT -> Pair(carrotYaw, carrotPitch) | ||
CropType.POTATO -> Pair(potatoYaw, potatoPitch) | ||
CropType.NETHER_WART -> Pair(netherWartYaw, netherWartPitch) | ||
CropType.PUMPKIN -> Pair(pumpkinYaw, pumpkinPitch) | ||
CropType.MELON -> Pair(melonYaw, melonPitch) | ||
CropType.COCOA_BEANS -> Pair(cocoaBeansYaw, cocoaBeansPitch) | ||
CropType.SUGAR_CANE -> Pair(sugarCaneYaw, sugarCanePitch) | ||
CropType.MUSHROOM -> Pair(mushroomYaw, mushroomPitch) | ||
} | ||
} | ||
|
||
private fun isSqueakyMousematEnabled() = GardenApi.inGarden() && config.signEnabled | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move the squeaky mousemat options into a new class that is part of this class here