diff options
author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-14 00:39:05 +0200 |
---|---|---|
committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-14 00:39:05 +0200 |
commit | c09d6ee504ae43acbc7789cdbf69bc1de387bd18 (patch) | |
tree | 1fc1a1bfff6b9787f258afe4f21dd724494ce54c /src/main/java/at/lorenz/mod/dungeon | |
parent | b025e2525b8fbf2aabd74870d4d3013405861e1b (diff) | |
download | skyhanni-c09d6ee504ae43acbc7789cdbf69bc1de387bd18.tar.gz skyhanni-c09d6ee504ae43acbc7789cdbf69bc1de387bd18.tar.bz2 skyhanni-c09d6ee504ae43acbc7789cdbf69bc1de387bd18.zip |
add clean dungeon end feature
Diffstat (limited to 'src/main/java/at/lorenz/mod/dungeon')
4 files changed, 142 insertions, 9 deletions
diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonCleanEnd.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonCleanEnd.kt new file mode 100644 index 000000000..62191a370 --- /dev/null +++ b/src/main/java/at/lorenz/mod/dungeon/DungeonCleanEnd.kt @@ -0,0 +1,120 @@ +package at.lorenz.mod.dungeon + +import at.lorenz.mod.LorenzMod +import at.lorenz.mod.events.CheckRenderEntityEvent +import at.lorenz.mod.events.DamageIndicatorFinalBossEvent +import at.lorenz.mod.events.LorenzChatEvent +import at.lorenz.mod.events.PacketEvent +import at.lorenz.mod.utils.LorenzUtils +import at.lorenz.mod.utils.LorenzUtils.matchRegex +import net.minecraft.client.Minecraft +import net.minecraft.client.entity.EntityOtherPlayerMP +import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.network.play.server.S1CPacketEntityMetadata +import net.minecraft.network.play.server.S2APacketParticles +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class DungeonCleanEnd { + + private var bossDone = false + private var chestsSpawned = false + private var lastBossId: Int = -1 + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.inDungeons) return + if (!LorenzMod.feature.dungeon.cleanEnd) return + + val message = event.message + + if (message.matchRegex("([ ]*)§r§c(The|Master Mode) Catacombs §r§8- §r§eFloor (.*)")) { + chestsSpawned = true + } + } + + private fun shouldBlock(): Boolean { + if (!LorenzUtils.inDungeons) return false + if (!LorenzMod.feature.dungeon.cleanEnd) return false + + if (!bossDone) return false + + //TODO remove + if (Minecraft.getMinecraft().thePlayer.isSneaking) return false + + return true + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + bossDone = false + chestsSpawned = false + lastBossId = -1 + } + + @SubscribeEvent + fun onBossDead(event: DamageIndicatorFinalBossEvent) { + if (!LorenzUtils.inDungeons) return + if (bossDone) return + + if (lastBossId == -1) { + lastBossId = event.id + } + } + + @SubscribeEvent + fun onHealthUpdatePacket(event: PacketEvent.ReceiveEvent) { + if (!LorenzUtils.inDungeons) return + if (!LorenzMod.feature.dungeon.cleanEnd) return + + if (bossDone) return + if (lastBossId == -1) return + + val packet = event.packet + if (packet !is S1CPacketEntityMetadata) return + if (packet.entityId != lastBossId) return + + for (watchableObject in packet.func_149376_c()) { + if (watchableObject.dataValueId == 6) { + val health = watchableObject.`object` as Float + if (health < 1) { + val dungeonFloor = DungeonData.dungeonFloor + LorenzUtils.chat("§eFloor $dungeonFloor done!") + bossDone = true + } + } + } + } + + @SubscribeEvent + fun onCheckRender(event: CheckRenderEntityEvent<*>) { + if (!shouldBlock()) return + + val entity = event.entity + + if (entity == Minecraft.getMinecraft().thePlayer) return + + if (chestsSpawned) { + if (entity is EntityArmorStand) { + if (!entity.hasCustomName()) { + return + } + } + if (entity is EntityOtherPlayerMP) { + return + } + } + + event.isCanceled = true + } + + @SubscribeEvent + fun onReceivePacket(event: PacketEvent.ReceiveEvent) { + if (!shouldBlock()) return + + + if (event.packet is S2APacketParticles) { + event.isCanceled = true + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/dungeon/damageindicator/DungeonBossDamageIndicator.kt b/src/main/java/at/lorenz/mod/dungeon/damageindicator/DungeonBossDamageIndicator.kt index 93de52220..5901dd29e 100644 --- a/src/main/java/at/lorenz/mod/dungeon/damageindicator/DungeonBossDamageIndicator.kt +++ b/src/main/java/at/lorenz/mod/dungeon/damageindicator/DungeonBossDamageIndicator.kt @@ -1,6 +1,7 @@ package at.lorenz.mod.dungeon.damageindicator import at.lorenz.mod.LorenzMod +import at.lorenz.mod.events.DamageIndicatorFinalBossEvent import at.lorenz.mod.events.DungeonEnterEvent import at.lorenz.mod.events.LorenzChatEvent import at.lorenz.mod.utils.LorenzColor @@ -25,6 +26,7 @@ class DungeonBossDamageIndicator { var data = mutableMapOf<EntityLivingBase, EntityData>() private var bossFinder: DungeonBossFinder? = null private val decimalFormat = DecimalFormat("0.0") + private val maxHealth = mutableMapOf<UUID, Double>() @SubscribeEvent fun onDungeonStart(event: DungeonEnterEvent) { @@ -101,6 +103,7 @@ class DungeonBossDamageIndicator { try { val entity = event.entity val result = bossFinder?.shouldShow(entity) ?: return + checkLastBossDead(result.finalBoss, entity.entityId) val ignoreBlocks = result.ignoreBlocks val delayedStart = result.delayedStart @@ -139,7 +142,11 @@ class DungeonBossDamageIndicator { } } - private val maxHealth = mutableMapOf<UUID, Double>() + private fun checkLastBossDead(finalBoss: Boolean, id: Int) { + if (finalBoss) { + DamageIndicatorFinalBossEvent(id).postAndCatch() + } + } private fun setMaxHealth(entity: EntityLivingBase, currentMaxHealth: Double) { maxHealth[entity.uniqueID!!] = currentMaxHealth diff --git a/src/main/java/at/lorenz/mod/dungeon/damageindicator/DungeonBossFinder.kt b/src/main/java/at/lorenz/mod/dungeon/damageindicator/DungeonBossFinder.kt index 4b6607d92..33f09967c 100644 --- a/src/main/java/at/lorenz/mod/dungeon/damageindicator/DungeonBossFinder.kt +++ b/src/main/java/at/lorenz/mod/dungeon/damageindicator/DungeonBossFinder.kt @@ -64,7 +64,7 @@ class DungeonBossFinder { if (floor1bonzo2) { if (entity is EntityOtherPlayerMP) { if (entity.name == "Bonzo ") { - return EntityResult(floor1bonzo2SpawnTime) + return EntityResult(floor1bonzo2SpawnTime, finalBoss = true) } } } @@ -93,7 +93,7 @@ class DungeonBossFinder { //TODO only show scarf after (all/at least x) summons are dead? val result = entity.name == "Scarf " if (result) { - return EntityResult(floor2secondPhaseSpawnTime) + return EntityResult(floor2secondPhaseSpawnTime, finalBoss = true) } } } @@ -123,7 +123,10 @@ class DungeonBossFinder { if (floor3Professor) { if (entity is EntityOtherPlayerMP) { if (entity.name == "The Professor") { - return EntityResult(floor3ProfessorSpawnTime, floor3ProfessorSpawnTime + 1_000 > System.currentTimeMillis()) + return EntityResult( + floor3ProfessorSpawnTime, + floor3ProfessorSpawnTime + 1_000 > System.currentTimeMillis() + ) } } } @@ -138,7 +141,7 @@ class DungeonBossFinder { if (entity is EntityGuardian) { if (floor3ProfessorGuardian) { if (entity == floor3ProfessorGuardianEntity) { - return EntityResult() + return EntityResult(finalBoss = true) } } } @@ -148,7 +151,7 @@ class DungeonBossFinder { if (entity is EntityOtherPlayerMP) { if (entity == floor5lividEntity) { // ignoreBlocks(entity.getLorenzVec().distance(5.5, 69.0, -2.5) < 5) - return EntityResult(floor5lividEntitySpawnTime, true) + return EntityResult(floor5lividEntitySpawnTime, true, finalBoss = true) } } } @@ -157,11 +160,14 @@ class DungeonBossFinder { if (entity is EntityGiantZombie && !entity.isInvisible) { if (floor6Giants && entity.posY > 68) { val extraDelay = checkExtraF6GiantsDelay(entity) - return EntityResult(floor6GiantsSpawnTime + extraDelay, floor6GiantsSpawnTime + extraDelay + 1_000 > System.currentTimeMillis()) + return EntityResult( + floor6GiantsSpawnTime + extraDelay, + floor6GiantsSpawnTime + extraDelay + 1_000 > System.currentTimeMillis() + ) } if (floor6Sadan) { - return EntityResult(floor6SadanSpawnTime) + return EntityResult(floor6SadanSpawnTime, finalBoss = true) } } } diff --git a/src/main/java/at/lorenz/mod/dungeon/damageindicator/EntityResult.kt b/src/main/java/at/lorenz/mod/dungeon/damageindicator/EntityResult.kt index ae229cf70..f0642b953 100644 --- a/src/main/java/at/lorenz/mod/dungeon/damageindicator/EntityResult.kt +++ b/src/main/java/at/lorenz/mod/dungeon/damageindicator/EntityResult.kt @@ -1,3 +1,3 @@ package at.lorenz.mod.dungeon.damageindicator -class EntityResult(val delayedStart: Long = -1L, val ignoreBlocks: Boolean = false)
\ No newline at end of file +class EntityResult(val delayedStart: Long = -1L, val ignoreBlocks: Boolean = false, val finalBoss: Boolean = false)
\ No newline at end of file |