ehlphabet/init.lua

125 lines
4.7 KiB
Lua
Raw Normal View History

2017-12-14 06:36:27 -08:00
local characters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0","!","#","$","%","&","(",")","*","+",",","-",".","/",":",";","<","=",">","?","@"}
2017-12-13 20:37:51 -08:00
2018-02-08 04:05:58 -08:00
-- Alias (Och_Noe 20180124)
local compat_characters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0"} -- for reference, unused
--
-- Alias (Och_Noe 20180124)
create_alias = true
--
2017-12-13 20:37:51 -08:00
for _, name in ipairs(characters) do --do this for all characters in the list
local byte = string.byte(name)
if byte < 10 then file = "00"..byte end
if byte > 10 and byte < 100 then file = "0"..byte end
if byte > 100 then file = tostring(byte) end
local desc = "The \'"..name.."\' Character"
minetest.register_node("ehlphabet:"..byte, {
description = "Ehlphabet Block \'"..name.."\'",
tiles = {"ehlphabet_"..file..".png"},
2017-12-14 06:40:23 -08:00
groups = {cracky=3,not_in_creative_inventory=1,not_in_crafting_guide=1}
2017-12-13 20:37:51 -08:00
})
minetest.register_craft ({ type="shapeless", output = "ehlphabet:block", recipe = {"ehlphabet:"..byte} })
2018-02-08 04:05:58 -08:00
if name == "!" then create_alias = false end
-- Alias (Och_Noe 20180124)
if create_alias then
minetest.register_alias("abjphabet:"..name:lower(),"ehlphabet:"..byte)
end
--
2017-12-13 20:37:51 -08:00
end
2018-02-08 04:05:58 -08:00
2017-12-13 20:37:51 -08:00
minetest.register_node("ehlphabet:machine", {
description = "Letter Machine",
2017-12-14 20:45:06 -08:00
tiles = {"ehlphabet_machine_top.png", "ehlphabet_machine_bottom.png", "ehlphabet_machine_side.png",
"ehlphabet_machine_side.png", "ehlphabet_machine_back.png", "ehlphabet_machine_front.png"},
2017-12-13 20:37:51 -08:00
paramtype = "light",
2017-12-15 06:37:23 -08:00
paramtype2 = "facedir",
2017-12-13 20:37:51 -08:00
groups = {cracky=2},
2017-12-14 10:41:11 -08:00
can_dig = function(pos, player) -- "Can you dig it?" -Cyrus
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
if not inv:is_empty("input") or not inv:is_empty("output") then
if player then
minetest.chat_send_player(player:get_player_name(), "You cannot dig the Letter Machine with blocks inside")
end -- end if player
return false
end -- end if not empty
return true
end, -- end can_dig function
2017-12-13 20:37:51 -08:00
after_place_node = function(pos, placer)
local meta = minetest.env:get_meta(pos)
end,
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", "invsize[8,6;]"..
"field[3.8,.5;1,1;lettername;Letter;]"..
"list[current_name;input;2.5,0.2;1,1;]"..
"list[current_name;output;4.5,0.2;1,1;]"..
"list[current_player;main;0,2;8,4;]"..
"button[2.54,-0.25;3,4;name;Blank -> Letter]")
local inv = meta:get_inventory()
inv:set_size("input", 1)
inv:set_size("output", 1)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local inputstack = inv:get_stack("input", 1)
if fields.lettername ~= nil and inputstack:get_name()=="ehlphabet:block" then
for _,v in pairs(characters) do
if v == fields.lettername then
local give = {}
give[1] = inv:add_item("output","ehlphabet:"..string.byte(fields.lettername))
inputstack:take_item()
inv:set_stack("input",1,inputstack)
break
end
end
end
end
})
2018-02-08 04:05:58 -08:00
-- Alias (Och_Noe 20180124)
minetest.register_alias("abjphabet:machine","ehlphabet:machine")
--
2017-12-13 20:37:51 -08:00
minetest.register_node("ehlphabet:block", {
2017-12-14 10:41:11 -08:00
description = "Ehlphabet Block (blank)",
2017-12-13 20:37:51 -08:00
tiles = {"ehlphabet_000.png"},
groups = {cracky=3},
})
--RECIPE: blank blocks
minetest.register_craft({ output = "ehlphabet:block 8",
recipe = {
{'default:paper', 'default:paper', 'default:paper'},
{'default:paper', '', 'default:paper'},
2017-12-13 20:37:51 -08:00
{'default:paper', 'default:paper', 'default:paper'},
}
})
--RECIPE: build the machine!
minetest.register_craft({ output = "ehlphabet:machine",
recipe = {
2017-12-14 10:58:42 -08:00
{'default:stick', 'default:coal_lump', 'default:stick'},
2017-12-13 20:37:51 -08:00
{'default:coal_lump', 'ehlphabet:block', 'default:coal_lump'},
2017-12-14 10:58:42 -08:00
{'default:stick', 'default:coal_lump', 'default:stick'},
2017-12-13 20:37:51 -08:00
}
})
--RECIPE: craft unused blocks back into paper
minetest.register_craft ({ output = "default:paper",
recipe = {"ehlphabet:block"},
type = "shapeless"
})