Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some missing getter functions to the lua API #2722

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+665 −8
Diff settings

Always

Just for now

@@ -1932,6 +1932,7 @@ and `minetest.auth_reload` call the authetification handler.
* `flags` is a flag field with the available flags: `dungeon`, `temple`, `cave_begin`,
`cave_end`, `large_cave_begin`, `large_cave_end`, `decoration`
* The second parameter is a list of IDS of decorations which notification is requested for
* `get_gen_notify()`: returns a flagstring and a table with the deco_ids
* `minetest.get_mapgen_object(objectname)`
* Return requested mapgen object if available (see "Mapgen objects")
* `minetest.get_mapgen_params()` Returns mapgen parameters, a table containing
@@ -1950,6 +1951,7 @@ and `minetest.auth_reload` call the authetification handler.
* Sets the noiseparams setting of `name` to the noiseparams table specified in `noiseparams`.
* `set_default` is an optional boolean (default: `true`) that specifies whether the setting
should be applied to the default config or current active config
* `minetest.get_noiseparams(name)`: returns a table of the noiseparams for name
* `minetest.generate_ores(vm, pos1, pos2)`
* Generate all registered ores within the VoxelManip `vm` and in the area from `pos1` to `pos2`.
* `pos1` and `pos2` are optional and default to mapchunk minp and maxp.
@@ -2412,17 +2414,22 @@ This is basically a reference to a C++ `ServerActiveObject`
* `get_wielded_item()`: returns an `ItemStack`
* `set_wielded_item(item)`: replaces the wielded item, returns `true` if successful
* `set_armor_groups({group1=rating, group2=rating, ...})`
* `get_armor_groups()`: returns a table with the armor group ratings
* `set_animation({x=1,y=1}, frame_speed=15, frame_blend=0)`
* `get_animation()`: returns range, frame_speed and frame_blend
* `set_attach(parent, bone, position, rotation)`
* `bone`: string
* `position`: `{x=num, y=num, z=num}` (relative)
* `rotation`: `{x=num, y=num, z=num}`
* `get_attach()`: returns parent, bone, position, rotation or nil if it isn't attached
* `set_detach()`
* `set_bone_position(bone, position, rotation)`
* `bone`: string
* `position`: `{x=num, y=num, z=num}` (relative)
* `rotation`: `{x=num, y=num, z=num}`
* `get_bone_position(bone)`: returns position and rotation of the bone
* `set_properties(object property table)`
* `get_properties()`: returns object property table
* `is_player()`: returns true for players, false otherwise

##### LuaEntitySAO-only (no-op for other objects)
@@ -2468,6 +2475,7 @@ This is basically a reference to a C++ `ServerActiveObject`
* `gravity`: multiplier to default gravity value (default: `1`)
* `sneak`: whether player can sneak (default: `true`)
* `sneak_glitch`: whether player can use the sneak glitch (default: `true`)
* `get_physics_override()`: returns the table given to set_physics_override
* `hud_add(hud definition)`: add a HUD element described by HUD def, returns ID
number on success
* `hud_remove(id)`: remove the HUD element of the specified id
@@ -2482,10 +2490,13 @@ This is basically a reference to a C++ `ServerActiveObject`
* returns `{ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true }`
* `hud_set_hotbar_itemcount(count)`: sets number of items in builtin hotbar
* `count`: number of items, must be between `1` and `23`
* `hud_get_hotbar_itemcount`: returns number of visible items
* `hud_set_hotbar_image(texturename)`
* sets background image for hotbar
* `hud_get_hotbar_image`: returns texturename
* `hud_set_hotbar_selected_image(texturename)`
* sets image for selected item of hotbar
* `hud_get_hotbar_selected_image`: returns texturename
* `hud_replace_builtin(name, hud_definition)`
* replace definition of a builtin hud element
* `name`: `"breath"` or `"health"`
@@ -2498,10 +2509,12 @@ This is basically a reference to a C++ `ServerActiveObject`
* `"plain"`: Uses 0 textures, `bgcolor` used
* **Note**: currently does not work directly in `on_joinplayer`; use
`minetest.after(0)` in there.
* `get_sky()`: returns bgcolor, type and a table with the textures
* `override_day_night_ratio(ratio or nil)`
* `0`...`1`: Overrides day-night ratio, controlling sunlight to a specific amount
* `nil`: Disables override, defaulting to sunlight based on day-night cycle
* `set_local_animation(walk, dig, walk+dig, frame_speed=frame_speed)`
* `get_day_night_ratio()`: returns the ratio or nil if it isn't overridden
* `set_local_animation(stand/idle, walk, dig, walk+dig, frame_speed=frame_speed)`

