From 907a9155e6b5973c7eeb71e895f972e31c6ea66e Mon Sep 17 00:00:00 2001 From: arsenicviscera Date: Tue, 10 Mar 2026 12:55:50 -0700 Subject: [PATCH] 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 --- Minecraft.World/EntityEvent.h | 2 ++ Minecraft.World/LivingEntity.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Minecraft.World/EntityEvent.h b/Minecraft.World/EntityEvent.h index 4d2064aba..29d9e6999 100644 --- a/Minecraft.World/EntityEvent.h +++ b/Minecraft.World/EntityEvent.h @@ -5,6 +5,8 @@ class EntityEvent public: static const BYTE JUMP = 1; static const BYTE HURT = 2; + static const BYTE CRITICAL_HURT = 19; + static const BYTE DEATH = 3; static const BYTE START_ATTACKING = 4; static const BYTE STOP_ATTACKING = 5; diff --git a/Minecraft.World/LivingEntity.cpp b/Minecraft.World/LivingEntity.cpp index 11161ac17..036adea3b 100644 --- a/Minecraft.World/LivingEntity.cpp +++ b/Minecraft.World/LivingEntity.cpp @@ -831,7 +831,12 @@ bool LivingEntity::hurt(DamageSource *source, float dmg) if (sound) { - level->broadcastEntityEvent(shared_from_this(), EntityEvent::HURT); + if (source->isCritical()) { + level->broadcastEntityEvent(shared_from_this(), EntityEvent::CRITICAL_HURT); + } + else { + level->broadcastEntityEvent(shared_from_this(), EntityEvent::HURT); + } if (source != DamageSource::drown) markHurt(); if (sourceEntity != nullptr) { @@ -1193,7 +1198,7 @@ void LivingEntity::swing() void LivingEntity::handleEntityEvent(byte id) { - if (id == EntityEvent::HURT) + if ((id == EntityEvent::HURT) || (id == EntityEvent::CRITICAL_HURT)) { walkAnimSpeed = 1.5f; @@ -1203,10 +1208,12 @@ void LivingEntity::handleEntityEvent(byte id) MemSect(31); // 4J-PB -added because villagers have no sounds - int iHurtSound=getHurtSound(); + int iHurtSound = iHurtSound = getHurtSound();; + int iCritSound = getCritHurtSound();; if(iHurtSound!=-1) { 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); hurt(DamageSource::genericSource, 0);