Skip to content

Commit

Permalink
MVPS: pull objects (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour authored and numberZero committed Oct 18, 2017
1 parent 1b10610 commit 748446b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
11 changes: 7 additions & 4 deletions mesecons_movestones/init.lua
Expand Up @@ -50,7 +50,6 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
minetest.get_node_timer(pos):start(timer_interval)
return
end
mesecon.mvps_process_stack(stack)
mesecon.mvps_move_objects(frontpos, direction, oldstack)

-- ### Step 2: Move the movestone ###
Expand All @@ -61,9 +60,13 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
minetest.get_node_timer(frontpos):start(timer_interval)

-- ### Step 3: If sticky, pull stack behind ###
if is_sticky then
local backpos = vector.subtract(pos, direction)
mesecon.mvps_pull_all(backpos, direction, max_pull)
if not is_sticky then
return
end
local backpos = vector.subtract(pos, direction)
success, stack, oldstack = mesecon.mvps_pull_all(backpos, direction, max_pull)
if success then
mesecon.mvps_move_objects(backpos, vector.multiply(direction, -1), oldstack, -1)
end
end

Expand Down
6 changes: 4 additions & 2 deletions mesecons_mvps/init.lua
Expand Up @@ -205,7 +205,7 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
return true, nodes, oldstack
end

function mesecon.mvps_move_objects(pos, dir, nodestack)
function mesecon.mvps_move_objects(pos, dir, nodestack, movefactor)
local objects_to_move = {}
local dir_k
local dir_l
Expand All @@ -216,6 +216,8 @@ function mesecon.mvps_move_objects(pos, dir, nodestack)
break
end
end
movefactor = movefactor or 1
dir = vector.multiply(dir, movefactor)
for id, obj in pairs(minetest.object_refs) do
local obj_pos = obj:get_pos()
local cbox = obj:get_properties().collisionbox
Expand All @@ -229,7 +231,7 @@ function mesecon.mvps_move_objects(pos, dir, nodestack)
edge2 = v + 0.51
else
edge1 = v - 0.5 * dir_l
edge2 = v + (#nodestack + 0.5) * dir_l
edge2 = v + (#nodestack + 0.5 * movefactor) * dir_l
-- Make sure, edge1 is bigger than edge2:
if edge1 > edge2 then
edge1, edge2 = edge2, edge1
Expand Down
10 changes: 6 additions & 4 deletions mesecons_pistons/init.lua
Expand Up @@ -101,10 +101,12 @@ local function piston_off(pos, node)
if not pistonspec.sticky then
return
end
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
local pullpos = vector.add(pos, vector.multiply(dir, 2))
local stack = mesecon.mvps_pull_single(pullpos, vector.multiply(dir, -1), max_pull)
mesecon.mvps_process_stack(pos, dir, stack)
local dir = minetest.facedir_to_dir(node.param2)
local pullpos = vector.add(pos, vector.multiply(dir, -2))
local success, stack, oldstack = mesecon.mvps_pull_single(pullpos, dir, max_pull)
if success then
mesecon.mvps_move_objects(pullpos, vector.multiply(dir, -1), oldstack, -1)
end
end

local orientations = {
Expand Down

0 comments on commit 748446b

Please sign in to comment.