Add ClientObjectRef:set_properties
This commit is contained in:
parent
7d7d4d675c
commit
6dc7a65d9e
@ -1414,6 +1414,7 @@ This is basically a reference to a C++ `GenericCAO`.
|
||||
* `get_nametag()`: returns the nametag (deprecated, use get_properties().nametag instead)
|
||||
* `get_item_textures()`: returns the textures (deprecated, use get_properties().textures instead)
|
||||
* `get_max_hp()`: returns the maximum heath (deprecated, use get_properties().hp_max instead)
|
||||
* `set_properties(object property table)`
|
||||
* `get_properties()`: returns object property table
|
||||
* `punch()`: punches the object
|
||||
* `rightclick()`: rightclicks the object
|
||||
|
@ -831,13 +831,13 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
|
||||
}
|
||||
|
||||
void GenericCAO::updateLight(u32 day_night_ratio)
|
||||
{
|
||||
{
|
||||
if (m_glow < 0)
|
||||
return;
|
||||
|
||||
u8 light_at_pos = 0;
|
||||
bool pos_ok = false;
|
||||
|
||||
|
||||
v3s16 pos[3];
|
||||
u16 npos = getLightPosition(pos);
|
||||
for (u16 i = 0; i < npos; i++) {
|
||||
@ -1629,6 +1629,57 @@ bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const
|
||||
(uses_legacy_texture && old.textures != new_.textures);
|
||||
}
|
||||
|
||||
void GenericCAO::setProperties(ObjectProperties newprops)
|
||||
{
|
||||
// Check what exactly changed
|
||||
bool expire_visuals = visualExpiryRequired(newprops);
|
||||
bool textures_changed = m_prop.textures != newprops.textures;
|
||||
|
||||
// Apply changes
|
||||
m_prop = std::move(newprops);
|
||||
|
||||
m_selection_box = m_prop.selectionbox;
|
||||
m_selection_box.MinEdge *= BS;
|
||||
m_selection_box.MaxEdge *= BS;
|
||||
|
||||
m_tx_size.X = 1.0f / m_prop.spritediv.X;
|
||||
m_tx_size.Y = 1.0f / m_prop.spritediv.Y;
|
||||
|
||||
if(!m_initial_tx_basepos_set){
|
||||
m_initial_tx_basepos_set = true;
|
||||
m_tx_basepos = m_prop.initial_sprite_basepos;
|
||||
}
|
||||
if (m_is_local_player) {
|
||||
LocalPlayer *player = m_env->getLocalPlayer();
|
||||
player->makes_footstep_sound = m_prop.makes_footstep_sound;
|
||||
aabb3f collision_box = m_prop.collisionbox;
|
||||
collision_box.MinEdge *= BS;
|
||||
collision_box.MaxEdge *= BS;
|
||||
player->setCollisionbox(collision_box);
|
||||
player->setEyeHeight(m_prop.eye_height);
|
||||
player->setZoomFOV(m_prop.zoom_fov);
|
||||
}
|
||||
|
||||
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
|
||||
m_prop.nametag = m_name;
|
||||
if (m_is_local_player)
|
||||
m_prop.show_on_minimap = false;
|
||||
|
||||
if (expire_visuals) {
|
||||
expireVisuals();
|
||||
} else {
|
||||
infostream << "GenericCAO: properties updated but expiring visuals"
|
||||
<< " not necessary" << std::endl;
|
||||
if (textures_changed) {
|
||||
// don't update while punch texture modifier is active
|
||||
if (m_reset_textures_timer < 0)
|
||||
updateTextures(m_current_texture_modifier);
|
||||
}
|
||||
updateNametag();
|
||||
updateMarker();
|
||||
}
|
||||
}
|
||||
|
||||
void GenericCAO::processMessage(const std::string &data)
|
||||
{
|
||||
//infostream<<"GenericCAO: Got message"<<std::endl;
|
||||
@ -1640,54 +1691,8 @@ void GenericCAO::processMessage(const std::string &data)
|
||||
newprops.show_on_minimap = m_is_player; // default
|
||||
|
||||
newprops.deSerialize(is);
|
||||
setProperties(newprops);
|
||||
|
||||
// Check what exactly changed
|
||||
bool expire_visuals = visualExpiryRequired(newprops);
|
||||
bool textures_changed = m_prop.textures != newprops.textures;
|
||||
|
||||
// Apply changes
|
||||
m_prop = std::move(newprops);
|
||||
|
||||
m_selection_box = m_prop.selectionbox;
|
||||
m_selection_box.MinEdge *= BS;
|
||||
m_selection_box.MaxEdge *= BS;
|
||||
|
||||
m_tx_size.X = 1.0f / m_prop.spritediv.X;
|
||||
m_tx_size.Y = 1.0f / m_prop.spritediv.Y;
|
||||
|
||||
if(!m_initial_tx_basepos_set){
|
||||
m_initial_tx_basepos_set = true;
|
||||
m_tx_basepos = m_prop.initial_sprite_basepos;
|
||||
}
|
||||
if (m_is_local_player) {
|
||||
LocalPlayer *player = m_env->getLocalPlayer();
|
||||
player->makes_footstep_sound = m_prop.makes_footstep_sound;
|
||||
aabb3f collision_box = m_prop.collisionbox;
|
||||
collision_box.MinEdge *= BS;
|
||||
collision_box.MaxEdge *= BS;
|
||||
player->setCollisionbox(collision_box);
|
||||
player->setEyeHeight(m_prop.eye_height);
|
||||
player->setZoomFOV(m_prop.zoom_fov);
|
||||
}
|
||||
|
||||
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
|
||||
m_prop.nametag = m_name;
|
||||
if (m_is_local_player)
|
||||
m_prop.show_on_minimap = false;
|
||||
|
||||
if (expire_visuals) {
|
||||
expireVisuals();
|
||||
} else {
|
||||
infostream << "GenericCAO: properties updated but expiring visuals"
|
||||
<< " not necessary" << std::endl;
|
||||
if (textures_changed) {
|
||||
// don't update while punch texture modifier is active
|
||||
if (m_reset_textures_timer < 0)
|
||||
updateTextures(m_current_texture_modifier);
|
||||
}
|
||||
updateNametag();
|
||||
updateMarker();
|
||||
}
|
||||
} else if (cmd == AO_CMD_UPDATE_POSITION) {
|
||||
// Not sent by the server if this object is an attachment.
|
||||
// We might however get here if the server notices the object being detached before the client.
|
||||
@ -1752,10 +1757,10 @@ void GenericCAO::processMessage(const std::string &data)
|
||||
if(m_is_local_player)
|
||||
{
|
||||
Client *client = m_env->getGameDef();
|
||||
|
||||
|
||||
if (client->modsLoaded() && client->getScript()->on_recieve_physics_override(override_speed, override_jump, override_gravity, sneak, sneak_glitch, new_move))
|
||||
return;
|
||||
|
||||
|
||||
LocalPlayer *player = m_env->getLocalPlayer();
|
||||
player->physics_override_speed = override_speed;
|
||||
player->physics_override_jump = override_jump;
|
||||
|
@ -181,7 +181,7 @@ public:
|
||||
{
|
||||
return m_velocity;
|
||||
}
|
||||
|
||||
|
||||
inline const u16 getHp() const
|
||||
{
|
||||
return m_hp;
|
||||
@ -307,13 +307,15 @@ public:
|
||||
{
|
||||
return m_prop.infotext;
|
||||
}
|
||||
|
||||
|
||||
float m_waiting_for_reattach;
|
||||
|
||||
|
||||
ObjectProperties *getProperties()
|
||||
{
|
||||
return &m_prop;
|
||||
}
|
||||
|
||||
void setProperties(ObjectProperties newprops);
|
||||
|
||||
void updateMeshCulling();
|
||||
};
|
||||
|
@ -200,7 +200,7 @@ void read_object_properties(lua_State *L, int index,
|
||||
if (getintfield(L, -1, "hp_max", hp_max)) {
|
||||
prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
|
||||
|
||||
if (prop->hp_max < sao->getHP()) {
|
||||
if (sao && prop->hp_max < sao->getHP()) {
|
||||
PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);
|
||||
sao->setHP(prop->hp_max, reason);
|
||||
if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER)
|
||||
@ -209,7 +209,7 @@ void read_object_properties(lua_State *L, int index,
|
||||
}
|
||||
|
||||
if (getintfield(L, -1, "breath_max", prop->breath_max)) {
|
||||
if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
|
||||
if (sao && sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
|
||||
PlayerSAO *player = (PlayerSAO *)sao;
|
||||
if (prop->breath_max < player->getBreath())
|
||||
player->setBreath(prop->breath_max);
|
||||
|
@ -160,6 +160,16 @@ int ClientObjectRef::l_get_properties(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_set_properties(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
ObjectProperties prop = *gcao->getProperties();
|
||||
read_object_properties(L, 2, nullptr, &prop, getClient(L)->idef());
|
||||
gcao->setProperties(prop);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_hp(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
@ -259,6 +269,7 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos),
|
||||
luamethod(ClientObjectRef, get_nametag),
|
||||
luamethod(ClientObjectRef, get_item_textures),
|
||||
luamethod(ClientObjectRef, get_properties),
|
||||
luamethod(ClientObjectRef, set_properties),
|
||||
luamethod(ClientObjectRef, get_hp),
|
||||
luamethod(ClientObjectRef, get_max_hp), luamethod(ClientObjectRef, punch),
|
||||
luamethod(ClientObjectRef, rightclick), {0, 0}};
|
||||
|
@ -75,12 +75,15 @@ private:
|
||||
// get_nametag(self)
|
||||
static int l_get_nametag(lua_State *L);
|
||||
|
||||
// get_textures(self)
|
||||
// get_item_textures(self)
|
||||
static int l_get_item_textures(lua_State *L);
|
||||
|
||||
// get_properties(self)
|
||||
static int l_get_properties(lua_State *L);
|
||||
|
||||
// set_properties(self, properties)
|
||||
static int l_set_properties(lua_State *L);
|
||||
|
||||
// get_hp(self)
|
||||
static int l_get_hp(lua_State *L);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user