^ Called when player is to be respawned
^ Called _before_ repositioning of player occurs
^ return true in func to disable regular player placement
+minetest.register_on_joinplayer(func(ObjectRef))
+^ Called when a player joins the game
+minetest.register_on_leaveplayer(func(ObjectRef))
+^ Called when a player leaves the game
minetest.register_on_chat_message(func(name, message))
Other registration functions:
- settexturemod(mod)
- setsprite(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
-- texture selection based on yaw relative to camera
+ ^ Select sprite from spritesheet with optional animation and DM-style
+ texture selection based on yaw relative to camera
- get_entity_name() (DEPRECATED: Will be removed in a future version)
- get_luaentity()
Player-only: (no-op for other objects)
- get_look_dir(): get camera direction as a unit vector
- get_look_pitch(): pitch in radians
- get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
+- set_inventory_formspec(formspec)
+ ^ Redefine player's inventory form
+ ^ Should usually be called in on_joinplayer
+- get_inventory_formspec() -> formspec string
InvRef: Reference to an inventory
methods:
}
})
+--[[minetest.register_on_joinplayer(function(player)
+ minetest.after(3, function()
+ player:set_inventory_formspec("invsize[8,7.5;]"..
+ "image[1,0.6;1,2;player.png]"..
+ "list[current_player;main;0,3.5;8,4;]"..
+ "list[current_player;craft;3,0;3,3;]"..
+ "list[current_player;craftpreview;7,1;1,1;]")
+ end)
+end)]]
+
minetest.log("experimental modname="..dump(minetest.get_current_modname()))
minetest.log("experimental modpath="..dump(minetest.get_modpath("experimental")))
minetest.log("experimental worldpath="..dump(minetest.get_worldpath()))
}
infostream<<std::endl;
}
+ else if(command == TOCLIENT_INVENTORY_FORMSPEC)
+ {
+ std::string datastring((char*)&data[2], datasize-2);
+ std::istringstream is(datastring, std::ios_base::binary);
+
+ // Store formspec in LocalPlayer
+ Player *player = m_env.getLocalPlayer();
+ assert(player != NULL);
+ player->inventory_formspec = deSerializeLongString(is);
+ }
else
{
infostream<<"Client: Ignoring unknown command "
PROTOCOL_VERSION 11:
TileDef in ContentFeatures
Nodebox drawtype
+ Added after a release: TOCLIENT_INVENTORY_FORMSPEC
*/
#define PROTOCOL_VERSION 11
u16 len
u8[len] privilege
*/
+
+ TOCLIENT_INVENTORY_FORMSPEC = 0x42,
+ /*
+ u16 command
+ u32 len
+ u8[len] formspec
+ */
};
enum ToServerCommand
v3s16 m_p;
};
+class PlayerInventoryFormSource: public IFormSource
+{
+public:
+ PlayerInventoryFormSource(Client *client):
+ m_client(client)
+ {
+ }
+ std::string getForm()
+ {
+ LocalPlayer* player = m_client->getEnv().getLocalPlayer();
+ return player->inventory_formspec;
+ }
+
+ Client *m_client;
+};
+
/*
Hotbar draw routine
*/
InventoryLocation inventoryloc;
inventoryloc.setCurrentPlayer();
- menu->setFormSpec(
- "invsize[8,7.5;]"
- //"image[1,0.6;1,2;player.png]"
- "list[current_player;main;0,3.5;8,4;]"
- "list[current_player;craft;3,0;3,3;]"
- "list[current_player;craftpreview;7,1;1,1;]"
- , inventoryloc);
-
+ PlayerInventoryFormSource *src = new PlayerInventoryFormSource(&client);
+ assert(src);
+ menu->setFormSpec(src->getForm(), inventoryloc);
+ menu->setFormSource(new PlayerInventoryFormSource(&client));
menu->drop();
}
else if(input->wasKeyDown(EscapeKey))
inventory.addList("craft", 9);
inventory.addList("craftpreview", 1);
inventory.addList("craftresult", 1);
+
+ // Can be redefined via Lua
+ inventory_formspec = "invsize[8,7.5;]"
+ //"image[1,0.6;1,2;player.png]"
+ "list[current_player;main;0,3.5;8,4;]"
+ "list[current_player;craft;3,0;3,3;]"
+ "list[current_player;craftpreview;7,1;1,1;]";
}
Player::~Player()
u16 peer_id;
+ std::string inventory_formspec;
+
protected:
IGameDef *m_gamedef;
return 1;
}
+ // set_inventory_formspec(self, formspec)
+ static int l_set_inventory_formspec(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if(player == NULL) return 0;
+ std::string formspec = luaL_checkstring(L, 2);
+
+ player->inventory_formspec = formspec;
+ get_server(L)->reportInventoryFormspecModified(player->getName());
+ lua_pushboolean(L, true);
+ return 1;
+ }
+
+ // get_inventory_formspec(self) -> formspec
+ static int l_get_inventory_formspec(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if(player == NULL) return 0;
+
+ std::string formspec = player->inventory_formspec;
+ lua_pushlstring(L, formspec.c_str(), formspec.size());
+ return 1;
+ }
+
public:
ObjectRef(ServerActiveObject *object):
m_object(object)
method(ObjectRef, get_look_dir),
method(ObjectRef, get_look_pitch),
method(ObjectRef, get_look_yaw),
+ method(ObjectRef, set_inventory_formspec),
+ method(ObjectRef, get_inventory_formspec),
{0,0}
};
// Send privileges
SendPlayerPrivileges(peer_id);
+ // Send inventory formspec
+ SendPlayerInventoryFormspec(peer_id);
+
// Send inventory
UpdateCrafting(peer_id);
SendInventory(peer_id);
{
Player *player = m_env->getPlayer(peer_id);
assert(player);
+ if(player->peer_id == PEER_ID_INEXISTENT)
+ return;
+
std::set<std::string> privs;
scriptapi_get_auth(m_lua, player->getName(), NULL, &privs);
m_con.Send(peer_id, 0, data, true);
}
+void Server::SendPlayerInventoryFormspec(u16 peer_id)
+{
+ Player *player = m_env->getPlayer(peer_id);
+ assert(player);
+ if(player->peer_id == PEER_ID_INEXISTENT)
+ return;
+
+ std::ostringstream os(std::ios_base::binary);
+ writeU16(os, TOCLIENT_INVENTORY_FORMSPEC);
+ os<<serializeLongString(player->inventory_formspec);
+
+ // Make data buffer
+ std::string s = os.str();
+ SharedBuffer<u8> data((u8*)s.c_str(), s.size());
+ // Send as reliable
+ m_con.Send(peer_id, 0, data, true);
+}
+
s32 Server::playSound(const SimpleSoundSpec &spec,
const ServerSoundParams ¶ms)
{
}
}
+void Server::reportInventoryFormspecModified(const std::string &name)
+{
+ Player *player = m_env->getPlayer(name.c_str());
+ if(!player)
+ return;
+ SendPlayerInventoryFormspec(player->peer_id);
+}
+
// Saves g_settings to configpath given at initialization
void Server::saveConfig()
{
std::set<std::string> getPlayerEffectivePrivs(const std::string &name);
bool checkPriv(const std::string &name, const std::string &priv);
void reportPrivsModified(const std::string &name=""); // ""=all
+ void reportInventoryFormspecModified(const std::string &name);
// Saves g_settings to configpath given at initialization
void saveConfig();
void SendPlayerHP(u16 peer_id);
void SendMovePlayer(u16 peer_id);
void SendPlayerPrivileges(u16 peer_id);
+ void SendPlayerInventoryFormspec(u16 peer_id);
/*
Send a node removal/addition event to all clients except ignore_id.
Additionally, if far_players!=NULL, players further away than