aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-02 22:21:20 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-02 22:21:20 +0100
commit71adca9654bb933405dce2bde970b0a678a55137 (patch)
tree58505ccd01859bc6a0797690061be961b9fae5f5 /src/main/java
parent7df75c9469bedda34ffce42273abc96f952f613a (diff)
downloadskyhanni-71adca9654bb933405dce2bde970b0a678a55137.tar.gz
skyhanni-71adca9654bb933405dce2bde970b0a678a55137.tar.bz2
skyhanni-71adca9654bb933405dce2bde970b0a678a55137.zip
code cleanup
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt41
1 files changed, 23 insertions, 18 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
index e0638c2f6..99f5910ea 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt
@@ -11,6 +11,7 @@ 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.LorenzVec
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson
import at.hannibal2.skyhanni.utils.toLorenzVec
@@ -24,11 +25,10 @@ import net.minecraft.network.play.client.C02PacketUseEntity
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class HighlightVisitorsOutsideOfGarden {
- var visitorJson = mapOf<String?, List<GardenJson.GardenVisitor>>()
+ private var visitorJson = mapOf<String?, List<GardenJson.GardenVisitor>>()
val config get() = SkyHanniMod.feature.garden.visitors
-
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
visitorJson = event.getConstant<GardenJson>(
@@ -36,22 +36,27 @@ class HighlightVisitorsOutsideOfGarden {
).visitors.values.groupBy {
it.mode
}
+ for (list in visitorJson.values) {
+ for (visitor in list) {
+ visitor.skinOrType = visitor.skinOrType?.replace("\\n", "")?.replace("\n", "")
+ }
+ }
}
- fun getSkinOrTypeFor(entity: Entity): String {
+ private fun getSkinOrTypeFor(entity: Entity): String {
if (entity is EntityPlayer) {
return entity.getSkinTexture() ?: "no skin"
}
return entity.javaClass.simpleName
}
- fun isVisitor(entity: Entity): Boolean {
+ private 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
+ (it.position == null || it.position!!.distance(entity.position.toLorenzVec()) < 1)
+ && it.skinOrType == skinOrType
}
}
@@ -69,14 +74,17 @@ class HighlightVisitorsOutsideOfGarden {
}
}
- val shouldBlock
+ private val shouldBlock
get() = when (config.blockInteracting) {
VisitorBlockBehaviour.DONT -> false
VisitorBlockBehaviour.ALWAYS -> true
- VisitorBlockBehaviour.ONLY_ON_BINGO -> SBInfo.getInstance().bingo
+ VisitorBlockBehaviour.ONLY_ON_BINGO -> LorenzUtils.isBingoProfile
null -> false
}
+ private fun isVisitorNearby(location: LorenzVec) =
+ EntityUtils.getEntitiesNearby<EntityLivingBase>(location, 2.0).any { isVisitor(it) }
+
@SubscribeEvent
fun onClickEntity(event: PacketEvent.SendEvent) {
if (!shouldBlock) return
@@ -85,17 +93,14 @@ class HighlightVisitorsOutsideOfGarden {
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) })
- ) {
+ if (isVisitor(entity) || (entity is EntityArmorStand && isVisitorNearby(entity.getLorenzVec()))) {
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"
- )
+ if (packet.action == C02PacketUseEntity.Action.INTERACT) {
+ LorenzUtils.clickableChat(
+ "§e[SkyHanni] Blocked you from interacting with a visitor. Sneak to bypass or click here to change settings.",
+ "/sh block interacting with visitors"
+ )
+ }
}
}
}