-Minetest Lua Modding API Reference 0.4.0
+Minetest Lua Modding API Reference 0.4.3
==========================================
More information at http://c55.me/minetest/
^ Redefine player's inventory form
^ Should usually be called in on_joinplayer
- get_inventory_formspec() -> formspec string
-
+- get_player_control(): returns table with player pressed keys
+ {jump=bool,right=bool,left=bool,LMB=bool,RMB=bool,sneak=bool,aux1=bool,down=bool,up=bool}
+- get_player_control_bits(): returns integer with bit packed player pressed keys
+ bit nr/meaning: 0/up ,1/down ,2/left ,3/right ,4/jump ,5/aux1 ,6/sneak ,7/LMB ,8/RMB
+
InvRef: Reference to an inventory
methods:
- is_empty(listname): return true if list is empty
v3s32 speed(sf.X*100, sf.Y*100, sf.Z*100);
s32 pitch = myplayer->getPitch() * 100;
s32 yaw = myplayer->getYaw() * 100;
-
+ u32 keyPressed=myplayer->keyPressed;
/*
Format:
[0] u16 command
[2+12] v3s32 speed*100
[2+12+12] s32 pitch*100
[2+12+12+4] s32 yaw*100
+ [2+12+12+4+4] u32 keyPressed
*/
-
- SharedBuffer<u8> data(2+12+12+4+4);
+ SharedBuffer<u8> data(2+12+12+4+4+4);
writeU16(&data[0], TOSERVER_PLAYERPOS);
writeV3S32(&data[2], position);
writeV3S32(&data[2+12], speed);
writeS32(&data[2+12+12], pitch);
- writeS32(&data[2+12+12+4], yaw);
-
+ writeS32(&data[2+12+12+4], yaw);
+ writeU32(&data[2+12+12+4+4], keyPressed);
// Send as unreliable
Send(0, data, false);
}
PROTOCOL_VERSION 13:
InventoryList field "Width" (deserialization fails with old versions)
PROTOCOL_VERSION 14:
- New messages for mesh and bone animation, as well as attachments
+ Added transfer of player pressed keys to the server
+ Added new messages for mesh and bone animation, as well as attachments
GENERIC_CMD_SET_ANIMATION
GENERIC_CMD_SET_BONE_POSITION
GENERIC_CMD_SET_ATTACHMENT
[2+12] v3s32 speed*100
[2+12+12] s32 pitch*100
[2+12+12+4] s32 yaw*100
+ [2+12+12+4+4] u32 keyPressed
*/
TOSERVER_GOTBLOCKS = 0x24,
wname.c_str(), video::SColor(255,255,255,255), node);
m_textnode->setPosition(v3f(0, BS*1.1, 0));
}
-
+
updateNodePos();
+ updateAnimation();
+ updateBonePosition();
+ updateAttachments();
}
void expireVisuals()
removeFromScene(false);
addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
- updateAnimation();
- updateBonePosition();
- updateAttachments();
// Attachments, part 2: Now that the parent has been refreshed, put its attachments back
for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
{
if(m_prop.visual == "mesh")
{
- for (u32 i = 0; i < m_prop.textures.size(); ++i)
+ for (u32 i = 0; i < m_prop.textures.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
{
std::string texturestring = m_prop.textures[i];
if(texturestring == "")
m_animated_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
m_animated_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
}
- for (u32 i = 0; i < m_prop.colors.size(); ++i)
+ for (u32 i = 0; i < m_prop.colors.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
{
// This allows setting per-material colors. However, until a real lighting
// system is added, the code below will have no effect. Once MineTest
bool a_jump,
bool a_superspeed,
bool a_sneak,
+ bool a_LMB,
+ bool a_RMB,
float a_pitch,
float a_yaw*/
PlayerControl control(
input->isKeyDown(getKeySetting("keymap_jump")),
input->isKeyDown(getKeySetting("keymap_special1")),
input->isKeyDown(getKeySetting("keymap_sneak")),
+ input->getLeftState(),
+ input->getRightState(),
camera_pitch,
camera_yaw
);
client.setPlayerControl(control);
+ u32 keyPressed=
+ 1*(int)input->isKeyDown(getKeySetting("keymap_forward"))+
+ 2*(int)input->isKeyDown(getKeySetting("keymap_backward"))+
+ 4*(int)input->isKeyDown(getKeySetting("keymap_left"))+
+ 8*(int)input->isKeyDown(getKeySetting("keymap_right"))+
+ 16*(int)input->isKeyDown(getKeySetting("keymap_jump"))+
+ 32*(int)input->isKeyDown(getKeySetting("keymap_special1"))+
+ 64*(int)input->isKeyDown(getKeySetting("keymap_sneak"))+
+ 128*(int)input->getLeftState()+
+ 256*(int)input->getRightState();
+ LocalPlayer* player = client.getEnv().getLocalPlayer();
+ player->keyPressed=keyPressed;
}
/*
#include "player.h"
-struct PlayerControl
-{
- PlayerControl()
- {
- up = false;
- down = false;
- left = false;
- right = false;
- jump = false;
- aux1 = false;
- sneak = false;
- pitch = 0;
- yaw = 0;
- }
- PlayerControl(
- bool a_up,
- bool a_down,
- bool a_left,
- bool a_right,
- bool a_jump,
- bool a_aux1,
- bool a_sneak,
- float a_pitch,
- float a_yaw
- )
- {
- up = a_up;
- down = a_down;
- left = a_left;
- right = a_right;
- jump = a_jump;
- aux1 = a_aux1;
- sneak = a_sneak;
- pitch = a_pitch;
- yaw = a_yaw;
- }
- bool up;
- bool down;
- bool left;
- bool right;
- bool jump;
- bool aux1;
- bool sneak;
- float pitch;
- float yaw;
-};
-
class LocalPlayer : public Player
{
public:
void applyControl(float dtime);
v3s16 getStandingNodePos();
-
- PlayerControl control;
-
private:
// This is used for determining the sneaking range
v3s16 m_sneak_node;
#define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
+struct PlayerControl
+{
+ PlayerControl()
+ {
+ up = false;
+ down = false;
+ left = false;
+ right = false;
+ jump = false;
+ aux1 = false;
+ sneak = false;
+ LMB = false;
+ RMB = false;
+ pitch = 0;
+ yaw = 0;
+ }
+ PlayerControl(
+ bool a_up,
+ bool a_down,
+ bool a_left,
+ bool a_right,
+ bool a_jump,
+ bool a_aux1,
+ bool a_sneak,
+ bool a_LMB,
+ bool a_RMB,
+ float a_pitch,
+ float a_yaw
+ )
+ {
+ up = a_up;
+ down = a_down;
+ left = a_left;
+ right = a_right;
+ jump = a_jump;
+ aux1 = a_aux1;
+ sneak = a_sneak;
+ LMB = a_LMB;
+ RMB = a_RMB;
+ pitch = a_pitch;
+ yaw = a_yaw;
+ }
+ bool up;
+ bool down;
+ bool left;
+ bool right;
+ bool jump;
+ bool aux1;
+ bool sneak;
+ bool LMB;
+ bool RMB;
+ float pitch;
+ float yaw;
+};
+
class Map;
class IGameDef;
struct CollisionInfo;
u16 hp;
u16 peer_id;
-
+
std::string inventory_formspec;
-
+
+ PlayerControl control;
+ PlayerControl getPlayerControl()
+ {
+ return control;
+ }
+
+ u32 keyPressed;
+
protected:
IGameDef *m_gamedef;
void setPlayerSAO(PlayerSAO *sao)
{ m_sao = sao; }
void setPosition(const v3f &position);
-
+
private:
PlayerSAO *m_sao;
};
lua_pushlstring(L, formspec.c_str(), formspec.size());
return 1;
}
-
+
+ // get_player_control(self)
+ static int l_get_player_control(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if(player == NULL){
+ lua_pushlstring(L, "", 0);
+ return 1;
+ }
+ // Do it
+ PlayerControl control = player->getPlayerControl();
+ lua_newtable(L);
+ lua_pushboolean(L, control.up);
+ lua_setfield(L, -2, "up");
+ lua_pushboolean(L, control.down);
+ lua_setfield(L, -2, "down");
+ lua_pushboolean(L, control.left);
+ lua_setfield(L, -2, "left");
+ lua_pushboolean(L, control.right);
+ lua_setfield(L, -2, "right");
+ lua_pushboolean(L, control.jump);
+ lua_setfield(L, -2, "jump");
+ lua_pushboolean(L, control.aux1);
+ lua_setfield(L, -2, "aux1");
+ lua_pushboolean(L, control.sneak);
+ lua_setfield(L, -2, "sneak");
+ lua_pushboolean(L, control.LMB);
+ lua_setfield(L, -2, "LMB");
+ lua_pushboolean(L, control.RMB);
+ lua_setfield(L, -2, "RMB");
+ return 1;
+ }
+
+ // get_player_control_bits(self)
+ static int l_get_player_control_bits(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if(player == NULL){
+ lua_pushlstring(L, "", 0);
+ return 1;
+ }
+ // Do it
+ lua_pushnumber(L, player->keyPressed);
+ return 1;
+ }
+
public:
ObjectRef(ServerActiveObject *object):
m_object(object)
method(ObjectRef, get_look_yaw),
method(ObjectRef, set_inventory_formspec),
method(ObjectRef, get_inventory_formspec),
+ method(ObjectRef, get_player_control),
+ method(ObjectRef, get_player_control_bits),
{0,0}
};
if(command == TOSERVER_PLAYERPOS)
{
- if(datasize < 2+12+12+4+4)
+ if(datasize < 2+12+12+4+4+4)
return;
u32 start = 0;
v3s32 ss = readV3S32(&data[start+2+12]);
f32 pitch = (f32)readS32(&data[2+12+12]) / 100.0;
f32 yaw = (f32)readS32(&data[2+12+12+4]) / 100.0;
+ u32 keyPressed = (u32)readU32(&data[2+12+12+4+4]);
v3f position((f32)ps.X/100., (f32)ps.Y/100., (f32)ps.Z/100.);
v3f speed((f32)ss.X/100., (f32)ss.Y/100., (f32)ss.Z/100.);
pitch = wrapDegrees(pitch);
player->setSpeed(speed);
player->setPitch(pitch);
player->setYaw(yaw);
+ player->keyPressed=keyPressed;
+ player->control.up = (bool)(keyPressed&1);
+ player->control.down = (bool)(keyPressed&2);
+ player->control.left = (bool)(keyPressed&4);
+ player->control.right = (bool)(keyPressed&8);
+ player->control.jump = (bool)(keyPressed&16);
+ player->control.aux1 = (bool)(keyPressed&32);
+ player->control.sneak = (bool)(keyPressed&64);
+ player->control.LMB = (bool)(keyPressed&128);
+ player->control.RMB = (bool)(keyPressed&256);
/*infostream<<"Server::ProcessData(): Moved player "<<peer_id<<" to "
<<"("<<position.X<<","<<position.Y<<","<<position.Z<<")"
}
} // action == 4
+
/*
Catch invalid actions