2019-03-07 11:12:14 -08:00
|
|
|
|
local S = minetest.get_translator("dice2")
|
2016-07-02 05:22:27 -07:00
|
|
|
|
|
2016-08-11 08:54:40 -07:00
|
|
|
|
local dice2 = {}
|
2016-07-02 05:22:27 -07:00
|
|
|
|
dice2.colors = { "white", "red" }
|
2016-08-07 09:25:27 -07:00
|
|
|
|
dice2.descriptions = { S("White dice"), S("Red dice") }
|
2016-07-02 05:22:27 -07:00
|
|
|
|
|
|
|
|
|
--[[ 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_dice_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 i=1,#dice2.colors do
|
2016-08-11 08:54:40 -07:00
|
|
|
|
local c = dice2.colors[i]
|
2016-10-30 16:07:58 -07:00
|
|
|
|
minetest.register_node("dice2:dice_"..c,
|
2016-07-02 05:22:27 -07:00
|
|
|
|
{
|
|
|
|
|
description = dice2.descriptions[i],
|
2016-11-15 21:39:14 -08:00
|
|
|
|
_doc_items_longdesc = S("A huge wooden dice with the numbers 1-6, just for fun."),
|
|
|
|
|
_doc_items_usagehelp = S("Rightclick on a placed dice to “throw” it, which rotates it randomly."),
|
2016-07-02 05:22:27 -07:00
|
|
|
|
tiles = {
|
|
|
|
|
"dice2_dice_"..c.."_6.png", "dice2_dice_"..c.."_1.png",
|
|
|
|
|
"dice2_dice_"..c.."_5.png", "dice2_dice_"..c.."_2.png",
|
|
|
|
|
"dice2_dice_"..c.."_4.png", "dice2_dice_"..c.."_3.png" },
|
|
|
|
|
groups = { choppy=2, flammable=1, dig_immediate=2 },
|
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
|
sounds = {
|
|
|
|
|
footstep = { name="dice2_dice_punchstep", gain = 0.75 },
|
|
|
|
|
dig = { name="dice2_dice_punchstep", gain = 0.8325 },
|
|
|
|
|
dug = { name="dice2_dice_punchstep", gain = 1 },
|
|
|
|
|
place = { name="dice2_dice_place", gain = 1 }, },
|
|
|
|
|
on_rightclick = dice2.throw,
|
2016-11-01 17:03:06 -07:00
|
|
|
|
on_construct = dice2.construct,
|
|
|
|
|
is_ground_content = false,
|
2016-07-02 05:22:27 -07:00
|
|
|
|
}
|
|
|
|
|
)
|
2016-10-30 16:07:58 -07:00
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
|
type = "fuel",
|
|
|
|
|
recipe = "dice2:dice_"..c,
|
|
|
|
|
burntime = 5,
|
|
|
|
|
})
|
2016-07-02 05:22:27 -07:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
|
output = "dice2:dice_white 5",
|
|
|
|
|
recipe = {
|
|
|
|
|
{ "group:wood", "", "group:wood" },
|
|
|
|
|
{ "", "group:wood", ""} ,
|
|
|
|
|
{ "group:wood", "", "group:wood" }
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if minetest.get_modpath("dye") ~= nil then
|
|
|
|
|
minetest.register_craft({
|
|
|
|
|
type = "shapeless",
|
|
|
|
|
output = "dice2:dice_white",
|
|
|
|
|
recipe = { "dice2:dice_red", "dye:white", "dye:black" }
|
|
|
|
|
})
|
|
|
|
|
minetest.register_craft({
|
|
|
|
|
type = "shapeless",
|
|
|
|
|
output = "dice2:dice_red",
|
|
|
|
|
recipe = { "dice2:dice_white", "dye:red", "dye:white" }
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|