Merge branch 'master' of git://github.com/celeron55/minetest

master
jachoo 2011-12-04 16:12:01 +01:00
commit e92ea680a9
8 changed files with 65 additions and 15 deletions

View File

@ -146,7 +146,9 @@
-- ^ Returns {name="ignore", ...} for unloaded area
-- - get_node_or_nil(pos)
-- ^ Returns nil for unloaded area
-- - add_luaentity(pos, name)
-- - get_node_light(pos, timeofday) -> 0...15 or nil
-- ^ timeofday: nil = current time, 0 = night, 0.5 = day
-- - add_entity(pos, name)
-- - add_item(pos, itemstring)
-- - add_rat(pos)
-- - add_firefly(pos)
@ -1333,7 +1335,7 @@ function nodeupdate_single(p)
n_bottom = minetest.env:get_node(p_bottom)
if n_bottom.name == "air" then
minetest.env:remove_node(p)
minetest.env:add_luaentity(p, "default:falling_"..n.name)
minetest.env:add_entity(p, "default:falling_"..n.name)
nodeupdate(p)
end
end
@ -1489,7 +1491,9 @@ minetest.register_on_chat_message(function(name, message)
print("Unable to spawn entity, player is nil")
return true -- Handled chat message
end
minetest.env:add_luaentity(player:getpos(), entityname)
local p = player:getpos()
p.y = p.y + 1
minetest.env:add_entity(p, entityname)
minetest.chat_send_player(name, '"'..entityname
..'" spawned.');
return true -- Handled chat message

View File

@ -1658,8 +1658,11 @@ std::string LuaEntitySAO::getStaticData()
void LuaEntitySAO::punch(ServerActiveObject *puncher, float time_from_last_punch)
{
if(!m_registered)
if(!m_registered){
// Delete unknown LuaEntities when punched
m_removed = true;
return;
}
lua_State *L = m_env->getLua();
scriptapi_luaentity_punch(L, m_id, puncher, time_from_last_punch);
}

View File

@ -104,9 +104,9 @@ HittingProperties getHittingProperties(const MaterialProperties *mp,
time_from_last_punch);
// If digging time would be 1 second, 2 hearts go in 1 second.
s16 hp = 2.0 * 2.0 / digprop.time + 0.5;
s16 hp = 2.0 * 2.0 / digprop.time;
// Wear is the same as for digging a single node
s16 wear = (float)digprop.wear + 0.5;
s16 wear = (float)digprop.wear;
return HittingProperties(hp, wear);
}

View File

@ -2402,11 +2402,39 @@ private:
}
}
// EnvRef:add_luaentity(pos, entityname)
// EnvRef:get_node_light(pos, timeofday)
// pos = {x=num, y=num, z=num}
static int l_add_luaentity(lua_State *L)
// timeofday: nil = current time, 0 = night, 0.5 = day
static int l_get_node_light(lua_State *L)
{
//infostream<<"EnvRef::l_add_luaentity()"<<std::endl;
EnvRef *o = checkobject(L, 1);
ServerEnvironment *env = o->m_env;
if(env == NULL) return 0;
// Do it
v3s16 pos = readpos(L, 2);
u32 time_of_day = env->getTimeOfDay();
if(lua_isnumber(L, 3))
time_of_day = 24000.0 * lua_tonumber(L, 3);
time_of_day %= 24000;
u32 dnr = time_to_daynight_ratio(time_of_day);
MapNode n = env->getMap().getNodeNoEx(pos);
try{
MapNode n = env->getMap().getNode(pos);
INodeDefManager *ndef = env->getGameDef()->ndef();
lua_pushinteger(L, n.getLightBlend(dnr, ndef));
return 1;
} catch(InvalidPositionException &e)
{
lua_pushnil(L);
return 1;
}
}
// EnvRef:add_entity(pos, entityname)
// pos = {x=num, y=num, z=num}
static int l_add_entity(lua_State *L)
{
//infostream<<"EnvRef::l_add_entity()"<<std::endl;
EnvRef *o = checkobject(L, 1);
ServerEnvironment *env = o->m_env;
if(env == NULL) return 0;
@ -2571,7 +2599,8 @@ const luaL_reg EnvRef::methods[] = {
method(EnvRef, remove_node),
method(EnvRef, get_node),
method(EnvRef, get_node_or_nil),
method(EnvRef, add_luaentity),
method(EnvRef, get_node_light),
method(EnvRef, add_entity),
method(EnvRef, add_item),
method(EnvRef, add_rat),
method(EnvRef, add_firefly),

View File

@ -2964,7 +2964,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
<<pointed.object_id<<std::endl;
// Do stuff
pointed_object->punch(srp);
pointed_object->punch(srp, srp->m_time_from_last_punch);
srp->m_time_from_last_punch = 0;
}
} // action == 0

View File

@ -31,11 +31,11 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env):
ServerActiveObject(env, v3f(0,0,0)),
m_last_good_position(0,0,0),
m_last_good_position_age(0),
m_additional_items(),
m_inventory_not_sent(false),
m_hp_not_sent(false),
m_respawn_active(false),
m_is_in_environment(false),
m_time_from_last_punch(0),
m_position_not_sent(false)
{
}
@ -43,9 +43,12 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 pee
const char *name_):
Player(env->getGameDef()),
ServerActiveObject(env, pos_),
m_last_good_position(0,0,0),
m_last_good_position_age(0),
m_inventory_not_sent(false),
m_hp_not_sent(false),
m_is_in_environment(false),
m_time_from_last_punch(0),
m_position_not_sent(false)
{
setPosition(pos_);
@ -93,6 +96,8 @@ bool ServerRemotePlayer::unlimitedTransferDistance() const
void ServerRemotePlayer::step(float dtime, bool send_recommended)
{
m_time_from_last_punch += dtime;
if(send_recommended == false)
return;
@ -157,9 +162,14 @@ void ServerRemotePlayer::punch(ServerActiveObject *puncher,
HittingProperties hitprop = getHittingProperties(&mp, &tp,
time_from_last_punch);
actionstream<<"Player "<<getName()<<" punched by "
<<puncher->getDescription()<<", damage "<<hitprop.hp
<<" HP"<<std::endl;
setHP(getHP() - hitprop.hp);
puncher->damageWieldedItem(hitprop.wear);
if(hitprop.hp != 0)
{
std::ostringstream os(std::ios::binary);
// command (1 = punched)

View File

@ -74,7 +74,8 @@ public:
void rightClick(ServerActiveObject *clicker);
void setPos(v3f pos);
void moveTo(v3f pos, bool continuous);
virtual std::string getDescription(){return getName();}
virtual std::string getDescription()
{return std::string("player ")+getName();}
virtual void getWieldDiggingProperties(ToolDiggingProperties *dst);
virtual void damageWieldedItem(u16 amount);
@ -93,6 +94,8 @@ public:
bool m_hp_not_sent;
bool m_respawn_active;
bool m_is_in_environment;
// Incremented by step(), read and reset by Server
float m_time_from_last_punch;
private:
bool m_position_not_sent;

View File

@ -38,7 +38,7 @@ struct ToolDiggingProperties
float dd_crumbliness;
float dd_cuttability;
ToolDiggingProperties(float full_punch_interval_=1.0,
ToolDiggingProperties(float full_punch_interval_=2.0,
float a=0.75, float b=0, float c=0, float d=0, float e=0,
float f=50, float g=0, float h=0, float i=0, float j=0);
};