91 lines
2.2 KiB
Lua
91 lines
2.2 KiB
Lua
local COOLDOWN = 1.8
|
|
local PARTICLE_TIME = COOLDOWN-0.2
|
|
|
|
local function roll_dice(pos)
|
|
local node = minetest.get_node(pos)
|
|
|
|
local timer = minetest.get_node_timer(pos)
|
|
if timer:is_started() then
|
|
return
|
|
end
|
|
timer:start(COOLDOWN)
|
|
|
|
local facedir = math.random(0, 23)
|
|
node.param2 = facedir
|
|
minetest.swap_node(pos, node)
|
|
|
|
local spawner_def = {
|
|
size = 0.6,
|
|
amount = 42,
|
|
time = 0.7,
|
|
glow = 10,
|
|
pos = {
|
|
min = vector.add(pos, vector.new(-0.5, -0.5, -0.5)),
|
|
max = vector.add(pos, vector.new(0.5, 0.5, 0.5)),
|
|
},
|
|
vel = {
|
|
min = { x = 2, y = 3, z = 2 },
|
|
|
|
max = { x = -2, y = 1, z = -2 },
|
|
},
|
|
acc = {
|
|
min = { x = 0, y = 10, z = 0 },
|
|
max = { x = 0, y = 10, z = 0 },
|
|
},
|
|
exptime = { min = 0.2, max = 0.5, },
|
|
vertical = false,
|
|
texture = "yl_dice_6sides.png",
|
|
animation = {
|
|
type = "sheet_2d",
|
|
frames_w = 2,
|
|
frames_h = 3,
|
|
frame_length = 0.1,
|
|
}
|
|
}
|
|
|
|
-- can't be bothered to figure out math for this
|
|
local V = {
|
|
1, 1, 1, 1,
|
|
2, 3, 4, 5,
|
|
4, 5, 2, 3,
|
|
5, 2, 3, 4,
|
|
3, 4, 5, 2,
|
|
6, 6, 6, 6,
|
|
}
|
|
|
|
minetest.add_particlespawner(spawner_def)
|
|
|
|
local val = V[facedir + 1] or 0
|
|
local particle_def = {
|
|
expirationtime = PARTICLE_TIME,
|
|
pos = vector.add(pos, vector.new(0.0, 0.8, 0.0)),
|
|
velocity = { x = 0, y = 0.1, z = 0 },
|
|
glow = 14,
|
|
texture = ("yl_dice_%d.png"):format(val),
|
|
size = 4,
|
|
}
|
|
minetest.add_particle(particle_def)
|
|
end
|
|
|
|
minetest.register_node("yl_dice:dice", {
|
|
description = "Dice",
|
|
drawtype = "mesh",
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
mesh = "yl_dice6.obj",
|
|
tiles = {
|
|
"yl_dice_6sides.png",
|
|
},
|
|
drop = "yl_dice:dice",
|
|
inventory_image = "yl_dice_3.png",
|
|
wield_image = "yl_dice_3.png",
|
|
groups = { dig_immediate = 2 },
|
|
|
|
on_construct = function(pos)
|
|
roll_dice(pos)
|
|
end,
|
|
on_rightclick = function(pos, node, puncher, itemstack, pointed_thing)
|
|
roll_dice(pos)
|
|
end
|
|
})
|