u8 version2 = 0;
u8 version = readU8(is);
- name = deSerializeString(is);
- state = deSerializeLongString(is);
+ name = deSerializeString16(is);
+ state = deSerializeString32(is);
if (version < 1)
break;
m_env->getScriptIface()->
luaentity_Activate(m_id, m_init_state, dtime_s);
} else {
+ // It's an unknown object
+ // Use entitystring as infotext for debugging
m_prop.infotext = m_init_name;
+ // Set unknown object texture
+ m_prop.textures.clear();
+ m_prop.textures.emplace_back("unknown_object.png");
}
}
+void LuaEntitySAO::dispatchScriptDeactivate(bool removal)
+{
+ // Ensure that this is in fact a registered entity,
+ // and that it isn't already gone.
+ // The latter also prevents this from ever being called twice.
+ if (m_registered && !isGone())
+ m_env->getScriptIface()->luaentity_Deactivate(m_id, removal);
+}
+
void LuaEntitySAO::step(float dtime, bool send_recommended)
{
if(!m_properties_sent)
// Each frame, parent position is copied if the object is attached, otherwise it's calculated normally
// If the object gets detached this comes into effect automatically from the last known origin
- if(isAttached())
- {
- v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
- m_base_position = pos;
+ if (auto *parent = getParent()) {
+ m_base_position = parent->getBasePosition();
m_velocity = v3f(0,0,0);
m_acceleration = v3f(0,0,0);
- }
- else
- {
+ } else {
if(m_prop.physical){
aabb3f box = m_prop.collisionbox;
box.MinEdge *= BS;
m_velocity = p_velocity;
m_acceleration = p_acceleration;
} else {
- m_base_position += dtime * m_velocity + 0.5 * dtime
- * dtime * m_acceleration;
+ m_base_position += (m_velocity + m_acceleration * 0.5f * dtime) * dtime;
m_velocity += dtime * m_acceleration;
}
}
}
+ if (fabs(m_prop.automatic_rotate) > 0.001f) {
+ m_rotation_add_yaw = modulo360f(m_rotation_add_yaw + dtime * core::RADTODEG *
+ m_prop.automatic_rotate);
+ }
+
if(m_registered) {
m_env->getScriptIface()->luaentity_Step(m_id, dtime, moveresult_p);
}
// PROTOCOL_VERSION >= 37
writeU8(os, 1); // version
- os << serializeString(""); // name
+ os << serializeString16(""); // name
writeU8(os, 0); // is_player
writeU16(os, getId()); //id
writeV3F32(os, m_base_position);
writeU16(os, m_hp);
std::ostringstream msg_os(std::ios::binary);
- msg_os << serializeLongString(getPropertyPacket()); // message 1
- msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2
- msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3
+ msg_os << serializeString32(getPropertyPacket()); // message 1
+ msg_os << serializeString32(generateUpdateArmorGroupsCommand()); // 2
+ msg_os << serializeString32(generateUpdateAnimationCommand()); // 3
for (const auto &bone_pos : m_bone_position) {
- msg_os << serializeLongString(generateUpdateBonePositionCommand(
- bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // m_bone_position.size
+ msg_os << serializeString32(generateUpdateBonePositionCommand(
+ bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // 3 + N
}
- msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4
+ msg_os << serializeString32(generateUpdateAttachmentCommand()); // 4 + m_bone_position.size
int message_count = 4 + m_bone_position.size();
for (const auto &id : getAttachmentChildIds()) {
if (ServerActiveObject *obj = m_env->getActiveObject(id)) {
message_count++;
- msg_os << serializeLongString(obj->generateUpdateInfantCommand(
+ msg_os << serializeString32(obj->generateUpdateInfantCommand(
id, protocol_version));
}
}
- msg_os << serializeLongString(generateSetTextureModCommand());
+ msg_os << serializeString32(generateSetTextureModCommand());
message_count++;
writeU8(os, message_count);
// version must be 1 to keep backwards-compatibility. See version2
writeU8(os, 1);
// name
- os<<serializeString(m_init_name);
+ os<<serializeString16(m_init_name);
// state
if(m_registered){
std::string state = m_env->getScriptIface()->
luaentity_GetStaticdata(m_id);
- os<<serializeLongString(state);
+ os<<serializeString32(state);
} else {
- os<<serializeLongString(m_init_state);
+ os<<serializeString32(m_init_state);
}
writeU16(os, m_hp);
- writeV3F1000(os, m_velocity);
+ writeV3F1000(os, clampToF1000(m_velocity));
// yaw
writeF1000(os, m_rotation.Y);
*result = os.str();
}
-u16 LuaEntitySAO::punch(v3f dir,
+u32 LuaEntitySAO::punch(v3f dir,
const ToolCapabilities *toolcap,
ServerActiveObject *puncher,
- float time_from_last_punch)
+ float time_from_last_punch,
+ u16 initial_wear)
{
if (!m_registered) {
// Delete unknown LuaEntities when punched
- m_pending_removal = true;
+ markForRemoval();
return 0;
}
m_armor_groups,
toolcap,
&tool_item,
- time_from_last_punch);
+ time_from_last_punch,
+ initial_wear);
bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
time_from_last_punch, toolcap, dir, result.did_punch ? result.damage : 0);
if (result.did_punch) {
setHP((s32)getHP() - result.damage,
PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
-
- // create message and add to list
- sendPunchCommand();
}
}
- if (getHP() == 0 && !isGone()) {
- clearParentAttachment();
- clearChildAttachments();
- m_env->getScriptIface()->luaentity_on_death(m_id, puncher);
- m_pending_removal = true;
- }
-
actionstream << puncher->getDescription() << " (id=" << puncher->getId() <<
", hp=" << puncher->getHP() << ") punched " <<
getDescription() << " (id=" << m_id << ", hp=" << m_hp <<
void LuaEntitySAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
{
m_hp = rangelim(hp, 0, U16_MAX);
+
+ sendPunchCommand();
+
+ if (m_hp == 0 && !isGone()) {
+ clearParentAttachment();
+ clearChildAttachments();
+ if (m_registered) {
+ ServerActiveObject *killer = nullptr;
+ if (reason.type == PlayerHPChangeReason::PLAYER_PUNCH)
+ killer = reason.object;
+ m_env->getScriptIface()->luaentity_on_death(m_id, killer);
+ }
+ markForRemoval();
+ }
}
u16 LuaEntitySAO::getHP() const
// command
writeU8(os, AO_CMD_SET_TEXTURE_MOD);
// parameters
- os << serializeString(m_current_texture_modifier);
+ os << serializeString16(m_current_texture_modifier);
return os.str();
}
if(isAttached())
return;
+ // Send attachment updates instantly to the client prior updating position
+ sendOutdatedData();
+
m_last_sent_move_precision = m_base_position.getDistanceFrom(
m_last_sent_position);
m_last_sent_position_timer = 0;