aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/DamageSource.cpp
diff options
context:
space:
mode:
authorLoki Rautio <lokirautio@gmail.com>2026-03-04 03:56:03 -0600
committerLoki Rautio <lokirautio@gmail.com>2026-03-04 03:56:03 -0600
commit42aec6dac53dffa6afe072560a7e1d4986112538 (patch)
tree0836426857391df1b6a83f6368a183f83ec9b104 /Minecraft.World/DamageSource.cpp
parentc9d58eeac7c72f0b3038e084667b4d89a6249fce (diff)
parentef9b6fd500dfabd9463267b0dd9e29577eea8a2b (diff)
Merge branch 'main' into pr/win64-world-saves
# Conflicts: # Minecraft.Client/MinecraftServer.cpp # README.md
Diffstat (limited to 'Minecraft.World/DamageSource.cpp')
-rw-r--r--Minecraft.World/DamageSource.cpp84
1 files changed, 64 insertions, 20 deletions
diff --git a/Minecraft.World/DamageSource.cpp b/Minecraft.World/DamageSource.cpp
index 29ea727e..1ed1c65f 100644
--- a/Minecraft.World/DamageSource.cpp
+++ b/Minecraft.World/DamageSource.cpp
@@ -2,65 +2,76 @@
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.entity.projectile.h"
+#include "net.minecraft.world.level.h"
#include "net.minecraft.world.damagesource.h"
#include "net.minecraft.world.food.h"
#include "net.minecraft.network.packet.h"
-DamageSource *DamageSource::inFire = (new DamageSource(ChatPacket::e_ChatDeathInFire))->setIsFire();
-DamageSource *DamageSource::onFire = (new DamageSource(ChatPacket::e_ChatDeathOnFire))->bypassArmor()->setIsFire();
-DamageSource *DamageSource::lava = (new DamageSource(ChatPacket::e_ChatDeathLava))->setIsFire();
+DamageSource *DamageSource::inFire = (new DamageSource(ChatPacket::e_ChatDeathInFire, ChatPacket::e_ChatDeathInFirePlayer))->setIsFire();
+DamageSource *DamageSource::onFire = (new DamageSource(ChatPacket::e_ChatDeathOnFire, ChatPacket::e_ChatDeathOnFirePlayer))->bypassArmor()->setIsFire();
+DamageSource *DamageSource::lava = (new DamageSource(ChatPacket::e_ChatDeathLava, ChatPacket::e_ChatDeathLavaPlayer))->setIsFire();
DamageSource *DamageSource::inWall = (new DamageSource(ChatPacket::e_ChatDeathInWall))->bypassArmor();
-DamageSource *DamageSource::drown = (new DamageSource(ChatPacket::e_ChatDeathDrown))->bypassArmor();
+DamageSource *DamageSource::drown = (new DamageSource(ChatPacket::e_ChatDeathDrown, ChatPacket::e_ChatDeathDrownPlayer))->bypassArmor();
DamageSource *DamageSource::starve = (new DamageSource(ChatPacket::e_ChatDeathStarve))->bypassArmor();
-DamageSource *DamageSource::cactus = new DamageSource(ChatPacket::e_ChatDeathCactus);
+DamageSource *DamageSource::cactus = new DamageSource(ChatPacket::e_ChatDeathCactus, ChatPacket::e_ChatDeathCactusPlayer);
DamageSource *DamageSource::fall = (new DamageSource(ChatPacket::e_ChatDeathFall))->bypassArmor();
DamageSource *DamageSource::outOfWorld = (new DamageSource(ChatPacket::e_ChatDeathOutOfWorld))->bypassArmor()->bypassInvul();
DamageSource *DamageSource::genericSource = (new DamageSource(ChatPacket::e_ChatDeathGeneric))->bypassArmor();
-DamageSource *DamageSource::explosion = (new DamageSource(ChatPacket::e_ChatDeathExplosion))->setScalesWithDifficulty();
-DamageSource *DamageSource::controlledExplosion = (new DamageSource(ChatPacket::e_ChatDeathExplosion));
DamageSource *DamageSource::magic = (new DamageSource(ChatPacket::e_ChatDeathMagic))->bypassArmor()->setMagic();
DamageSource *DamageSource::dragonbreath = (new DamageSource(ChatPacket::e_ChatDeathDragonBreath))->bypassArmor();
DamageSource *DamageSource::wither = (new DamageSource(ChatPacket::e_ChatDeathWither))->bypassArmor();
DamageSource *DamageSource::anvil = (new DamageSource(ChatPacket::e_ChatDeathAnvil));
DamageSource *DamageSource::fallingBlock = (new DamageSource(ChatPacket::e_ChatDeathFallingBlock));
-DamageSource *DamageSource::mobAttack(shared_ptr<Mob> mob)
+DamageSource *DamageSource::mobAttack(shared_ptr<LivingEntity> mob)
{
- return new EntityDamageSource(ChatPacket::e_ChatDeathMob, mob);
+ return new EntityDamageSource(ChatPacket::e_ChatDeathMob, ChatPacket::e_ChatDeathMob, mob);
}
DamageSource *DamageSource::playerAttack(shared_ptr<Player> player)
{
- return new EntityDamageSource(ChatPacket::e_ChatDeathPlayer, player);
+ return new EntityDamageSource(ChatPacket::e_ChatDeathPlayer, ChatPacket::e_ChatDeathPlayerItem, player);
}
DamageSource *DamageSource::arrow(shared_ptr<Arrow> arrow, shared_ptr<Entity> owner)
{
- return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathArrow, arrow, owner))->setProjectile();
+ return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathArrow, ChatPacket::e_ChatDeathArrowItem, arrow, owner))->setProjectile();
}
DamageSource *DamageSource::fireball(shared_ptr<Fireball> fireball, shared_ptr<Entity> owner)
{
if (owner == NULL)
{
- return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathOnFire, fireball, fireball))->setIsFire()->setProjectile();
+ return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathOnFire, ChatPacket::e_ChatDeathOnFire, fireball, fireball))->setIsFire()->setProjectile();
}
- return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathFireball, fireball, owner))->setIsFire()->setProjectile();
+ return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathFireball, ChatPacket::e_ChatDeathArrowItem, fireball, owner))->setIsFire()->setProjectile();
}
DamageSource *DamageSource::thrown(shared_ptr<Entity> entity, shared_ptr<Entity> owner)
{
- return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathThrown, entity, owner))->setProjectile();
+ return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathThrown, ChatPacket::e_ChatDeathThrownItem, entity, owner))->setProjectile();
}
DamageSource *DamageSource::indirectMagic(shared_ptr<Entity> entity, shared_ptr<Entity> owner)
{
- return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathIndirectMagic, entity, owner) )->bypassArmor()->setMagic();;
+ return (new IndirectEntityDamageSource(ChatPacket::e_ChatDeathIndirectMagic, ChatPacket::e_ChatDeathIndirectMagicItem, entity, owner) )->bypassArmor()->setMagic();;
}
DamageSource *DamageSource::thorns(shared_ptr<Entity> source)
{
- return (new EntityDamageSource(ChatPacket::e_ChatDeathThorns, source))->setMagic();
+ return (new EntityDamageSource(ChatPacket::e_ChatDeathThorns, ChatPacket::e_ChatDeathThorns, source))->setMagic();
+}
+
+DamageSource *DamageSource::explosion(Explosion *explosion)
+{
+ if ( (explosion != NULL) && (explosion->getSourceMob() != NULL) )
+ {
+ return (new EntityDamageSource(ChatPacket::e_ChatDeathExplosionPlayer, ChatPacket::e_ChatDeathExplosionPlayer, explosion->getSourceMob()))->setScalesWithDifficulty()->setExplosion();
+ }
+ else
+ {
+ return (new DamageSource(ChatPacket::e_ChatDeathExplosion))->setScalesWithDifficulty()->setExplosion();
+ }
}
bool DamageSource::isProjectile()
@@ -70,7 +81,18 @@ bool DamageSource::isProjectile()
DamageSource *DamageSource::setProjectile()
{
- this->_isProjectile = true;
+ _isProjectile = true;
+ return this;
+}
+
+bool DamageSource::isExplosion()
+{
+ return _isExplosion;
+}
+
+DamageSource *DamageSource::setExplosion()
+{
+ _isExplosion = true;
return this;
}
@@ -91,7 +113,7 @@ bool DamageSource::isBypassInvul()
//DamageSource::DamageSource(const wstring &msgId)
-DamageSource::DamageSource(ChatPacket::EChatPacketMessage msgId)
+DamageSource::DamageSource(ChatPacket::EChatPacketMessage msgId, ChatPacket::EChatPacketMessage msgWithItemId)
{
// 4J added initialisors
_bypassArmor = false;
@@ -101,9 +123,11 @@ DamageSource::DamageSource(ChatPacket::EChatPacketMessage msgId)
isFireSource = false;
_isProjectile = false;
_isMagic = false;
+ _isExplosion = false;
//this->msgId = msgId;
m_msgId = msgId;
+ m_msgWithItemId = msgWithItemId;
}
shared_ptr<Entity> DamageSource::getDirectEntity()
@@ -164,9 +188,17 @@ DamageSource *DamageSource::setMagic()
// //return I18n.get(L"death." + msgId, player.name);
//}
-shared_ptr<ChatPacket> DamageSource::getDeathMessagePacket(shared_ptr<Player> player)
+shared_ptr<ChatPacket> DamageSource::getDeathMessagePacket(shared_ptr<LivingEntity> player)
{
- return shared_ptr<ChatPacket>( new ChatPacket(player->name, m_msgId ) );
+ shared_ptr<LivingEntity> source = player->getKillCredit();
+ if(source != NULL)
+ {
+ return shared_ptr<ChatPacket>( new ChatPacket(player->getNetworkName(), m_msgWithItemId != ChatPacket::e_ChatCustom ? m_msgWithItemId : m_msgId, source->GetType(), source->getNetworkName() ) );
+ }
+ else
+ {
+ return shared_ptr<ChatPacket>( new ChatPacket(player->getNetworkName(), m_msgId ) );
+ }
}
bool DamageSource::isFire()
@@ -177,4 +209,16 @@ bool DamageSource::isFire()
ChatPacket::EChatPacketMessage DamageSource::getMsgId()
{
return m_msgId;
+}
+
+// 4J: Very limited check for equality (used to detect fall damage, etc)
+bool DamageSource::equals(DamageSource *source)
+{
+ return m_msgId == source->m_msgId && m_msgWithItemId == source->m_msgWithItemId;
+}
+
+// 4J: Copy function
+DamageSource *DamageSource::copy()
+{
+ return new DamageSource(*this);
} \ No newline at end of file