getboolfield(L, index, "liquids_pointable", def.liquids_pointable);
- warn_if_field_exists(L, index, "tool_digging_properties",
- "Obsolete; use tool_capabilities");
-
lua_getfield(L, index, "tool_capabilities");
if(lua_istable(L, -1)){
def.tool_capabilities = new ToolCapabilities(
// "" = no prediction
getstringfield(L, index, "node_placement_prediction",
def.node_placement_prediction);
+
+ getintfield(L, index, "place_param2", def.place_param2);
}
/******************************************************************************/
lua_setfield(L, -2, "name");
lua_pushstring(L, i.description.c_str());
lua_setfield(L, -2, "description");
- lua_pushstring(L, i.short_description.c_str());
- lua_setfield(L, -2, "short_description");
+ if (!i.short_description.empty()) {
+ lua_pushstring(L, i.short_description.c_str());
+ lua_setfield(L, -2, "short_description");
+ }
lua_pushstring(L, type.c_str());
lua_setfield(L, -2, "type");
lua_pushstring(L, i.inventory_image.c_str());
if (getintfield(L, -1, "hp_max", hp_max)) {
prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
- if (prop->hp_max < sao->getHP()) {
+ if (sao && prop->hp_max < sao->getHP()) {
PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);
sao->setHP(prop->hp_max, reason);
- if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER)
- sao->getEnv()->getGameDef()->SendPlayerHPOrDie((PlayerSAO *)sao, reason);
}
}
if (getintfield(L, -1, "breath_max", prop->breath_max)) {
- if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
+ if (sao && sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
PlayerSAO *player = (PlayerSAO *)sao;
if (prop->breath_max < player->getBreath())
player->setBreath(prop->breath_max);
prop->nametag_color = color;
}
lua_pop(L, 1);
+ lua_getfield(L, -1, "nametag_bgcolor");
+ if (!lua_isnil(L, -1)) {
+ if (lua_toboolean(L, -1)) {
+ video::SColor color;
+ if (read_color(L, -1, &color))
+ prop->nametag_bgcolor = color;
+ } else {
+ prop->nametag_bgcolor = nullopt;
+ }
+ }
+ lua_pop(L, 1);
lua_getfield(L, -1, "automatic_face_movement_max_rotation_per_sec");
if (lua_isnumber(L, -1)) {
lua_setfield(L, -2, "nametag");
push_ARGB8(L, prop->nametag_color);
lua_setfield(L, -2, "nametag_color");
+ if (prop->nametag_bgcolor) {
+ push_ARGB8(L, prop->nametag_bgcolor.value());
+ lua_setfield(L, -2, "nametag_bgcolor");
+ } else {
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "nametag_bgcolor");
+ }
lua_pushnumber(L, prop->automatic_face_movement_max_rotation_per_sec);
lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec");
lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size());
return tiledef;
}
+/******************************************************************************/
+void push_tiledef(lua_State *L, TileDef tiledef)
+{
+ lua_newtable(L);
+ setstringfield(L, -1, "name", tiledef.name);
+ setboolfield(L, -1, "backface_culling", tiledef.backface_culling);
+ setboolfield(L, -1, "tileable_horizontal", tiledef.tileable_horizontal);
+ setboolfield(L, -1, "tileable_vertical", tiledef.tileable_vertical);
+ std::string align_style;
+ switch (tiledef.align_style) {
+ case ALIGN_STYLE_USER_DEFINED:
+ align_style = "user";
+ break;
+ case ALIGN_STYLE_WORLD:
+ align_style = "world";
+ break;
+ default:
+ align_style = "node";
+ }
+ setstringfield(L, -1, "align_style", align_style);
+ setintfield(L, -1, "scale", tiledef.scale);
+ if (tiledef.has_color) {
+ push_ARGB8(L, tiledef.color);
+ lua_setfield(L, -2, "color");
+ }
+ push_animation_definition(L, tiledef.animation);
+ lua_setfield(L, -2, "animation");
+}
+
/******************************************************************************/
void read_content_features(lua_State *L, ContentFeatures &f, int index)
{
}
lua_pop(L, 1);
- f.alpha = getintfield_default(L, index, "alpha", 255);
+ /* alpha & use_texture_alpha */
+ // This is a bit complicated due to compatibility
+
+ f.setDefaultAlphaMode();
+
+ warn_if_field_exists(L, index, "alpha",
+ "Obsolete, only limited compatibility provided; "
+ "replaced by \"use_texture_alpha\"");
+ if (getintfield_default(L, index, "alpha", 255) != 255)
+ f.alpha = ALPHAMODE_BLEND;
+
+ lua_getfield(L, index, "use_texture_alpha");
+ if (lua_isboolean(L, -1)) {
+ warn_if_field_exists(L, index, "use_texture_alpha",
+ "Boolean values are deprecated; use the new choices");
+ if (lua_toboolean(L, -1))
+ f.alpha = (f.drawtype == NDT_NORMAL) ? ALPHAMODE_CLIP : ALPHAMODE_BLEND;
+ } else if (check_field_or_nil(L, -1, LUA_TSTRING, "use_texture_alpha")) {
+ int result = f.alpha;
+ string_to_enum(ScriptApiNode::es_TextureAlphaMode, result,
+ std::string(lua_tostring(L, -1)));
+ f.alpha = static_cast<enum AlphaMode>(result);
+ }
+ lua_pop(L, 1);
- bool usealpha = getboolfield_default(L, index,
- "use_texture_alpha", false);
- if (usealpha)
- f.alpha = 0;
+ /* Other stuff */
- // Read node color.
lua_getfield(L, index, "color");
read_color(L, -1, &f.color);
lua_pop(L, 1);
getstringfield(L, index, "palette", f.palette_name);
- /* Other stuff */
-
lua_getfield(L, index, "post_effect_color");
read_color(L, -1, &f.post_effect_color);
lua_pop(L, 1);
if (!f.palette_name.empty() &&
!(f.param_type_2 == CPT2_COLOR ||
f.param_type_2 == CPT2_COLORED_FACEDIR ||
- f.param_type_2 == CPT2_COLORED_WALLMOUNTED))
+ f.param_type_2 == CPT2_COLORED_WALLMOUNTED ||
+ f.param_type_2 == CPT2_COLORED_DEGROTATE))
warningstream << "Node " << f.name.c_str()
<< " has a palette, but not a suitable paramtype2." << std::endl;
- // Warn about some obsolete fields
- warn_if_field_exists(L, index, "wall_mounted",
- "Obsolete; use paramtype2 = 'wallmounted'");
- warn_if_field_exists(L, index, "light_propagates",
- "Obsolete; determined from paramtype");
- warn_if_field_exists(L, index, "dug_item",
- "Obsolete; use 'drop' field");
- warn_if_field_exists(L, index, "extra_dug_item",
- "Obsolete; use 'drop' field");
- warn_if_field_exists(L, index, "extra_dug_item_rarity",
- "Obsolete; use 'drop' field");
- warn_if_field_exists(L, index, "metadata_name",
- "Obsolete; use on_add and metadata callbacks");
-
// True for all ground-like things like stone and mud, false for eg. trees
getboolfield(L, index, "is_ground_content", f.is_ground_content);
f.light_propagates = (f.param_type == CPT_LIGHT);
// the slowest possible
f.liquid_viscosity = getintfield_default(L, index,
"liquid_viscosity", f.liquid_viscosity);
+ // If move_resistance is not set explicitly,
+ // move_resistance is equal to liquid_viscosity
+ f.move_resistance = f.liquid_viscosity;
f.liquid_range = getintfield_default(L, index,
"liquid_range", f.liquid_range);
f.leveled = getintfield_default(L, index, "leveled", f.leveled);
getstringfield(L, index, "node_dig_prediction",
f.node_dig_prediction);
+ // How much the node slows down players, ranging from 1 to 7,
+ // the higher, the slower.
+ f.move_resistance = getintfield_default(L, index,
+ "move_resistance", f.move_resistance);
+
+ // Whether e.g. players in this node will have liquid movement physics
+ lua_getfield(L, index, "liquid_move_physics");
+ if(lua_isboolean(L, -1)) {
+ f.liquid_move_physics = lua_toboolean(L, -1);
+ } else if(lua_isnil(L, -1)) {
+ f.liquid_move_physics = f.liquid_type != LIQUID_NONE;
+ } else {
+ errorstream << "Field \"liquid_move_physics\": Invalid type!" << std::endl;
+ }
+ lua_pop(L, 1);
}
void push_content_features(lua_State *L, const ContentFeatures &c)
std::string drawtype(ScriptApiNode::es_DrawType[(int)c.drawtype].str);
std::string liquid_type(ScriptApiNode::es_LiquidType[(int)c.liquid_type].str);
- /* Missing "tiles" because I don't see a usecase (at least not yet). */
+ lua_newtable(L);
+
+ // tiles
+ lua_newtable(L);
+ for (int i = 0; i < 6; i++) {
+ push_tiledef(L, c.tiledef[i]);
+ lua_rawseti(L, -2, i + 1);
+ }
+ lua_setfield(L, -2, "tiles");
+
+ // overlay_tiles
+ lua_newtable(L);
+ for (int i = 0; i < 6; i++) {
+ push_tiledef(L, c.tiledef_overlay[i]);
+ lua_rawseti(L, -2, i + 1);
+ }
+ lua_setfield(L, -2, "overlay_tiles");
+ // special_tiles
lua_newtable(L);
+ for (int i = 0; i < CF_SPECIAL_COUNT; i++) {
+ push_tiledef(L, c.tiledef_special[i]);
+ lua_rawseti(L, -2, i + 1);
+ }
+ lua_setfield(L, -2, "special_tiles");
+
lua_pushboolean(L, c.has_on_construct);
lua_setfield(L, -2, "has_on_construct");
lua_pushboolean(L, c.has_on_destruct);
lua_setfield(L, -2, "legacy_wallmounted");
lua_pushstring(L, c.node_dig_prediction.c_str());
lua_setfield(L, -2, "node_dig_prediction");
+ lua_pushnumber(L, c.move_resistance);
+ lua_setfield(L, -2, "move_resistance");
+ lua_pushboolean(L, c.liquid_move_physics);
+ lua_setfield(L, -2, "liquid_move_physics");
}
/******************************************************************************/
}
/******************************************************************************/
-void push_inventory(lua_State *L, Inventory *inventory)
+void push_inventory_list(lua_State *L, const InventoryList &invlist)
{
- std::vector<const InventoryList*> lists = inventory->getLists();
- std::vector<const InventoryList*>::iterator iter = lists.begin();
- lua_createtable(L, 0, lists.size());
- for (; iter != lists.end(); iter++) {
- const char* name = (*iter)->getName().c_str();
- lua_pushstring(L, name);
- push_inventory_list(L, inventory, name);
- lua_rawset(L, -3);
- }
+ push_items(L, invlist.getItems());
}
/******************************************************************************/
-void push_inventory_list(lua_State *L, Inventory *inv, const char *name)
+void push_inventory_lists(lua_State *L, const Inventory &inv)
{
- InventoryList *invlist = inv->getList(name);
- if(invlist == NULL){
- lua_pushnil(L);
- return;
+ const auto &lists = inv.getLists();
+ lua_createtable(L, 0, lists.size());
+ for(const InventoryList *list : lists) {
+ const std::string &name = list->getName();
+ lua_pushlstring(L, name.c_str(), name.size());
+ push_inventory_list(L, *list);
+ lua_rawset(L, -3);
}
- std::vector<ItemStack> items;
- for(u32 i=0; i<invlist->getSize(); i++)
- items.push_back(invlist->getItem(i));
- push_items(L, items);
}
/******************************************************************************/
void read_inventory_list(lua_State *L, int tableindex,
- Inventory *inv, const char *name, Server* srv, int forcesize)
+ Inventory *inv, const char *name, IGameDef *gdef, int forcesize)
{
if(tableindex < 0)
tableindex = lua_gettop(L) + 1 + tableindex;
+
// If nil, delete list
if(lua_isnil(L, tableindex)){
inv->deleteList(name);
return;
}
- // Otherwise set list
- std::vector<ItemStack> items = read_items(L, tableindex,srv);
- int listsize = (forcesize != -1) ? forcesize : items.size();
+
+ // Get Lua-specified items to insert into the list
+ std::vector<ItemStack> items = read_items(L, tableindex, gdef);
+ size_t listsize = (forcesize >= 0) ? forcesize : items.size();
+
+ // Create or resize/clear list
InventoryList *invlist = inv->addList(name, listsize);
- int index = 0;
- for(std::vector<ItemStack>::const_iterator
- i = items.begin(); i != items.end(); ++i){
- if(forcesize != -1 && index == forcesize)
- break;
- invlist->changeItem(index, *i);
- index++;
+ if (!invlist) {
+ luaL_error(L, "inventory list: cannot create list named '%s'", name);
+ return;
}
- while(forcesize != -1 && index < forcesize){
- invlist->deleteItem(index);
- index++;
+
+ for (size_t i = 0; i < items.size(); ++i) {
+ if (i == listsize)
+ break; // Truncate provided list of items
+ invlist->changeItem(i, items[i]);
}
}
return anim;
}
+void push_animation_definition(lua_State *L, struct TileAnimationParams anim)
+{
+ switch (anim.type) {
+ case TAT_NONE:
+ lua_pushnil(L);
+ break;
+ case TAT_VERTICAL_FRAMES:
+ lua_newtable(L);
+ setstringfield(L, -1, "type", "vertical_frames");
+ setfloatfield(L, -1, "aspect_w", anim.vertical_frames.aspect_w);
+ setfloatfield(L, -1, "aspect_h", anim.vertical_frames.aspect_h);
+ setfloatfield(L, -1, "length", anim.vertical_frames.length);
+ break;
+ case TAT_SHEET_2D:
+ lua_newtable(L);
+ setstringfield(L, -1, "type", "sheet_2d");
+ setintfield(L, -1, "frames_w", anim.sheet_2d.frames_w);
+ setintfield(L, -1, "frames_h", anim.sheet_2d.frames_h);
+ setintfield(L, -1, "frame_length", anim.sheet_2d.frame_length);
+ break;
+ }
+}
+
/******************************************************************************/
ToolCapabilities read_tool_capabilities(
lua_State *L, int table)
}
/******************************************************************************/
-std::vector<ItemStack> read_items(lua_State *L, int index, Server *srv)
+std::vector<ItemStack> read_items(lua_State *L, int index, IGameDef *gdef)
{
if(index < 0)
index = lua_gettop(L) + 1 + index;
if (items.size() < (u32) key) {
items.resize(key);
}
- items[key - 1] = read_item(L, -1, srv->idef());
+ items[key - 1] = read_item(L, -1, gdef->idef());
lua_pop(L, 1);
}
return items;
void push_noiseparams(lua_State *L, NoiseParams *np)
{
lua_newtable(L);
- push_float_string(L, np->offset);
- lua_setfield(L, -2, "offset");
- push_float_string(L, np->scale);
- lua_setfield(L, -2, "scale");
- push_float_string(L, np->persist);
- lua_setfield(L, -2, "persistence");
- push_float_string(L, np->lacunarity);
- lua_setfield(L, -2, "lacunarity");
- lua_pushnumber(L, np->seed);
- lua_setfield(L, -2, "seed");
- lua_pushnumber(L, np->octaves);
- lua_setfield(L, -2, "octaves");
+ setfloatfield(L, -1, "offset", np->offset);
+ setfloatfield(L, -1, "scale", np->scale);
+ setfloatfield(L, -1, "persist", np->persist);
+ setfloatfield(L, -1, "persistence", np->persist);
+ setfloatfield(L, -1, "lacunarity", np->lacunarity);
+ setintfield( L, -1, "seed", np->seed);
+ setintfield( L, -1, "octaves", np->octaves);
push_flags_string(L, flagdesc_noiseparams, np->flags,
np->flags);
lua_setfield(L, -2, "flags");
- push_v3_float_string(L, np->spread);
+ push_v3f(L, np->spread);
lua_setfield(L, -2, "spread");
}
} else if (pointed.type == POINTEDTHING_OBJECT) {
lua_pushstring(L, "object");
lua_setfield(L, -2, "type");
- if (csm) {
-#ifndef SERVER
- ClientObjectRef::create(L, pointed.object_id);
-#endif
- } else {
- push_objectRef(L, pointed.object_id);
- }
-
+ push_objectRef(L, pointed.object_id);
lua_setfield(L, -2, "ref");
} else {
lua_pushstring(L, "nothing");
elem->world_pos = lua_istable(L, -1) ? read_v3f(L, -1) : v3f();
lua_pop(L, 1);
+ elem->style = getintfield_default(L, 2, "style", 0);
+
/* check for known deprecated element usage */
if ((elem->type == HUD_ELEM_STATBAR) && (elem->size == v2s32()))
log_deprecated(L,"Deprecated usage of statbar without size!");
lua_pushnumber(L, elem->number);
lua_setfield(L, -2, "number");
+ if (elem->type == HUD_ELEM_WAYPOINT) {
+ // waypoints reuse the item field to store precision, precision = item - 1
+ lua_pushnumber(L, elem->item - 1);
+ lua_setfield(L, -2, "precision");
+ }
+ // push the item field for waypoints as well for backwards compatibility
lua_pushnumber(L, elem->item);
lua_setfield(L, -2, "item");
lua_pushstring(L, elem->text2.c_str());
lua_setfield(L, -2, "text2");
+
+ lua_pushinteger(L, elem->style);
+ lua_setfield(L, -2, "style");
}
-HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
+bool read_hud_change(lua_State *L, HudElementStat &stat, HudElement *elem, void **value)
{
- HudElementStat stat = HUD_STAT_NUMBER;
- std::string statstr;
- if (lua_isstring(L, 3)) {
+ std::string statstr = lua_tostring(L, 3);
+ {
int statint;
- statstr = lua_tostring(L, 3);
- stat = string_to_enum(es_HudElementStat, statint, statstr) ?
- (HudElementStat)statint : stat;
+ if (!string_to_enum(es_HudElementStat, statint, statstr)) {
+ script_log_unique(L, "Unknown HUD stat type: " + statstr, warningstream);
+ return false;
+ }
+
+ stat = (HudElementStat)statint;
}
switch (stat) {
elem->text2 = luaL_checkstring(L, 4);
*value = &elem->text2;
break;
+ case HUD_STAT_STYLE:
+ elem->style = luaL_checknumber(L, 4);
+ *value = &elem->style;
+ break;
}
- return stat;
+
+ return true;
}
/******************************************************************************/
/**/
}
+/******************************************************************************/
void push_physics_override(lua_State *L, float speed, float jump, float gravity, bool sneak, bool sneak_glitch, bool new_move)
{
lua_createtable(L, 0, 6);
-
+
lua_pushnumber(L, speed);
lua_setfield(L, -2, "speed");