summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2019-05-27 22:41:27 -0500
committercheapie <no-email-for-you@example.com>2019-05-27 22:41:27 -0500
commitc8eb88f2dac95e41937ef08b3ccf10d9e8d8efba (patch)
tree71a5f6dc8dd165eaac43e6309f79c66ecd1ae17c
downloadprinter-c8eb88f2dac95e41937ef08b3ccf10d9e8d8efba.tar
printer-c8eb88f2dac95e41937ef08b3ccf10d9e8d8efba.tar.gz
printer-c8eb88f2dac95e41937ef08b3ccf10d9e8d8efba.tar.bz2
printer-c8eb88f2dac95e41937ef08b3ccf10d9e8d8efba.tar.xz
printer-c8eb88f2dac95e41937ef08b3ccf10d9e8d8efba.zip
Add initial content
-rw-r--r--COPYING22
-rw-r--r--README15
-rw-r--r--depends.txt2
-rw-r--r--init.lua316
-rw-r--r--sounds/printer_feed.oggbin0 -> 18822 bytes
-rw-r--r--sounds/printer_print.oggbin0 -> 40167 bytes
-rw-r--r--sounds/printer_print_receipt.oggbin0 -> 18084 bytes
-rw-r--r--textures/printer_document.pngbin0 -> 1089 bytes
-rw-r--r--textures/printer_receipt.pngbin0 -> 1064 bytes
-rw-r--r--textures/printer_receipt_top.pngbin0 -> 176 bytes
-rw-r--r--textures/printer_receiptpaper_core.pngbin0 -> 203 bytes
-rw-r--r--textures/printer_receiptpaper_roll.pngbin0 -> 240 bytes
-rw-r--r--textures/printer_sides.pngbin0 -> 159 bytes
-rw-r--r--textures/printer_top.pngbin0 -> 194 bytes
14 files changed, 355 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..b3dbff0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,22 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README b/README
new file mode 100644
index 0000000..85f41c9
--- /dev/null
+++ b/README
@@ -0,0 +1,15 @@
+Printer mod for Minetest
+========================
+
+Adds two nodes, a regular (computer) printer and a receipt printer.
+
+Both respond to digilines commands:
+
+{command="get_status"}
+Returns a table with the status of the printer
+
+{command="print",origin="Some text, optional, receipt printer only",title="Some text, optional, regular printer only",contents="Some text"}
+Prints a document
+
+{command="formfeed"}
+Ejects an empty page (regular printer only)
diff --git a/depends.txt b/depends.txt
new file mode 100644
index 0000000..6346be3
--- /dev/null
+++ b/depends.txt
@@ -0,0 +1,2 @@
+digilines
+default
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000..ff96202
--- /dev/null
+++ b/init.lua
@@ -0,0 +1,316 @@
+local function eject_item(pos,dir,item,speed)
+ if not speed then speed = 3 end
+ local spawnpos = vector.add(pos,vector.multiply(dir,-0.6))
+ local velocity = vector.multiply(dir,speed*-1)
+ local item = minetest.add_item(spawnpos,item)
+ item:set_velocity(velocity)
+end
+
+minetest.register_craftitem("printer:document",{
+ description = "Printed Document",
+ inventory_image = "printer_document.png",
+ stack_max = 1,
+ groups = {
+ not_in_creative_inventory = 1,
+ },
+ on_place = function(itemstack,placer)
+ if not placer then return end
+ local contents = itemstack:get_meta():get_string("contents")
+ local fs = string.format("size[4,6]textarea[0.25,1;4,6;text;;%s]button_exit[0,0;2,1;exit;Exit]",minetest.formspec_escape(contents))
+ minetest.show_formspec(placer:get_player_name(),"printer:document_text",fs)
+ end,
+})
+
+minetest.register_node("printer:printer",{
+ description = "Digilines Printer",
+ paramtype = "light",
+ sunlight_propagates = true,
+ paramtype2 = "facedir",
+ is_ground_content = false,
+ tiles = {
+ "printer_top.png",
+ "printer_sides.png",
+ "printer_sides.png",
+ "printer_sides.png",
+ "printer_sides.png",
+ "printer_sides.png",
+ },
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.3,-0.5,-0.2,0.3,-0.2,0.2},
+ {-0.2,-0.5,-0.5,0.2,-0.4,-0.2},
+ },
+ },
+ groups = {
+ dig_immediate = 2,
+ },
+ on_construct = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:get_inventory():set_size("paper",1)
+ meta:set_string("formspec","size[8,6]label[1,0;Paper Tray]list[context;paper;1,0.5;1,1]list[current_player;main;0,2;8,4]listring[]field[3,0.75;2,1;channel;Channel;${channel}]button_exit[5,0.5;2,1;set;Set]")
+ end,
+ can_dig = function(pos,player)
+ local name = player:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return false
+ end
+ return minetest.get_meta(pos):get_inventory():is_empty("paper")
+ end,
+ on_receive_fields = function(pos,_,fields,sender)
+ local name = sender:get_player_name()
+ if not fields.set then return end
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return
+ end
+ minetest.get_meta(pos):set_string("channel",fields.channel)
+ end,
+ allow_metadata_inventory_put = function(pos,_,_,stack,player)
+ local name = player:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return 0
+ end
+ if stack:get_name() ~= "default:paper" then
+ minetest.chat_send_player(name,"Only paper can be inserted here.")
+ return 0
+ end
+ return stack:get_count()
+ end,
+ allow_metadata_inventory_take = function(pos,_,_,stack,player)
+ local name = player:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return 0
+ end
+ return stack:get_count()
+ end,
+ digiline = {
+ wire = {
+ rules = {
+ {x = 1,y = 0,z = 0,},
+ {x = -1,y = 0,z = 0,},
+ {x = 0,y = 1,z = 0,},
+ {x = 0,y = -1,z = 0,},
+ {x = 0,y = 0,z = 1,},
+ {x = 0,y = 0,z = -1,},
+ {x = 0,y = -2,z = 0,},
+ },
+ },
+ receptor = {},
+ effector = {
+ action = function(pos,node,channel,msg)
+ local meta = minetest.get_meta(pos)
+ if channel ~= meta:get_string("channel") or type(msg) ~= "table" or not msg.command then return end
+ local paperstack = meta:get_inventory():get_stack("paper",1)
+ local facedir = minetest.facedir_to_dir(node.param2)
+ if msg.command == "get_status" then
+ if paperstack:get_count() > 0 then
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "OK",paper_left = paperstack:get_count(),})
+ else
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "no_paper",paper_left = paperstack:get_count(),})
+ end
+ elseif msg.command == "formfeed" then
+ if paperstack:get_count() > 0 then
+ eject_item(pos,facedir,ItemStack("default:paper"))
+ paperstack:take_item(1)
+ minetest.sound_play("printer_feed",{pos=pos})
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "OK",paper_left = paperstack:get_count(),})
+ else
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "no_paper",paper_left = paperstack:get_count(),})
+ end
+ elseif msg.command == "print" then
+ if paperstack:get_count() > 0 then
+ local document = ItemStack("printer:document")
+ local stackmeta = document:get_meta()
+ if type(msg.title) ~= "string" then msg.title = "(no title)" end
+ if type(msg.contents) ~= "string" then msg.contents = "" end
+ stackmeta:set_string("description","Printed Document: "..msg.title)
+ stackmeta:set_string("contents",msg.contents)
+ eject_item(pos,facedir,document)
+ paperstack:take_item(1)
+ minetest.sound_play("printer_print",{pos=pos})
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "OK",paper_left = paperstack:get_count(),})
+ else
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "no_paper",paper_left = paperstack:get_count(),})
+ end
+ end
+ meta:get_inventory():set_stack("paper",1,paperstack)
+ end,
+ },
+ },
+})
+
+minetest.register_craftitem("printer:receipt",{
+ description = "Receipt",
+ inventory_image = "printer_receipt.png",
+ stack_max = 1,
+ groups = {
+ not_in_creative_inventory = 1,
+ },
+ on_place = function(itemstack,placer)
+ if not placer then return end
+ local contents = itemstack:get_meta():get_string("contents")
+ local fs = string.format("size[3,8]textarea[0.25,1;3,8;text;;%s]button_exit[0,0;2,1;exit;Exit]",minetest.formspec_escape(contents))
+ minetest.show_formspec(placer:get_player_name(),"printer:document_text",fs)
+ end,
+})
+
+minetest.register_craftitem("printer:receiptpaper_core",{
+ description = "Empty Receipt Paper Roll",
+ inventory_image = "printer_receiptpaper_core.png",
+})
+
+minetest.register_tool("printer:receiptpaper_roll",{
+ description = "Roll of Receipt Paper",
+ inventory_image = "printer_receiptpaper_roll.png",
+})
+
+minetest.register_node("printer:receipt_printer",{
+ description = "Digilines Receipt Printer",
+ paramtype = "light",
+ sunlight_propagates = true,
+ paramtype2 = "facedir",
+ is_ground_content = false,
+ tiles = {
+ "printer_receipt_top.png",
+ "printer_sides.png",
+ "printer_sides.png",
+ "printer_sides.png",
+ "printer_sides.png",
+ "printer_sides.png",
+ },
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.15,-0.5,-0.2,0.15,-0.2,0.2},
+ },
+ },
+ groups = {
+ dig_immediate = 2,
+ },
+ on_construct = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:get_inventory():set_size("paper",1)
+ meta:set_string("formspec","size[8,6]label[1,0;Paper Compartment]list[context;paper;1,0.5;1,1]list[current_player;main;0,2;8,4]listring[]field[3,0.75;2,1;channel;Channel;${channel}]button_exit[5,0.5;2,1;set;Set]")
+ end,
+ can_dig = function(pos,player)
+ local name = player:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return false
+ end
+ return minetest.get_meta(pos):get_inventory():is_empty("paper")
+ end,
+ on_receive_fields = function(pos,_,fields,sender)
+ local name = sender:get_player_name()
+ if not fields.set then return end
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return
+ end
+ minetest.get_meta(pos):set_string("channel",fields.channel)
+ end,
+ allow_metadata_inventory_put = function(pos,_,_,stack,player)
+ local name = player:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return 0
+ end
+ if stack:get_name() ~= "printer:receiptpaper_roll" then
+ minetest.chat_send_player(name,"Only receipt paper rolls can be inserted here.")
+ return 0
+ end
+ return stack:get_count()
+ end,
+ allow_metadata_inventory_take = function(pos,_,_,stack,player)
+ local name = player:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.record_protection_violation(pos,name)
+ return 0
+ end
+ return stack:get_count()
+ end,
+ digiline = {
+ wire = {
+ rules = {
+ {x = 1,y = 0,z = 0,},
+ {x = -1,y = 0,z = 0,},
+ {x = 0,y = 1,z = 0,},
+ {x = 0,y = -1,z = 0,},
+ {x = 0,y = 0,z = 1,},
+ {x = 0,y = 0,z = -1,},
+ {x = 0,y = -2,z = 0,},
+ },
+ },
+ receptor = {},
+ effector = {
+ action = function(pos,node,channel,msg)
+ local meta = minetest.get_meta(pos)
+ if channel ~= meta:get_string("channel") or type(msg) ~= "table" or not msg.command then return end
+ local paperstack = meta:get_inventory():get_stack("paper",1)
+ local facedir = minetest.facedir_to_dir(node.param2)
+ if msg.command == "get_status" then
+ if paperstack:get_count() > 0 and paperstack:get_name() == "printer:receiptpaper_roll" then
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "OK",paper_left = 65535-paperstack:get_wear(),})
+ else
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "no_paper",paper_left = 0,})
+ end
+ elseif msg.command == "print" then
+ if paperstack:get_count() > 0 and paperstack:get_name() == "printer:receiptpaper_roll" then
+ local document = ItemStack("printer:receipt")
+ local stackmeta = document:get_meta()
+ if type(msg.origin) ~= "string" then msg.origin = "somewhere" end
+ if type(msg.contents) ~= "string" then msg.contents = "" end
+ stackmeta:set_string("description","Receipt from "..msg.origin)
+ stackmeta:set_string("contents",msg.contents)
+ eject_item(pos,facedir,document)
+ minetest.sound_play("printer_print_receipt",{pos=pos})
+ local newwear = paperstack:get_wear()+math.floor(string.len(msg.contents)/10)
+ if newwear >= 65535 then
+ paperstack = ItemStack("printer:receiptpaper_core")
+ else
+ paperstack:set_wear(newwear)
+ end
+ meta:get_inventory():set_stack("paper",1,paperstack)
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "OK",paper_left = math.max(0,65535-newwear),})
+ else
+ digiline:receptor_send(pos,digiline.rules.default,channel,{status = "no_paper",paper_left = 0,})
+ end
+ end
+ end,
+ },
+ },
+})
+
+minetest.register_craft({
+ output = "printer:printer",
+ recipe = {{"","basic_materials:plastic_sheet","basic_materials:ic"},
+ {"homedecor:motor","default:steel_ingot","basic_materials:steel_bar"},
+ {"","basic_materials:plastic_sheet","homedecor:motor"}},
+})
+
+minetest.register_craft({
+ output = "printer:receipt_printer",
+ recipe = {{"","basic_materials:plastic_sheet","basic_materials:ic"},
+ {"","basic_materials:heating_element",""},
+ {"","basic_materials:plastic_sheet","homedecor:motor"}},
+})
+
+minetest.register_craft({
+ output = "printer:receiptpaper_core",
+ recipe = {{"","basic_materials:plastic_sheet",""},
+ {"basic_materials:plastic_sheet","dye:black","basic_materials:plastic_sheet"},
+ {"","basic_materials:plastic_sheet",""}},
+})
+
+minetest.register_craft({
+ output = "printer:receiptpaper_roll",
+ recipe = {{"default:paper","default:paper","default:paper"},
+ {"default:paper","printer:receiptpaper_core","default:paper"},
+ {"default:paper","default:paper","default:paper"}},
+})
diff --git a/sounds/printer_feed.ogg b/sounds/printer_feed.ogg
new file mode 100644
index 0000000..11b3bdb
--- /dev/null
+++ b/sounds/printer_feed.ogg
Binary files differ
diff --git a/sounds/printer_print.ogg b/sounds/printer_print.ogg
new file mode 100644
index 0000000..79d7c6d
--- /dev/null
+++ b/sounds/printer_print.ogg
Binary files differ
diff --git a/sounds/printer_print_receipt.ogg b/sounds/printer_print_receipt.ogg
new file mode 100644
index 0000000..e9c8708
--- /dev/null
+++ b/sounds/printer_print_receipt.ogg
Binary files differ
diff --git a/textures/printer_document.png b/textures/printer_document.png
new file mode 100644
index 0000000..6c74615
--- /dev/null
+++ b/textures/printer_document.png
Binary files differ
diff --git a/textures/printer_receipt.png b/textures/printer_receipt.png
new file mode 100644
index 0000000..d15ccd6
--- /dev/null
+++ b/textures/printer_receipt.png
Binary files differ
diff --git a/textures/printer_receipt_top.png b/textures/printer_receipt_top.png
new file mode 100644
index 0000000..aed426b
--- /dev/null
+++ b/textures/printer_receipt_top.png
Binary files differ
diff --git a/textures/printer_receiptpaper_core.png b/textures/printer_receiptpaper_core.png
new file mode 100644
index 0000000..6fc376b
--- /dev/null
+++ b/textures/printer_receiptpaper_core.png
Binary files differ
diff --git a/textures/printer_receiptpaper_roll.png b/textures/printer_receiptpaper_roll.png
new file mode 100644
index 0000000..2d1a2ca
--- /dev/null
+++ b/textures/printer_receiptpaper_roll.png
Binary files differ
diff --git a/textures/printer_sides.png b/textures/printer_sides.png
new file mode 100644
index 0000000..91cbf82
--- /dev/null
+++ b/textures/printer_sides.png
Binary files differ
diff --git a/textures/printer_top.png b/textures/printer_top.png
new file mode 100644
index 0000000..1d269e0
--- /dev/null
+++ b/textures/printer_top.png
Binary files differ