|
|
@ -25,7 +25,6 @@ local id_counter = 0 |
|
|
|
-- Table containing the currently active contraptions keyed by their id. |
|
|
|
-- Table containing the currently active contraptions keyed by their id. |
|
|
|
local active_contraptions = {} |
|
|
|
local active_contraptions = {} |
|
|
|
|
|
|
|
|
|
|
|
-- TODO: Push along players. |
|
|
|
|
|
|
|
-- TODO: Friction depending on ground. |
|
|
|
-- TODO: Friction depending on ground. |
|
|
|
-- TODO: Gravity. |
|
|
|
-- TODO: Gravity. |
|
|
|
-- TODO: Water physics! |
|
|
|
-- TODO: Water physics! |
|
|
@ -200,8 +199,11 @@ function contraption.load_from_string(id, str) |
|
|
|
local result = setmetatable({ |
|
|
|
local result = setmetatable({ |
|
|
|
id = id, |
|
|
|
id = id, |
|
|
|
|
|
|
|
|
|
|
|
region = obj.region, |
|
|
|
region = { |
|
|
|
nodes = obj.nodes, |
|
|
|
min = vector.convert(obj.region.min), |
|
|
|
|
|
|
|
max = vector.convert(obj.region.max) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
nodes = obj.nodes, |
|
|
|
num_nodes = obj.num_nodes, |
|
|
|
num_nodes = obj.num_nodes, |
|
|
|
|
|
|
|
|
|
|
|
motion = obj.motion and vector.convert(obj.motion ) or nil, |
|
|
|
motion = obj.motion and vector.convert(obj.motion ) or nil, |
|
|
@ -272,10 +274,24 @@ function contraption:update(delta_time) |
|
|
|
end |
|
|
|
end |
|
|
|
-- .. and move it 1 step into that direction. |
|
|
|
-- .. and move it 1 step into that direction. |
|
|
|
if which ~= 0 then |
|
|
|
if which ~= 0 then |
|
|
|
|
|
|
|
local objects_to_move = {} |
|
|
|
|
|
|
|
local pos1 = self.region.min:offset(-1, -1, -1) |
|
|
|
|
|
|
|
local pos2 = self.region.max:offset( 1, 2, 1) |
|
|
|
|
|
|
|
for _, obj in ipairs(minetest.get_objects_in_area(pos1, pos2)) do |
|
|
|
|
|
|
|
if obj:is_player() then |
|
|
|
|
|
|
|
local adjusted_pos = vector.offset(obj:get_pos(), 0, -0.5, 0) |
|
|
|
|
|
|
|
local rel_pos = adjusted_pos:round() - self.region.min |
|
|
|
|
|
|
|
if self.nodes[rel_pos:hash()] then |
|
|
|
|
|
|
|
table_insert(objects_to_move, obj) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local step = vector.zero() |
|
|
|
local step = vector.zero() |
|
|
|
step[which] = math.sign(self.partial[which]) |
|
|
|
step[which] = math.sign(self.partial[which]) |
|
|
|
if self:move(step) then |
|
|
|
if self:move(step) then |
|
|
|
self.partial = self.partial - step |
|
|
|
self.partial = self.partial - step |
|
|
|
|
|
|
|
for _, obj in ipairs(objects_to_move) do obj:set_pos(vector.add(obj:get_pos(), step)) end |
|
|
|
else |
|
|
|
else |
|
|
|
-- Reset motion into the direction that we bumped into. |
|
|
|
-- Reset motion into the direction that we bumped into. |
|
|
|
-- Allows for "sliding" along walls instead of stopping outright. |
|
|
|
-- Allows for "sliding" along walls instead of stopping outright. |
|
|
|