aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-12 02:53:31 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-12 02:53:31 +0200
commita1be9b628b6006904f14a24abe3ea7d00b2dd1de (patch)
treefd6d9de0a7cce654c2d2b58c6b5de62e270344ce /src/main/java/at/hannibal2/skyhanni/features
parent407221c659f4cee2c81fbd50eaeaca77481cc6c6 (diff)
downloadskyhanni-a1be9b628b6006904f14a24abe3ea7d00b2dd1de.tar.gz
skyhanni-a1be9b628b6006904f14a24abe3ea7d00b2dd1de.tar.bz2
skyhanni-a1be9b628b6006904f14a24abe3ea7d00b2dd1de.zip
finished defence blocks
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveDefenceBlocks.kt155
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveLivingMetalHelper.kt32
2 files changed, 135 insertions, 52 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveDefenceBlocks.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveDefenceBlocks.kt
index 30475b712..745246bef 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveDefenceBlocks.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveDefenceBlocks.kt
@@ -3,16 +3,21 @@ package at.hannibal2.skyhanni.features.rift.area.livingcave
import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.ReceiveParticleEvent
import at.hannibal2.skyhanni.events.ServerBlockChangeEvent
+import at.hannibal2.skyhanni.events.withAlpha
import at.hannibal2.skyhanni.features.rift.everywhere.RiftAPI
+import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
-import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
-import at.hannibal2.skyhanni.utils.LorenzColor
+import at.hannibal2.skyhanni.utils.EntityUtils.getEntitiesNearby
+import at.hannibal2.skyhanni.utils.EntityUtils.isAtFullHealth
+import at.hannibal2.skyhanni.utils.LocationUtils.distanceTo
import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy
-import at.hannibal2.skyhanni.utils.LorenzUtils.round
+import at.hannibal2.skyhanni.utils.LorenzUtils.toChromaColor
import at.hannibal2.skyhanni.utils.LorenzVec
+import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
+import at.hannibal2.skyhanni.utils.getLorenzVec
import net.minecraft.client.Minecraft
-import net.minecraft.entity.EntityLiving
+import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.network.play.server.S22PacketMultiBlockChange
import net.minecraft.network.play.server.S23PacketBlockChange
import net.minecraft.util.EnumParticleTypes
@@ -21,46 +26,72 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class LivingCaveDefenceBlocks {
- val config get() = RiftAPI.config.area.livingCaveConfig
- private var movingBlocks = mapOf<LorenzVec, Long>()
- private var staticBlocks = emptyList<LorenzVec>()
+ private val config get() = RiftAPI.config.area.livingCaveConfig.defenceBlockConfig
+ private var movingBlocks = mapOf<DefenceBlock, Long>()
+ private var staticBlocks = emptyList<DefenceBlock>()
+// private var helpLocation = emptyList<LorenzVec>()
- class DefenceBlock(val entity: EntityLiving, val location: LorenzVec)
+ class DefenceBlock(val entity: EntityOtherPlayerMP, val location: LorenzVec, var hidden: Boolean = false)
@SubscribeEvent
fun onReceiveParticle(event: ReceiveParticleEvent) {
- if (!isEnabled()) return
+ val location = event.location.add(-0.5, 0.0, -0.5)
+// if (event.type == EnumParticleTypes.CRIT_MAGIC) {
+// helpLocation = helpLocation.editCopy { add(location) }
+// }
+
+ // TODO remove
Minecraft.getMinecraft().thePlayer?.let {
if (it.isSneaking) {
staticBlocks = emptyList()
+// helpLocation = emptyList()
}
}
+ if (!isEnabled()) return
movingBlocks = movingBlocks.editCopy {
- values.removeIf { System.currentTimeMillis() > it }
- keys.removeIf { staticBlocks.any { others -> others.distance(it) < 1.5 } }
+ values.removeIf { System.currentTimeMillis() > it + 2000 }
+ keys.removeIf { staticBlocks.any { others -> others.location.distance(it.location) < 1.5 } }
}
- val location = event.location.add(-0.5, 0.0, -0.5)
-// if (staticBlocks.any { it.distance(location) < 2.5 }) {
- if (staticBlocks.any { it.distance(location) < 3 }) {
+
+ // Ignore particles around blocks
+ if (staticBlocks.any { it.location.distance(location) < 3 }) {
event.isCanceled = true
return
}
if (event.type == EnumParticleTypes.CRIT_MAGIC) {
-// movingBlocks.keys.find { it.distance(location) < 0.3 }?.let {
- movingBlocks.keys.find { it.distance(location) < 0.5 }?.let {
- movingBlocks = movingBlocks.editCopy { remove(it) }
+ var entity: EntityOtherPlayerMP? = null
+
+ // read old entity data
+ getNearestMovingDefenceBlock(location)?.let {
+ if (it.location.distance(location) < 0.5) {
+ movingBlocks = movingBlocks.editCopy {
+ it.hidden = true
+ }
+ entity = it.entity
+ }
+ }
+
+ if (entity == null) {
+ // read new entity data
+ val compareLocation = event.location.add(-0.5, -1.5, -0.5)
+ entity = Minecraft.getMinecraft().theWorld.getEntitiesNearby<EntityOtherPlayerMP>(compareLocation, 2.0)
+ .filter { it.name == "Autonull " || it.name == "Autoboots " }
+ .filter { !it.isAtFullHealth() }
+ .minByOrNull { it.distanceTo(compareLocation) }
}
- movingBlocks = movingBlocks.editCopy { this[location] = System.currentTimeMillis() + 500 }
+ val defenceBlock = entity?.let { DefenceBlock(it, location) } ?: return
+
+ movingBlocks = movingBlocks.editCopy { this[defenceBlock] = System.currentTimeMillis() + 250 }
event.isCanceled = true
}
}
- // TODO move somewhere else
+ // TODO move to somewhere else
@SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
fun onChatPacket(event: PacketEvent.ReceiveEvent) {
val packet = event.packet
@@ -80,52 +111,72 @@ class LivingCaveDefenceBlocks {
val location = event.location
val old = event.old
val new = event.new
- val distanceToPlayer = location.distanceToPlayer()
+ // spawn block
if (old == "air" && (new == "stained_glass" || new == "diamond_block")) {
- println("detect spawn: ${distanceToPlayer.round(1)}")
- staticBlocks = staticBlocks.editCopy { add(location) }
- } else if (new == "air" && location in staticBlocks) {
- println("detect despawn: ${distanceToPlayer.round(1)}")
- staticBlocks = staticBlocks.editCopy { remove(location) }
- } else {
-// if (distanceToPlayer < 3) {
- if (distanceToPlayer < 10) {
-// if (old == "lapis_ore" || new == "lapis_ore") {
-// println("block change: $old -> $new")
-// }
- if (old == "wool") return
- if (new == "wool") return
- if (old == "lapis_block") return
- if (new == "lapis_block") return
- if (old == "stained_glass" && new == "stone") return
- if (old == "stone" && new == "stained_glass") return
- if (old == "stained_glass" && new == "stained_hardened_clay") return
-// println("block change: $old -> $new")
+ val entity = getNearestMovingDefenceBlock(location)?.entity ?: return
+ staticBlocks = staticBlocks.editCopy {
+ add(DefenceBlock(entity, location))
+ RenderLivingEntityHelper.setEntityColor(
+ entity,
+ color.withAlpha(50)
+ ) { isEnabled() && staticBlocks.any { it.entity == entity } }
}
}
-// if (old.contains("air") && new.contains("diamond_block")) {
-// println("detect big spawn: ${distanceToPlayer.round(1)}")
-// }
-// if (old.contains("diamond_block") && new.contains("air")) {
-// println("detect big despawn: ${distanceToPlayer.round(1)}")
-// }
+
+ // despawn block
+ val nearestBlock = getNearestStaticDefenceBlock(location)
+ if (new == "air" && location == nearestBlock?.location) {
+ staticBlocks = staticBlocks.editCopy { remove(nearestBlock) }
+ }
}
+ private fun getNearestMovingDefenceBlock(location: LorenzVec) =
+ movingBlocks.keys.filter { it.location.distance(location) < 15 }.minByOrNull { it.location.distance(location) }
+
+ private fun getNearestStaticDefenceBlock(location: LorenzVec) =
+ staticBlocks.filter { it.location.distance(location) < 15 }.minByOrNull { it.location.distance(location) }
+
@SubscribeEvent
fun onRenderWorld(event: RenderWorldLastEvent) {
+// for (location in helpLocation) {
+// event.drawWaypointFilled(location, LorenzColor.GREEN.toColor())
+// event.drawDynamicText(location, "§aTest", 1.5)
+//
+// }
if (!isEnabled()) return
- for (location in movingBlocks.keys) {
- event.drawWaypointFilled(location, LorenzColor.WHITE.toColor())
- event.drawDynamicText(location, "Defense Block", 1.5)
+ for ((block, time) in movingBlocks) {
+ if (block.hidden) continue
+ if (time > System.currentTimeMillis()) {
+ val location = block.location
+ event.drawWaypointFilled(location, color)
+ event.draw3DLine(
+ block.entity.getLorenzVec().add(0.0, 0.5, 0.0),
+ location.add(0.5, 0.5, 0.5),
+ color,
+ 1,
+ false
+ )
+ }
}
- for (location in staticBlocks) {
- event.drawWaypointFilled(location, LorenzColor.WHITE.toColor())
- event.drawDynamicText(location, "Defense Block", 1.5)
+ for (block in staticBlocks) {
+ val location = block.location
+ event.drawWaypointFilled(location, color)
+ event.drawDynamicText(location, "§bBreak!", 1.5)
+
+ event.draw3DLine(
+ block.entity.getLorenzVec().add(0.0, 0.5, 0.0),
+ location.add(0.5, 0.5, 0.5),
+ color,
+ 3,
+ false
+ )
}
}
- fun isEnabled() = RiftAPI.inRift() && config.defenceBlocks && RiftAPI.inLivingCave()
+ val color get() = config.color.get().toChromaColor()
+
+ fun isEnabled() = RiftAPI.inRift() && config.enabled && RiftAPI.inLivingCave()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveLivingMetalHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveLivingMetalHelper.kt
new file mode 100644
index 000000000..696479a37
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveLivingMetalHelper.kt
@@ -0,0 +1,32 @@
+package at.hannibal2.skyhanni.features.rift.area.livingcave
+
+import at.hannibal2.skyhanni.events.ServerBlockChangeEvent
+import at.hannibal2.skyhanni.features.rift.everywhere.RiftAPI
+import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class LivingCaveLivingMetalHelper {
+ private val config get() = RiftAPI.config.area.livingCaveConfig.livingCaveLivingMetalConfig
+
+ @SubscribeEvent
+ fun onBlockChange(event: ServerBlockChangeEvent) {
+ val location = event.location
+ val old = event.old
+ val new = event.new
+ val distanceToPlayer = location.distanceToPlayer()
+
+ if (distanceToPlayer < 10) {
+ if (old == "lapis_ore" || new == "lapis_ore") {
+ println("block change: $old -> $new")
+ }
+// if (old == "wool") return
+// if (new == "wool") return
+// if (old == "lapis_block") return
+// if (new == "lapis_block") return
+// if (old == "stained_glass" && new == "stone") return
+// if (old == "stone" && new == "stained_glass") return
+// if (old == "stained_glass" && new == "stained_hardened_clay") return
+// println("block change: $old -> $new")
+ }
+ }
+}