feat: pokemon wake when players move nearby

This commit is contained in:
whatsy committed 2026-11-28 20:03:40 -05:00
1 parent bfb9b28d65
commit 4e1133e4b4
1 file changed
+23 -1
@@ -25,7 +25,10 @@ import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
import com.cobblemon.mod.common.pokemon.status.PersistentStatusContainer
import com.cobblemon.mod.common.util.asExpression
import com.cobblemon.mod.common.util.resolveBoolean
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.player.Player
import net.minecraft.world.phys.AABB
/**
* Sleeps the entity.
@@ -99,6 +102,25 @@ class GoToSleep(
wakeUp(entity)
return false
}
entity as PokemonEntity
// Players nearby will interrupt sleep, unless sneaking or invisible
val nearbyPlayers = entity.level().getEntitiesOfClass(
Player::class.java,
entity.boundingBox.inflate(4.0, 2.0, 4.0)
)
val disturbedPlayer = nearbyPlayers.firstOrNull {
!it.isCrouching && !it.hasEffect(MobEffects.INVISIBILITY) && !it.isSpectator
}
if (disturbedPlayer != null) {
wakeUp(entity)
entity.lookAt(disturbedPlayer, 30.0f, 30.0f)
return false
}
return true
}
@@ -111,8 +133,8 @@ class GoToSleep(
if (hasSleepStatus) {
entity.pokemon.status = null
}
entity.brain.eraseMemory(CobblemonMemories.POKEMON_DROWSY)
entity.brain.eraseMemory(CobblemonMemories.POKEMON_SLEEPING)
}
}