MVPS: pull objects (#374)

This commit is contained in:
DS 2017-10-18 21:53:22 +02:00 committed by Vitaliy
parent 1b10610f92
commit 748446b3cc
3 changed files with 17 additions and 10 deletions

View File

@ -50,7 +50,6 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
minetest.get_node_timer(pos):start(timer_interval) minetest.get_node_timer(pos):start(timer_interval)
return return
end end
mesecon.mvps_process_stack(stack)
mesecon.mvps_move_objects(frontpos, direction, oldstack) mesecon.mvps_move_objects(frontpos, direction, oldstack)
-- ### Step 2: Move the movestone ### -- ### Step 2: Move the movestone ###
@ -61,9 +60,13 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical)
minetest.get_node_timer(frontpos):start(timer_interval) minetest.get_node_timer(frontpos):start(timer_interval)
-- ### Step 3: If sticky, pull stack behind ### -- ### Step 3: If sticky, pull stack behind ###
if is_sticky then if not is_sticky then
local backpos = vector.subtract(pos, direction) return
mesecon.mvps_pull_all(backpos, direction, max_pull) 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
end end

View File

@ -205,7 +205,7 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
return true, nodes, oldstack return true, nodes, oldstack
end end
function mesecon.mvps_move_objects(pos, dir, nodestack) function mesecon.mvps_move_objects(pos, dir, nodestack, movefactor)
local objects_to_move = {} local objects_to_move = {}
local dir_k local dir_k
local dir_l local dir_l
@ -216,6 +216,8 @@ function mesecon.mvps_move_objects(pos, dir, nodestack)
break break
end end
end end
movefactor = movefactor or 1
dir = vector.multiply(dir, movefactor)
for id, obj in pairs(minetest.object_refs) do for id, obj in pairs(minetest.object_refs) do
local obj_pos = obj:get_pos() local obj_pos = obj:get_pos()
local cbox = obj:get_properties().collisionbox local cbox = obj:get_properties().collisionbox
@ -229,7 +231,7 @@ function mesecon.mvps_move_objects(pos, dir, nodestack)
edge2 = v + 0.51 edge2 = v + 0.51
else else
edge1 = v - 0.5 * dir_l 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: -- Make sure, edge1 is bigger than edge2:
if edge1 > edge2 then if edge1 > edge2 then
edge1, edge2 = edge2, edge1 edge1, edge2 = edge2, edge1

View File

@ -101,10 +101,12 @@ local function piston_off(pos, node)
if not pistonspec.sticky then if not pistonspec.sticky then
return return
end end
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1) local dir = minetest.facedir_to_dir(node.param2)
local pullpos = vector.add(pos, vector.multiply(dir, 2)) local pullpos = vector.add(pos, vector.multiply(dir, -2))
local stack = mesecon.mvps_pull_single(pullpos, vector.multiply(dir, -1), max_pull) local success, stack, oldstack = mesecon.mvps_pull_single(pullpos, dir, max_pull)
mesecon.mvps_process_stack(pos, dir, stack) if success then
mesecon.mvps_move_objects(pullpos, vector.multiply(dir, -1), oldstack, -1)
end
end end
local orientations = { local orientations = {