local reg_node = ocutil.safe_register_node -- Boilerplate to support localized strings if intllib mod is installed. local S if (minetest.get_modpath("intllib")) then S = intllib.Getter() else S = function ( s ) return s end end dice2 = {} local dice2_param = { { "white" , "#FFFFFF" } , { "red" , "#AA0000" } , { "green" , "#00BB00" } , { "blue" , "#0000AA" } , { "orange" , "#ee6200" } , { "violet" , "#6E00CB" } , { "brown" , "#654321" } , } --[[ throw dice (randomly change facedir and play sound ]] function dice2.throw(pos, node, clicker, itemstack, pointed_thing) local newnode = node --[[ Why math.random(0,23), you ask? This includes the facing direction (1 out of 6) and the rotation (1 out of 4). This is basically the same as math.random(0,5) + math.random(0,4)*6 . Don’t worry, the probability is still 1/6 for each facing direction. ]] newnode.param2 = math.random(0,23) minetest.swap_node(pos,newnode) minetest.sound_play( {name="dice2_throw", gain=1 }, {pos=pos, loop=false}) return itemstack end --[[ place dice and use a random facedir ]] function dice2.construct(pos) --, placer, itemstack, pointed_thing) local newnode = minetest.get_node(pos) newnode.param2 = math.random(0,23) minetest.swap_node(pos,newnode) end for _, row in ipairs (dice2_param) do local color_name = row [1] local color_code = row [2] local pngbase = "dice2_" .. color_name local postmod = "" if color_name == "white" then pngbase = "dice2_blank.png^[colorize:#000000" .. ":255^dice2_trans" postmod = "^[invert:rgb" else pngbase = "dice2_blank.png^[colorize:" .. color_code .. ":255^dice2_trans" end local node_name = "dice2:" .. color_name local node_alt = "dice2:dice_" .. color_name reg_node (node_name, { description = ocutil.first_to_upper (color_name) .. " dice" , tiles = { pngbase .. "6.png" .. postmod , pngbase .. "1.png" .. postmod , pngbase .. "5.png" .. postmod , pngbase .. "2.png" .. postmod , pngbase .. "4.png" .. postmod , pngbase .. "3.png" .. postmod , } , groups = { choppy=2, flammable=1, dig_immediate=2 } , paramtype2 = "facedir" , sounds = { footstep = { name="dice2_punchstep" , gain = 0.75 } , dig = { name="dice2_punchstep" , gain = 0.8325 } , dug = { name="dice2_punchstep" , gain = 1 } , place = { name="dice2_place" , gain = 1 } , } , on_rightclick = dice2.throw , on_construct = dice2.construct , is_ground_content = false , }) minetest.register_alias (node_alt, node_name) minetest.register_craft({ type = "fuel" , recipe = node_name , burntime = 5 , }) local obj = "dye:" .. color_name if color_name ~= "white" and ocutil.thing_exists (obj) then minetest.register_craft ({ type = "shapeless", output = node_name , recipe = { "dice2:dice_white", obj, "dye:white" } }) end end minetest.register_craft({ output = "dice2:dice_white 5", recipe = { { "group:wood", "", "group:wood" }, { "", "group:wood", ""} , { "group:wood", "", "group:wood" } } })