Update GameStateListener.kt
Fix block breaking
This commit is contained in:
@@ -72,10 +72,10 @@ class GameStateListener : Listener {
|
||||
)
|
||||
|
||||
private val alwaysMaterials = mapOf(
|
||||
Material.RED_MUSHROOM to Sound.BLOCK_GRASS_BREAK,
|
||||
Material.RED_MUSHROOM to Sound.BLOCK_GRASS_BREAK,
|
||||
Material.BROWN_MUSHROOM to Sound.BLOCK_GRASS_BREAK,
|
||||
Material.COCOA_BEANS to Sound.BLOCK_WOOD_BREAK,
|
||||
Material.CACTUS to Sound.BLOCK_WOOL_BREAK
|
||||
Material.COCOA to Sound.BLOCK_WOOD_BREAK, // ← Block heißt COCOA, nicht COCOA_BEANS
|
||||
Material.CACTUS to Sound.BLOCK_WOOL_BREAK
|
||||
)
|
||||
|
||||
@EventHandler
|
||||
@@ -114,21 +114,9 @@ class GameStateListener : Listener {
|
||||
return
|
||||
}
|
||||
|
||||
// Invincibility: nur Whitelist-Blöcke erlaubt
|
||||
if ( gameManager.currentState == GameState.INVINCIBILITY )
|
||||
{
|
||||
if ( beforeInvisMaterials.containsKey( block.type ) ||
|
||||
alwaysMaterials.containsKey( block.type ) )
|
||||
{
|
||||
pickupBlock( event, player )
|
||||
} else {
|
||||
event.isCancelled = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// INGAME: alle Blöcke direkt in Inventar — nie auf den Boden fallen lassen
|
||||
// (ItemDespawnEvent cancelt sonst alle Drops sofort)
|
||||
// BUG 2 FIX: Kein separater Invis-Whitelist-Block mehr.
|
||||
// Beide States (INVINCIBILITY + INGAME) laufen direkt in pickupBlock —
|
||||
// Map-Protection (Diamant, Eisen) ist bereits oben abgehandelt.
|
||||
pickupBlock( event, player )
|
||||
}
|
||||
|
||||
@@ -138,7 +126,6 @@ class GameStateListener : Listener {
|
||||
) {
|
||||
val block = event.block
|
||||
|
||||
// In pickupBlock, direkt vor event.isCancelled = true:
|
||||
if ( block.type == Material.RED_MUSHROOM ||
|
||||
block.type == Material.BROWN_MUSHROOM )
|
||||
{
|
||||
@@ -150,23 +137,32 @@ class GameStateListener : Listener {
|
||||
|
||||
event.isCancelled = true
|
||||
|
||||
// BUG 1 FIX: !! entfernt → Elvis mit null-Safe-Fallback auf GENERIC_SOUND.
|
||||
// Blöcke, die in keiner Map stehen (z.B. Erde, Gras im INGAME-State),
|
||||
// bekommen einen neutralen Standard-Sound statt einer NPE.
|
||||
val sound = beforeInvisMaterials[ block.type ]
|
||||
?: alwaysMaterials[ block.type ]!!
|
||||
?: alwaysMaterials[ block.type ]
|
||||
?: Sound.BLOCK_STONE_BREAK
|
||||
|
||||
// block.getDrops( tool, player ) gibt den korrekten Vanilla-Drop-Context
|
||||
// inkl. Age-State bei Cocoa, Fortune-Enchant, Silk-Touch usw.
|
||||
// BUG 3 FIX: block.getDrops(tool, player) gibt für Material.COCOA
|
||||
// korrekt Material.COCOA_BEANS zurück — Paper löst den Block→Item-
|
||||
// Mapping intern auf. Kein manueller Sonderfall nötig.
|
||||
val drops = block.getDrops( player.inventory.itemInMainHand, player )
|
||||
|
||||
if ( !hasInventorySpace( player ) )
|
||||
{
|
||||
drops.forEach { player.world.dropItem( block.location, it ) }
|
||||
player.playSound( player.location, sound, 1f, 1f )
|
||||
block.type = Material.AIR
|
||||
|
||||
if ( sound != Sound.BLOCK_STONE_BREAK )
|
||||
player.playSound( player.location, sound, 1f, 1f )
|
||||
return
|
||||
}
|
||||
|
||||
if ( sound != Sound.BLOCK_STONE_BREAK )
|
||||
player.playSound( player.location, sound, 1f, 1f )
|
||||
|
||||
drops.forEach { player.inventory.addItem( it ) }
|
||||
player.playSound( player.location, sound, 1f, 1f )
|
||||
block.type = Material.AIR
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user