Skip to content

Commit

Permalink
Apply review.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfence committed Feb 22, 2024
1 parent 1435e59 commit 8ef15fb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
8 changes: 4 additions & 4 deletions games/devtest/mods/callbacks/players.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local message = function(msg)
end

core.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
if not hitter then
message("Player "..player:get_player_name().." punched without hitter.")
end
end)
if not hitter then
message("Player "..player:get_player_name().." punched without hitter.")
end
end)
2 changes: 1 addition & 1 deletion src/script/cpp_api/s_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool ScriptApiEntity::luaentity_Punch(u16 id,
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, object); // self
if (puncher)
objectrefGetOrCreate(L, puncher); // Clicker reference
objectrefGetOrCreate(L, puncher); // Puncher reference
else
lua_pushnil(L);
lua_pushnumber(L, time_from_last_punch);
Expand Down
10 changes: 2 additions & 8 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,9 @@ int ObjectRef::l_punch(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkObject<ObjectRef>(L, 1);
ObjectRef *puncher_ref = nullptr;
try {
puncher_ref = checkObject<ObjectRef>(L, 2);
}
catch (...) {
puncher_ref = nullptr;
}
ObjectRef *puncher_ref = lua_isnoneornil(L, 2) ? nullptr : checkObject<ObjectRef>(L, 2);
ServerActiveObject *sao = getobject(ref);
ServerActiveObject *puncher = (puncher_ref)?(getobject(puncher_ref)):(nullptr);
ServerActiveObject *puncher = puncher_ref ? getobject(puncher_ref) : nullptr;
if (sao == nullptr)
return 0;

Expand Down
21 changes: 10 additions & 11 deletions src/server/luaentity_sao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ u32 LuaEntitySAO::punch(v3f dir,
PunchDamageResult result = getPunchDamage(
m_armor_groups,
toolcap,
(puncher)?(&tool_item):(nullptr),
puncher ? &tool_item : nullptr,
time_from_last_punch,
initial_wear);

Expand All @@ -349,17 +349,16 @@ u32 LuaEntitySAO::punch(v3f dir,
}
}

if (puncher)
if (puncher) {
actionstream << puncher->getDescription() << " (id=" << puncher->getId() <<
", hp=" << puncher->getHP() << ") punched " <<
getDescription() << " (id=" << m_id << ", hp=" << m_hp <<
"), damage=" << (old_hp - (s32)getHP()) <<
(damage_handled ? " (handled by Lua)" : "") << std::endl;
else
actionstream << getDescription() << " (id=" << m_id << ", hp=" << m_hp <<
"), damage=" << (old_hp - (s32)getHP()) <<
(damage_handled ? " (handled by Lua)" : "") << " punched without puncher" << std::endl;

", hp=" << puncher->getHP() << ")";
} else {
actionstream << "(none)";
}
actionstream << " punched " <<
getDescription() << " (id=" << m_id << ", hp=" << m_hp <<
"), damage=" << (old_hp - (s32)getHP()) <<
(damage_handled ? " (handled by Lua)" : "") << std::endl;
// TODO: give Lua control over wear
return result.wear;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ PunchDamageResult getPunchDamage(
{
if (do_hit && punchitem) {
if (itemgroup_get(armor_groups, "punch_operable") &&
(toolcap == NULL || (punchitem && punchitem->name.empty())))
(toolcap == NULL || punchitem->name.empty()))
do_hit = false;
}

Expand Down

0 comments on commit 8ef15fb

Please sign in to comment.