diff --git a/README.md b/README.md index f8ec35c..a5d8074 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,6 @@ Changelog: - 1.0 - Added ability for custom lucky blocks to use their own block list - 1.1 - Spawning mobs can now select randomly from a table or single string - 1.2 - Code tidy and fixed wishing well replacements +- 1.3 - Add lightning staff as rare drop, tidy code, lightning fire check -Lucky Blocks: 259 (depending on mods enabled) +Lucky Blocks: 260 (depending on mods enabled) diff --git a/api.txt b/api.txt index 6edd8df..7bf7743 100644 --- a/api.txt +++ b/api.txt @@ -57,7 +57,7 @@ e.g. lucky_block:add_chest_items({ {name = "default:apple", max = 3}, {name = "default:steel_ingot", max = 2}, - {name = "default:pick_steel", max = 1} + {name = "default:pick_diamond", max = 1, chance = 5}, }) @@ -150,9 +150,12 @@ Place a chest containing random items from default chest items list {"nod", "default:chest", 0} -Place chest as above only add up to 5x roses as well +Place chest as above only add up to 5 roses and a 1/5 chance of mese also - {"nod", "default:chest", 0, { {name = "flowers:rose, max = 4} }} + {"nod", "default:chest", 0, { + {name = "flowers:rose", max = 5}, + {name = "default:mese", max = 1, chance = 5}, + }} Place fire at player position diff --git a/blocks.lua b/blocks.lua index d016124..a09bcdd 100644 --- a/blocks.lua +++ b/blocks.lua @@ -227,11 +227,90 @@ local function bushy(pos, player) green .. S("Dry shrub takeover!")) end +-- lightning staff +minetest.register_tool("lucky_block:lightning_staff", { + description = S("Lightning Staff"), + inventory_image = "lucky_lightning_staff.png", + range = 10, + groups = {not_in_creative_inventory = 1}, + + on_use = function(itemstack, user, pointed_thing) + + local pos = user:get_pos() + if pointed_thing.type == "object" then + pos = pointed_thing.ref:get_pos() + elseif pointed_thing.type == "node" then + pos = pointed_thing.above + end + + local bnod = minetest.get_node_or_nil(pos) + local bref = bnod and minetest.registered_items[bnod.name] + + if bref and bref.buildable_to == true then + local nod = "fire:basic_flame" + minetest.set_node(pos, {name = nod}) + end + + local radius = 4 + local objs = minetest.get_objects_inside_radius(pos, radius) + local obj_pos, dist + + -- add temp entity to cause damage + local tmp_ent = minetest.add_entity(pos, "lucky_block:temp") + + for n = 1, #objs do + + obj_pos = objs[n]:get_pos() + + dist = vector.distance(pos, obj_pos) + + if dist < 1 then dist = 1 end + + local damage = math.floor((4 / dist) * radius) + local ent = objs[n]:get_luaentity() + + objs[n]:punch(tmp_ent, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = damage}, + }, pos) + end + + minetest.add_particle({ + pos = pos, + velocity = {x = 0, y = 0, z = 0}, + acceleration = {x = 0, y = 0, z = 0}, + expirationtime = 1.0, + collisiondetection = false, + texture = "lucky_lightning.png", + size = math.random(100, 150), + glow = 15, + }) + + minetest.sound_play("lightning", { + pos = pos, + gain = 1.0, + max_hear_distance = 25 + }) + + itemstack:add_wear(65535 / 100) -- 100 uses + + return itemstack + end, +}) + lucky_block:add_blocks({ {"cus", pint}, {"cus", bushy}, {"cus", punchy}, {"dro", {"lucky_block:pint_sized_potion"}, 1}, + {"nod", "default:chest", 0, { + {name = "default:stick", max = 10}, + {name = "default:acacia_bush_stem", max = 10}, + {name = "default:bush_stem", max = 10}, + {name = "default:pine_bush_stem", max = 10}, + {name = "default:grass_1", max = 10}, + {name = "default:dry_grass_1", max = 10}, + {name = "lucky_block:lightning_staff", max = 1, chance = 10}}}, }) -- wool mod diff --git a/init.lua b/init.lua index 849ea42..d81e8a6 100644 --- a/init.lua +++ b/init.lua @@ -55,9 +55,10 @@ local all_colours = { 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} + {name = "default:gold_ingot", max = 2, chance = 2}, + {name = "default:diamond", max = 1, chance = 2}, + {name = "default:pick_steel", max = 1, chance = 2}, + {name = "default:mese_fragment", max = 3, chance = 3}, } @@ -175,10 +176,14 @@ local function fill_chest(pos, items) if not inv:contains_item("main", stacks[s]) then - inv:set_stack("main", math.random(1, 32), { - name = stacks[s].name, - count = math.random(1, stacks[s].max) - }) + if not stacks[s].chance + or math.random(1, stacks[s].chance) == 1 then + + inv:set_stack("main", math.random(1, 32), { + name = stacks[s].name, + count = math.random(1, stacks[s].max) + }) + end end end end @@ -425,7 +430,10 @@ local lb_lightning = function(pos, digger, def) pos = digger:get_pos() - if nod then + local bnod = minetest.get_node_or_nil(pos) + local bref = bnod and minetest.registered_items[bnod.name] + + if bref and bref.buildable_to then minetest.set_node(pos, {name = nod}) end @@ -575,7 +583,7 @@ function lucky_block:open(pos, digger, blocks_list) -- make sure it's really random math.randomseed(minetest.get_timeofday() + pos.x + pos.z - os.time()) - local luck = math.random(1, #blocks_list) ; -- luck = 1 + local luck = math.random(1, #blocks_list) ; --luck = 1 local action = blocks_list[luck][1] -- print ("luck ["..luck.." of "..#blocks_list.."]", action) diff --git a/schematics/corals.mts b/schematics/corals.mts new file mode 100644 index 0000000..e1bd7de Binary files /dev/null and b/schematics/corals.mts differ diff --git a/textures/lucky_lightning_staff.png b/textures/lucky_lightning_staff.png new file mode 100644 index 0000000..3a1c36e Binary files /dev/null and b/textures/lucky_lightning_staff.png differ