aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-09-17 09:35:17 +0200
committerGitHub <noreply@github.com>2024-09-17 09:35:17 +0200
commit46d39d831c23b02481c3ed0b34ebf74ac26bc088 (patch)
treee21b4d9a6aadbeaa0c7aff42bc5ae87d83852e01
parent1247a11ea7846af1531546263c525b3e005d0eed (diff)
downloadskyhanni-46d39d831c23b02481c3ed0b34ebf74ac26bc088.tar.gz
skyhanni-46d39d831c23b02481c3ed0b34ebf74ac26bc088.tar.bz2
skyhanni-46d39d831c23b02481c3ed0b34ebf74ac26bc088.zip
Fix: Efficient Miner on Ore Mined Event (#2526)
Co-authored-by: ItsEmpa <itsempa@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt39
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/OreBlock.kt2
3 files changed, 26 insertions, 19 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
index ecf90172d..fd399ae8b 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
@@ -8,11 +8,13 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.PlaySoundEvent
import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.ServerBlockChangeEvent
import at.hannibal2.skyhanni.events.mining.OreMinedEvent
import at.hannibal2.skyhanni.events.player.PlayerDeathEvent
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern
import at.hannibal2.skyhanni.features.mining.OreBlock
+import at.hannibal2.skyhanni.features.mining.isTitanium
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.countBy
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
@@ -50,8 +52,7 @@ object MiningAPI {
private var lastInitSound = SimpleTimeMark.farPast()
- private var waitingForInitBlock = false
- private var waitingForInitBlockPos: LorenzVec? = null
+ private var initBlockPos: LorenzVec? = null
private var waitingForInitSound = true
private var waitingForEffMinerSound = false
@@ -146,8 +147,8 @@ object MiningAPI {
val pos = event.location.roundLocationToBlock()
if (recentClickedBlocks.none { it.first == pos }) return
waitingForInitSound = false
- waitingForInitBlock = true
- waitingForInitBlockPos = event.location.roundLocationToBlock()
+ waitingForEffMinerBlock = true
+ initBlockPos = event.location.roundLocationToBlock()
lastInitSound = SimpleTimeMark.now()
}
return
@@ -164,21 +165,25 @@ object MiningAPI {
@SubscribeEvent
fun onBlockChange(event: ServerBlockChangeEvent) {
if (!inCustomMiningIsland()) return
- if (event.newState.block.let { it != Blocks.air && it != Blocks.bedrock }) return
- if (event.oldState.block.let { it == Blocks.air || it == Blocks.bedrock }) return
- if (event.oldState.block == Blocks.air) return
+ val oldState = event.oldState
+ val newState = event.newState
+ val oldBlock = oldState.block
+ val newBlock = newState.block
+
+ if (oldState == newState) return
+ if (oldBlock == Blocks.air || oldBlock == Blocks.bedrock) return
+ if (newBlock != Blocks.air && newBlock != Blocks.bedrock && !isTitanium(newState)) return
+
val pos = event.location
if (pos.distanceToPlayer() > 7) return
if (lastInitSound.passedSince() > 100.milliseconds) return
- val ore = OreBlock.getByStateOrNull(event.oldState) ?: return
+ val ore = OreBlock.getByStateOrNull(oldState) ?: return
- if (waitingForInitBlock) {
- if (waitingForInitBlockPos != pos) return
- waitingForInitBlock = false
+ if (initBlockPos == pos) {
surroundingMinedBlocks += MinedBlock(ore, true) to pos
- waitingForEffMinerBlock = true
+ runEvent()
return
}
if (waitingForEffMinerBlock) {
@@ -205,7 +210,11 @@ object MiningAPI {
if (waitingForInitSound) return
if (lastInitSound.passedSince() < 200.milliseconds) return
+ // in case the init block is not found
+ resetOreEvent()
+ }
+ private fun runEvent() {
resetOreEvent()
if (surroundingMinedBlocks.isEmpty()) return
@@ -237,8 +246,7 @@ object MiningAPI {
private fun resetOreEvent() {
lastInitSound = SimpleTimeMark.farPast()
waitingForInitSound = true
- waitingForInitBlock = false
- waitingForInitBlockPos = null
+ initBlockPos = null
waitingForEffMinerSound = false
waitingForEffMinerBlock = false
}
@@ -258,8 +266,7 @@ object MiningAPI {
add("lastInitSound: ${lastInitSound.passedSince().format()}")
}
add("waitingForInitSound: $waitingForInitSound")
- add("waitingForInitBlock: $waitingForInitBlock")
- add("waitingForInitBlockPos: $waitingForInitBlockPos")
+ add("waitingForInitBlockPos: $initBlockPos")
add("waitingForEffMinerSound: $waitingForEffMinerSound")
add("waitingForEffMinerBlock: $waitingForEffMinerBlock")
add("recentlyClickedBlocks: ${recentClickedBlocks.joinToString { "(${it.first.toCleanString()}" }}")
diff --git a/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt
index 07aa7630e..106ee2821 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/ServerBlockChangeEvent.kt
@@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.utils.toLorenzVec
import net.minecraft.block.state.IBlockState
import net.minecraft.util.BlockPos
-class ServerBlockChangeEvent(private val blockPos: BlockPos, private val blockState: IBlockState) : LorenzEvent() {
+class ServerBlockChangeEvent(blockPos: BlockPos, blockState: IBlockState) : LorenzEvent() {
val location by lazy { blockPos.toLorenzVec() }
val old by lazy { location.getBlockAt().toString().getName() }
@@ -17,7 +17,7 @@ class ServerBlockChangeEvent(private val blockPos: BlockPos, private val blockSt
companion object {
- val pattern = "Block\\{minecraft:(?<name>.*)}".toPattern()
+ private val pattern = "Block\\{minecraft:(?<name>.*)}".toPattern()
private fun String.getName() = pattern.matchMatcher(this) {
group("name")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/OreBlock.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/OreBlock.kt
index 7f5582036..c5d9774b1 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mining/OreBlock.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/OreBlock.kt
@@ -252,7 +252,7 @@ private fun isHighTierMithril(state: IBlockState): Boolean {
return (state.block == Blocks.wool && state.getValue(BlockColored.COLOR) == EnumDyeColor.LIGHT_BLUE)
}
-private fun isTitanium(state: IBlockState): Boolean {
+fun isTitanium(state: IBlockState): Boolean {
return (state.block == Blocks.stone && state.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH)
}