diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-07-12 02:53:31 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-07-12 02:53:31 +0200 |
commit | a1be9b628b6006904f14a24abe3ea7d00b2dd1de (patch) | |
tree | fd6d9de0a7cce654c2d2b58c6b5de62e270344ce /src/main | |
parent | 407221c659f4cee2c81fbd50eaeaca77481cc6c6 (diff) | |
download | skyhanni-a1be9b628b6006904f14a24abe3ea7d00b2dd1de.tar.gz skyhanni-a1be9b628b6006904f14a24abe3ea7d00b2dd1de.tar.bz2 skyhanni-a1be9b628b6006904f14a24abe3ea7d00b2dd1de.zip |
finished defence blocks
Diffstat (limited to 'src/main')
7 files changed, 184 insertions, 59 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 6e98bc8e1..6c536e28c 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -68,6 +68,7 @@ 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.LivingCaveLivingMetalHelper 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 @@ -345,6 +346,7 @@ class SkyHanniMod { loadModule(VampireSlayerFeatures()) loadModule(BlobbercystsHighlight()) loadModule(LivingCaveDefenceBlocks()) + loadModule(LivingCaveLivingMetalHelper()) 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 ff1679b0d..393fb28dd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java @@ -447,7 +447,6 @@ public class RiftConfig { public static class LivingCaveConfig { - @Expose @ConfigOption(name = "Living Metal Suit Progress", desc = "") @Accordion @@ -470,9 +469,37 @@ public class RiftConfig { } @Expose - @ConfigOption(name = "Defence Blocks", desc = "Show the defence blocks.") - @ConfigEditorBoolean - public boolean defenceBlocks = true; + @ConfigOption(name = "Living Metal Helper", desc = "") + @Accordion + public DefenceBlockConfig defenceBlockConfig = new DefenceBlockConfig(); + + public static class DefenceBlockConfig { + + @Expose + @ConfigOption(name = "Defence Blocks", desc = "Show a line between the defence blocks and the mob and highlight the blocks.") + @ConfigEditorBoolean + public boolean enabled = false; + + @Expose + @ConfigOption(name = "Color", desc = "Set the color of the lines, blocks and the entity.") + @ConfigEditorColour + public Property<String> color = Property.of("0:255:77:104:255"); + + } + + @Expose + @ConfigOption(name = "Living Metal Helper", desc = "") + @Accordion + public LivingCaveLivingMetalConfig livingCaveLivingMetalConfig = new LivingCaveLivingMetalConfig(); + + public static class LivingCaveLivingMetalConfig { + + @Expose + @ConfigOption(name = "Living Metal", desc = "Show the Living Metal.") + @ConfigEditorBoolean + public boolean enabled = true; + + } } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt index 41d8ea946..b8ac2eb28 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt @@ -6,8 +6,8 @@ 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() } +class ServerBlockChangeEvent(private val blockPos: BlockPos, private val blockState: IBlockState) : LorenzEvent() { + val location by lazy { blockPos.toLorenzVec() } val old by lazy { location.getBlockAt().toString().getName() } val new by lazy { blockState.block.toString().getName() } 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") + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt index 6af83a805..b9a4c4bcb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt @@ -1,8 +1,10 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture +import at.hannibal2.skyhanni.utils.LocationUtils.distanceTo import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth import net.minecraft.client.multiplayer.WorldClient +import net.minecraft.entity.Entity import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand import net.minecraft.entity.monster.EntityBlaze @@ -123,6 +125,14 @@ object EntityUtils { ?.value } + inline fun <reified T : Entity> WorldClient.getEntitiesNextToPlayer(radius: Double): List<T> = + getEntitiesNearby(LocationUtils.playerLocation(), radius) + + inline fun <reified T : Entity> WorldClient.getEntitiesNearby(location: LorenzVec, radius: Double): List<T> = + getLoadedEntityList().filterIsInstance<T>().filter { it.distanceTo(location) < radius } + + fun EntityLivingBase.isAtFullHealth() = baseMaxHealth == health.toInt() + fun WorldClient.getEntitiesNearby( clazz: Class<EntityBlaze>, location: LorenzVec, @@ -140,5 +150,6 @@ object EntityUtils { fun EntityLivingBase.hasPotionEffect(potion: Potion) = getActivePotionEffect(potion) != null - fun EntityLivingBase.getArmorInventory(): Array<ItemStack?>? = if (this is EntityPlayer) inventory.armorInventory else null + fun EntityLivingBase.getArmorInventory(): Array<ItemStack?>? = + if (this is EntityPlayer) inventory.armorInventory else null }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt index bf7a0f1ee..1c1bd5b1b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt @@ -16,6 +16,8 @@ object LocationUtils { fun Entity.distanceToPlayer() = getLorenzVec().distance(playerLocation()) + fun Entity.distanceTo(location: LorenzVec) = getLorenzVec().distance(location) + fun playerEyeLocation(): LorenzVec { val player = Minecraft.getMinecraft().thePlayer val vec = player.getLorenzVec() |