printer/printer.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

84 lines
3.2 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 printer = clone_node("default:chest")
printer.description = "Printer"
printer.tiles[1] = "printer_printer.png^pipeworks_tube_connection_metallic.png"
printer.tiles[2] = "printer_printer.png^pipeworks_tube_connection_metallic.png"
printer.tiles[3] = "printer_printer.png^pipeworks_tube_connection_metallic.png"
printer.tiles[4] = "printer_printer.png^pipeworks_tube_connection_metallic.png"
printer.tiles[5] = "printer_printer.png^pipeworks_tube_connection_metallic.png"
printer.tiles[6] = "printer_printer.png"
printer.groups.tubedevice = 1
printer.groups.tubedevice_receiver = 1
printer.tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item("main", stack)
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
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}
}
printer.after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
printer.after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
printer.digiline = {
receptor = {},
effector = {
action = function(pos, node, channel, msg)
if channel == "print" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
-- Check paper left, and warn when low
local paperleft = 0
for i = 1,inv:get_size("main") do
local st = inv:get_stack("main", i)
if st:get_name() == "default:paper" then
paperleft = paperleft + st:get_count()
end
end
if paperleft <= 10 then
digiline:receptor_send(pos, digiline.rules.default, "print", {action="status", status="paper low", count=paperleft})
end
local stack = inv:remove_item("main", ItemStack("default:paper 1"))
if stack:get_count() ~= 1 then
dbg.v1("Out of paper at "..minetest.pos_to_string(pos))
return
end
stack = ItemStack({name="memorandum:letter", count=1, wear=0, metadata=msg..'00'})
if not inv:room_for_item("main", stack) then
digiline:receptor_send(pos, digiline.rules.default, "print", {action="status", status="jam"})
dbg.v1("No room for printer output at "..minetest.pos_to_string(pos))
return
end
inv:add_item("main", stack)
dbg.v1("Printed '"..msg.."' at "..minetest.pos_to_string(pos))
end
end
},
}
minetest.register_node("printer:printer", printer)