set animation for player model in third person view

@@ -2510,10 +2523,11 @@ This is basically a reference to a C++ `ServerActiveObject`
{x=189, y=198}, -- < dig animation key frames
{x=200, y=219}, -- < walk+dig animation key frames
frame_speed=30): -- < animation frame speed

* `get_local_animation()`: returns stand, walk, dig, dig+walk tables and frame_speed
* `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
* in first person view
* in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
* `get_eye_offset()`: returns offset_first and offset_third
* `get_nametag_attributes()`
* returns a table with the attributes of the nametag of the player
* {
@@ -533,6 +533,11 @@ void LuaEntitySAO::setArmorGroups(const ItemGroupList &armor_groups)
m_armor_groups_sent = false;
}

ItemGroupList LuaEntitySAO::getArmorGroups()
{
return m_armor_groups;
}

void LuaEntitySAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend)
{
m_animation_range = frame_range;
@@ -541,12 +546,25 @@ void LuaEntitySAO::setAnimation(v2f frame_range, float frame_speed, float frame_
m_animation_sent = false;
}

void LuaEntitySAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend)
{
*frame_range = m_animation_range;
*frame_speed = m_animation_speed;
*frame_blend = m_animation_blend;
}

void LuaEntitySAO::setBonePosition(const std::string &bone, v3f position, v3f rotation)
{
m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
m_bone_position_sent = false;
}

void LuaEntitySAO::getBonePosition(const std::string &bone, v3f *position, v3f *rotation)
{
*position = m_bone_position[bone].X;
*rotation = m_bone_position[bone].Y;
}

void LuaEntitySAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation)
{
// Attachments need to be handled on both the server and client.
@@ -564,6 +582,15 @@ void LuaEntitySAO::setAttachment(int parent_id, const std::string &bone, v3f pos
m_attachment_sent = false;
}

void LuaEntitySAO::getAttachment(int *parent_id, std::string *bone, v3f *position,
v3f *rotation)
{
*parent_id = m_attachment_parent_id;
*bone = m_attachment_bone;
*position = m_attachment_position;
*rotation = m_attachment_rotation;
}

ObjectProperties* LuaEntitySAO::accessObjectProperties()
{
return &m_prop;
@@ -1133,6 +1160,11 @@ void PlayerSAO::setArmorGroups(const ItemGroupList &armor_groups)
m_armor_groups_sent = false;
}

ItemGroupList PlayerSAO::getArmorGroups()
{
return m_armor_groups;
}

void PlayerSAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend)
{
// store these so they can be updated to clients
@@ -1142,13 +1174,26 @@ void PlayerSAO::setAnimation(v2f frame_range, float frame_speed, float frame_ble
m_animation_sent = false;
}

void PlayerSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend)
{
*frame_range = m_animation_range;
*frame_speed = m_animation_speed;
*frame_blend = m_animation_blend;
}

void PlayerSAO::setBonePosition(const std::string &bone, v3f position, v3f rotation)
{
// store these so they can be updated to clients
m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
m_bone_position_sent = false;
}

void PlayerSAO::getBonePosition(const std::string &bone, v3f *position, v3f *rotation)
{
*position = m_bone_position[bone].X;
*rotation = m_bone_position[bone].Y;
}

void PlayerSAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation)
{
// Attachments need to be handled on both the server and client.
@@ -1166,6 +1211,15 @@ void PlayerSAO::setAttachment(int parent_id, const std::string &bone, v3f positi
m_attachment_sent = false;
}

void PlayerSAO::getAttachment(int *parent_id, std::string *bone, v3f *position,
v3f *rotation)
{
*parent_id = m_attachment_parent_id;
*bone = m_attachment_bone;
*position = m_attachment_position;
*rotation = m_attachment_rotation;
}

ObjectProperties* PlayerSAO::accessObjectProperties()
{
return &m_prop;
@@ -58,9 +58,13 @@ class LuaEntitySAO : public ServerActiveObject
void setHP(s16 hp);
s16 getHP() const;
void setArmorGroups(const ItemGroupList &armor_groups);
ItemGroupList getArmorGroups();
void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend);
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
/* LuaEntitySAO-specific */
@@ -192,9 +196,13 @@ class PlayerSAO : public ServerActiveObject
u16 getBreath() const;
void setBreath(u16 breath);
void setArmorGroups(const ItemGroupList &armor_groups);
ItemGroupList getArmorGroups();
void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend);
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
void setNametagColor(video::SColor color);
@@ -42,8 +42,6 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef, const char *name):
last_pitch(0),
last_yaw(0),
last_keyPressed(0),
eye_offset_first(v3f(0,0,0)),
eye_offset_third(v3f(0,0,0)),
last_animation(NO_ANIM),
hotbar_image(""),
hotbar_selected_image(""),
@@ -59,6 +57,8 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef, const char *name):
// Initialize hp to 0, so that no hearts will be shown if server
// doesn't support health points
hp = 0;
eye_offset_first = v3f(0,0,0);
eye_offset_third = v3f(0,0,0);
}

LocalPlayer::~LocalPlayer()
@@ -62,8 +62,6 @@ class LocalPlayer : public Player
unsigned int last_keyPressed;

float camera_impact;
v3f eye_offset_first;
v3f eye_offset_third;

int last_animation;
float last_animation_speed;
@@ -215,6 +215,56 @@ class Player
return size;
}

void setHotbarItemcount(s32 hotbar_itemcount) {
hud_hotbar_itemcount = hotbar_itemcount;
}
s32 getHotbarItemcount() {
return hud_hotbar_itemcount;
}
void setHotbarImage(std::string name) {
hud_hotbar_image = name;
}
std::string getHotbarImage() {
return hud_hotbar_image;
}
void setHotbarSelectedImage(std::string name) {
hud_hotbar_selected_image = name;
}
std::string getHotbarSelectedImage() {
return hud_hotbar_selected_image;
}

void setSky(const video::SColor &bgcolor, const std::string &type,
const std::vector<std::string> &params) {
m_sky_bgcolor = bgcolor;
m_sky_type = type;
m_sky_params = params;
}
void getSky(video::SColor *bgcolor, std::string *type,
std::vector<std::string> *params) {
*bgcolor = m_sky_bgcolor;
*type = m_sky_type;
*params = m_sky_params;
}
void overrideDayNightRatio(bool do_override, float ratio) {
m_day_night_ratio_do_override = do_override;
m_day_night_ratio = ratio;
}
void getDayNightRatio(bool *do_override, float *ratio) {
*do_override = m_day_night_ratio_do_override;
*ratio = m_day_night_ratio;
}
void setLocalAnimations(v2s32 frames[4], float frame_speed) {
for (int i = 0; i < 4; i++)
local_animations[i] = frames[i];
local_animation_speed = frame_speed;
}
void getLocalAnimations(v2s32 *frames, float *frame_speed) {
for (int i = 0; i < 4; i++)
frames[i] = local_animations[i];
*frame_speed = local_animation_speed;
}

virtual bool isLocal() const
{ return false; }
virtual PlayerSAO *getPlayerSAO()
@@ -255,6 +305,8 @@ class Player
bool is_climbing;
bool swimming_vertical;
bool camera_barely_in_ceiling;
v3f eye_offset_first;
v3f eye_offset_third;

Inventory inventory;

@@ -308,6 +360,8 @@ class Player

u32 hud_flags;
s32 hud_hotbar_itemcount;
std::string hud_hotbar_image;
std::string hud_hotbar_selected_image;
protected:
IGameDef *m_gamedef;

@@ -322,6 +376,13 @@ class Player
bool m_dirty;

std::vector<HudElement *> hud;

std::string m_sky_type;
video::SColor m_sky_bgcolor;
std::vector<std::string> m_sky_params;

bool m_day_night_ratio_do_override;
float m_day_night_ratio;
private:
// Protect some critical areas
// hud for example can be modified by EmergeThread
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.