Add Entity get_texture_mod() to Lua API
Send texture modifier to clients connecting later toomutilcraft-mt53
parent
72535d3328
commit
c57b4ff9b5
|
@ -2848,6 +2848,7 @@ This is basically a reference to a C++ `ServerActiveObject`
|
|||
* `set_yaw(radians)`
|
||||
* `get_yaw()`: returns number in radians
|
||||
* `set_texture_mod(mod)`
|
||||
* `get_texture_mod()` returns current texture modifier
|
||||
* `set_sprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
|
||||
select_horiz_by_yawpitch=false)`
|
||||
* Select sprite from spritesheet with optional animation and DM-style
|
||||
|
|
|
@ -574,6 +574,8 @@ GenericCAO::GenericCAO(Client *client, ClientEnvironment *env):
|
|||
m_anim_framelength(0.2),
|
||||
m_anim_timer(0),
|
||||
m_reset_textures_timer(-1),
|
||||
m_previous_texture_modifier(""),
|
||||
m_current_texture_modifier(""),
|
||||
m_visuals_expired(false),
|
||||
m_step_distance_counter(0),
|
||||
m_last_light(255),
|
||||
|
@ -952,7 +954,10 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr,
|
|||
infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
|
||||
<<"\" not supported"<<std::endl;
|
||||
}
|
||||
updateTextures("");
|
||||
|
||||
/* don't update while punch texture modifier is active */
|
||||
if (m_reset_textures_timer < 0)
|
||||
updateTextures(m_current_texture_modifier);
|
||||
|
||||
scene::ISceneNode *node = getSceneNode();
|
||||
if (node && m_prop.nametag != "" && !m_is_local_player) {
|
||||
|
@ -1221,9 +1226,9 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
|
|||
if(m_reset_textures_timer >= 0)
|
||||
{
|
||||
m_reset_textures_timer -= dtime;
|
||||
if(m_reset_textures_timer <= 0){
|
||||
if(m_reset_textures_timer <= 0) {
|
||||
m_reset_textures_timer = -1;
|
||||
updateTextures("");
|
||||
updateTextures(m_previous_texture_modifier);
|
||||
}
|
||||
}
|
||||
if(getParent() == NULL && fabs(m_prop.automatic_rotate) > 0.001)
|
||||
|
@ -1301,7 +1306,7 @@ void GenericCAO::updateTexturePos()
|
|||
}
|
||||
}
|
||||
|
||||
void GenericCAO::updateTextures(const std::string &mod)
|
||||
void GenericCAO::updateTextures(const std::string mod)
|
||||
{
|
||||
ITextureSource *tsrc = m_client->tsrc();
|
||||
|
||||
|
@ -1309,6 +1314,9 @@ void GenericCAO::updateTextures(const std::string &mod)
|
|||
bool use_bilinear_filter = g_settings->getBool("bilinear_filter");
|
||||
bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
|
||||
|
||||
m_previous_texture_modifier = m_current_texture_modifier;
|
||||
m_current_texture_modifier = mod;
|
||||
|
||||
if(m_spritenode)
|
||||
{
|
||||
if(m_prop.visual == "sprite")
|
||||
|
@ -1611,6 +1619,12 @@ void GenericCAO::processMessage(const std::string &data)
|
|||
updateNodePos();
|
||||
} else if (cmd == GENERIC_CMD_SET_TEXTURE_MOD) {
|
||||
std::string mod = deSerializeString(is);
|
||||
|
||||
// immediatly reset a engine issued texture modifier if a mod sends a different one
|
||||
if (m_reset_textures_timer > 0) {
|
||||
m_reset_textures_timer = -1;
|
||||
updateTextures(m_previous_texture_modifier);
|
||||
}
|
||||
updateTextures(mod);
|
||||
} else if (cmd == GENERIC_CMD_SET_SPRITE) {
|
||||
v2s16 p = readV2S16(is);
|
||||
|
@ -1734,7 +1748,7 @@ void GenericCAO::processMessage(const std::string &data)
|
|||
m_reset_textures_timer = 0.05;
|
||||
if(damage >= 2)
|
||||
m_reset_textures_timer += 0.05 * damage;
|
||||
updateTextures("^[brighten");
|
||||
updateTextures(m_current_texture_modifier + "^[brighten");
|
||||
}
|
||||
}
|
||||
} else if (cmd == GENERIC_CMD_UPDATE_ARMOR_GROUPS) {
|
||||
|
@ -1802,7 +1816,7 @@ bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem,
|
|||
m_reset_textures_timer = 0.05;
|
||||
if(result.damage >= 2)
|
||||
m_reset_textures_timer += 0.05 * result.damage;
|
||||
updateTextures("^[brighten");
|
||||
updateTextures(m_current_texture_modifier + "^[brighten");
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -102,6 +102,8 @@ private:
|
|||
float m_anim_timer;
|
||||
ItemGroupList m_armor_groups;
|
||||
float m_reset_textures_timer;
|
||||
std::string m_previous_texture_modifier; // stores texture modifier before punch update
|
||||
std::string m_current_texture_modifier; // last applied texture modifier
|
||||
bool m_visuals_expired;
|
||||
float m_step_distance_counter;
|
||||
u8 m_last_light;
|
||||
|
@ -198,7 +200,7 @@ public:
|
|||
|
||||
void updateTexturePos();
|
||||
|
||||
void updateTextures(const std::string &mod);
|
||||
void updateTextures(const std::string mod);
|
||||
|
||||
void updateAnimation();
|
||||
|
||||
|
|
|
@ -257,7 +257,8 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
|
|||
m_last_sent_position(0,0,0),
|
||||
m_last_sent_velocity(0,0,0),
|
||||
m_last_sent_position_timer(0),
|
||||
m_last_sent_move_precision(0)
|
||||
m_last_sent_move_precision(0),
|
||||
m_current_texture_modifier("")
|
||||
{
|
||||
// Only register type if no environment supplied
|
||||
if(env == NULL){
|
||||
|
@ -511,6 +512,9 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
|
|||
}
|
||||
}
|
||||
|
||||
msg_os << serializeLongString(gob_cmd_set_texture_mod(m_current_texture_modifier));
|
||||
message_count++;
|
||||
|
||||
writeU8(os, message_count);
|
||||
os.write(msg_os.str().c_str(), msg_os.str().size());
|
||||
}
|
||||
|
@ -687,11 +691,17 @@ v3f LuaEntitySAO::getAcceleration()
|
|||
void LuaEntitySAO::setTextureMod(const std::string &mod)
|
||||
{
|
||||
std::string str = gob_cmd_set_texture_mod(mod);
|
||||
m_current_texture_modifier = mod;
|
||||
// create message and add to list
|
||||
ActiveObjectMessage aom(getId(), true, str);
|
||||
m_messages_out.push(aom);
|
||||
}
|
||||
|
||||
std::string LuaEntitySAO::getTextureMod() const
|
||||
{
|
||||
return m_current_texture_modifier;
|
||||
}
|
||||
|
||||
void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength,
|
||||
bool select_horiz_by_yawpitch)
|
||||
{
|
||||
|
|
|
@ -122,6 +122,7 @@ public:
|
|||
v3f getAcceleration();
|
||||
|
||||
void setTextureMod(const std::string &mod);
|
||||
std::string getTextureMod() const;
|
||||
void setSprite(v2s16 p, int num_frames, float framelength,
|
||||
bool select_horiz_by_yawpitch);
|
||||
std::string getName();
|
||||
|
@ -143,6 +144,7 @@ private:
|
|||
v3f m_last_sent_velocity;
|
||||
float m_last_sent_position_timer;
|
||||
float m_last_sent_move_precision;
|
||||
std::string m_current_texture_modifier;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -900,6 +900,19 @@ int ObjectRef::l_set_texture_mod(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// get_texture_mod(self)
|
||||
int ObjectRef::l_get_texture_mod(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
ObjectRef *ref = checkobject(L, 1);
|
||||
LuaEntitySAO *co = getluaobject(ref);
|
||||
if (co == NULL) return 0;
|
||||
// Do it
|
||||
std::string mod = co->getTextureMod();
|
||||
lua_pushstring(L, mod.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
|
||||
// select_horiz_by_yawpitch=false)
|
||||
int ObjectRef::l_set_sprite(lua_State *L)
|
||||
|
|
|
@ -164,6 +164,9 @@ private:
|
|||
// set_texture_mod(self, mod)
|
||||
static int l_set_texture_mod(lua_State *L);
|
||||
|
||||
// l_get_texture_mod(self)
|
||||
static int l_get_texture_mod(lua_State *L);
|
||||
|
||||
// set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
|
||||
// select_horiz_by_yawpitch=false)
|
||||
static int l_set_sprite(lua_State *L);
|
||||
|
|
Loading…
Reference in New Issue