-
Notifications
You must be signed in to change notification settings - Fork 123
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
mvps: improve object move #367
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good.
mesecons_mvps/init.lua
Outdated
obj:setpos(np) | ||
if ok then | ||
local ent = obj:get_luaentity() | ||
if not ent or not mesecon.is_mvps_unmov(ent.name) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ent and ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not (ent and …)
mesecons_mvps/init.lua
Outdated
local nn = minetest.get_node(np) | ||
local node_def = minetest.registered_nodes[nn.name] | ||
if (node_def and not node_def.walkable) or | ||
math.abs(obj_pos[dir_k]) <= #nodestack - 0.5 + math.abs(pos[dir_k]) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if signs of pos[dir_k]
and obj_pos[dir_k]
are different?
mesecons_mvps/init.lua
Outdated
local edge1, edge2 | ||
if k ~= dir_k then | ||
edge1 = v - 0.5 | ||
edge2 = v + 0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Objects lying on top of the nodestack aren't moved anymore. Bad?
You mean, when pushing horizontally? That’s acceptable, but may be fixed by increasing (slightly) constant here, if I understand the code correctly.
mesecons_mvps/init.lua
Outdated
if edge1 > edge2 then | ||
edge1, edge2 = edge2, edge1 | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edge
s may be pre-calculated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? This works well enough imo, I can't find a simpler way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exact way, but before for id, obj in pairs(minetest.object_refs) do
and not in the inner loop.
local objects = minetest.get_objects_inside_radius(p_above, 1) | ||
for _, obj in ipairs(objects) do | ||
table.insert(objects_to_move, obj) | ||
for id, obj in pairs(minetest.object_refs) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems horribly, but that’s the only way; MT itself does the same, all the time...
Comments addressed. |
mesecons_mvps/init.lua
Outdated
obj:setpos(np) | ||
if ok then | ||
local ent = obj:get_luaentity() | ||
if not (ent and mesecon.is_mvps_unmov(ent.name)) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work at all?
The correct way seems to be if ent and not mesecon.is_mvps_unmov(ent.name) then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct, don't forget players.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry.
Then the previous variant was better. But such clever code needs a comment, at least.
And, well, there is is_player
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if obj:is_player() or not mesecon.is_mvps_unmov(obj:get_luaentity().name) then
?
mesecons_mvps/init.lua
Outdated
if edge1 > edge2 then | ||
edge1, edge2 = edge2, edge1 | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exact way, but before for id, obj in pairs(minetest.object_refs) do
and not in the inner loop.
mesecons_mvps/init.lua
Outdated
local np = vector.add(obj_pos, dir) | ||
-- Move only if destination is not solid or object is inside stack: | ||
local nn = minetest.get_node(np) | ||
local node_def = minetest.registered_nodes[nn.name] | ||
local nodestack_front = (#nodestack - 0.5 + math.abs(pos[dir_k])) | ||
nodestack_front = nodestack_front * pos[dir_k]/math.abs(pos[dir_k]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird math. Can you write something simpler? Remember that you have dir_l
.
Or let me do that (a bit later).
Make the check logic obvious. Also, it won't try to move unknown or bogus things, if any.
ef9aef6
to
83f503b
Compare
Objects with big collision boxes are moved.
Objects in stack are moved, not only at front. Ergo fixes #361.
Objects lying on top of the nodestack aren't moved anymore. Bad?Edit: fixed.