Skip to content

Commit

Permalink
fix: attribute being reset between breaking vanilla & custom block
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed May 17, 2024
1 parent 994a4ea commit 03f96c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BlockyGenericListener : Listener {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
fun BlockDamageEvent.onDamageCustomBlock() {
player.miningAttribute?.removeModifier(player)
player.miningAttribute?.takeUnless { block.isVanillaNoteBlock }?.removeModifier(player)
if (player.gameMode == GameMode.CREATIVE) return

val breaking = block.toGearyOrNull()?.get<BlockyBreaking>() ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.mineinabyss.geary.papermc.tracking.blocks.helpers.toGearyOrNull
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.idofront.entities.rightClicked
import com.mineinabyss.idofront.messaging.broadcastVal
import org.bukkit.GameMode
import org.bukkit.Material
import org.bukkit.attribute.Attribute
import org.bukkit.block.data.type.NoteBlock
Expand All @@ -34,9 +35,10 @@ class BlockyNoteBlockListener : Listener {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
fun BlockDamageEvent.onDamageVanillaBlock() {
player.miningAttribute?.removeModifier(player)
// Return before removing as this is handled by BlockyGenericListener
player.miningAttribute?.takeUnless { block.isBlockyBlock }?.removeModifier(player)

if (!block.isVanillaNoteBlock) return
if (player.gameMode == GameMode.CREATIVE || !block.isVanillaNoteBlock) return

val mining = PlayerMiningAttribute(NoteBlockHelpers.vanillaBreakingComponent.createBreakingModifier(player, block))
player.toGearyOrNull()?.set(mining)
Expand Down

0 comments on commit 03f96c2

Please sign in to comment.