forked from Mirrorlandia_minetest/digistuff
Add magnetic card reader/writer and cards to go with it
This commit is contained in:
parent
f0ce665a64
commit
77b4fbe12d
9
README
9
README
@ -71,3 +71,12 @@ As in, [digiline][junction box][dirt][junction box][digiline] will work to trans
|
|||||||
How to use the I/O expander:
|
How to use the I/O expander:
|
||||||
After setting a channel, send a table (same format as a Luacontroller's "port" table) to set the output states.
|
After setting a channel, send a table (same format as a Luacontroller's "port" table) to set the output states.
|
||||||
A table in this same format will be sent back whenever an input changes or you manually poll it by sending a "GET" message.
|
A table in this same format will be sent back whenever an input changes or you manually poll it by sending a "GET" message.
|
||||||
|
|
||||||
|
How to use the card reader:
|
||||||
|
After setting a channel, swiping a card (punch the reader with the card to swipe) will send a message in the following format:
|
||||||
|
{event = "read",data = "The data that was on the card"}
|
||||||
|
To write a card, send a command in the following format:
|
||||||
|
{command = "write",data = "The data to put on the card",description = "A description of what the card is for"}
|
||||||
|
After sending the write command, swipe the card to be written and the reader will send back the following message:
|
||||||
|
{event = "write"}
|
||||||
|
Both blank and previously written cards can be written to. If the card was not blank, it will be overwritten.
|
||||||
|
118
cardreader.lua
Normal file
118
cardreader.lua
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
local cardreader_rules = {
|
||||||
|
{x = 1, y = 0,z = 0,},
|
||||||
|
{x = 2, y = 0,z = 0,},
|
||||||
|
{x = -1, y = 0,z = 0,},
|
||||||
|
{x = -2, y = 0,z = 0,},
|
||||||
|
{x = 0, y = 1,z = 0,},
|
||||||
|
{x = 0, y = 2,z = 0,},
|
||||||
|
{x = 0, y = -1,z = 0,},
|
||||||
|
{x = 0, y = -2,z = 0,},
|
||||||
|
{x = 0, y = 0,z = 1,},
|
||||||
|
{x = 0, y = 0,z = 2,},
|
||||||
|
{x = 0, y = 0,z = -1,},
|
||||||
|
{x = 0, y = 0,z = -2,},
|
||||||
|
}
|
||||||
|
|
||||||
|
minetest.register_craftitem("digistuff:card",{
|
||||||
|
description = "Blank Magnetic Card",
|
||||||
|
image = "digistuff_magnetic_card.png",
|
||||||
|
stack_max = 1,
|
||||||
|
on_use = function(stack,_,pointed)
|
||||||
|
local pos = pointed.under
|
||||||
|
if minetest.get_node(pos).name ~= "digistuff:card_reader" then return end
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local channel = meta:get_string("channel")
|
||||||
|
local stackmeta = stack:get_meta()
|
||||||
|
if meta:get_int("writepending") > 0 then
|
||||||
|
local data = meta:get_string("writedata")
|
||||||
|
meta:set_int("writepending",0)
|
||||||
|
meta:set_string("infotext","Ready to Read")
|
||||||
|
digiline:receptor_send(pos,cardreader_rules,channel,{event = "write",})
|
||||||
|
stackmeta:set_string("data",data)
|
||||||
|
stackmeta:set_string("description",string.format("Magnetic Card (%s)",meta:get_string("writedescription")))
|
||||||
|
return stack
|
||||||
|
else
|
||||||
|
local channel = meta:get_string("channel")
|
||||||
|
local data = stackmeta:get_string("data")
|
||||||
|
digiline:receptor_send(pos,cardreader_rules,channel,{event = "read",data = data,})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_node("digistuff:card_reader",{
|
||||||
|
description = "Digilines Magnetic Card Reader/Writer",
|
||||||
|
groups = {cracky = 3,digiline_receiver = 1,},
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("formspec","field[channel;Channel;${channel}")
|
||||||
|
meta:set_int("writepending",0)
|
||||||
|
meta:set_string("infotext","Ready to Read")
|
||||||
|
end,
|
||||||
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
|
local name = sender: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
|
||||||
|
end
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if fields.channel then meta:set_string("channel",fields.channel) end
|
||||||
|
end,
|
||||||
|
paramtype = "light",
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
tiles = {
|
||||||
|
"digistuff_cardreader_sides.png",
|
||||||
|
"digistuff_cardreader_sides.png",
|
||||||
|
"digistuff_cardreader_sides.png",
|
||||||
|
"digistuff_cardreader_sides.png",
|
||||||
|
"digistuff_cardreader_sides.png",
|
||||||
|
"digistuff_cardreader_top.png",
|
||||||
|
},
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {
|
||||||
|
{-0.08,-0.12,0.4,0.08,0.12,0.5},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
digiline = {
|
||||||
|
receptor = {},
|
||||||
|
wire = {
|
||||||
|
rules = cardreader_rules,
|
||||||
|
},
|
||||||
|
effector = {
|
||||||
|
action = function(pos,node,channel,msg)
|
||||||
|
local setchannel = minetest.get_meta(pos):get_string("channel")
|
||||||
|
if channel ~= setchannel or type(msg) ~= "table" then return end
|
||||||
|
if msg.command == "write" and (type(msg.data) == "string" or type(msg.data) == "number") then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("infotext","Ready to Write")
|
||||||
|
meta:set_int("writepending",1)
|
||||||
|
if type(msg.data) ~= "string" then msg.data = tostring(msg.data) end
|
||||||
|
meta:set_string("writedata",string.sub(msg.data,1,256))
|
||||||
|
if type(msg.description == "string") then
|
||||||
|
meta:set_string("writedescription",string.sub(msg.description,1,64))
|
||||||
|
else
|
||||||
|
meta:set_string("writedescription","no name")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "digistuff:card",
|
||||||
|
recipe = {
|
||||||
|
{"basic_materials:plastic_sheet",},
|
||||||
|
{"default:iron_lump",},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "digistuff:card_reader",
|
||||||
|
recipe = {
|
||||||
|
{"basic_materials:plastic_sheet","basic_materials:plastic_sheet","digilines:wire_std_00000000",},
|
||||||
|
{"basic_materials:plastic_sheet","basic_materials:copper_wire","mesecons_luacontroller:luacontroller0000",},
|
||||||
|
{"basic_materials:plastic_sheet","basic_materials:plastic_sheet","",},
|
||||||
|
}
|
||||||
|
})
|
1
init.lua
1
init.lua
@ -13,6 +13,7 @@ local components = {
|
|||||||
"detector",
|
"detector",
|
||||||
"piston",
|
"piston",
|
||||||
"timer",
|
"timer",
|
||||||
|
"cardreader",
|
||||||
}
|
}
|
||||||
|
|
||||||
if minetest.get_modpath("mesecons_luacontroller") then table.insert(components,"ioexpander") end
|
if minetest.get_modpath("mesecons_luacontroller") then table.insert(components,"ioexpander") end
|
||||||
|
BIN
textures/digistuff_cardreader_sides.png
Normal file
BIN
textures/digistuff_cardreader_sides.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
BIN
textures/digistuff_cardreader_top.png
Normal file
BIN
textures/digistuff_cardreader_top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
BIN
textures/digistuff_magnetic_card.png
Normal file
BIN
textures/digistuff_magnetic_card.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 635 B |
Loading…
Reference in New Issue
Block a user