diff --git a/contraption.lua b/contraption.lua index 60f60bc..2cc5b32 100755 --- a/contraption.lua +++ b/contraption.lua @@ -165,8 +165,8 @@ function contraption.create(region) -- Change nodes from base nodes to their contraption version. for pos_hash, node in pairs(nodes) do - local rel_pos = minetest.get_position_from_hash(pos_hash) - local abs_pos = vector.add(region.min, rel_pos) + local rel_pos = vector.copy(minetest.get_position_from_hash(pos_hash)) + local abs_pos = region.min + rel_pos minetest.set_node(abs_pos, node) end @@ -178,11 +178,11 @@ end function contraption:on_initialize() local above_nodes = {} for orig_pos_hash, node in pairs(self.nodes) do - local orig_pos = minetest.get_position_from_hash(orig_pos_hash) + local orig_pos = vector.copy(minetest.get_position_from_hash(orig_pos_hash)) -- Calculate the nodes above the contraption that it -- could potentially pull along with it as it moves. - local above_pos = vector.offset(orig_pos, 0, 1, 0) + local above_pos = orig_pos:offset(0, 1, 0) local above_pos_hash = minetest.hash_node_position(above_pos) if not self.nodes[above_pos_hash] then -- Non-contraption block above this one. Move items here along. @@ -234,8 +234,8 @@ function contraption:destroy() active_contraptions[self.id] = nil for pos_hash, node in pairs(self.nodes) do - local rel_pos = minetest.get_position_from_hash(pos_hash) - local abs_pos = vector.add(self.region.min, rel_pos) + local rel_pos = vector.copy(minetest.get_position_from_hash(pos_hash)) + local abs_pos = self.region.min + rel_pos local def = minetest.registered_nodes[node.name] minetest.set_node(abs_pos, def.drop_in_place) end @@ -251,7 +251,7 @@ function contraption:push(pusher, dir) self.recent_pusher[pusher_name] = 1.0 -- seconds self.motion = self.motion or vector.zero() - self.motion = vector.add(self.motion, dir) + self.motion = self.motion + dir end function contraption:update(delta_time) @@ -329,11 +329,11 @@ function contraption:move(offset) end for old_rel_pos_hash, node in pairs(self.nodes) do - local old_rel_pos = minetest.get_position_from_hash(old_rel_pos_hash) - local old_abs_pos = vector.add(self.region.min, old_rel_pos) + local old_rel_pos = vector.copy(minetest.get_position_from_hash(old_rel_pos_hash)) + local old_abs_pos = self.region.min + old_rel_pos - local new_abs_pos = vector.add(old_abs_pos, offset) - local new_rel_pos = vector.add(old_rel_pos, offset) + local new_abs_pos = old_abs_pos + offset + local new_rel_pos = old_rel_pos + offset local new_rel_pos_hash = minetest.hash_node_position(new_rel_pos) -- Node is being moved to this position, no need to clear here. @@ -390,8 +390,8 @@ function contraption:move(offset) -- The `to_push` table contains "lose" nodes that are not directly -- pushed by the contraption, and may or may not be pushed. for pos_hash, node in pairs(to_push) do - local rel_pos = minetest.get_position_from_hash(pos_hash) - local forward_rel_pos = vector.add(rel_pos, offset) + local rel_pos = vector.copy(minetest.get_position_from_hash(pos_hash)) + local forward_rel_pos = rel_pos + offset local forward_rel_pos_hash = minetest.hash_node_position(forward_rel_pos) -- If there's a node to push ahead of this one, skip. @@ -411,7 +411,7 @@ function contraption:move(offset) to_set[forward_rel_pos_hash] = node while true do - local backward_rel_pos = vector.add(rel_pos, -offset) + local backward_rel_pos = rel_pos - offset local backward_rel_pos_hash = minetest.hash_node_position(backward_rel_pos) node = to_push[backward_rel_pos_hash] if not node then break end @@ -428,16 +428,16 @@ function contraption:move(offset) -- Set nodes that need to be changed. -- TODO: Can this use a vector key instead of hash, or an array? for pos_hash, node in pairs(to_set) do - local rel_pos = minetest.get_position_from_hash(pos_hash) - local abs_pos = vector.add(self.region.min, rel_pos) + local rel_pos = vector.copy(minetest.get_position_from_hash(pos_hash)) + local abs_pos = self.region.min + rel_pos minetest.set_node(abs_pos, node.node or node) if node.meta then minetest.get_meta(abs_pos):from_table(node.meta) end end -- Clear nodes that need to be cleared (to AIR). for pos_hash, node in pairs(to_clear) do - local rel_pos = minetest.get_position_from_hash(pos_hash) - local abs_pos = vector.add(self.region.min, rel_pos) + local rel_pos = vector.copy(minetest.get_position_from_hash(pos_hash)) + local abs_pos = self.region.min + rel_pos minetest.set_node(abs_pos, node) end