Added crit implementation for players

Now the crit sound will play for players in addition to just mobs. Added a new EntityEvent that functions the same way as EntityEvent::Hurt, but just plays another sound
This commit is contained in:
arsenicviscera 2026-03-10 12:55:50 -07:00
parent dbc9313c51
commit 907a9155e6
2 changed files with 12 additions and 3 deletions

View file

@ -5,6 +5,8 @@ class EntityEvent
public: public:
static const BYTE JUMP = 1; static const BYTE JUMP = 1;
static const BYTE HURT = 2; static const BYTE HURT = 2;
static const BYTE CRITICAL_HURT = 19;
static const BYTE DEATH = 3; static const BYTE DEATH = 3;
static const BYTE START_ATTACKING = 4; static const BYTE START_ATTACKING = 4;
static const BYTE STOP_ATTACKING = 5; static const BYTE STOP_ATTACKING = 5;

View file

@ -831,7 +831,12 @@ bool LivingEntity::hurt(DamageSource *source, float dmg)
if (sound) if (sound)
{ {
if (source->isCritical()) {
level->broadcastEntityEvent(shared_from_this(), EntityEvent::CRITICAL_HURT);
}
else {
level->broadcastEntityEvent(shared_from_this(), EntityEvent::HURT); level->broadcastEntityEvent(shared_from_this(), EntityEvent::HURT);
}
if (source != DamageSource::drown) markHurt(); if (source != DamageSource::drown) markHurt();
if (sourceEntity != nullptr) if (sourceEntity != nullptr)
{ {
@ -1193,7 +1198,7 @@ void LivingEntity::swing()
void LivingEntity::handleEntityEvent(byte id) void LivingEntity::handleEntityEvent(byte id)
{ {
if (id == EntityEvent::HURT) if ((id == EntityEvent::HURT) || (id == EntityEvent::CRITICAL_HURT))
{ {
walkAnimSpeed = 1.5f; walkAnimSpeed = 1.5f;
@ -1203,10 +1208,12 @@ void LivingEntity::handleEntityEvent(byte id)
MemSect(31); MemSect(31);
// 4J-PB -added because villagers have no sounds // 4J-PB -added because villagers have no sounds
int iHurtSound=getHurtSound(); int iHurtSound = iHurtSound = getHurtSound();;
int iCritSound = getCritHurtSound();;
if(iHurtSound!=-1) if(iHurtSound!=-1)
{ {
playSound(iHurtSound, getSoundVolume(), (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f); playSound(iHurtSound, getSoundVolume(), (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f);
if (id == EntityEvent::CRITICAL_HURT) {playSound(iCritSound, getSoundVolume(), (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f); }
} }
MemSect(0); MemSect(0);
hurt(DamageSource::genericSource, 0); hurt(DamageSource::genericSource, 0);