aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <nea@nea.moe>2023-03-31 21:32:42 +0200
committerGitHub <noreply@github.com>2023-03-31 21:32:42 +0200
commit53c1440fa4a42613b140f4f099b60c3664ba0fdd (patch)
tree0341c3b48d533fdc3f2efa9e172cd4f6c37eeb14 /src/main/java/at/hannibal2/skyhanni/features
parente6bcc8f902e410c348ff720ab73de14e5cf04280 (diff)
downloadskyhanni-53c1440fa4a42613b140f4f099b60c3664ba0fdd.tar.gz
skyhanni-53c1440fa4a42613b140f4f099b60c3664ba0fdd.tar.bz2
skyhanni-53c1440fa4a42613b140f4f099b60c3664ba0fdd.zip
Add rancher boot overlay for optimal crop speeds (#25)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt28
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt39
3 files changed, 57 insertions, 18 deletions
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 5de01ffaa..1d71c8553 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropType.kt
@@ -1,18 +1,24 @@
package at.hannibal2.skyhanni.features.garden
-enum class CropType(val cropName: String, val toolName: String) {
- WHEAT("Wheat", "THEORETICAL_HOE_WHEAT"),
- CARROT("Carrot", "THEORETICAL_HOE_CARROT"),
- POTATO("Potato", "THEORETICAL_HOE_POTATO"),
- NETHER_WART("Nether Wart", "THEORETICAL_HOE_WARTS"),
- PUMPKIN("Pumpkin", "PUMPKIN_DICER"),
- MELON("Melon", "MELON_DICER"),
- COCOA_BEANS("Cocoa Beans", "COCO_CHOPPER"),
- SUGAR_CANE("Sugar Cane", "THEORETICAL_HOE_CANE"),
- CACTUS("Cactus", "CACTUS_KNIFE"),
- MUSHROOM("Mushroom", "FUNGI_CUTTER"),
+import net.minecraft.init.Blocks
+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) }),
;
+ val icon by lazy { iconSupplier() }
override fun toString(): String {
return cropName
}
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 1168b7f40..67b543c03 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
@@ -128,15 +128,9 @@ class GardenAPI {
return CropType.getByName(itemName)
}
- private fun getItemStackForCrop(crop: CropType): ItemStack {
- val cropName = if (crop == CropType.MUSHROOM) "Red Mushroom Block" else crop.cropName
- val internalName = NEUItems.getInternalName(cropName)
- return NEUItems.getItemStack(internalName)
- }
-
fun addGardenCropToList(crop: CropType, list: MutableList<Any>) {
try {
- list.add(getItemStackForCrop(crop))
+ list.add(crop.icon)
} catch (e: NullPointerException) {
e.printStackTrace()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
index 1fa138455..2a1f8b4dc 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt
@@ -7,7 +7,15 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign
import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiEditSign
+import net.minecraft.util.ChatComponentText
+import net.minecraftforge.client.event.GuiOpenEvent
+import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
@@ -19,6 +27,7 @@ class GardenOptimalSpeed {
private val currentSpeedPattern = Pattern.compile(" Speed: §r§f✦(.*)")
private var lastWarnTime = 0L
private var cropInHand: CropType? = null
+ private var rancherOverlayList: List<List<Any?>> = emptyList()
@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
@@ -30,6 +39,35 @@ class GardenOptimalSpeed {
}
}
+
+ @SubscribeEvent
+ fun onGuiOpen(event: GuiOpenEvent) {
+ rancherOverlayList = CropType.values().map { crop ->
+ listOf(crop.icon, Renderable.link("${crop.cropName} - ${crop.getOptimalSpeed()}") {
+ val gui = Minecraft.getMinecraft().currentScreen
+ if (gui !is GuiEditSign) return@link
+ gui as AccessorGuiEditSign
+ gui.tileSign.signText[0] = ChatComponentText("${crop.getOptimalSpeed()}")
+ })
+ }
+ }
+
+ @SubscribeEvent
+ fun onGuiRender(event: DrawScreenEvent.Post) {
+ if (!isRancherOverlayEnabled()) return
+ val gui = event.gui
+ if (gui !is GuiEditSign) return
+ gui as AccessorGuiEditSign
+ if (gui.tileSign.signText[1].unformattedText.removeColor() != "^^^^^^"
+ || gui.tileSign.signText[2].unformattedText.removeColor() != "Set your"
+ || gui.tileSign.signText[3].unformattedText.removeColor() != "speed cap!"
+ ) return
+ config.optimalSpeedSignPosition.renderStringsAndItems(
+ rancherOverlayList,
+ posLabel = "Optimal Speed Rancher Overlay"
+ )
+ }
+
@SubscribeEvent
fun onGardenToolChange(event: GardenToolChangeEvent) {
cropInHand = event.crop
@@ -75,5 +113,6 @@ class GardenOptimalSpeed {
}
}
+ private fun isRancherOverlayEnabled() = GardenAPI.inGarden() && config.optimalSpeedSignEnabled
private fun isEnabled() = GardenAPI.inGarden() && config.optimalSpeedEnabled
} \ No newline at end of file