Skip to content
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: Ability to adjust opacity of players near shared & guessed egg waypoints #1582

Merged
merged 9 commits into from
May 3, 2024
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import at.hannibal2.skyhanni.features.event.diana.MythologicalCreatureTracker
import at.hannibal2.skyhanni.features.event.diana.SoopyGuessBurrow
import at.hannibal2.skyhanni.features.event.hoppity.HoppityCollectionStats
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggLocator
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggPlayerOpacityChanger
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsShared
import at.hannibal2.skyhanni.features.event.hoppity.HoppityNpc
Expand Down Expand Up @@ -655,6 +656,7 @@ class SkyHanniMod {
loadModule(HoppityEggsManager)
loadModule(HoppityEggLocator)
loadModule(HoppityEggsShared)
loadModule(HoppityEggPlayerOpacityChanger)
loadModule(HoppityCollectionStats)
loadModule(SpawnTimers())
loadModule(MarkedPlayerManager())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import at.hannibal2.skyhanni.config.core.config.Position;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

Expand Down Expand Up @@ -33,6 +34,11 @@ public class HoppityEggsConfig {
@FeatureToggle
public boolean sharedWaypoints = true;

@Expose
@ConfigOption(name = "Adjust player opacity", desc = "Adjust the opacity of players near shared & guessed egg waypoints. (in %)")
@ConfigEditorSlider(minValue = 0, maxValue = 100, minStep = 1)
public int playerOpacity = 40;

@Expose
@ConfigLink(owner = HoppityEggsConfig.class, field = "showClaimedEggs")
public Position position = new Position(33, 72, false, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

object HoppityEggLocator {

private val config get() = HoppityEggsManager.config

private val locatorItem = "EGGLOCATOR".asInternalName()
Expand All @@ -36,13 +35,13 @@ object HoppityEggLocator {
private var drawLocations = false
private var firstPos = LorenzVec()
private var secondPos = LorenzVec()
private var possibleEggLocations = listOf<LorenzVec>()

private var ticksSinceLastParticleFound = -1
private var lastGuessMade = SimpleTimeMark.farPast()
private var eggLocationWeights = listOf<Double>()

var sharedEggLocation: LorenzVec? = null
var possibleEggLocations = listOf<LorenzVec>()
var currentEggType: HoppityEggType? = null

var eggLocations: Map<IslandType, List<LorenzVec>> = mapOf()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package at.hannibal2.skyhanni.features.event.hoppity

import at.hannibal2.skyhanni.events.SkyHanniRenderEntityEvent
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI
import at.hannibal2.skyhanni.utils.EntityUtils.getArmorInventory
import at.hannibal2.skyhanni.utils.LocationUtils.distanceTo
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.opengl.GL11

object HoppityEggPlayerOpacityChanger {
private val config get() = HoppityEggsManager.config
private var armor = mapOf<Int, ItemStack>()

private fun hideNearbyPlayer(entity: EntityPlayer, location: LorenzVec) {
if (entity.distanceTo(location) >= 4.0) return
GlStateManager.enableBlend()
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
GlStateManager.color(1.0f, 1.0f, 1.0f, config.playerOpacity / 100f)
val armorInventory = entity.getArmorInventory() ?: return

armor = buildMap {
for ((i, stack) in armorInventory.withIndex()) {
stack?.let {
this[i] = it.copy()
armorInventory[i] = null
}
}
}
}

@SubscribeEvent
fun onPreRenderPlayer(event: SkyHanniRenderEntityEvent.Pre<EntityLivingBase>) {
if (!isEnabled()) return
if (event.entity !is EntityPlayer) return
if (event.entity.name == LorenzUtils.getPlayerName()) return
HoppityEggLocator.sharedEggLocation?.let { hideNearbyPlayer(event.entity, it) }
HoppityEggLocator.possibleEggLocations.forEach { hideNearbyPlayer(event.entity, it) }
}

@SubscribeEvent
fun onPostRenderPlayer(event: SkyHanniRenderEntityEvent.Post<EntityLivingBase>) {
if (!isEnabled()) return
GlStateManager.color(1f, 1f, 1f, 1f)
GlStateManager.disableBlend()
val armorInventory = event.entity.getArmorInventory() ?: return

for ((index, stack) in armor) { // restore armor after players leave the area
armorInventory[index] = stack
}
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config.waypoints
&& ChocolateFactoryAPI.isHoppityEvent() && config.playerOpacity != 100
}
Loading