Use new doc_items field names
[minetest_dice2.git] / init.lua
blobe2feac0d381563ae3fc11f2aa2533d7ce1ccbad0
1 -- Boilerplate to support localized strings if intllib mod is installed.
2 local S
3 if (minetest.get_modpath("intllib")) then
4 S = intllib.Getter()
5 else
6 S = function ( s ) return s end
7 end
9 local dice2 = {}
10 dice2.colors = { "white", "red" }
11 dice2.descriptions = { S("White dice"), S("Red dice") }
13 --[[ throw dice (randomly change facedir and play sound ]]
14 function dice2.throw(pos, node, clicker, itemstack, pointed_thing)
15 local newnode = node
17 --[[ Why math.random(0,23), you ask?
18 This includes the facing direction (1 out of 6) and the rotation (1 out of 4).
19 This is basically the same as
20 math.random(0,5) + math.random(0,4)*6
22 Don’t worry, the probability is still 1/6 for each facing direction. ]]
23 newnode.param2 = math.random(0,23)
24 minetest.swap_node(pos,newnode)
25 minetest.sound_play( {name="dice2_dice_throw", gain=1 }, {pos=pos, loop=false})
26 return itemstack
27 end
29 --[[ place dice and use a random facedir ]]
30 function dice2.construct(pos) --, placer, itemstack, pointed_thing)
31 local newnode = minetest.get_node(pos)
32 newnode.param2 = math.random(0,23)
33 minetest.swap_node(pos,newnode)
34 end
36 for i=1,#dice2.colors do
37 local c = dice2.colors[i]
38 minetest.register_node("dice2:dice_"..c,
40 description = dice2.descriptions[i],
41 _doc_items_longdesc = S("A huge wooden dice with the numbers 1-6, just for fun."),
42 _doc_items_usagehelp = S("Rightclick on a placed dice to “throw” it, which rotates it randomly."),
43 tiles = {
44 "dice2_dice_"..c.."_6.png", "dice2_dice_"..c.."_1.png",
45 "dice2_dice_"..c.."_5.png", "dice2_dice_"..c.."_2.png",
46 "dice2_dice_"..c.."_4.png", "dice2_dice_"..c.."_3.png" },
47 groups = { choppy=2, flammable=1, dig_immediate=2 },
48 paramtype2 = "facedir",
49 sounds = {
50 footstep = { name="dice2_dice_punchstep", gain = 0.75 },
51 dig = { name="dice2_dice_punchstep", gain = 0.8325 },
52 dug = { name="dice2_dice_punchstep", gain = 1 },
53 place = { name="dice2_dice_place", gain = 1 }, },
54 on_rightclick = dice2.throw,
55 on_construct = dice2.construct,
56 is_ground_content = false,
60 minetest.register_craft({
61 type = "fuel",
62 recipe = "dice2:dice_"..c,
63 burntime = 5,
65 end
67 minetest.register_craft({
68 output = "dice2:dice_white 5",
69 recipe = {
70 { "group:wood", "", "group:wood" },
71 { "", "group:wood", ""} ,
72 { "group:wood", "", "group:wood" }
76 if minetest.get_modpath("dye") ~= nil then
77 minetest.register_craft({
78 type = "shapeless",
79 output = "dice2:dice_white",
80 recipe = { "dice2:dice_red", "dye:white", "dye:black" }
82 minetest.register_craft({
83 type = "shapeless",
84 output = "dice2:dice_red",
85 recipe = { "dice2:dice_white", "dye:red", "dye:white" }
87 end