Skip to content

Commit

Permalink
Object properties: Fix loss of custom selectionbox
Browse files Browse the repository at this point in the history
Only adjust it to the collisionbox value when the collisionbox was really set.
  • Loading branch information
SmallJoker committed Sep 10, 2017
1 parent 829bbaf commit 5f489ef
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/script/common/c_content.cpp
Expand Up @@ -199,16 +199,18 @@ void read_object_properties(lua_State *L, int index,
getfloatfield(L, -1, "weight", prop->weight);

lua_getfield(L, -1, "collisionbox");
if(lua_istable(L, -1))
bool collisionbox_defined = lua_istable(L, -1);
if (collisionbox_defined)
prop->collisionbox = read_aabb3f(L, -1, 1.0);
lua_pop(L, 1);

lua_getfield(L, -1, "selectionbox");
if (lua_istable(L, -1))
prop->selectionbox = read_aabb3f(L, -1, 1.0);
else
else if (collisionbox_defined)

This comment has been minimized.

Copy link
@HybridDog

HybridDog Sep 11, 2017

Contributor

Why does this fix the selectionbox overriding?

This comment has been minimized.

Copy link
@SmallJoker

SmallJoker Sep 11, 2017

Author Member

See commit description. Every time when set_properties is called without selectionbox being set, it was reset to the collisionbox value, no matter if it was redefined or not.

This comment has been minimized.

Copy link
@HybridDog

HybridDog Sep 12, 2017

Contributor

Thanks, so this fixes selectionbox overriding when neither selectionbox nor collisionbox was set in the passed table.
There's still a bug left. If you set the selectionbox and then the collisionbox, the custom selectionbox is overridden.

self.object:set_properties({
	selectionbox = {0,0,0, 1,1,1},
})
self.object:set_properties({
	collisionbox = {0.5,0.5,0.5, 1,1,0.7},
})

lt could be fixed by adding a boolean which becomes set to true if the selectionbox was set by the modder.

prop->selectionbox = prop->collisionbox;
lua_pop(L, 1);

getboolfield(L, -1, "pointable", prop->pointable);
getstringfield(L, -1, "visual", prop->visual);

Expand Down

1 comment on commit 5f489ef

@stujones11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SmallJoker nice catch :)

Please sign in to comment.