printer/scanner.lua
Ciaran Gultnieks 3cb7e53867 Make printer and scanner visually distinguishable
They're still ugly, which I don't care about for now, but at least you
can tell what they are without inspecting them.
2015-05-06 07:45:09 +01:00

87 lines
2.9 KiB
Lua

local dbg
if moddebug then dbg=moddebug.dbg("printer") else dbg={v1=function() end,v2=function() end,v3=function() end} end
local function clone_node(name)
local node2 = {}
local node = minetest.registered_nodes[name]
for k, v in pairs(node) do
node2[k] = v
end
return node2
end
local scanner = clone_node("default:chest")
scanner.description = "Scanner"
scanner.tiles[1] = "printer_scanner.png^pipeworks_tube_connection_metallic.png"
scanner.tiles[2] = "printer_scanner.png^pipeworks_tube_connection_metallic.png"
scanner.tiles[3] = "printer_scanner.png^pipeworks_tube_connection_metallic.png"
scanner.tiles[4] = "printer_scanner.png^pipeworks_tube_connection_metallic.png"
scanner.tiles[5] = "printer_scanner.png^pipeworks_tube_connection_metallic.png"
scanner.tiles[6] = "printer_scanner.png"
scanner.groups.tubedevice = 1
scanner.groups.tubedevice_receiver = 1
scanner.tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local res = inv:add_item("main", stack)
if res then
if stack:get_name() == "memorandum:letter" then
local channel = "scanner"
local text = stack:get_metadata()
-- TODO: Parsing code from memorandum - would be better if
-- that module exposed this as a callable function.
local scnt = string.sub (text, -2, -1)
if scnt == "00" then
mssg = string.sub (text, 1, -3)
sgnd = ""
elseif tonumber(scnt) == nil then -- to support previous versions
mssg = string.sub (text, 37, -1)
sgnd = ""
else
mssg = string.sub (text, 1, -scnt -3)
sgnd = string.sub (text, -scnt-2, -3)
end
digiline:receptor_send(pos, digiline.rules.default, channel, {text=mssg, signed=sgnd})
dbg.v1("Scanned '"..mssg.."' at "..minetest.pos_to_string(pos))
end
end
return res
end,
can_insert = function(pos, node, stack, direction)
-- Only letters can be scanned - don't even accept anything else.
if stack:get_name() ~= "memorandum:letter" then
return false
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:room_for_item("main", stack) then
return true
end
-- Shred something when full
inv:remove_item("main", "memorandum:letter")
dbg.v1("Scanner shredded a letter at "..minetest.pos_to_string(pos))
return inv:room_for_item("main", stack)
end,
input_inventory = "main",
connect_sides = {top=1, back=1, left=1, right=1, bottom=1, front=1}
}
scanner.after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
scanner.after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
scanner.digiline = {
receptor = {},
}
minetest.register_node("printer:scanner", scanner)