Commit 3b546346 authored by Fedja Beader's avatar Fedja Beader
Browse files

Only translate positions within the jumpdrive radius

parent b5728d33
......@@ -61,12 +61,12 @@ local biofuel = minetest.deserialize(mod_storage:get_string("biofuel_state")) o
refineries = {},
}
register_on_jumpdrive_jump(function (offset)
register_on_jumpdrive_jump(function (jump)
l:info("translating coordinates on jump")
translate_position_list(biofuel.canister_crafters, offset)
translate_position_list(biofuel.stick_crafters, offset)
translate_position_list(biofuel.wood_crafters, offset)
translate_position_list(biofuel.refineries, offset)
translate_position_list(jump, biofuel.canister_crafters)
translate_position_list(jump, biofuel.stick_crafters)
translate_position_list(jump, biofuel.wood_crafters)
translate_position_list(jump, biofuel.refineries)
mod_storage:set_string("biofuel_state", minetest.serialize(biofuel))
end)
......
......@@ -22,13 +22,26 @@ function register_on_jumpdrive_jump(func)
table.insert(jd_watchlist, func)
end
function translate_position(jump, pos)
if jump.from.x - jump.radius <= pos.x and pos.x <= jump.from.x + jump.radius
and jump.from.y - jump.radius <= pos.y and pos.y <= jump.from.y + jump.radius
and jump.from.z - jump.radius <= pos.z and pos.z <= jump.from.z + jump.radius
then
local old_pos_str = minetest.pos_to_string(pos)
pos.x = pos.x + jump.offset.x
pos.y = pos.y + jump.offset.y
pos.z = pos.z + jump.offset.z
l:debug("Translated position " .. old_pos_str .. " to " .. minetest.pos_to_string(pos))
end
end
-- List translation helper
function translate_position_list(list, offset)
function translate_position_list(jump, list)
for i = 1,#list do
local pos = list[i]
pos.x = pos.x + offset.x
pos.y = pos.y + offset.y
pos.z = pos.z + offset.z
translate_position(jump, pos)
end
end
......@@ -37,17 +50,24 @@ core.register_on_sending_fields(function(pos, formname, fields)
local x = tonumber(fields.x)
local y = tonumber(fields.y)
local z = tonumber(fields.z)
local radius = tonumber(fields.radius)
if x and y and z then
if x and y and z and radius then
local new_pos = { x = x, y = y, z = z }
local offset = vector.subtract(new_pos, pos)
l:debug("Jump from: " .. minetest.pos_to_string(pos)
.. " to " .. minetest.pos_to_string(new_pos)
.. " to " .. minetest.pos_to_string(new_pos)
.. " offset " .. minetest.pos_to_string(offset))
local jump = {}
jump.from = pos
jump.to = new_pos
jump.radius = radius
jump.offset = offset
for i=1,#jd_watchlist do
jd_watchlist[i](offset)
jd_watchlist[i](jump)
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment