2016-04-13 17:46:45 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
lucky_block = {}
|
2015-12-11 13:48:18 +01:00
|
|
|
lucky_schems = {}
|
2015-12-11 12:08:57 +01:00
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2017-08-28 12:22:18 +02:00
|
|
|
-- Load support for intllib.
|
|
|
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
local S, NS = dofile(MP.."/intllib.lua")
|
|
|
|
|
|
|
|
|
2016-09-30 14:25:00 +02:00
|
|
|
-- example custom function (punches player with 5 damage)
|
|
|
|
local function punchy(pos, player)
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-09-30 14:25:00 +02:00
|
|
|
player:punch(player, 1.0, {
|
|
|
|
full_punch_interval = 1.0,
|
|
|
|
damage_groups = {fleshy = 5}
|
|
|
|
}, nil)
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2017-08-28 12:22:18 +02:00
|
|
|
minetest.chat_send_player(player:get_player_name(), S("Stop hitting yourself!"))
|
2016-12-08 20:42:54 +01:00
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-12-08 20:42:54 +01:00
|
|
|
local function drop(pos, itemstack)
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-12-08 20:42:54 +01:00
|
|
|
local obj = minetest.add_item(pos, itemstack:take_item(itemstack:get_count()))
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-12-08 20:42:54 +01:00
|
|
|
if obj then
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-12-08 20:42:54 +01:00
|
|
|
obj:setvelocity({
|
|
|
|
x = math.random(-10, 10) / 9,
|
|
|
|
y = 5,
|
|
|
|
z = math.random(-10, 10) / 9,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-12-08 20:42:54 +01:00
|
|
|
-- custom function to drop player inventory and replace with dry shrubs
|
|
|
|
local function bushy(pos, player)
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2017-10-09 16:13:23 +02:00
|
|
|
local player_inv = player:get_inventory() ; pos = player:get_pos() or pos
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-12-08 20:42:54 +01:00
|
|
|
for i = 1, player_inv:get_size("main") do
|
|
|
|
drop(pos, player_inv:get_stack("main", i))
|
|
|
|
player_inv:set_stack("main", i, "default:dry_shrub")
|
|
|
|
end
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2017-08-28 12:22:18 +02:00
|
|
|
minetest.chat_send_player(player:get_player_name(), S("Dry shrub takeover!"))
|
2016-09-30 14:25:00 +02:00
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-11-23 17:12:39 +01:00
|
|
|
-- default blocks
|
2015-09-21 12:55:29 +02:00
|
|
|
local lucky_list = {
|
2018-04-10 16:47:46 +02:00
|
|
|
{"sch", "wishingwell", 0, true},
|
2016-12-08 20:42:54 +01:00
|
|
|
{"cus", bushy},
|
2016-09-30 14:25:00 +02:00
|
|
|
{"cus", punchy},
|
2015-09-21 12:55:29 +02:00
|
|
|
{"fal", {"default:wood", "default:gravel", "default:sand", "default:desert_sand", "default:stone", "default:dirt", "default:goldblock"}, 0},
|
|
|
|
{"lig"},
|
|
|
|
{"nod", "lucky_block:super_lucky_block", 0},
|
2017-07-09 10:40:54 +02:00
|
|
|
{"exp", 2},
|
2015-09-21 12:55:29 +02:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- ability to add new blocks to list
|
|
|
|
function lucky_block:add_blocks(list)
|
2016-06-06 16:11:55 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
for s = 1, #list do
|
|
|
|
table.insert(lucky_list, list[s])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-09-30 12:19:47 +02:00
|
|
|
-- call to purge the block list
|
|
|
|
function lucky_block:purge_block_list()
|
2015-11-23 17:12:39 +01:00
|
|
|
lucky_list = {
|
|
|
|
{"nod", "lucky_block:super_lucky_block", 0}
|
|
|
|
}
|
2015-09-30 12:19:47 +02:00
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-12-11 13:48:18 +01:00
|
|
|
-- add schematics to global list
|
|
|
|
function lucky_block:add_schematics(list)
|
2016-06-06 16:11:55 +02:00
|
|
|
|
2015-12-11 13:48:18 +01:00
|
|
|
for s = 1, #list do
|
|
|
|
table.insert(lucky_schems, list[s])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-02-01 19:55:23 +01:00
|
|
|
-- import schematics and default blocks
|
2016-06-06 16:11:55 +02:00
|
|
|
dofile(minetest.get_modpath("lucky_block") .. "/schems.lua")
|
|
|
|
dofile(minetest.get_modpath("lucky_block") .. "/blocks.lua")
|
2015-09-21 12:55:29 +02:00
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- for random colour selection
|
|
|
|
local all_colours = {
|
|
|
|
"grey", "black", "red", "yellow", "green", "cyan", "blue", "magenta",
|
|
|
|
"orange", "violet", "brown", "pink", "dark_grey", "dark_green", "white"
|
|
|
|
}
|
|
|
|
|
|
|
|
-- default items in chests
|
|
|
|
local chest_stuff = {
|
|
|
|
{name = "default:apple", max = 3},
|
|
|
|
{name = "default:steel_ingot", max = 2},
|
|
|
|
{name = "default:gold_ingot", max = 2},
|
|
|
|
{name = "default:diamond", max = 1},
|
|
|
|
{name = "default:pick_steel", max = 1}
|
|
|
|
}
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-09-30 12:19:47 +02:00
|
|
|
-- call to purge the chest items list
|
|
|
|
function lucky_block:purge_chest_items()
|
|
|
|
chest_stuff = {}
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
|
|
|
-- ability to add to chest items list
|
2015-09-30 12:19:47 +02:00
|
|
|
function lucky_block:add_chest_items(list)
|
2016-06-06 16:11:55 +02:00
|
|
|
|
2015-09-30 12:19:47 +02:00
|
|
|
for s = 1, #list do
|
|
|
|
table.insert(chest_stuff, list[s])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- particle effects
|
2017-07-09 10:40:54 +02:00
|
|
|
local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow)
|
|
|
|
|
|
|
|
radius = radius or 2
|
|
|
|
min_size = min_size or 0.5
|
|
|
|
max_size = max_size or 1
|
|
|
|
gravity = gravity or -10
|
|
|
|
glow = glow or 0
|
2016-06-06 16:11:55 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
minetest.add_particlespawner({
|
|
|
|
amount = amount,
|
2017-07-09 10:40:54 +02:00
|
|
|
time = 0.25,
|
|
|
|
minpos = pos,
|
|
|
|
maxpos = pos,
|
|
|
|
minvel = {x = -radius, y = -radius, z = -radius},
|
|
|
|
maxvel = {x = radius, y = radius, z = radius},
|
|
|
|
minacc = {x = 0, y = gravity, z = 0},
|
|
|
|
maxacc = {x = 0, y = gravity, z = 0},
|
|
|
|
minexptime = 0.1,
|
|
|
|
maxexptime = 1,
|
|
|
|
minsize = min_size,
|
|
|
|
maxsize = max_size,
|
2015-09-21 12:55:29 +02:00
|
|
|
texture = texture,
|
2017-07-09 10:40:54 +02:00
|
|
|
glow = glow,
|
2015-09-21 12:55:29 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2018-04-20 13:59:44 +02:00
|
|
|
-- temp entity for mob damage
|
|
|
|
minetest.register_entity("lucky_block:temp", {
|
|
|
|
physical = true,
|
|
|
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
|
|
|
visual_size = {x = 0, y = 0},
|
|
|
|
visual = "sprite",
|
|
|
|
textures = {"tnt_smoke.png"},
|
|
|
|
|
|
|
|
on_step = function(self, dtime)
|
|
|
|
|
|
|
|
self.timer = (self.timer or 0) + dtime
|
|
|
|
|
|
|
|
if self.timer > 0.5 then
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
-- modified from TNT mod to deal entity damage only
|
2017-07-09 10:40:54 +02:00
|
|
|
local function entity_physics(pos, radius)
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
radius = radius * 2
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local objs = minetest.get_objects_inside_radius(pos, radius)
|
2015-11-05 12:43:56 +01:00
|
|
|
local obj_pos, dist
|
|
|
|
|
2018-04-20 13:59:44 +02:00
|
|
|
-- add temp entity to cause damage
|
|
|
|
local tmp_ent = minetest.add_entity(pos, "lucky_block:temp")
|
|
|
|
|
2016-06-06 16:11:55 +02:00
|
|
|
for n = 1, #objs do
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-10-09 16:13:23 +02:00
|
|
|
obj_pos = objs[n]:get_pos()
|
2016-04-13 17:46:45 +02:00
|
|
|
|
2016-06-06 16:11:55 +02:00
|
|
|
dist = vector.distance(pos, obj_pos)
|
|
|
|
if dist < 1 then dist = 1 end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
|
|
|
local damage = math.floor((4 / dist) * radius)
|
2016-06-06 16:11:55 +02:00
|
|
|
local ent = objs[n]:get_luaentity()
|
2016-04-13 17:46:45 +02:00
|
|
|
|
2016-06-06 16:11:55 +02:00
|
|
|
if objs[n]:is_player() then
|
|
|
|
objs[n]:set_hp(objs[n]:get_hp() - damage)
|
2016-04-13 17:46:45 +02:00
|
|
|
|
|
|
|
else --if ent.health then
|
|
|
|
|
2018-04-20 13:59:44 +02:00
|
|
|
--objs[n]:punch(objs[n], 1.0, {
|
|
|
|
objs[n]:punch(tmp_ent, 1.0, {
|
2016-04-13 17:46:45 +02:00
|
|
|
full_punch_interval = 1.0,
|
|
|
|
damage_groups = {fleshy = damage},
|
2017-09-08 10:08:57 +02:00
|
|
|
}, pos)
|
2016-04-13 17:46:45 +02:00
|
|
|
end
|
2015-09-21 12:55:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
|
|
|
-- fill chest with random items from list
|
2017-07-09 10:40:54 +02:00
|
|
|
local function fill_chest(pos, items)
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local stacks = items or {}
|
2016-06-06 16:11:55 +02:00
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
inv:set_size("main", 8 * 4)
|
|
|
|
|
|
|
|
for i = 0, 2, 1 do
|
|
|
|
local stuff = chest_stuff[math.random(1, #chest_stuff)]
|
|
|
|
table.insert(stacks, {name = stuff.name, count = math.random(1, stuff.max)})
|
|
|
|
end
|
|
|
|
|
|
|
|
for s = 1, #stacks do
|
|
|
|
if not inv:contains_item("main", stacks[s]) then
|
|
|
|
inv:set_stack("main", math.random(1, 32), stacks[s])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2017-07-14 16:15:05 +02:00
|
|
|
-- explosion with protection check
|
|
|
|
local function explode(pos, radius, sound)
|
|
|
|
|
|
|
|
sound = sound or "tnt_explode"
|
|
|
|
|
|
|
|
if minetest.get_modpath("tnt") and tnt and tnt.boom
|
|
|
|
and not minetest.is_protected(pos, "") then
|
|
|
|
|
|
|
|
tnt.boom(pos, {
|
|
|
|
radius = radius,
|
|
|
|
damage_radius = radius,
|
|
|
|
sound = sound,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
minetest.sound_play(sound, {pos = pos, gain = 1.0,
|
|
|
|
max_hear_distance = 32})
|
|
|
|
|
|
|
|
entity_physics(pos, radius)
|
|
|
|
|
|
|
|
effect(pos, 32, "tnt_smoke.png", radius * 3, radius * 5, radius, 1, 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- this is what happens when you dig a lucky block
|
|
|
|
local lucky_block = function(pos, digger)
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2018-04-20 13:59:44 +02:00
|
|
|
math.randomseed(os.time()) -- make sure it's really random
|
|
|
|
math.random()
|
|
|
|
|
2017-07-23 16:37:52 +02:00
|
|
|
local luck = math.random(1, #lucky_list) ; -- luck = 1
|
2015-09-21 12:55:29 +02:00
|
|
|
local action = lucky_list[luck][1]
|
|
|
|
local schem
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
-- print ("luck ["..luck.." of "..#lucky_list.."]", action)
|
2015-09-21 12:55:29 +02:00
|
|
|
|
|
|
|
-- place schematic
|
|
|
|
if action == "sch" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 13:48:18 +01:00
|
|
|
if #lucky_schems == 0 then
|
|
|
|
print ("[lucky block] No schematics")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local schem = lucky_list[luck][2]
|
2016-01-02 14:18:26 +01:00
|
|
|
local switch = lucky_list[luck][3] or 0
|
|
|
|
local force = lucky_list[luck][4]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if switch == 1 then
|
2017-10-09 16:13:23 +02:00
|
|
|
pos = vector.round(digger:get_pos())
|
2015-09-21 12:55:29 +02:00
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 13:48:18 +01:00
|
|
|
for i = 1, #lucky_schems do
|
|
|
|
|
|
|
|
if schem == lucky_schems[i][1] then
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
local p1 = vector.subtract(pos, lucky_schems[i][3])
|
2015-12-11 13:48:18 +01:00
|
|
|
|
|
|
|
minetest.place_schematic(p1, lucky_schems[i][2], "", {}, force)
|
|
|
|
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2015-09-21 12:55:29 +02:00
|
|
|
|
2016-09-18 18:37:39 +02:00
|
|
|
if switch == 1 then
|
|
|
|
digger:setpos(pos, false)
|
|
|
|
end
|
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- place node (if chest then fill chest)
|
|
|
|
elseif action == "nod" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local nod = lucky_list[luck][2]
|
|
|
|
local switch = lucky_list[luck][3]
|
|
|
|
local items = lucky_list[luck][4]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if switch == 1 then
|
2017-10-09 16:13:23 +02:00
|
|
|
pos = digger:get_pos()
|
2015-09-21 12:55:29 +02:00
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if not minetest.registered_nodes[nod] then
|
|
|
|
print (nod)
|
|
|
|
nod = "default:goldblock"
|
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-07-09 10:40:54 +02:00
|
|
|
effect(pos, 25, "tnt_smoke.png", 8, 8, 2, 1, 0)
|
2016-06-06 16:11:55 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
minetest.set_node(pos, {name = nod})
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if nod == "default:chest" then
|
|
|
|
fill_chest(pos, items)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- place entity
|
|
|
|
elseif action == "spw" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local pos2 = {}
|
2015-11-05 12:43:56 +01:00
|
|
|
local num = lucky_list[luck][3] or 1
|
2015-09-21 12:55:29 +02:00
|
|
|
local tame = lucky_list[luck][4]
|
|
|
|
local own = lucky_list[luck][5]
|
2015-12-11 12:08:57 +01:00
|
|
|
local range = lucky_list[luck][6] or 5
|
2016-01-03 13:30:57 +01:00
|
|
|
local name = lucky_list[luck][7]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
for i = 1, num do
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-08-04 11:33:10 +02:00
|
|
|
pos2.x = pos.x + math.random(-range, range)
|
2015-09-21 12:55:29 +02:00
|
|
|
pos2.y = pos.y + 1
|
2017-08-04 11:33:10 +02:00
|
|
|
pos2.z = pos.z + math.random(-range, range)
|
|
|
|
|
|
|
|
local nod = minetest.get_node(pos2)
|
|
|
|
local def = minetest.registered_nodes[nod.name]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-08-04 11:33:10 +02:00
|
|
|
if def and def.walkable == false then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local entity = lucky_list[luck][2]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- coloured sheep
|
|
|
|
if entity == "mobs:sheep" then
|
|
|
|
local colour = "_" .. all_colours[math.random(#all_colours)]
|
|
|
|
entity = "mobs:sheep" .. colour
|
|
|
|
end
|
|
|
|
|
2017-09-08 10:08:57 +02:00
|
|
|
-- has entity been registered?
|
|
|
|
if minetest.registered_entities[entity] then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-09-08 10:08:57 +02:00
|
|
|
local ent = minetest.add_entity(pos2, entity):get_luaentity()
|
2015-12-11 12:08:57 +01:00
|
|
|
|
|
|
|
if tame then
|
|
|
|
ent.tamed = true
|
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
if own then
|
|
|
|
ent.owner = digger:get_player_name()
|
|
|
|
end
|
2016-01-03 13:30:57 +01:00
|
|
|
|
|
|
|
if name then
|
|
|
|
ent.nametag = name
|
|
|
|
ent.object:set_properties({
|
|
|
|
nametag = name,
|
|
|
|
nametag_color = "#FFFF00"
|
|
|
|
})
|
|
|
|
end
|
2015-12-11 12:08:57 +01:00
|
|
|
else
|
|
|
|
print ("[lucky_block] " .. entity .. " could not be spawned")
|
2015-09-21 12:55:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- explosion
|
|
|
|
elseif action == "exp" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-04-25 11:23:00 +02:00
|
|
|
local rad = lucky_list[luck][2] or 2
|
2017-07-09 10:40:54 +02:00
|
|
|
local snd = lucky_list[luck][3] or "tnt_explode"
|
|
|
|
|
2017-07-14 16:15:05 +02:00
|
|
|
explode(pos, rad, snd)
|
2015-09-21 12:55:29 +02:00
|
|
|
|
|
|
|
-- teleport
|
|
|
|
elseif action == "tel" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
local xz_range = lucky_list[luck][2] or 10
|
|
|
|
local y_range = lucky_list[luck][3] or 5
|
|
|
|
|
2017-08-04 11:33:10 +02:00
|
|
|
pos.x = pos.x + math.random(-xz_range, xz_range)
|
|
|
|
pos.x = pos.y + math.random(-y_range, y_range)
|
|
|
|
pos.x = pos.z + math.random(-xz_range, xz_range)
|
2015-12-11 12:08:57 +01:00
|
|
|
|
2017-07-09 10:40:54 +02:00
|
|
|
effect(pos, 25, "tnt_smoke.png", 8, 8, 1, -10, 0)
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2016-04-13 17:46:45 +02:00
|
|
|
digger:setpos(pos, false)
|
2015-09-21 12:55:29 +02:00
|
|
|
|
2017-07-09 10:40:54 +02:00
|
|
|
effect(pos, 25, "tnt_smoke.png", 8, 8, 1, -10, 0)
|
|
|
|
|
2017-08-28 12:22:18 +02:00
|
|
|
minetest.chat_send_player(digger:get_player_name(), S("Random Teleport!"))
|
2017-04-25 11:23:00 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- drop items
|
|
|
|
elseif action == "dro" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
local num = lucky_list[luck][3] or 1
|
2015-09-21 12:55:29 +02:00
|
|
|
local colours = lucky_list[luck][4]
|
|
|
|
local items = #lucky_list[luck][2]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
for i = 1, num do
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local item = lucky_list[luck][2][math.random(1, items)]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if colours then
|
|
|
|
item = item .. all_colours[math.random(#all_colours)]
|
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2016-10-30 22:41:22 +01:00
|
|
|
if not minetest.registered_nodes[item]
|
|
|
|
and not minetest.registered_craftitems[item]
|
|
|
|
and not minetest.registered_tools[item] then
|
|
|
|
item = "default:coal_lump"
|
|
|
|
end
|
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
local obj = minetest.add_item(pos, item)
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if obj then
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
obj:setvelocity({
|
2016-06-06 16:11:55 +02:00
|
|
|
x = math.random(-10, 10) / 9,
|
2016-04-13 17:46:45 +02:00
|
|
|
y = 5,
|
2016-06-06 16:11:55 +02:00
|
|
|
z = math.random(-10, 10) / 9,
|
2015-09-21 12:55:29 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- lightning strike
|
|
|
|
elseif action == "lig" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
local nod = lucky_list[luck][2]
|
|
|
|
|
|
|
|
if nod and not minetest.registered_nodes[nod] then
|
|
|
|
print (nod)
|
|
|
|
nod = "fire:basic_flame"
|
|
|
|
end
|
|
|
|
|
2017-10-09 16:13:23 +02:00
|
|
|
pos = digger:get_pos()
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
if nod then
|
|
|
|
minetest.set_node(pos, {name = nod})
|
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-03-11 22:39:10 +01:00
|
|
|
minetest.add_particle({
|
|
|
|
pos = pos,
|
|
|
|
velocity = {x = 0, y = 0, z = 0},
|
|
|
|
acceleration = {x = 0, y = 0, z = 0},
|
|
|
|
expirationtime = 1.0,
|
|
|
|
collisiondetection = false,
|
2015-09-21 12:55:29 +02:00
|
|
|
texture = "lucky_lightning.png",
|
2017-03-11 22:39:10 +01:00
|
|
|
size = math.random(100, 150),
|
|
|
|
glow = 15,
|
2015-09-21 12:55:29 +02:00
|
|
|
})
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
entity_physics(pos, 2)
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
minetest.sound_play("lightning", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 25
|
|
|
|
})
|
|
|
|
|
|
|
|
-- falling nodes
|
|
|
|
elseif action == "fal" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local nods = lucky_list[luck][2]
|
|
|
|
local switch = lucky_list[luck][3]
|
2015-12-11 12:08:57 +01:00
|
|
|
local spread = lucky_list[luck][4]
|
|
|
|
local range = lucky_list[luck][5] or 5
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if switch == 1 then
|
2017-10-09 16:13:23 +02:00
|
|
|
pos = digger:get_pos()
|
2015-09-21 12:55:29 +02:00
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
if spread then
|
|
|
|
pos.y = pos.y + 10
|
|
|
|
else
|
|
|
|
pos.y = pos.y + #nods
|
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
|
2016-04-13 17:46:45 +02:00
|
|
|
local pos2 = {x = pos.x, y = pos.y, z = pos.z}
|
2015-12-11 12:08:57 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
for s = 1, #nods do
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
minetest.after(0.5 * s, function()
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-12-11 12:08:57 +01:00
|
|
|
if spread then
|
2017-08-04 11:33:10 +02:00
|
|
|
pos2.x = pos.x + math.random(-range, range)
|
|
|
|
pos2.z = pos.z + math.random(-range, range)
|
2015-12-11 12:08:57 +01:00
|
|
|
end
|
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local n = minetest.registered_nodes[nods[s]]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-09-08 10:08:57 +02:00
|
|
|
if n then
|
|
|
|
|
|
|
|
local obj = minetest.add_entity(pos2, "__builtin:falling_node")
|
|
|
|
|
2016-06-06 16:11:55 +02:00
|
|
|
obj:get_luaentity():set_node(n)
|
|
|
|
end
|
2015-09-21 12:55:29 +02:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- troll block, disappears or explodes after 2 seconds
|
|
|
|
elseif action == "tro" then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
local nod = lucky_list[luck][2]
|
|
|
|
local snd = lucky_list[luck][3]
|
|
|
|
local exp = lucky_list[luck][4]
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
minetest.set_node(pos, {name = nod})
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if snd then
|
|
|
|
minetest.sound_play(snd, {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 10
|
|
|
|
})
|
|
|
|
end
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2016-10-30 22:41:22 +01:00
|
|
|
if not minetest.registered_nodes[nod] then
|
|
|
|
print (nod)
|
|
|
|
nod = "default:goldblock"
|
|
|
|
end
|
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
minetest.after(2.0, function()
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
if exp then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-07-14 16:15:05 +02:00
|
|
|
minetest.set_node(pos, {name = "air"})
|
|
|
|
|
|
|
|
explode(pos, 2)
|
2015-09-21 12:55:29 +02:00
|
|
|
else
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
minetest.set_node(pos, {name = "air"})
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
minetest.sound_play("default_hard_footstep", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 10
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-08-13 21:13:57 +02:00
|
|
|
-- floor paint
|
|
|
|
elseif action == "flo" then
|
|
|
|
|
|
|
|
local size = lucky_list[luck][2] or 1
|
|
|
|
local nods = lucky_list[luck][3] or {"default:dirt"}
|
|
|
|
local offs = lucky_list[luck][4] or 0
|
|
|
|
local num = 1
|
|
|
|
|
|
|
|
for x = 0, size - 1 do
|
|
|
|
for z = 0, size - 1 do
|
|
|
|
|
|
|
|
minetest.after(0.5 * num, function()
|
|
|
|
|
|
|
|
minetest.set_node({
|
|
|
|
x = (pos.x + x) - offs,
|
|
|
|
y = pos.y - 1,
|
|
|
|
z = (pos.z + z) - offs
|
|
|
|
}, {name = nods[math.random(#nods)]})
|
|
|
|
|
|
|
|
minetest.sound_play("default_place_node", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 10
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
|
|
|
num = num + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-30 14:25:00 +02:00
|
|
|
-- custom function
|
|
|
|
elseif action == "cus" then
|
|
|
|
|
|
|
|
local func = lucky_list[luck][2]
|
|
|
|
|
2017-07-14 16:15:05 +02:00
|
|
|
if func then func(pos, digger) end
|
2015-09-21 12:55:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- lucky block itself
|
|
|
|
minetest.register_node('lucky_block:lucky_block', {
|
2017-08-28 12:22:18 +02:00
|
|
|
description = S("Lucky Block"),
|
2015-11-25 13:09:19 +01:00
|
|
|
tiles = {{
|
2016-06-06 16:11:55 +02:00
|
|
|
name = "lucky_block_animated.png",
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 16,
|
|
|
|
aspect_h = 16,
|
|
|
|
length = 1
|
|
|
|
},
|
2015-11-25 13:09:19 +01:00
|
|
|
}},
|
2015-09-21 12:55:29 +02:00
|
|
|
inventory_image = minetest.inventorycube("lucky_block.png"),
|
|
|
|
sunlight_propagates = false,
|
|
|
|
is_ground_content = false,
|
2016-06-06 16:11:55 +02:00
|
|
|
paramtype = "light",
|
2015-09-21 12:55:29 +02:00
|
|
|
light_source = 3,
|
|
|
|
groups = {oddly_breakable_by_hand = 3},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
on_dig = function(pos, node, digger)
|
|
|
|
minetest.set_node(pos, {name = "air"})
|
|
|
|
lucky_block(pos, digger)
|
|
|
|
end,
|
2017-08-04 11:33:10 +02:00
|
|
|
|
|
|
|
on_blast = function() end,
|
2015-09-21 12:55:29 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "lucky_block:lucky_block",
|
|
|
|
recipe = {
|
|
|
|
{"default:gold_ingot", "default:gold_ingot", "default:gold_ingot"},
|
|
|
|
{"default:gold_ingot", "default:chest", "default:gold_ingot"},
|
|
|
|
{"default:gold_ingot", "default:gold_ingot", "default:gold_ingot"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
-- super lucky block
|
|
|
|
minetest.register_node('lucky_block:super_lucky_block', {
|
2017-08-28 12:22:18 +02:00
|
|
|
description = S("Super Lucky Block (use pick)"),
|
2015-11-25 13:09:19 +01:00
|
|
|
tiles = {{
|
|
|
|
name="lucky_block_super_animated.png",
|
2016-06-06 16:11:55 +02:00
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 16,
|
|
|
|
aspect_h = 16,
|
|
|
|
length = 1
|
|
|
|
},
|
2015-11-25 13:09:19 +01:00
|
|
|
}},
|
2015-09-21 12:55:29 +02:00
|
|
|
inventory_image = minetest.inventorycube("lucky_block_super.png"),
|
|
|
|
sunlight_propagates = false,
|
|
|
|
is_ground_content = false,
|
2016-06-06 16:11:55 +02:00
|
|
|
paramtype = "light",
|
2015-09-21 12:55:29 +02:00
|
|
|
groups = {cracky = 1, level = 2},
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("infotext", "Super Lucky Block")
|
|
|
|
end,
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2015-09-21 12:55:29 +02:00
|
|
|
on_dig = function(pos)
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2016-06-06 16:11:55 +02:00
|
|
|
if math.random(1, 10) < 8 then
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2016-06-06 16:11:55 +02:00
|
|
|
minetest.set_node(pos, {name = "air"})
|
2015-11-05 12:43:56 +01:00
|
|
|
|
2017-07-09 10:40:54 +02:00
|
|
|
effect(pos, 25, "tnt_smoke.png", 8, 8, 1, -10, 0)
|
2016-06-06 16:11:55 +02:00
|
|
|
|
|
|
|
minetest.sound_play("fart1", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 10
|
|
|
|
})
|
2017-07-23 16:37:52 +02:00
|
|
|
|
|
|
|
if math.random(1, 5) == 1 then
|
|
|
|
pos.y = pos.y + 0.5
|
2017-08-04 11:33:10 +02:00
|
|
|
minetest.add_item(pos, "default:goldblock " .. math.random(1, 5))
|
2017-07-23 16:37:52 +02:00
|
|
|
end
|
|
|
|
|
2016-06-06 16:11:55 +02:00
|
|
|
else
|
|
|
|
minetest.set_node(pos, {name = "lucky_block:lucky_block"})
|
|
|
|
end
|
2015-09-21 12:55:29 +02:00
|
|
|
end,
|
2017-08-04 11:33:10 +02:00
|
|
|
|
|
|
|
on_blast = function() end,
|
2015-09-21 12:55:29 +02:00
|
|
|
})
|
|
|
|
|
2017-06-08 15:36:57 +02:00
|
|
|
|
2016-11-12 12:19:52 +01:00
|
|
|
minetest.after(0, function()
|
2017-08-28 12:22:18 +02:00
|
|
|
print (S("[MOD] Lucky Blocks loaded (@1 in total)", #lucky_list))
|
2016-11-12 12:19:52 +01:00
|
|
|
end)
|
|
|
|
|