diff --git a/README.md b/README.md index 3248575..6cd1458 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,4 @@ Changelog: - 0.1 - Initial release - 0.2 - New api commands added thanks to blert2112 - 0.3 - New blocks added, also error checking, new options and schematic rehaul +- 0.4 - Added ability to add custom functions within lucky blocks diff --git a/api.txt b/api.txt index fe41dba..8b45630 100644 --- a/api.txt +++ b/api.txt @@ -263,6 +263,28 @@ Strike player and place permanent flame {"lig", "fire:permanent_flame"} +Custom Function +--------------- + +This allows mod makers to use there own functions when opening lucky blocks and +passes the block position and player opening it. + +{"cus", myfunction} + +e.g. + +Punch player and deal 5 damage points (function first then line to add l.block) + +local function punchy(pos, player) + player:punch(player, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = 5} + }, nil) +end + + {"cus", punchy} + + Final Words =========== diff --git a/init.lua b/init.lua index f6da0d4..f2f415e 100644 --- a/init.lua +++ b/init.lua @@ -3,8 +3,17 @@ lucky_block = {} lucky_schems = {} lucky_block.seed = PseudoRandom(os.time()) +-- example custom function (punches player with 5 damage) +local function punchy(pos, player) + player:punch(player, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = 5} + }, nil) +end + -- default blocks local lucky_list = { + {"cus", punchy}, {"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}, @@ -503,6 +512,12 @@ local lucky_block = function(pos, digger) end end) + -- custom function + elseif action == "cus" then + + local func = lucky_list[luck][2] + + func(pos, digger) end end