diff options
author | HiZe <super@hize.be> | 2024-09-08 09:53:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-08 09:53:42 +0200 |
commit | 68044ebd31dc1af39c01a26285b1de1eb46c3263 (patch) | |
tree | cde0c1480a9cc4042e4f74fa98b2f3224f99c135 /src/main/java/at/hannibal2/skyhanni/features/rift | |
parent | 3db3627ec03baa134940a92e596e591f2d88aa0c (diff) | |
download | skyhanni-68044ebd31dc1af39c01a26285b1de1eb46c3263.tar.gz skyhanni-68044ebd31dc1af39c01a26285b1de1eb46c3263.tar.bz2 skyhanni-68044ebd31dc1af39c01a26285b1de1eb46c3263.zip |
Feature: Mirrorverse Crafting Room Helper (#2178)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/rift')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/rift/area/mirrorverse/CraftRoomHolographicMob.kt | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/mirrorverse/CraftRoomHolographicMob.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/mirrorverse/CraftRoomHolographicMob.kt new file mode 100644 index 000000000..ab5060be3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/mirrorverse/CraftRoomHolographicMob.kt @@ -0,0 +1,99 @@ +package at.hannibal2.skyhanni.features.rift.area.mirrorverse + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.CheckRenderEntityEvent +import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.features.rift.RiftAPI +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy +import at.hannibal2.skyhanni.utils.EntityUtils +import at.hannibal2.skyhanni.utils.HolographicEntities +import at.hannibal2.skyhanni.utils.LocationUtils +import at.hannibal2.skyhanni.utils.LocationUtils.isInside +import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import at.hannibal2.skyhanni.utils.getLorenzVec +import net.minecraft.client.entity.EntityOtherPlayerMP +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.monster.EntityCaveSpider +import net.minecraft.entity.monster.EntitySlime +import net.minecraft.entity.monster.EntityZombie +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.util.AxisAlignedBB +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.math.abs + +@SkyHanniModule +object CraftRoomHolographicMob { + + private val config get() = SkyHanniMod.feature.rift.area.mirrorverse.craftingRoom + private val craftRoomArea = AxisAlignedBB( + -108.0, 58.0, -106.0, + -117.0, 51.0, -128.0, + ) + private var entitiesList = listOf<HolographicEntities.HolographicEntity<out EntityLivingBase>>() + private var entityToHolographicEntity = mapOf( + EntityZombie::class.java to HolographicEntities.zombie, + EntitySlime::class.java to HolographicEntities.slime, + EntityCaveSpider::class.java to HolographicEntities.caveSpider, + ) + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled()) return + for (entity in entitiesList) { + entity.moveTo(entity.position.up(.1), (entity.yaw + 5) % 360) + } + } + + @SubscribeEvent + fun onWorldRender(event: LorenzRenderWorldEvent) { + if (!isEnabled()) return + + for (theMob in EntityUtils.getEntitiesNearby<EntityLivingBase>(LocationUtils.playerLocation(), 25.0)) { + if (theMob is EntityPlayer) continue + + if (!craftRoomArea.isInside(theMob.getLorenzVec())) continue + + val mobPos = theMob.getLorenzVec() + val wallZ = -116.5 + val dist = abs(mobPos.z - wallZ) + val holographicMobPos = mobPos.add(z = dist * 2) + val displayString = buildString { + val mobName = theMob.displayName.formattedText + if (config.showName) { + append("§a$mobName ") + } + if (config.showHealth) { + append("§c${theMob.health}♥") + } + }.trim() + + val mob = entityToHolographicEntity[theMob::class.java] ?: continue + + val instance = mob.instance(holographicMobPos, -theMob.rotationYaw) + + instance.isChild = theMob.isChild + + HolographicEntities.renderHolographicEntity(instance, event.partialTicks) + + if (displayString.isNotEmpty()) { + event.drawString(holographicMobPos.add(y = theMob.eyeHeight + .5), displayString) + } + + entitiesList = entitiesList.editCopy { add(instance) } + } + } + + @SubscribeEvent(receiveCanceled = true) + fun onPlayerRender(event: CheckRenderEntityEvent<*>) { + if (!RiftAPI.inRift() || !config.hidePlayers) return + + val entity = event.entity + if (entity is EntityOtherPlayerMP && craftRoomArea.isInside(entity.getLorenzVec())) { + event.cancel() + } + } + + private fun isEnabled() = config.enabled && RiftAPI.inRift() +} |