*result = os.str();
}
-int LuaEntitySAO::punch(v3f dir,
+u16 LuaEntitySAO::punch(v3f dir,
const ToolCapabilities *toolcap,
ServerActiveObject *puncher,
float time_from_last_punch)
FATAL_ERROR_IF(!puncher, "Punch action called without SAO");
s32 old_hp = getHP();
- const ItemStack &punchitem = puncher->getWieldedItem();
+ ItemStack selected_item, hand_item;
+ ItemStack tool_item = puncher->getWieldedItem(&selected_item, &hand_item);
PunchDamageResult result = getPunchDamage(
m_armor_groups,
toolcap,
- &punchitem,
+ &tool_item,
time_from_last_punch);
bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
if (!damage_handled) {
if (result.did_punch) {
setHP((s32)getHP() - result.damage,
- PlayerHPChangeReason(PlayerHPChangeReason::SET_HP));
+ PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
std::string str = gob_cmd_punched(getHP());
// create message and add to list
}
if (getHP() == 0 && !isGone()) {
- m_pending_removal = true;
clearParentAttachment();
clearChildAttachments();
m_env->getScriptIface()->luaentity_on_death(m_id, puncher);
+ m_pending_removal = true;
}
actionstream << puncher->getDescription() << " (id=" << puncher->getId() <<
"), damage=" << (old_hp - (s32)getHP()) <<
(damage_handled ? " (handled by Lua)" : "") << std::endl;
+ // TODO: give Lua control over wear
return result.wear;
}
m_peer_id(peer_id_),
m_is_singleplayer(is_singleplayer)
{
- assert(m_peer_id != 0); // pre-condition
+ SANITY_CHECK(m_peer_id != PEER_ID_INEXISTENT);
m_prop.hp_max = PLAYER_MAX_HP_DEFAULT;
m_prop.breath_max = PLAYER_MAX_BREATH_DEFAULT;
m_prop.physical = false;
- m_prop.weight = 75;
m_prop.collisionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f);
m_prop.selectionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f);
m_prop.pointable = true;
void PlayerSAO::getStaticData(std::string * result) const
{
- FATAL_ERROR("Deprecated function");
+ FATAL_ERROR("Obsolete function");
}
void PlayerSAO::step(float dtime, bool send_recommended)
if (!isImmortal() && m_drowning_interval.step(dtime, 2.0f)) {
// Get nose/mouth position, approximate with eye position
v3s16 p = floatToInt(getEyePosition(), BS);
- MapNode n = m_env->getMap().getNodeNoEx(p);
+ MapNode n = m_env->getMap().getNode(p);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
// If node generates drown
if (c.drowning > 0 && m_hp > 0) {
if (m_breathing_interval.step(dtime, 0.5f) && !isImmortal()) {
// Get nose/mouth position, approximate with eye position
v3s16 p = floatToInt(getEyePosition(), BS);
- MapNode n = m_env->getMap().getNodeNoEx(p);
+ MapNode n = m_env->getMap().getNode(p);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
// If player is alive & not drowning & not in ignore & not immortal, breathe
if (m_breath < m_prop.breath_max && c.drowning == 0 &&
for (float dam_height = 0.1f; dam_height < dam_top; dam_height++) {
v3s16 p = floatToInt(m_base_position +
v3f(0.0f, dam_height * BS, 0.0f), BS);
- MapNode n = m_env->getMap().getNodeNoEx(p);
+ MapNode n = m_env->getMap().getNode(p);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
if (c.damage_per_second > damage_per_second) {
damage_per_second = c.damage_per_second;
// Top damage point
v3s16 ptop = floatToInt(m_base_position +
v3f(0.0f, dam_top * BS, 0.0f), BS);
- MapNode ntop = m_env->getMap().getNodeNoEx(ptop);
+ MapNode ntop = m_env->getMap().getNode(ptop);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(ntop);
if (c.damage_per_second > damage_per_second) {
damage_per_second = c.damage_per_second;
if (!send_recommended)
return;
- // If the object is attached client-side, don't waste bandwidth sending its
- // position or rotation to clients.
- if (m_position_not_sent && !isAttached()) {
+ if (m_position_not_sent) {
m_position_not_sent = false;
float update_interval = m_env->getSendRecommendedInterval();
v3f pos;
- if (isAttached()) // Just in case we ever do send attachment position too
- pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
+ // When attached, the position is only sent to clients where the
+ // parent isn't known
+ if (isAttached())
+ pos = m_last_good_position;
else
pos = m_base_position;
m_env->getGameDef()->SendMovePlayer(m_peer_id);
}
-int PlayerSAO::punch(v3f dir,
+u16 PlayerSAO::punch(v3f dir,
const ToolCapabilities *toolcap,
ServerActiveObject *puncher,
float time_from_last_punch)
return m_player->getWieldIndex();
}
-ItemStack PlayerSAO::getWieldedItem() const
+ItemStack PlayerSAO::getWieldedItem(ItemStack *selected, ItemStack *hand) const
{
- ItemStack selected_item, hand_item;
- return m_player->getWieldedItem(&selected_item, &hand_item);
+ return m_player->getWieldedItem(selected, hand);
}
bool PlayerSAO::setWieldedItem(const ItemStack &item)
void PlayerSAO::disconnected()
{
- m_peer_id = 0;
+ m_peer_id = PEER_ID_INEXISTENT;
m_pending_removal = true;
}