diff options
author | Linnea Gräf <nea@nea.moe> | 2023-11-02 22:20:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 22:20:32 +0100 |
commit | 7df75c9469bedda34ffce42273abc96f952f613a (patch) | |
tree | e8916f3a0964e65d28197ee1247916eec2b97a83 /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 2ce84766100584a5aaf516a2cbf0907585aaa07e (diff) | |
download | skyhanni-7df75c9469bedda34ffce42273abc96f952f613a.tar.gz skyhanni-7df75c9469bedda34ffce42273abc96f952f613a.tar.bz2 skyhanni-7df75c9469bedda34ffce42273abc96f952f613a.zip |
Add visitor highlighter/blocker (#653)
Added Highlight Visitors in SkyBlock. Block Interacting with Visitors. #653
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt new file mode 100644 index 000000000..e0638c2f6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt @@ -0,0 +1,101 @@ +package at.hannibal2.skyhanni.features.garden.visitor + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.features.GardenConfig.VisitorConfig.VisitorBlockBehaviour +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.events.withAlpha +import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper +import at.hannibal2.skyhanni.utils.EntityUtils +import at.hannibal2.skyhanni.utils.EntityUtils.getSkinTexture +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.getLorenzVec +import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson +import at.hannibal2.skyhanni.utils.toLorenzVec +import io.github.moulberry.notenoughupdates.util.SBInfo +import net.minecraft.client.Minecraft +import net.minecraft.entity.Entity +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.network.play.client.C02PacketUseEntity +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class HighlightVisitorsOutsideOfGarden { + var visitorJson = mapOf<String?, List<GardenJson.GardenVisitor>>() + + val config get() = SkyHanniMod.feature.garden.visitors + + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + visitorJson = event.getConstant<GardenJson>( + "Garden", GardenJson::class.java + ).visitors.values.groupBy { + it.mode + } + } + + fun getSkinOrTypeFor(entity: Entity): String { + if (entity is EntityPlayer) { + return entity.getSkinTexture() ?: "no skin" + } + return entity.javaClass.simpleName + } + + fun isVisitor(entity: Entity): Boolean { + val mode = SBInfo.getInstance().getLocation() + val possibleJsons = visitorJson[mode] ?: return false + val skinOrType = getSkinOrTypeFor(entity) + return possibleJsons.any { + ((it.position == null) || it.position!!.distance(entity.position.toLorenzVec()) < 1) + && it.skinOrType?.replace("\\n", "")?.replace("\n", "") == skinOrType + } + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!config.highlightVisitors) return + if (!event.repeatSeconds(1)) return + EntityUtils.getEntities<EntityLivingBase>() + .filter { it !is EntityArmorStand && isVisitor(it) } + .forEach { + RenderLivingEntityHelper.setEntityColor( + it, + LorenzColor.DARK_RED.toColor().withAlpha(50) + ) { config.highlightVisitors } + } + } + + val shouldBlock + get() = when (config.blockInteracting) { + VisitorBlockBehaviour.DONT -> false + VisitorBlockBehaviour.ALWAYS -> true + VisitorBlockBehaviour.ONLY_ON_BINGO -> SBInfo.getInstance().bingo + null -> false + } + + @SubscribeEvent + fun onClickEntity(event: PacketEvent.SendEvent) { + if (!shouldBlock) return + val world = Minecraft.getMinecraft().theWorld ?: return + val player = Minecraft.getMinecraft().thePlayer ?: return + if (player.isSneaking) return + val packet = event.packet as? C02PacketUseEntity ?: return + val entity = packet.getEntityFromWorld(world) ?: return + if (isVisitor(entity) + || (entity is EntityArmorStand && EntityUtils.getEntitiesNearby<EntityLivingBase>( + entity.getLorenzVec(), + 2.0 + ).any { isVisitor(it) }) + ) { + event.isCanceled = true + LorenzUtils.clickableChat( + "§e[SkyHanniBal] Blocked you from interacting with a visitor. Sneak to bypass or click here to change settings.", + "/sh block interacting with visitors" + ) + } + } +} |