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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
minetest.register_alias("darkage:box", "castle:crate")
minetest.register_alias("cottages:straw", "farming:straw")
minetest.register_alias("castle:straw", "farming:straw")
minetest.register_alias("darkage:straw", "farming:straw")
minetest.register_alias("cottages:straw_bale", "castle:bound_straw")
minetest.register_alias("darkage:straw_bale", "castle:bound_straw")
minetest.register_alias("darkage:lamp", "castle:street_light")
minetest.register_alias("castle:pavement", "castle:pavement_brick")
minetest.register_node("castle:anvil",{
drawtype = "nodebox",
description = "Anvil",
tiles = {"castle_steel.png"},
groups = {cracky=2,falling_node=1},
sounds = default.node_sound_stone_defaults(),
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {
{-0.500000,-0.500000,-0.500000,0.500000,-0.250000,0.500000},
{-0.187500,-0.500000,-0.375000,0.187500,0.312500,0.375000},
{-0.375000,-0.500000,-0.437500,0.375000,-0.125000,0.437500},
{-0.500000,0.312500,-0.500000,0.500000,0.500000,0.500000},
{-0.375000,0.187500,-0.437500,0.375000,0.425000,0.437500},
},
},
})
minetest.register_craft({
output = "castle:anvil",
recipe = {
{"default:steel_ingot","default:steel_ingot","default:steel_ingot"},
{"","default:steel_ingot", ""},
{"default:steel_ingot", "default:steel_ingot","default:steel_ingot"},
}
})
minetest.register_node("castle:workbench",{
description = "Workbench",
tiles = {"castle_workbench_top.png", "castle_workbench_bottom.png", "castle_workbench_side.png", "castle_workbench_side.png", "castle_workbench_back.png", "castle_workbench_front.png"},
paramtype2 = "facedir",
paramtype = "light",
groups = {choppy=2,oddly_breakable_by_hand=2,flammable=2},
sounds = default.node_sound_wood_defaults(),
drawtype = "normal",
on_construct = function ( pos )
local meta = minetest.get_meta( pos )
meta:set_string( 'formspec',
'size[10,10;]' ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
'label[1,0;Source Material]' ..
'list[context;src;1,1;2,4;]' ..
'label[4,0;Recipe to Use]' ..
'list[context;rec;4,1;3,3;]' ..
'label[7.5,0;Craft Output]' ..
'list[context;dst;8,1;1,4;]' ..
'list[current_player;main;1,6;8,4;]' )
meta:set_string( 'infotext', 'Workbench' )
local inv = meta:get_inventory()
inv:set_size( 'src', 2 * 4 )
inv:set_size( 'rec', 3 * 3 )
inv:set_size( 'dst', 1 * 4 )
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name()..
" moves stuff in workbench at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" moves stuff to workbench at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" takes stuff from workbench at "..minetest.pos_to_string(pos))
end,
})
local get_recipe = function ( inv )
local result, needed, input
needed = inv:get_list( 'rec' )
result, input = minetest.get_craft_result( {
method = 'normal',
width = 3,
items = needed
})
local totalneed = {}
if result.item:is_empty() then
result = nil
else
result = result.item
for _, item in ipairs( needed ) do
if item ~= nil and not item:is_empty() and not inv:contains_item( 'src', item ) then
result = nil
break
end
if item ~= nil and not item:is_empty() then
if totalneed[item:get_name()] == nil then
totalneed[item:get_name()] = 1
else
totalneed[item:get_name()] = totalneed[item:get_name()] + 1
end
end
end
for name, number in pairs( totalneed ) do
local totallist = inv:get_list( 'src' )
for i, srcitem in pairs( totallist ) do
if srcitem:get_name() == name then
local taken = srcitem:take_item( number )
number = number - taken:get_count()
totallist[i] = srcitem
end
if number <= 0 then
break
end
end
if number > 0 then
result = nil
break
end
end
end
return needed, input, result
end
minetest.register_abm( {
nodenames = { 'castle:workbench' },
interval = 5,
chance = 1,
action = function ( pos, node )
local meta = minetest.get_meta( pos )
local inv = meta:get_inventory()
local result, newinput, needed
if not inv:is_empty( 'src' ) then
-- Check for a valid recipe and sufficient resources to craft it
needed, newinput, result = get_recipe( inv )
if result ~= nil and inv:room_for_item( 'dst', result ) then
inv:add_item( 'dst', result )
for i, item in pairs( needed ) do
if item ~= nil and item ~= '' then
inv:remove_item( 'src', ItemStack( item ) )
end
if newinput[i] ~= nil and not newinput[i]:is_empty() then
inv:add_item( 'src', newinput[i] )
end
end
end
end
end
} )
local function has_locked_chest_privilege(meta, player)
if player:get_player_name() ~= meta:get_string("owner") then
return false
end
return true
end
minetest.register_craft({
output = "castle:workbench",
recipe = {
{"default:steel_ingot","default:steel_ingot","default:steel_ingot"},
{"default:wood", "default:wood","default:steel_ingot"},
{"default:tree", "default:tree","default:steel_ingot"},
}
})
minetest.register_node("castle:dungeon_stone", {
description = "Dungeon Stone",
drawtype = "normal",
tiles = {"castle_dungeon_stone.png"},
groups = {cracky=2},
paramtype = "light",
sounds = default.node_sound_stone_defaults(),
})
minetest.register_craft({
output = "castle:dungeon_stone",
recipe = {
{"default:stonebrick", "default:obsidian"},
}
})
minetest.register_craft({
output = "castle:dungeon_stone",
recipe = {
{"default:stonebrick"},
{"default:obsidian"},
}
})
minetest.register_node("castle:crate", {
description = "Crate",
drawtype = "normal",
tiles = {"castle_crate_top.png","castle_crate_top.png","castle_crate.png","castle_crate.png","castle_crate.png","castle_crate.png"},
groups = {choppy=3},
sounds = default.node_sound_wood_defaults(),
paramtype = "light",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[8,9]"..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[current_name;main;0,0;8,5;]"..
"list[current_player;main;0,5;8,4;]")
meta:set_string("infotext", "Crate")
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name()..
" moves stuff in crate at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" moves stuff to crate at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" takes stuff from crate at "..minetest.pos_to_string(pos))
end,
})
minetest.register_craft({
output = "castle:crate",
recipe = {
{"default:wood", "default:wood", "default:wood"},
{"default:wood", "default:steel_ingot", "default:wood"},
}
})
minetest.register_node("castle:bound_straw", {
description = "Bound Straw",
drawtype = "normal",
tiles = {"castle_straw_bale.png"},
groups = {choppy=4, flammable=1, oddly_breakable_by_hand=3},
sounds = default.node_sound_leaves_defaults(),
paramtype = "light",
})
minetest.register_craft({
output = "castle:bound_straw",
recipe = {
{"castle:straw", "castle:ropes"},
}
})
minetest.register_node("castle:pavement_brick", {
description = "Paving Stone",
drawtype = "normal",
tiles = {"castle_pavement_brick.png"},
groups = {cracky=2},
paramtype = "light",
sounds = default.node_sound_stone_defaults(),
})
minetest.register_craft({
output = "castle:pavement_brick 4",
recipe = {
{"default:stone", "default:cobble"},
{"default:cobble", "default:stone"},
}
})
minetest.register_node("castle:light",{
drawtype = "glasslike",
description = "Light Block",
sunlight_propagates = true,
light_source = 14,
tiles = {"castle_street_light.png"},
groups = {cracky=2},
sounds = default.node_sound_glass_defaults(),
paramtype = "light",
})
minetest.register_craft({
output = "castle:light",
recipe = {
{"default:stick", "default:glass", "default:stick"},
{"default:glass", "default:torch", "default:glass"},
{"default:stick", "default:glass", "default:stick"},
}
})
if minetest.get_modpath("moreblocks") then
stairsplus:register_all("castle", "dungeon_stone", "castle:dungeon_stone", {
description = "Dungeon Stone",
tiles = {"castle_dungeon_stone.png"},
groups = {cracky=2, not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
sunlight_propagates = true,
})
stairsplus:register_all("castle", "pavement_brick", "castle:pavement_brick", {
description = "Pavement Brick",
tiles = {"castle_pavement_brick.png"},
groups = {cracky=2, not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
sunlight_propagates = true,
})
else
stairs.register_stair_and_slab("dungeon_stone", "castle:dungeon_stone",
{cracky=2},
{"castle_dungeon_stone.png"},
"Dungeon Stone Stair",
"Dungeon Stone Slab",
default.node_sound_stone_defaults()
)
stairs.register_stair_and_slab("pavement_brick", "castle:pavement_brick",
{cracky=2},
{"castle_pavement_brick.png"},
"Castle Pavement Stair",
"Castle Pavement Slab",
default.node_sound_stone_defaults()
)
end
minetest.register_node( "castle:chandelier", {
drawtype = "plantlike",
description = "Chandelier",
paramtype = "light",
wield_image = "castle_chandelier_wield.png",
inventory_image = "castle_chandelier_wield.png",
groups = {cracky=2},
sounds = default.node_sound_glass_defaults(),
sunlight_propagates = true,
light_source = 14,
tiles = {
{
name = "castle_chandelier.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.0
},
},
},
selection_box = {
type = "fixed",
fixed = {
{0.35,-0.375,0.35,-0.35,0.5,-0.35},
},
},
})
minetest.register_node( "castle:chandelier_chain", {
drawtype = "plantlike",
description = "Chandelier Chain",
paramtype = "light",
wield_image = "castle_chandelier_chain.png",
inventory_image = "castle_chandelier_chain.png",
groups = {cracky=2},
sounds = default.node_sound_glass_defaults(),
sunlight_propagates = true,
tiles = {"castle_chandelier_chain.png"},
selection_box = {
type = "fixed",
fixed = {
{0.1,-0.5,0.1,-0.1,0.5,-0.1},
},
},
})
|