mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
Add node pos to node damage HP change reason (#13196)
This commit is contained in:
parent
1d88d85f1c
commit
73391013f7
@ -5266,6 +5266,7 @@ Call these functions only at load time!
|
||||
* `fall`
|
||||
* `node_damage`: `damage_per_second` from a neighboring node.
|
||||
`reason.node` will hold the node name or nil.
|
||||
`reason.node_pos` will hold the position of the node
|
||||
* `drown`
|
||||
* `respawn`
|
||||
* Any of the above types may have additional fields from mods.
|
||||
|
@ -488,6 +488,9 @@ void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeR
|
||||
if (!reason.node.empty()) {
|
||||
lua_pushstring(L, reason.node.c_str());
|
||||
lua_setfield(L, -2, "node");
|
||||
|
||||
push_v3s16(L, reason.node_pos);
|
||||
lua_setfield(L, -2, "node_pos");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,6 +185,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
|
||||
if (!isImmortal() && m_node_hurt_interval.step(dtime, 1.0f)) {
|
||||
u32 damage_per_second = 0;
|
||||
std::string nodename;
|
||||
v3s16 node_pos;
|
||||
// Lowest and highest damage points are 0.1 within collisionbox
|
||||
float dam_top = m_prop.collisionbox.MaxEdge.Y - 0.1f;
|
||||
|
||||
@ -198,6 +199,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
|
||||
if (c.damage_per_second > damage_per_second) {
|
||||
damage_per_second = c.damage_per_second;
|
||||
nodename = c.name;
|
||||
node_pos = p;
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,11 +211,12 @@ void PlayerSAO::step(float dtime, bool send_recommended)
|
||||
if (c.damage_per_second > damage_per_second) {
|
||||
damage_per_second = c.damage_per_second;
|
||||
nodename = c.name;
|
||||
node_pos = ptop;
|
||||
}
|
||||
|
||||
if (damage_per_second != 0 && m_hp > 0) {
|
||||
s32 newhp = (s32)m_hp - (s32)damage_per_second;
|
||||
PlayerHPChangeReason reason(PlayerHPChangeReason::NODE_DAMAGE, nodename);
|
||||
PlayerHPChangeReason reason(PlayerHPChangeReason::NODE_DAMAGE, nodename, node_pos);
|
||||
setHP(newhp, reason);
|
||||
}
|
||||
}
|
||||
|
@ -245,6 +245,7 @@ struct PlayerHPChangeReason
|
||||
ServerActiveObject *object = nullptr;
|
||||
// For NODE_DAMAGE
|
||||
std::string node;
|
||||
v3s16 node_pos;
|
||||
|
||||
inline bool hasLuaReference() const { return lua_reference >= 0; }
|
||||
|
||||
@ -296,5 +297,5 @@ struct PlayerHPChangeReason
|
||||
{
|
||||
}
|
||||
|
||||
PlayerHPChangeReason(Type type, std::string node) : type(type), node(node) {}
|
||||
PlayerHPChangeReason(Type type, std::string node, v3s16 node_pos) : type(type), node(node), node_pos(node_pos) {}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user