Skip to content

Commit

Permalink
very dumb shit
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Jan 17, 2025
1 parent e88a698 commit 32f7742
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/script/common/c_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,13 @@ const std::array<const char *, 33> object_property_keys = {
"shaded",
"damage_texture_modifier",
"show_on_minimap",
// "node" is intentionally not here as it's gated behind `fallback` below!
};

/******************************************************************************/
void read_object_properties(lua_State *L, int index,
ServerActiveObject *sao, ObjectProperties *prop, IItemDefManager *idef)
ServerActiveObject *sao, ObjectProperties *prop, IItemDefManager *idef,
bool fallback)
{
if(index < 0)
index = lua_gettop(L) + 1 + index;
Expand Down Expand Up @@ -382,11 +384,15 @@ void read_object_properties(lua_State *L, int index,
}
lua_pop(L, 1);

lua_getfield(L, -1, "node");
if (lua_istable(L, -1)) {
prop->node = readnode(L, -1);
// This hack exists because the name 'node' easily collides with mods own
// usage (or in this case literally builtin/game/falling.lua).
if (!fallback) {
lua_getfield(L, -1, "node");
if (lua_istable(L, -1)) {
prop->node = readnode(L, -1);
}
lua_pop(L, 1);
}
lua_pop(L, 1);

lua_getfield(L, -1, "spritediv");
if(lua_istable(L, -1))
Expand Down
4 changes: 3 additions & 1 deletion src/script/common/c_content.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ void push_item_definition (lua_State *L,
void push_item_definition_full (lua_State *L,
const ItemDefinition &i);

/// @param fallback set to true if reading from bare entity table (not initial_properties)
void read_object_properties (lua_State *L, int index,
ServerActiveObject *sao,
ObjectProperties *prop,
IItemDefManager *idef);
IItemDefManager *idef,
bool fallback = false);

void push_object_properties (lua_State *L,
const ObjectProperties *prop);
Expand Down
8 changes: 6 additions & 2 deletions src/script/cpp_api/s_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,17 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
// Set default values that differ from ObjectProperties defaults
prop->hp_max = 10;

auto *idef = getServer()->idef();

// Deprecated: read object properties directly
// TODO: this should be changed to not read the legacy place
// if `initial_properties` exists!
logDeprecationForExistingProperties(L, -1, entity_name);
read_object_properties(L, -1, self, prop, getServer()->idef());
read_object_properties(L, -1, self, prop, idef, true);

// Read initial_properties
lua_getfield(L, -1, "initial_properties");
read_object_properties(L, -1, self, prop, getServer()->idef());
read_object_properties(L, -1, self, prop, idef);
lua_pop(L, 1);
}

Expand Down

0 comments on commit 32f7742

Please sign in to comment.