1 -- Boilerplate to support localized strings if intllib mod is installed.
3 if (minetest
.get_modpath("intllib")) then
4 dofile(minetest
.get_modpath("intllib").."/intllib.lua")
5 S
= intllib
.Getter(minetest
.get_current_modname())
7 S
= function ( s
) return s
end
11 dice2
.colors
= { "white", "red" }
12 dice2
.descriptions
= { S("white dice"), S("red dice") }
14 --[[ throw dice (randomly change facedir and play sound ]]
15 function dice2
.throw(pos
, node
, clicker
, itemstack
, pointed_thing
)
18 --[[ Why math.random(0,23), you ask?
19 This includes the facing direction (1 out of 6) and the rotation (1 out of 4).
20 This is basically the same as
21 math.random(0,5) + math.random(0,4)*6
23 Don’t worry, the probability is still 1/6 for each facing direction. ]]
24 newnode
.param2
= math
.random(0,23)
25 minetest
.swap_node(pos
,newnode
)
26 minetest
.sound_play( {name
="dice2_dice_throw", gain
=1 }, {pos
=pos
, loop
=false})
30 --[[ place dice and use a random facedir ]]
31 function dice2
.construct(pos
) --, placer, itemstack, pointed_thing)
32 local newnode
= minetest
.get_node(pos
)
33 newnode
.param2
= math
.random(0,23)
34 minetest
.swap_node(pos
,newnode
)
37 for i
=1,#dice2
.colors
do
39 minetest
.register_node("dice2:dice_"..c
,
41 description
= dice2
.descriptions
[i
],
43 "dice2_dice_"..c
.."_6.png", "dice2_dice_"..c
.."_1.png",
44 "dice2_dice_"..c
.."_5.png", "dice2_dice_"..c
.."_2.png",
45 "dice2_dice_"..c
.."_4.png", "dice2_dice_"..c
.."_3.png" },
46 groups
= { choppy
=2, flammable
=1, dig_immediate
=2 },
47 paramtype2
= "facedir",
49 footstep
= { name
="dice2_dice_punchstep", gain
= 0.75 },
50 dig
= { name
="dice2_dice_punchstep", gain
= 0.8325 },
51 dug
= { name
="dice2_dice_punchstep", gain
= 1 },
52 place
= { name
="dice2_dice_place", gain
= 1 }, },
53 on_rightclick
= dice2
.throw
,
54 on_construct
= dice2
.construct
59 minetest
.register_craft({
60 output
= "dice2:dice_white 5",
62 { "group:wood", "", "group:wood" },
63 { "", "group:wood", ""} ,
64 { "group:wood", "", "group:wood" }
68 if minetest
.get_modpath("dye") ~= nil then
69 minetest
.register_craft({
71 output
= "dice2:dice_white",
72 recipe
= { "dice2:dice_red", "dye:white", "dye:black" }
74 minetest
.register_craft({
76 output
= "dice2:dice_red",
77 recipe
= { "dice2:dice_white", "dye:red", "dye:white" }
82 if minetest
.get_modpath("doc_items") ~= nil then
83 local longdesc
= S("A huge wooden dice with the numbers 1-6, just for fun.")
84 local usagehelp
= S("Rightclick on a placed dice to “throw” it, which rotates it randomly.")
86 doc
.sub
.items
.set_items_longdesc({
87 ["dice2:dice_white"] = longdesc
,
88 ["dice2:dice_red"] = longdesc
,
90 doc
.sub
.items
.set_items_usagehelp({
91 ["dice2:dice_white"] = usagehelp
,
92 ["dice2:dice_red"] = usagehelp
,