mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-12-01 12:38:55 -05:00
feat: pokemon wake when players move nearby
This commit is contained in:
1 parent
bfb9b28d65
commit
4e1133e4b4
1 file changed
+23
-1
+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)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user