Skip to content

Commit e774d8c

Browse files
committedMar 5, 2020
Fixes around ServerActiveObject on_punch handling
1 parent 8d6a0b9 commit e774d8c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed
 

Diff for: ‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,7 @@ Callbacks:
39003900
* `dir`: unit vector of direction of punch. Always defined. Points from the
39013901
puncher to the punched.
39023902
* `damage`: damage that will be done to entity.
3903+
* Can return `true` to prevent the default damage mechanism.
39033904
* `on_death(self, killer)`
39043905
* Called when the object dies.
39053906
* `killer`: an `ObjectRef` (can be `nil`)

Diff for: ‎src/content_sao.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ u16 LuaEntitySAO::punch(v3f dir,
653653
if (!damage_handled) {
654654
if (result.did_punch) {
655655
setHP((s32)getHP() - result.damage,
656-
PlayerHPChangeReason(PlayerHPChangeReason::SET_HP));
656+
PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
657657

658658
std::string str = gob_cmd_punched(getHP());
659659
// create message and add to list
@@ -663,10 +663,10 @@ u16 LuaEntitySAO::punch(v3f dir,
663663
}
664664

665665
if (getHP() == 0 && !isGone()) {
666-
m_pending_removal = true;
667666
clearParentAttachment();
668667
clearChildAttachments();
669668
m_env->getScriptIface()->luaentity_on_death(m_id, puncher);
669+
m_pending_removal = true;
670670
}
671671

672672
actionstream << puncher->getDescription() << " (id=" << puncher->getId() <<
@@ -675,6 +675,7 @@ u16 LuaEntitySAO::punch(v3f dir,
675675
"), damage=" << (old_hp - (s32)getHP()) <<
676676
(damage_handled ? " (handled by Lua)" : "") << std::endl;
677677

678+
// TODO: give Lua control over wear
678679
return result.wear;
679680
}
680681

Diff for: ‎src/network/serverpackethandler.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,8 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
11661166
u16 wear = pointed_object->punch(dir, &toolcap, playersao,
11671167
time_from_last_punch);
11681168

1169+
// Callback may have changed item, so get it again
1170+
playersao->getWieldedItem(&selected_item);
11691171
bool changed = selected_item.addWear(wear, m_itemdef);
11701172
if (changed)
11711173
playersao->setWieldedItem(selected_item);

0 commit comments

Comments
 (0)
Please sign in to comment.