From 7edfb6cb9b87893f2ceca8f53bceab76c47719c9 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Sat, 8 May 2021 12:23:00 -0700 Subject: [PATCH] Use settings to determine spawn chance, frequency, level, & light requirements --- README.md | 29 +++++++++++++++++++++++++++++ init.lua | 13 +++++++++++-- settings.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ settingtypes.txt | 20 ++++++++++++++++++++ spawn.lua | 32 ++++++++++++++++---------------- 5 files changed, 122 insertions(+), 18 deletions(-) create mode 100644 settings.lua create mode 100644 settingtypes.txt diff --git a/README.md b/README.md index 407eebf..ad0c40f 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,35 @@ An explosive nuisance for [Minetest](http://minetest.net/). - Original by Rui: WTFPL - tnt_function code: [MIT](tnt_function.lua) +--- +### Usage: + +Settings: +- ***sneeker.spawn_chance*** + - Sets possibility for spawn. + - type: int + - default: 10000 +- ***sneeker.spawn_interval*** + - Sets frequency of spawn chance. + - type: int + - default: 240 (4 minutes) +- ***sneeker.spawn_minlight*** + - Sets the minimum light that a node must have for spawn to occur. + - type: int + - default: 0 +- ***sneeker.spawn_maxlight*** + - Sets the maximum light that a node can have for spawn to occur. + - type: int + - default: 9 +- ***sneeker.spawn_minheight*** + - Sets the maximum light that a node can have for spawn to occur. + - type: int + - default: -31000 +- ***sneeker.spawn_maxheight*** + - Sets the lowest position at which sneeker can spawn. + - type: int + - default 31000 + --- ### Links: diff --git a/init.lua b/init.lua index 7e484ca..838c6f8 100644 --- a/init.lua +++ b/init.lua @@ -1,8 +1,17 @@ sneeker = {} +sneeker.modname = core.get_current_modname() +sneeker.modpath = core.get_modpath(sneeker.modname) -dofile(minetest.get_modpath("sneeker").."/tnt_function.lua") -dofile(minetest.get_modpath("sneeker").."/spawn.lua") +local scripts = { + "settings", + "tnt_function", + "spawn", +} + +for _, script in ipairs(scripts) do + dofile(sneeker.modpath .. "/" .. script .. ".lua") +end local function jump(self, pos, direction) diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..6cab9f0 --- /dev/null +++ b/settings.lua @@ -0,0 +1,46 @@ +-- Settings for sneeker mod + + +local time_min = 60 + +--- Sets possibility for spawn. +-- +-- Inverted value (e.g. 10000 = 1/10000). +-- +-- @setting sneeker.spawn_chance +sneeker.spawn_chance = tonumber(core.settings:get("sneeker.spawn_chance") or 10000) + +--- Sets frequency of spawn chance. +-- +-- Default 240 is equivalent to 4 minutes (60 * 4). +-- +-- @setting sneeker.spawn_interval +sneeker.spawn_interval = tonumber(core.settings:get("sneeker.spawn_interval") or time_min * 4) + +--- Sets the minimum light that a node must have for spawn to occur. +-- +-- Default: 0 +-- +-- @setting sneeker.spawn_minlight +sneeker.spawn_minlight = tonumber(core.settings:get("sneeker.spawn_minlight") or 0) + +--- Sets the maximum light that a node can have for spawn to occur. +-- +-- Default: 4 +-- +-- @setting sneeker.spawn_maxlight +sneeker.spawn_maxlight = tonumber(core.settings:get("sneeker.spawn_maxlight") or 4) + +--- Sets the lowest position at which sneeker can spawn. +-- +-- Default: -31000 +-- +-- @setting sneeker.spawn_minheight +sneeker.spawn_minheight = tonumber(core.settings:get("sneeker.spawn_minheight") or -31000) + +--- Sets the highest position at which sneeker can spawn. +-- +-- Default: 31000 +-- +-- @setting sneeker.spawn_maxheight +sneeker.spawn_maxheight = tonumber(core.settings:get("sneeker.spawn_maxheight") or 31000) diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..2247a19 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,20 @@ + +# Sets possibility for spawn. +# +# Rate is the inverted value (e.g. 1/value). +sneeker.spawn_chance (Sneeker spawn chance) int 10000 + +# Sets frequency of spawn chance. Default 240 is equivalent to 4 minutes (60 * 4). +sneeker.spawn_interval (Sneeker spawn interval) int 240 + +# Sets the minimum light that a node must have for spawn to occur. +sneeker.spawn_minlight (Sneeker min light for spawn) int 0 + +# Sets the maximum light that a node can have for spawn to occur. +sneeker.spawn_maxlight (Sneeker max light for spawn) int 4 + +# Sets the lowest position at which sneeker can spawn. +sneeker.spawn_minheight (Sneeker min spawn height) int -31000 + +# Sets the highest position at which sneeker can spawn. +sneeker.spawn_maxheight (Sneeker max spawn height) int 31000 diff --git a/spawn.lua b/spawn.lua index c1e6c07..ff674da 100644 --- a/spawn.lua +++ b/spawn.lua @@ -12,32 +12,32 @@ end core.register_abm({ nodenames = spawn_nodes, neighbors = {"air"}, - interval = 30, - chance = 9000, + interval = sneeker.spawn_interval, + chance = sneeker.spawn_chance, action = function(pos, node, _, active_object_count_wider) if active_object_count_wider > 5 then return end - pos.y = pos.y+1 - if not core.get_node_light(pos) then + + if pos.y > sneeker.spawn_maxheight then return end - if core.get_node_light(pos) > 5 then + if pos.y < sneeker.spawn_minheight then return end - if core.get_node_light(pos) < -1 then - return - end - if pos.y > 31000 then - return - end - if core.get_node(pos).name ~= "air" then - return - end - pos.y = pos.y+1 - if core.get_node(pos).name ~= "air" then + + -- needs two vertical air nodes to spawn + for _, node_pos in ipairs({pos, {x=pos.x, y=pos.y+1, z=pos.z}}) do + if core.get_node(node_pos).name ~= "air" then + return + end + end + + local llevel = core.get_node_light(pos) + if not llevel or llevel > sneeker.spawn_maxlight or llevel < sneeker.spawn_minlight then return end + core.add_entity(pos, "sneeker:sneeker") end })