diff options
author | Brady <thatgravyboat@gmail.com> | 2024-05-08 20:22:54 -0230 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-09 00:52:54 +0200 |
commit | e0b6473a1411ba3509cc5f303d9c1c28caafa4a7 (patch) | |
tree | 4818b7e6c6015bb4cfa231a40ec1dc0c5d76bdbd /src/main/java/at/hannibal2/skyhanni | |
parent | 2d9844426886cd488703d05ee58558e05d4c3987 (diff) | |
download | skyhanni-e0b6473a1411ba3509cc5f303d9c1c28caafa4a7.tar.gz skyhanni-e0b6473a1411ba3509cc5f303d9c1c28caafa4a7.tar.bz2 skyhanni-e0b6473a1411ba3509cc5f303d9c1c28caafa4a7.zip |
Improvement: Cleanup HoppityEggPlayerOpacityChanger (#1696)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
7 files changed, 86 insertions, 63 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index f04a7de46..c19d288a4 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -141,7 +141,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.HoppityEggDisplayManager import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsShared import at.hannibal2.skyhanni.features.event.hoppity.HoppityNpc @@ -669,7 +669,7 @@ class SkyHanniMod { loadModule(HoppityEggsManager) loadModule(HoppityEggLocator) loadModule(HoppityEggsShared) - loadModule(HoppityEggPlayerOpacityChanger) + loadModule(HoppityEggDisplayManager) loadModule(HoppityCollectionStats) loadModule(SpawnTimers()) loadModule(MarkedPlayerManager()) diff --git a/src/main/java/at/hannibal2/skyhanni/events/render/EntityRenderLayersEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/render/EntityRenderLayersEvent.kt new file mode 100644 index 000000000..ff951736e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/render/EntityRenderLayersEvent.kt @@ -0,0 +1,15 @@ +package at.hannibal2.skyhanni.events.render + +import at.hannibal2.skyhanni.events.LorenzEvent +import net.minecraft.entity.Entity +import net.minecraftforge.fml.common.eventhandler.Cancelable + +open class EntityRenderLayersEvent<T : Entity>( + val entity: T, +) : LorenzEvent() { + + @Cancelable + class Pre<T : Entity>( + entity: T, + ) : EntityRenderLayersEvent<T>(entity) +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggDisplayManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggDisplayManager.kt new file mode 100644 index 000000000..914b10b0e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggDisplayManager.kt @@ -0,0 +1,56 @@ +package at.hannibal2.skyhanni.features.event.hoppity + +import at.hannibal2.skyhanni.data.mob.MobFilter.isRealPlayer +import at.hannibal2.skyhanni.events.SkyHanniRenderEntityEvent +import at.hannibal2.skyhanni.events.render.EntityRenderLayersEvent +import at.hannibal2.skyhanni.utils.LocationUtils.distanceTo +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.player.EntityPlayer +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.opengl.GL11 + +object HoppityEggDisplayManager { + + private val config get() = HoppityEggsManager.config + private var shouldHidePlayer: Boolean = false + + private fun canChangeOpacity(entity: EntityLivingBase): Boolean { + if (!HoppityEggLocator.isEnabled()) return false + if (entity !is EntityPlayer) return false + if (entity == LorenzUtils.getPlayer()) return false + if (!entity.isRealPlayer()) return false + return config.playerOpacity < 100 + } + + @SubscribeEvent + fun onPreRenderPlayer(event: SkyHanniRenderEntityEvent.Pre<EntityLivingBase>) { + if (!canChangeOpacity(event.entity)) return + + shouldHidePlayer = HoppityEggLocator.sharedEggLocation?.let { event.entity.distanceTo(it) < 4.0 } + ?: HoppityEggLocator.possibleEggLocations.any { event.entity.distanceTo(it) < 4.0 } + + if (!shouldHidePlayer) return + if (config.playerOpacity <= 0) return event.cancel() + + 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) + } + + @SubscribeEvent + fun onPostRenderPlayer(event: SkyHanniRenderEntityEvent.Post<EntityLivingBase>) { + if (!canChangeOpacity(event.entity)) return + + GlStateManager.color(1f, 1f, 1f, 1f) + GlStateManager.disableBlend() + } + + @SubscribeEvent + fun onRenderPlayerLayers(event: EntityRenderLayersEvent.Pre<EntityLivingBase>) { + if (!canChangeOpacity(event.entity)) return + if (!shouldHidePlayer) return + event.cancel() + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocator.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocator.kt index c57ec2b33..012532f3b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocator.kt @@ -248,7 +248,7 @@ object HoppityEggLocator { private fun ReceiveParticleEvent.isEnchantmentParticle() = type == EnumParticleTypes.ENCHANTMENT_TABLE && speed == -2.0f && count == 10 - private fun isEnabled() = LorenzUtils.inSkyBlock && config.waypoints && !GardenAPI.inGarden() + fun isEnabled() = LorenzUtils.inSkyBlock && config.waypoints && !GardenAPI.inGarden() && !ReminderUtils.isBusy(true) && ChocolateFactoryAPI.isHoppityEvent() private val ItemStack.isLocatorItem get() = getInternalName() == locatorItem diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggPlayerOpacityChanger.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggPlayerOpacityChanger.kt deleted file mode 100644 index 68436438f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggPlayerOpacityChanger.kt +++ /dev/null @@ -1,60 +0,0 @@ -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 -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java index eb1b5afda..f23b290f1 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinRendererLivingEntity.java @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.mixins.transformers.renderer; +import at.hannibal2.skyhanni.events.render.EntityRenderLayersEvent; import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; @@ -10,6 +11,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(value = RendererLivingEntity.class, priority = 1001) @@ -28,4 +30,11 @@ public abstract class MixinRendererLivingEntity<T extends EntityLivingBase> exte private int changeHurtTime(EntityLivingBase entity) { return RenderLivingEntityHelper.Companion.internalChangeHurtTime(entity); } + + @Inject(method = "renderLayers", at = @At("HEAD"), cancellable = true) + private void onRenderLayersPre(T entity, float p_177093_2_, float p_177093_3_, float partialTicks, float p_177093_5_, float p_177093_6_, float p_177093_7_, float p_177093_8_, CallbackInfo ci) { + if (new EntityRenderLayersEvent.Pre<>(entity).postAndCatch()) { + ci.cancel(); + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index fbc76f1b2..05ea212b1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -22,6 +22,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.toDashlessUUID import at.hannibal2.skyhanni.utils.renderables.Renderable import com.google.gson.JsonPrimitive import net.minecraft.client.Minecraft +import net.minecraft.client.entity.EntityPlayerSP import net.minecraft.client.gui.inventory.GuiEditSign import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.SharedMonsterAttributes @@ -162,6 +163,8 @@ object LorenzUtils { fun getPlayerName(): String = Minecraft.getMinecraft().thePlayer.name + fun getPlayer(): EntityPlayerSP? = Minecraft.getMinecraft()?.thePlayer + fun fillTable( data: List<DisplayTableEntry>, padding: Int = 1, |