aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-06-02 12:54:34 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-06-02 12:54:34 +0200
commita6fce6eca80132823d941a7da620d7f67097229a (patch)
treedfcc61ded82a4e9f83190368bcdbc7fecbfe1480 /src/main/java/at/hannibal2/skyhanni
parent746c82be7379eeea2208e1d82d4e375826ebdd1c (diff)
downloadskyhanni-a6fce6eca80132823d941a7da620d7f67097229a.tar.gz
skyhanni-a6fce6eca80132823d941a7da620d7f67097229a.tar.bz2
skyhanni-a6fce6eca80132823d941a7da620d7f67097229a.zip
Showing fished item names
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt90
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt17
4 files changed, 120 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 8cf8f782e..1d46252aa 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -283,6 +283,7 @@ class SkyHanniMod {
loadModule(ServerRestartTitle())
loadModule(CityProjectFeatures())
loadModule(GardenPlotIcon)
+ loadModule(ShowFishingItemName())
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java
index 58fa58a84..5f781fa54 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java
@@ -121,6 +121,25 @@ public class Fishing {
}
@Expose
+ @ConfigOption(name = "Fished Item Name", desc = "")
+ @Accordion
+ public FishedItemName fishedItemName = new FishedItemName();
+
+ public static class FishedItemName {
+
+ @Expose
+ @ConfigOption(name = "Enabled", desc = "Show the fished item name above the item when fishing.")
+ @ConfigEditorBoolean
+ public boolean enabled = false;
+
+ @Expose
+ @ConfigOption(name = "Show Bait", desc = "Also how the name of the consumed bait.")
+ @ConfigEditorBoolean
+ public boolean showBaits = false;
+
+ }
+
+ @Expose
@ConfigOption(
name = "Shark Fish Counter",
desc = "Counts how many sharks have been caught."
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt
new file mode 100644
index 000000000..1e72f0c4f
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/ShowFishingItemName.kt
@@ -0,0 +1,90 @@
+package at.hannibal2.skyhanni.features.fishing
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LocationUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzVec
+import at.hannibal2.skyhanni.utils.RenderUtils.drawString
+import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import com.google.common.cache.CacheBuilder
+import net.minecraft.client.Minecraft
+import net.minecraft.entity.item.EntityItem
+import net.minecraftforge.client.event.RenderWorldLastEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent
+import java.util.concurrent.TimeUnit
+
+class ShowFishingItemName {
+ private val config get() = SkyHanniMod.feature.fishing.fishedItemName
+ private var tick = 0
+ private var hasRodInHand = false
+ private var cache =
+ CacheBuilder.newBuilder().expireAfterWrite(750, TimeUnit.MILLISECONDS)
+ .build<EntityItem, Pair<LorenzVec, String>>()
+
+ // Taken from Skytils
+ private val cheapCoins = setOf(
+ "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTM4MDcxNzIxY2M1YjRjZDQwNmNlNDMxYTEzZjg2MDgzYTg5NzNlMTA2NGQyZjg4OTc4Njk5MzBlZTZlNTIzNyJ9fX0=",
+ "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZGZhMDg3ZWI3NmU3Njg3YTgxZTRlZjgxYTdlNjc3MjY0OTk5MGY2MTY3Y2ViMGY3NTBhNGM1ZGViNmM0ZmJhZCJ9fX0="
+ )
+
+ @SubscribeEvent
+ fun onTick(event: TickEvent.ClientTickEvent) {
+ if (event.phase != TickEvent.Phase.START) return
+ if (!isEnabled()) return
+
+ tick++
+ if (tick % 10 == 0) {
+ hasRodInHand = isFishingRod()
+ }
+ }
+
+ private fun isFishingRod() = InventoryUtils.getItemInHand()?.name?.contains("Rod") ?: false
+
+ @SubscribeEvent
+ fun onRenderWorld(event: RenderWorldLastEvent) {
+ if (!isEnabled()) return
+ if (hasRodInHand) {
+ for (entityItem in Minecraft.getMinecraft().theWorld.loadedEntityList.filterIsInstance<EntityItem>()) {
+ val location = event.exactLocation(entityItem).add(0.0, 0.8, 0.0)
+ if (location.distance(LocationUtils.playerLocation()) > 15) continue
+ val itemStack = entityItem.entityItem
+ var name = itemStack.name ?: continue
+
+ // Hypixel sometimes replaces the bait item mid air with a stone
+ if (name.removeColor() == "Stone") continue
+
+ val size = itemStack.stackSize
+ val isBait = name.endsWith(" Bait") && size == 1
+ val prefix = if (!isBait) {
+ "§a§l+"
+ } else {
+ if (!config.showBaits) continue
+ name = "§7" + name.removeColor()
+ "§c§l-"
+ }
+
+ itemStack?.tagCompound?.getTag("SkullOwner")?.toString()?.let {
+ for (coin in cheapCoins) {
+ if (it.contains(coin)) {
+ name = "§6Coins"
+ }
+ }
+ }
+
+ val sizeText = if (size != 1) "§7x$size §r" else ""
+ cache.put(entityItem, location to "$prefix §r$sizeText$name")
+ }
+ }
+
+ for ((location, text) in cache.asMap().values) {
+ event.drawString(location, text)
+ }
+ }
+
+ fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled
+
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index 7e56be09e..58e000ce7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -85,13 +85,7 @@ object RenderUtils {
}
- fun getViewerPos(partialTicks: Float): LorenzVec {
- val viewer = Minecraft.getMinecraft().renderViewEntity
- val viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks
- val viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks
- val viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks
- return LorenzVec(viewerX, viewerY, viewerZ)
- }
+ fun getViewerPos(partialTicks: Float) = exactLocation(Minecraft.getMinecraft().renderViewEntity, partialTicks)
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
@@ -791,5 +785,14 @@ object RenderUtils {
GlStateManager.enableDepth()
}
+ fun RenderWorldLastEvent.exactLocation(entity: Entity): LorenzVec {
+ return exactLocation(entity, partialTicks)
+ }
+ fun exactLocation(entity: Entity, partialTicks: Float): LorenzVec {
+ val x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks
+ val y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks
+ val z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks
+ return LorenzVec(x, y, z)
+ }
}