1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
local digits = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
local base_chars = {
"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"
}
local special_chars = {
"!", "#", "$", "%", "&", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";",
"<", "=", ">", "?", "@", "'", '"'
}
local cyrillic_chars = {
"А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й", "К", "Л", "М", "Н",
"О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ы", "Ь",
"Э", "Ю", "Я"
}
local characters = {}
ehlphabet = {}
ehlphabet.path = minetest.get_modpath(minetest.get_current_modname())
local function table_merge(t1, t2)
for k, v in ipairs(t2) do
table.insert(t1, v)
end
return t1
end
local function is_multibyte(ch)
local byte = ch:byte()
return (208 == byte) or (209 == byte)
end
table_merge(characters, base_chars)
table_merge(characters, digits)
table_merge(characters, special_chars)
table_merge(characters, cyrillic_chars)
local create_alias = true
-- generate all available blocks
for _, name in ipairs(characters) do
local desc = "The '" .. name .. "' Character"
local byte = name:byte()
local mb = is_multibyte(name)
local file, key
if mb then
mb = byte
byte = name:byte(2)
key = "ehlphabet:" .. mb .. byte
file = ("%03d_%03d"):format(mb, byte)
else
key = "ehlphabet:" .. byte
file = ("%03d"):format(byte)
end
minetest.register_node(
key,
{
description = "Ehlphabet Block '" .. name .. "'",
tiles = {"ehlphabet_" .. file .. ".png"},
groups = {cracky = 3, not_in_creative_inventory = 1, not_in_crafting_guide = 1}
}
)
minetest.register_craft({type = "shapeless", output = "ehlphabet:block", recipe = {key}})
if create_alias then
minetest.register_alias("abjphabet:" .. name, key)
end
-- deactivate alias creation on last latin character
if name == "Z" then
create_alias = false
end
end
minetest.register_node(
"ehlphabet:machine",
{
description = "Letter Machine",
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"
},
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky = 2},
-- "Can you dig it?" -Cyrus
can_dig = function(pos, player)
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
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)
local ch = fields.lettername
if ch ~= nil and inputstack:get_name() == "ehlphabet:block" then
local mb = is_multibyte(ch)
local key = mb and (ch:byte(1) .. ch:byte(2)) or ch:byte()
for _, v in pairs(characters) do
if v == fields.lettername then
local give = {}
give[1] = inv:add_item("output", "ehlphabet:" .. key)
inputstack:take_item()
inv:set_stack("input", 1, inputstack)
break
end
end
end
end
}
)
-- Alias (Och_Noe 20180124)
minetest.register_alias("abjphabet:machine", "ehlphabet:machine")
--
minetest.register_node(
"ehlphabet:block",
{
description = "Ehlphabet Block (blank)",
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"},
{"default:paper", "default:paper", "default:paper"}
}
})
--RECIPE: build the machine!
minetest.register_craft({
output = "ehlphabet:machine",
recipe = {
{"default:stick", "default:coal_lump", "default:stick"},
{"default:coal_lump", "ehlphabet:block", "default:coal_lump"},
{"default:stick", "default:coal_lump", "default:stick"}
}
})
--RECIPE: craft unused blocks back into paper
minetest.register_craft({
output = "default:paper",
recipe = {"ehlphabet:block"},
type = "shapeless"
})
|