Initial upload

This commit is contained in:
TenPlus1 2015-09-21 11:55:29 +01:00
parent 7f6274d466
commit 7c152c30a3
10 changed files with 831 additions and 0 deletions

125
api.txt Normal file

@ -0,0 +1,125 @@
Lucky Block API
===============
Please make sure that lucky_block appears in the depends.txt file of your mod.
USAGE: (check blocks.lua for many examples)
lucky_block:add_block({line})
LINE COMMANDS:
-= Place Node
{"nod", "node name", position, chest items}
e.g.
Replace Lucky Block with Dirt Block
{"nod", "default:dirt", 0}
Place Fire at player position
{"nod", "fire:basic_flame", 1}
Replace Lucky Block with chest containing random items from default list
{"nod", "default:chest", 0}
Replace Lucky Block with chest containing random items PLUS a few extra
{"nod", "default:chest", 0, {{name="flowers:rose", max=5}, {name="default:goldblock", max=2}}}
-= Drop Item(s)
{"dro", {"item names"}, number to drop, random colour}
e.g.
Drop 5x Torches
{"dro", {"default:torch"}, 5}
Drop 10x randomly Coloured Wool (colour name added to end of item string)
{"dro", {"wool:"}, 10, true}
Drop 5x random Tools from list
{"dro", {"default:pick_mese", "default:shovel_steel", "default:axe_diamond"}, 5}
-= Place Schematic
{"sch", "filename / schematic table", position, {schematic xyz offset}, force placement}
e.g.
Replace Lucky Block with Tree
{"sch", minetest.get_modpath("default").."/schematics/apple_tree.mts", 0, {x=1, y=0, z=1}, false}
Place 2x Lava at player position
{"sch", {
size = {x = 1, y = 2, z = 1},
data = {
{name="default:lava_source", param1=255}, {name="default:lava_source", param1=255},
}, 1, {x=0, y=0, z=0}, true}
-= Spawn Entity(s)
{"spw", "entity name", number to spawn, tamed, owned}
e.g.
Spawn 2x Dirt Monsters
{"spw", "mobs:dirt_monster", 2}
Spawn 5x randomly coloured Sheep (random colour only works with sheep)
{"spw", "mobs:sheep", 5}
Spawn NPC who is tamed and owned by player
{"spw", "mobs:npc", 1, true, true}
-= Falling Blocks
{"fal", {node list}, position}
e.g.
Remove Lucky Block and Drop 2x Sand topped with 1x Gold Block
{"fal", {"default:sand", "default:sand", "default:goldblock"}, 0}
Drop 2x Obsidian onto player
{"fal", {"default:obsidian", "default:obsidian"}, 1}
-= Troll Block
{"tro", "node name", "sound", explosion},
e.g.
Add diamond block then after 2 seconds remove with explosion
{"tro", "default:diamondblock", nil, true}
Add gold block with wood sound, then after 2 seconds remove with pop
{"tro", "default:goldblock", "default_wood_footstep", nil}
-= Explosion (no settings, Lucky Block explodes and deals damage to all nearby)
{"exp"}
-= Teleport (no settings, player teleports +/- 10 blocks in any direction)
{"tel"}
-= Lightning Strike (no settings, Lucky Block is hit by lightning and deals damage)
{"lig"}

295
blocks.lua Normal file

@ -0,0 +1,295 @@
-- Generate schematics
local a = "air"
local l = "default:lava_source"
local s = "default:sand"
local d = "default:dirt"
local w = "farming:soil_wet"
local v = "default:water_source"
local c = "farming:cotton_8"
local h = "farming:wheat_8"
local o = "default:obsidian_glass"
local insta_farm = {
size = {x = 5, y = 3, z = 3},
data = {
-- left slice, middle slice, right slice (bottom to top)
{name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255},
{name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255},
{name=c, param1=255}, {name=c, param1=255}, {name=c, param1=255}, {name=c, param1=255}, {name=c, param1=255},
{name=w, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=w, param1=255},
{name=w, param1=255}, {name=v, param1=255}, {name=v, param1=255}, {name=v, param1=255}, {name=w, param1=255},
{name=c, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=h, param1=255},
{name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=s, param1=255},
{name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255},
{name=h, param1=255}, {name=h, param1=255}, {name=h, param1=255}, {name=h, param1=255}, {name=h, param1=255},
},
}
local lava_trap = {
size = {x = 3, y = 6, z = 3},
data = {
-- left slice, middle slice, right slice (bottom to top)
{name=l, param1=255}, {name=l, param1=255}, {name=l, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=l, param1=255}, {name=l, param1=255}, {name=l, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=l, param1=255}, {name=l, param1=255}, {name=l, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
{name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255},
},
}
local sand_trap = {
size = {x = 3, y = 3, z = 3},
data = {
-- left slice, middle slice, right slice (bottom to top)
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
{name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255},
},
}
local water_trap = {
size = {x = 3, y = 3, z = 3},
data = {
-- left slice, middle slice, right slice (bottom to top)
{name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255},
{name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255},
{name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255},
{name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255},
{name=o, param1=255}, {name=v, param1=255}, {name=o, param1=255},
{name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255},
{name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255},
{name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255},
{name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255},
},
}
-- Default blocks
lucky_block:add_blocks({
{"sch", water_trap, 1, {x = 1, y = 0, z = 1}, true},
{"tel"},
{"dro", {"wool:"}, 10, true},
{"dro", {"default:apple"}, 10},
{"dro", {"default:snow"}, 10},
{"nod", "default:chest", 0, {
{name = "bucket:bucket_water", max = 1},
{name = "default:wood", max = 3},
{name = "default:pick_diamond", max = 1},
{name = "default:coal_lump", max = 3}}},
{"sch", sand_trap, 1, {x = 1, y = 0, z = 1}, true},
{"nod", "flowers:rose", 0},
{"sch", lava_trap, 1, {x = 1, y = 5, z = 1}, true},
{"dro", {"default:mese_crystal_fragment", "default:mese_crystal"}, 10},
{"exp"},
{"nod", "default:diamondblock", 0},
{"nod", "default:steelblock", 0},
{"nod", "default:dirt", 0},
{"dro", {"default:sword_steel"}, 1},
{"dro", {"default:pick_steel"}, 1},
{"dro", {"default:shovel_steel"}, 1},
{"dro", {"default:coal_lump"}, 3},
{"dro", {"default:axe_steel"}, 1},
{"dro", {"default:sword_bronze"}, 1},
{"nod", "default:wood", 0},
{"dro", {"default:pick_bronze"}, 1},
{"dro", {"default:shovel_bronze"}, 1},
{"nod", "default:gravel", 0},
{"dro", {"default:axe_bronze"}, 1},
})
-- Farming mod
if minetest.get_modpath("farming") then
lucky_block:add_blocks({
{"dro", {"farming:bread"}, 5},
{"sch", insta_farm, 0, {x = 2, y = 2, z = 1}, true},
})
if farming.mod and farming.mod == "redo" then
lucky_block:add_blocks({
{"dro", {"farming:corn"}, 5},
{"dro", {"farming:coffee_cup_hot"}, 1},
{"dro", {"farming:bread"}, 5},
{"nod", "farming:jackolantern", 0},
{"dro", {"farming:bottle_ethanol"}, 1},
{"nod", "farming:melon", 0},
{"dro", {"farming:donut", "farming:donut_chocolate", "farming:donut_apple"}, 5},
})
end
end
-- Mobs mod
if minetest.get_modpath("mobs") then
lucky_block:add_blocks({
{"spw", "mobs:sheep", 5},
{"spw", "mobs:dungeon_master", 1},
{"spw", "mobs:sand_monster", 3},
{"spw", "mobs:stone_monster", 3},
{"dro", {"mobs:meat_raw"}, 5},
{"spw", "mobs:rat", 5},
{"spw", "mobs:dirt_monster", 3},
{"spw", "mobs:tree_monster", 3},
{"spw", "mobs:oerkki", 3},
{"dro", {"mobs:rat_cooked"}, 5},
})
if mobs.mod and mobs.mod == "redo" then
lucky_block:add_blocks({
{"spw", "mobs:bunny", 3},
{"spw", "mobs:spider", 5},
{"nod", "mobs:honey_block", 0},
{"spw", "mobs:pumba", 5},
{"spw", "mobs:mese_monster", 2},
{"nod", "mobs:cheeseblock", 0},
{"spw", "mobs:chicken", 5},
{"dro", {"mobs:egg"}, 5},
{"spw", "mobs:lava_flan", 3},
{"spw", "mobs:cow", 5},
{"dro", {"mobs:bucket_milk"}, 10},
{"spw", "mobs:kitten", 2},
{"tro", "default:nyancat", "mobs_kitten", true},
{"nod", "default:chest", 0, {
{name = "mobs:lava_orb", max = 1}}},
})
end
end
-- Home Decor mod
if minetest.get_modpath("homedecor") then
lucky_block:add_blocks({
{"nod", "homedecor:toilet", 0},
})
end
-- Teleport Potion mod
if minetest.get_modpath("teleport_potion") then
lucky_block:add_blocks({
{"dro", {"teleport_potion:potion"}, 1},
})
end
-- Protector mod
if minetest.get_modpath("protector") then
lucky_block:add_blocks({
{"dro", {"protector:protect"}, 3},
})
if protector.mod and protector.mod == "redo" then
lucky_block:add_blocks({
{"dro", {"protector:protect2"}, 3},
{"dro", {"protector:door_wood"}, 1},
{"dro", {"protector:door_steel"}, 1},
{"dro", {"protector:chest"}, 1},
})
end
end
-- Ethereal mod
if minetest.get_modpath("ethereal") then
local epath = minetest.get_modpath("ethereal") .. "/schematics/"
lucky_block:add_blocks({
{"nod", "ethereal:crystal_spike", 1},
{"sch", epath .. "pinetree.mts", 0, {x = 3, y = 0, z = 3}},
{"dro", {"ethereal:orange"}, 10},
{"sch", ethereal.appletree, 0, {x = 1, y = 0, z = 1}},
{"dro", {"ethereal:strawberry"}, 10},
{"sch", ethereal.bananatree, 0, {x = 3, y = 0, z = 3}},
{"sch", ethereal.orangetree, 0, {x = 1, y = 0, z = 1}},
{"dro", {"ethereal:banana"}, 10},
{"sch", epath .. "acaciatree.mts", 0, {x = 5, y = 0, z = 5}},
{"dro", {"ethereal:golden_apple"}, 3},
{"sch", epath .. "palmtree.mts", 0, {x = 4, y = 0, z = 4}},
{"dro", {"ethereal:tree_sapling", "ethereal:orange_tree_sapling", "ethereal:banana_tree_sapling"}, 10},
{"dro", {"ethereal:green_dirt", "ethereal:prairie_dirt", "ethereal:grove_dirt", "ethereal:cold_dirt"}, 10},
{"dro", {"ethereal:axe_crystal"}, 1},
{"dro", {"ethereal:sword_crystal"}, 1},
{"dro", {"ethereal:pick_crystal"}, 1},
{"dro", {"ethereal:fish_raw"}, 1},
{"dro", {"ethereal:shovel_crystal"}, 1},
{"dro", {"ethereal:fishing_rod_baited"}, 1},
})
end
-- 3D Armor mod
if minetest.get_modpath("3d_armor") then
lucky_block:add_blocks({
{"dro", {"3d_armor:boots_wood", "3d_armor:leggings_wood", "3d_armor:chestplate_wood", "3d_armor:helmet_wood", "shields:shield_wood"}, 3},
{"dro", {"3d_armor:boots_steel", "3d_armor:leggings_steel", "3d_armor:chestplate_steel", "3d_armor:helmet_steel", "shields:shield_steel"}, 3},
{"dro", {"3d_armor:boots_gold", "3d_armor:leggings_gold", "3d_armor:chestplate_gold", "3d_armor:helmet_gold", "shields:shield_gold"}, 3},
{"dro", {"3d_armor:boots_cactus", "3d_armor:leggings_cactus", "3d_armor:chestplate_cactus", "3d_armor:helmet_cactus", "shields:shield_cactus"}, 3},
{"dro", {"3d_armor:boots_bronze", "3d_armor:leggings_bronze", "3d_armor:chestplate_bronze", "3d_armor:helmet_bronze", "shields:shield_bronze"}, 3},
})
end
-- Fire mod
if minetest.get_modpath("fire") then
lucky_block:add_blocks({
{"nod", "fire:basic_flame", 1},
})
end
-- Pie mod
if minetest.get_modpath("pie") then
lucky_block:add_blocks({
{"nod", "pie:pie_0", 0},
{"nod", "pie:choc_0", 0},
{"nod", "pie:coff_0", 0},
{"nod", "pie:rvel_0", 0},
{"nod", "pie:scsk_0", 0},
{"nod", "pie:meat_0", 0},
})
end
-- Bakedclay mod
if minetest.get_modpath("bakedclay") then
lucky_block:add_blocks({
{"dro", {"bakedclay:"}, 10, true}
})
end
-- Xanadu Server specific
if minetest.get_modpath("xanadu") then
lucky_block:add_blocks({
{"dro", {"xanadu:cupcake"}, 8},
{"spw", "mobs:creeper", 1},
{"spw", "mobs:npc", 1, true, true},
{"nod", "default:chest", 0, {
{name = "xanadu:axe_super", max = 1},
{name = "xanadu:pizza", max = 2}}},
{"dro", {"paintings:"}, 10, true},
{"spw", "mobs:greensmall", 4},
{"dro", {"carpet:"}, 10, true},
{"dro", {"carpet:wallpaper_"}, 10, true},
{"nod", "default:chest", 0, {
{name = "mobs:mese_monster_wing", max = 1}}}
})
end

9
depends.txt Normal file

@ -0,0 +1,9 @@
default
farming?
mobs?
ethereal?
bakedclay?
pie?
paintings?
carpet?
3d_armor?

402
init.lua Normal file

@ -0,0 +1,402 @@
lucky_block = {}
-- default block
local lucky_list = {
{"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},
}
-- ability to add new blocks to list
function lucky_block:add_blocks(list)
for s = 1, #list do
table.insert(lucky_list, list[s])
end
end
-- import blocks
dofile(minetest.get_modpath("lucky_block").."/blocks.lua")
-- 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}
}
-- particle effects
function effect(pos, amount, texture, max_size)
minetest.add_particlespawner({
amount = amount,
time = 0.5,
minpos = {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
maxpos = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
minvel = {x = -5, y = -5, z = -5},
maxvel = {x = 5, y = 5, z = 5},
minacc = {x = -4, y = -4, z = -4},
maxacc = {x = 4, y = 4, z = 4},
minexptime = 1,
maxexptime = 3,
minsize = 0.5,
maxsize = (max_size or 1),
texture = texture,
})
end
-- from TNT mod
function calc_velocity(pos1, pos2, old_vel, power)
local vel = vector.direction(pos1, pos2)
vel = vector.normalize(vel)
vel = vector.multiply(vel, power)
local dist = vector.distance(pos1, pos2)
dist = math.max(dist, 1)
vel = vector.divide(vel, dist)
vel = vector.add(vel, old_vel)
return vel
end
-- modified from TNT mod
function entity_physics(pos, radius)
radius = radius * 2
local objs = minetest.get_objects_inside_radius(pos, radius)
local obj_pos, obj_vel, dist
for _, obj in pairs(objs) do
obj_pos = obj:getpos()
obj_vel = obj:getvelocity()
dist = math.max(1, vector.distance(pos, obj_pos))
if obj_vel ~= nil then
obj:setvelocity(calc_velocity(pos, obj_pos, obj_vel, radius * 10))
end
local damage = (4 / dist) * radius
obj:set_hp(obj:get_hp() - damage)
end
end
-- explosion
function explosion(pos, radius)
local pos = vector.round(pos)
local vm = VoxelManip()
local minp, maxp = vm:read_from_map(vector.subtract(pos, radius), vector.add(pos, radius))
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
local data = vm:get_data()
local p = {}
local c_air = minetest.get_content_id("air")
local c_ignore = minetest.get_content_id("ignore")
local c_obsidian = minetest.get_content_id("default:obsidian")
local c_brick = minetest.get_content_id("default:obsidianbrick")
local c_chest = minetest.get_content_id("default:chest_locked")
minetest.sound_play("tnt_explode", {
pos = pos,
gain = 1.0,
max_hear_distance = 16
})
-- if area protected then no blast damage
if minetest.is_protected(pos, "") then
return
end
for z = -radius, radius do
for y = -radius, radius do
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
for x = -radius, radius do
p.x = pos.x + x
p.y = pos.y + y
p.z = pos.z + z
if data[vi] ~= c_air
and data[vi] ~= c_ignore
and data[vi] ~= c_obsidian
and data[vi] ~= c_brick
and data[vi] ~= c_chest then
local n = minetest.get_node(p).name
if minetest.get_item_group(n, "unbreakable") ~= 1 then
-- if chest then drop items inside
if n == "default:chest" then
local meta = minetest.get_meta(p)
local inv = meta:get_inventory()
for i = 1, 32 do
local m_stack = inv:get_stack("main", i)
local obj = minetest.add_item(p, m_stack)
if obj then
obj:setvelocity({
x = math.random(-2, 2),
y = 7,
z = math.random(-2, 2)
})
end
end
end
minetest.set_node(p, {name = "air"})
effect(p, 2, "tnt_smoke.png", 5)
end
end
vi = vi + 1
end
end
end
end
function fill_chest(pos, items)
local stacks = items or {}
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
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
-- this is what happens when you dig a lucky block
local lucky_block = function(pos, digger)
local luck = math.random(1, #lucky_list) ; --luck = 1
local action = lucky_list[luck][1]
local schem
print ("luck ["..luck.." of "..#lucky_list.."]", action)
-- place schematic
if action == "sch" then
local offset = lucky_list[luck][4]
local switch = lucky_list[luck][3]
local schem = lucky_list[luck][2]
local force = lucky_list[luck][5] or false
if switch == 1 then
pos = digger:getpos()
end
minetest.place_schematic(
{
x = pos.x - offset.x,
y = pos.y - offset.y,
z = pos.z - offset.z
},
schem, "", {}, force)
-- place node (if chest then fill chest)
elseif action == "nod" then
local nod = lucky_list[luck][2]
local switch = lucky_list[luck][3]
local items = lucky_list[luck][4]
if switch == 1 then
pos = digger:getpos()
end
if not minetest.registered_nodes[nod] then
print (nod)
nod = "default:goldblock"
end
effect(pos, 25, "tnt_smoke.png", 8)
minetest.set_node(pos, {name = nod})
if nod == "default:chest" then
fill_chest(pos, items)
end
-- place entity
elseif action == "spw" then
local pos2 = {}
local num = lucky_list[luck][3]
local tame = lucky_list[luck][4]
local own = lucky_list[luck][5]
for i = 1, num do
pos2.x = pos.x + math.random(-5, 5)
pos2.y = pos.y + 1
pos2.z = pos.z + math.random(-5, 5)
local nod = minetest.get_node_or_nil(pos2)
if nod and nod.name == "air" then
local entity = lucky_list[luck][2]
-- coloured sheep
if entity == "mobs:sheep" then
local colour = "_" .. all_colours[math.random(#all_colours)]
--if colour == "_white" then colour = "" end
entity = "mobs:sheep" .. colour
end
local mob = minetest.add_entity(pos2, entity)
local ent = mob:get_luaentity()
if tame then
ent.tamed = true
end
if own then
ent.owner = digger:get_player_name()
end
end
end
-- explosion
elseif action == "exp" then
explosion(pos, 2)
entity_physics(pos, 2)
-- teleport
elseif action == "tel" then
--pos = digger:getpos()
pos.x = pos.x + math.random(-10, 10)
pos.x = pos.y + math.random(-5, 20)
pos.x = pos.z + math.random(-10, 10)
digger:moveto(pos, false)
-- drop items
elseif action == "dro" then
local num = lucky_list[luck][3]
local colours = lucky_list[luck][4]
local items = #lucky_list[luck][2]
for i = 1, num do
local item = lucky_list[luck][2][math.random(1, items)]
if colours then
item = item .. all_colours[math.random(#all_colours)]
end
local obj = core.add_item(pos, item)
if obj then
obj:setvelocity({
x = math.random(-1.5, 1.5),
y = 6,
z = math.random(-1.5, 1.5)
})
end
end
-- lightning strike
elseif action == "lig" then
pos = digger:getpos()
minetest.set_node(pos, {name = "fire:basic_flame"})
minetest.add_particlespawner({
amount = 1,
time = 1,
minpos = {x = pos.x, y = pos.y , z = pos.z},
maxpos = {x = pos.x, y = pos.y, z = pos.z},
minvel = {x = 0, y = 0, z = 0},
maxvel = {x = 0, y = 0, z = 0},
minacc = {x = 0, y = 0, z = 0},
maxacc = {x = 0, y = 0, z = 0},
minexptime = 1,
maxexptime = 3,
minsize = 100,
maxsize = 150,
texture = "lucky_lightning.png",
})
entity_physics(pos, 2)
minetest.sound_play("lightning", {
pos = pos,
gain = 1.0,
max_hear_distance = 25
})
-- falling nodes
elseif action == "fal" then
local nods = lucky_list[luck][2]
local switch = lucky_list[luck][3]
if switch == 1 then
pos = digger:getpos()
end
pos.y = pos.y + #nods
for s = 1, #nods do
minetest.after(0.5 * s, function()
local n = minetest.registered_nodes[nods[s]]
core.remove_node(pos)
local obj = core.add_entity(pos, "__builtin:falling_node")
obj:get_luaentity():set_node(n)
end)
end
-- troll block, disappears or explodes after 2 seconds
elseif action == "tro" then
local nod = lucky_list[luck][2]
local snd = lucky_list[luck][3]
local exp = lucky_list[luck][4]
minetest.set_node(pos, {name = nod})
if snd then
minetest.sound_play(snd, {
pos = pos,
gain = 1.0,
max_hear_distance = 10
})
end
minetest.after(2.0, function()
if exp then
explosion(pos, 2)
entity_physics(pos, 2)
else
minetest.set_node(pos, {name = "air"})
minetest.sound_play("default_hard_footstep", {
pos = pos,
gain = 1.0,
max_hear_distance = 10
})
end
end)
end
end
-- lucky block itself
minetest.register_node('lucky_block:lucky_block', {
description = "Lucky Block",
drawtype = "nodebox",
tiles = {"lucky_block.png"},
inventory_image = minetest.inventorycube("lucky_block.png"),
sunlight_propagates = false,
is_ground_content = false,
paramtype = 'light',
light_source = 3,
groups = {oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
on_dig = function(pos, node, digger)
minetest.set_node(pos, {name = "air"})
lucky_block(pos, digger)
end,
})
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"}
}
})
-- super lucky block
minetest.register_node('lucky_block:super_lucky_block', {
description = "Super Lucky Block (use Pick)",
drawtype = "nodebox",
tiles = {"lucky_block_super.png"},
inventory_image = minetest.inventorycube("lucky_block_super.png"),
sunlight_propagates = false,
is_ground_content = false,
paramtype = 'light',
groups = {cracky = 1, level = 2},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Super Lucky Block")
end,
on_dig = function(pos)
minetest.set_node(pos, {name = "air"})
effect(pos, 25, "tnt_smoke.png", 8)
minetest.sound_play("fart1", {
pos = pos,
gain = 1.0,
max_hear_distance = 10
})
end,
})
print ("[MOD] Lucky Blocks loaded ("..#lucky_list.." in total)")

BIN
sounds/fart1.ogg Normal file

Binary file not shown.

BIN
sounds/lightning.ogg Normal file

Binary file not shown.

BIN
textures/lucky_block.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
textures/tnt_smoke.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B