mirror of
https://github.com/minetest/minetest.git
synced 2024-08-18 20:44:16 +02:00
Implement on_rightclickplayer callback (#10775)
Co-authored-by: rubenwardy <rw@rubenwardy.com>
This commit is contained in:
parent
fcb3ed840a
commit
08ee9794fb
@ -617,6 +617,7 @@ core.registered_can_bypass_userlimit, core.register_can_bypass_userlimit = make_
|
||||
core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration()
|
||||
core.registered_on_player_inventory_actions, core.register_on_player_inventory_action = make_registration()
|
||||
core.registered_allow_player_inventory_actions, core.register_allow_player_inventory_action = make_registration()
|
||||
core.registered_on_rightclickplayers, core.register_on_rightclickplayer = make_registration()
|
||||
|
||||
--
|
||||
-- Compatibility for on_mapgen_init()
|
||||
|
@ -2113,7 +2113,7 @@ Examples
|
||||
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;]
|
||||
|
||||
|
||||
Version History
|
||||
---------------
|
||||
|
||||
@ -4587,6 +4587,10 @@ Call these functions only at load time!
|
||||
the puncher to the punched.
|
||||
* `damage`: Number that represents the damage calculated by the engine
|
||||
* should return `true` to prevent the default damage mechanism
|
||||
* `minetest.register_on_rightclickplayer(function(player, clicker))`
|
||||
* Called when a player is right-clicked
|
||||
* `player`: ObjectRef - Player that was right-clicked
|
||||
* `clicker`: ObjectRef - Object that right-clicked, may or may not be a player
|
||||
* `minetest.register_on_player_hpchange(function(player, hp_change, reason), modifier)`
|
||||
* Called when the player gets damaged or healed
|
||||
* `player`: ObjectRef of the player
|
||||
@ -7641,12 +7645,12 @@ Used by `minetest.register_node`.
|
||||
-- intensity: 1.0 = mid range of regular TNT.
|
||||
-- If defined, called when an explosion touches the node, instead of
|
||||
-- removing the node.
|
||||
|
||||
|
||||
mod_origin = "modname",
|
||||
-- stores which mod actually registered a node
|
||||
-- if it can not find a source, returns "??"
|
||||
-- useful for getting what mod truly registered something
|
||||
-- example: if a node is registered as ":othermodname:nodename",
|
||||
-- example: if a node is registered as ":othermodname:nodename",
|
||||
-- nodename will show "othermodname", but mod_orgin will say "modname"
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,19 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player,
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player,
|
||||
ServerActiveObject *clicker)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
// Get core.registered_on_rightclickplayers
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_rightclickplayers");
|
||||
// Call callbacks
|
||||
objectrefGetOrCreate(L, player);
|
||||
objectrefGetOrCreate(L, clicker);
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
|
||||
s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,
|
||||
s32 hp_change, const PlayerHPChangeReason &reason)
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter,
|
||||
float time_from_last_punch, const ToolCapabilities *toolcap,
|
||||
v3f dir, s16 damage);
|
||||
void on_rightclickplayer(ServerActiveObject *player, ServerActiveObject *clicker);
|
||||
s32 on_player_hpchange(ServerActiveObject *player, s32 hp_change,
|
||||
const PlayerHPChangeReason &reason);
|
||||
void on_playerReceiveFields(ServerActiveObject *player,
|
||||
|
@ -456,6 +456,11 @@ u16 PlayerSAO::punch(v3f dir,
|
||||
return hitparams.wear;
|
||||
}
|
||||
|
||||
void PlayerSAO::rightClick(ServerActiveObject *clicker)
|
||||
{
|
||||
m_env->getScriptIface()->on_rightclickplayer(this, clicker);
|
||||
}
|
||||
|
||||
void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
|
||||
{
|
||||
if (hp == (s32)m_hp)
|
||||
|
@ -111,7 +111,7 @@ public:
|
||||
|
||||
u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
|
||||
float time_from_last_punch);
|
||||
void rightClick(ServerActiveObject *clicker) {}
|
||||
void rightClick(ServerActiveObject *clicker);
|
||||
void setHP(s32 hp, const PlayerHPChangeReason &reason);
|
||||
void setHPRaw(u16 hp) { m_hp = hp; }
|
||||
s16 readDamage();
|
||||
|
Loading…
Reference in New Issue
Block a user