1 local S
= minetest
.get_translator("dice2")
4 dice2
.colors
= { "white", "red" }
5 dice2
.descriptions
= { S("White dice"), S("Red dice") }
7 --[[ throw dice (randomly change facedir and play sound ]]
8 function dice2
.throw(pos
, node
, clicker
, itemstack
, pointed_thing
)
11 --[[ Why math.random(0,23), you ask?
12 This includes the facing direction (1 out of 6) and the rotation (1 out of 4).
13 This is basically the same as
14 math.random(0,5) + math.random(0,4)*6
16 Don’t worry, the probability is still 1/6 for each facing direction. ]]
17 newnode
.param2
= math
.random(0,23)
18 minetest
.swap_node(pos
,newnode
)
19 minetest
.sound_play( {name
="dice2_dice_throw", gain
=1 }, {pos
=pos
, loop
=false}, true)
23 --[[ place dice and use a random facedir ]]
24 function dice2
.construct(pos
) --, placer, itemstack, pointed_thing)
25 local newnode
= minetest
.get_node(pos
)
26 newnode
.param2
= math
.random(0,23)
27 minetest
.swap_node(pos
,newnode
)
30 for i
=1,#dice2
.colors
do
31 local c
= dice2
.colors
[i
]
32 minetest
.register_node("dice2:dice_"..c
,
34 description
= dice2
.descriptions
[i
],
35 _doc_items_longdesc
= S("A huge wooden dice with the numbers 1-6, just for fun."),
36 _doc_items_usagehelp
= S("Rightclick on a placed dice to “throw” it, which rotates it randomly."),
38 "dice2_dice_"..c
.."_6.png", "dice2_dice_"..c
.."_1.png",
39 "dice2_dice_"..c
.."_5.png", "dice2_dice_"..c
.."_2.png",
40 "dice2_dice_"..c
.."_4.png", "dice2_dice_"..c
.."_3.png" },
41 groups
= { choppy
=2, flammable
=1, dig_immediate
=2 },
42 paramtype2
= "facedir",
44 footstep
= { name
="dice2_dice_punchstep", gain
= 0.75 },
45 dig
= { name
="dice2_dice_punchstep", gain
= 0.8325 },
46 dug
= { name
="dice2_dice_punchstep", gain
= 1 },
47 place
= { name
="dice2_dice_place", gain
= 1 }, },
48 on_rightclick
= dice2
.throw
,
49 on_construct
= dice2
.construct
,
50 is_ground_content
= false,
54 minetest
.register_craft({
56 recipe
= "dice2:dice_"..c
,
61 minetest
.register_craft({
62 output
= "dice2:dice_white 5",
64 { "group:wood", "", "group:wood" },
65 { "", "group:wood", ""} ,
66 { "group:wood", "", "group:wood" }
70 if minetest
.get_modpath("dye") ~= nil then
71 minetest
.register_craft({
73 output
= "dice2:dice_white",
74 recipe
= { "dice2:dice_red", "dye:white", "dye:black" }
76 minetest
.register_craft({
78 output
= "dice2:dice_red",
79 recipe
= { "dice2:dice_white", "dye:red", "dye:white" }