aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveDefenceBlocks.kt131
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt2
5 files changed, 165 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 25a23c963..6e98bc8e1 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -67,6 +67,7 @@ import at.hannibal2.skyhanni.features.rift.area.RiftLarva
import at.hannibal2.skyhanni.features.rift.area.colosseum.BlobbercystsHighlight
import at.hannibal2.skyhanni.features.rift.area.dreadfarm.RiftAgaricusCap
import at.hannibal2.skyhanni.features.rift.area.dreadfarm.VoltHighlighter
+import at.hannibal2.skyhanni.features.rift.area.livingcave.LivingCaveDefenceBlocks
import at.hannibal2.skyhanni.features.rift.area.livingcave.LivingMetalSuitProgress
import at.hannibal2.skyhanni.features.rift.area.mirrorverse.DanceRoomHelper
import at.hannibal2.skyhanni.features.rift.area.mirrorverse.RiftLavaMazeParkour
@@ -343,6 +344,7 @@ class SkyHanniMod {
loadModule(LivingMetalSuitProgress())
loadModule(VampireSlayerFeatures())
loadModule(BlobbercystsHighlight())
+ loadModule(LivingCaveDefenceBlocks())
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
index 0ab3b06f2..ff1679b0d 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
@@ -468,6 +468,11 @@ public class RiftConfig {
@Expose
public Position position = new Position(100, 100);
}
+
+ @Expose
+ @ConfigOption(name = "Defence Blocks", desc = "Show the defence blocks.")
+ @ConfigEditorBoolean
+ public boolean defenceBlocks = true;
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt
new file mode 100644
index 000000000..41d8ea946
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt
@@ -0,0 +1,25 @@
+package at.hannibal2.skyhanni.events
+
+import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.toLorenzVec
+import net.minecraft.block.state.IBlockState
+import net.minecraft.util.BlockPos
+
+class ServerBlockChangeEvent(val pos: BlockPos, val blockState: IBlockState) : LorenzEvent() {
+ val location by lazy { pos.toLorenzVec() }
+ val old by lazy { location.getBlockAt().toString().getName() }
+ val new by lazy { blockState.block.toString().getName() }
+
+ companion object {
+ val pattern = "Block\\{minecraft:(?<name>.*)}".toPattern()
+
+ private fun String.getName() = pattern.matchMatcher(this) {
+ group("name")
+ } ?: this
+
+ }
+
+}
+
+
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
new file mode 100644
index 000000000..30475b712
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/livingcave/LivingCaveDefenceBlocks.kt
@@ -0,0 +1,131 @@
+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.features.rift.everywhere.RiftAPI
+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.LorenzUtils.editCopy
+import at.hannibal2.skyhanni.utils.LorenzUtils.round
+import at.hannibal2.skyhanni.utils.LorenzVec
+import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
+import net.minecraft.client.Minecraft
+import net.minecraft.entity.EntityLiving
+import net.minecraft.network.play.server.S22PacketMultiBlockChange
+import net.minecraft.network.play.server.S23PacketBlockChange
+import net.minecraft.util.EnumParticleTypes
+import net.minecraftforge.client.event.RenderWorldLastEvent
+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>()
+
+ class DefenceBlock(val entity: EntityLiving, val location: LorenzVec)
+
+ @SubscribeEvent
+ fun onReceiveParticle(event: ReceiveParticleEvent) {
+ if (!isEnabled()) return
+
+ Minecraft.getMinecraft().thePlayer?.let {
+ if (it.isSneaking) {
+ staticBlocks = emptyList()
+ }
+ }
+
+ movingBlocks = movingBlocks.editCopy {
+ values.removeIf { System.currentTimeMillis() > it }
+ keys.removeIf { staticBlocks.any { others -> others.distance(it) < 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 }) {
+ 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) }
+ }
+
+ movingBlocks = movingBlocks.editCopy { this[location] = System.currentTimeMillis() + 500 }
+ event.isCanceled = true
+ }
+ }
+
+ // TODO move somewhere else
+ @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
+ fun onChatPacket(event: PacketEvent.ReceiveEvent) {
+ val packet = event.packet
+
+ if (packet is S23PacketBlockChange) {
+ ServerBlockChangeEvent(packet.blockPosition, packet.blockState).postAndCatch()
+ } else if (packet is S22PacketMultiBlockChange) {
+ for (block in packet.changedBlocks) {
+ ServerBlockChangeEvent(block.pos, block.blockState).postAndCatch()
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onBlockChange(event: ServerBlockChangeEvent) {
+ if (!isEnabled()) return
+ val location = event.location
+ val old = event.old
+ val new = event.new
+ val distanceToPlayer = location.distanceToPlayer()
+
+ 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")
+ }
+ }
+// 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)}")
+// }
+ }
+
+ @SubscribeEvent
+ fun onRenderWorld(event: RenderWorldLastEvent) {
+ if (!isEnabled()) return
+
+
+ for (location in movingBlocks.keys) {
+ event.drawWaypointFilled(location, LorenzColor.WHITE.toColor())
+ event.drawDynamicText(location, "Defense Block", 1.5)
+ }
+ for (location in staticBlocks) {
+ event.drawWaypointFilled(location, LorenzColor.WHITE.toColor())
+ event.drawDynamicText(location, "Defense Block", 1.5)
+ }
+ }
+
+ fun isEnabled() = RiftAPI.inRift() && config.defenceBlocks && RiftAPI.inLivingCave()
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt
index 5fa19f20e..b3f00cc08 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftAPI.kt
@@ -16,4 +16,6 @@ object RiftAPI {
var motesPrice = emptyMap<String, Double>()
fun ItemStack.motesNpcPrice() = motesPrice[getInternalName()]
+
+ fun inLivingCave() = LorenzUtils.skyBlockArea == "Living Cave"
} \ No newline at end of file