2019-04-28 22:34:21 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
|
|
|
LGPLv2.1+
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
Helper functions
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
|
|
|
local P = minetest.string_to_pos
|
|
|
|
local M = minetest.get_meta
|
|
|
|
|
|
|
|
-- Load support for intllib.
|
|
|
|
local MP = minetest.get_modpath("techage")
|
|
|
|
local I,_ = dofile(MP.."/intllib.lua")
|
|
|
|
|
2019-04-27 18:42:50 +03:00
|
|
|
function techage.range(val, min, max)
|
|
|
|
val = tonumber(val)
|
|
|
|
if val < min then return min end
|
|
|
|
if val > max then return max end
|
|
|
|
return val
|
|
|
|
end
|
|
|
|
|
|
|
|
function techage.one_of(val, selection)
|
|
|
|
for _,v in ipairs(selection) do
|
|
|
|
if val == v then return val end
|
|
|
|
end
|
|
|
|
return selection[1]
|
|
|
|
end
|
|
|
|
|
2019-06-09 01:25:25 +03:00
|
|
|
function techage.get_node_lvm(pos)
|
|
|
|
local node = minetest.get_node_or_nil(pos)
|
|
|
|
if node then
|
|
|
|
return node
|
|
|
|
end
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
|
|
|
|
local data = vm:get_data()
|
|
|
|
local param2_data = vm:get_param2_data()
|
|
|
|
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
|
|
|
|
local idx = area:index(pos.x, pos.y, pos.z)
|
|
|
|
node = {
|
|
|
|
name = minetest.get_name_from_content_id(data[idx]),
|
|
|
|
param2 = param2_data[idx]
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-28 22:34:21 +03:00
|
|
|
--
|
|
|
|
-- Functions used to hide electric cable and biogas pipes
|
|
|
|
--
|
|
|
|
-- Overridden method of tubelib2!
|
|
|
|
function techage.get_primary_node_param2(pos, dir)
|
|
|
|
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
|
|
|
|
local param2 = M(npos):get_int("tl2_param2")
|
|
|
|
if param2 ~= 0 then
|
|
|
|
return param2, npos
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Overridden method of tubelib2!
|
|
|
|
function techage.is_primary_node(pos, dir)
|
|
|
|
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
|
|
|
|
local param2 = M(npos):get_int("tl2_param2")
|
|
|
|
return param2 ~= 0
|
|
|
|
end
|
2019-06-08 23:57:01 +03:00
|
|
|
|
2019-06-09 22:24:39 +03:00
|
|
|
-- returns true, if node can be dug, otherwise false
|
|
|
|
function techage.can_node_dig(node, ndef)
|
|
|
|
if not ndef then return false end
|
|
|
|
if node.name == "ignore" then return false end
|
|
|
|
if node.name == "air" then return true end
|
|
|
|
if ndef.buildable_to == true then return true end
|
2019-06-08 23:57:01 +03:00
|
|
|
if ndef.diggable == false then return false end
|
|
|
|
if ndef.after_dig_node then return false end
|
|
|
|
return true
|
|
|
|
end
|
2019-06-09 22:24:39 +03:00
|
|
|
|
|
|
|
-- returns the node name, if node can be dropped, otherwise nil
|
|
|
|
function techage.dropped_node(node, ndef)
|
|
|
|
if node.name == "air" then return end
|
|
|
|
if ndef.buildable_to == true then return end
|
|
|
|
if ndef.drop == "" then return end
|
|
|
|
return ndef.drop or node.name
|
|
|
|
end
|