summaryrefslogtreecommitdiff
path: root/src/script/common/c_content.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/common/c_content.cpp')
-rw-r--r--src/script/common/c_content.cpp83
1 files changed, 60 insertions, 23 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 6995f6b61..8a5a3fe71 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -119,6 +119,8 @@ void read_item_definition(lua_State* L, int index,
// "" = no prediction
getstringfield(L, index, "node_placement_prediction",
def.node_placement_prediction);
+
+ getintfield(L, index, "place_param2", def.place_param2);
}
/******************************************************************************/
@@ -198,8 +200,6 @@ void read_object_properties(lua_State *L, int index,
if (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);
}
}
@@ -683,7 +683,8 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
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;
@@ -718,6 +719,9 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
// 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);
@@ -821,6 +825,21 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
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)
@@ -948,6 +967,10 @@ void push_content_features(lua_State *L, const ContentFeatures &c)
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");
}
/******************************************************************************/
@@ -1347,26 +1370,28 @@ void read_inventory_list(lua_State *L, int tableindex,
{
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
+
+ // Get Lua-specified items to insert into the list
std::vector<ItemStack> items = read_items(L, tableindex,srv);
- int listsize = (forcesize != -1) ? forcesize : items.size();
+ 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]);
}
}
@@ -1923,6 +1948,8 @@ void read_hud_element(lua_State *L, HudElement *elem)
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!");
@@ -1977,17 +2004,22 @@ void push_hud_element(lua_State *L, HudElement *elem)
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) {
@@ -2045,8 +2077,13 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
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;
}
/******************************************************************************/