forked from MineClone5/MineClone5
Lava sparks: performance improvement
This commit is contained in:
parent
f0b8e8ea11
commit
b6a4c1a995
|
@ -54,17 +54,60 @@ minetest.register_abm({
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
-- Production of sparks from lava
|
-- Production of sparks from lava
|
||||||
|
--
|
||||||
|
|
||||||
|
local LAVA_SPARK_ABM_INTERVAL = 5
|
||||||
|
local lava_spark_limit = minetest.settings:get("mcl_core_lava_spark_limit")
|
||||||
|
if lava_spark_limit == nil then
|
||||||
|
lava_spark_limit = 10
|
||||||
|
else
|
||||||
|
lava_spark_limit = tonumber(lava_spark_limit)
|
||||||
|
end
|
||||||
|
local lava_spark_chance = 0
|
||||||
|
local lava_spark_abm_census = 0
|
||||||
|
local lava_spark_census = 0
|
||||||
|
|
||||||
|
function mcl_core.lava_spark_set_chance()
|
||||||
|
lava_spark_chance = lava_spark_limit / lava_spark_abm_census
|
||||||
|
minetest.after(LAVA_SPARK_ABM_INTERVAL, mcl_core.lava_spark_set_chance)
|
||||||
|
lava_spark_abm_census = 0
|
||||||
|
lava_spark_census = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if lava_spark_limit > 0 then
|
||||||
|
mcl_core.lava_spark_set_chance()
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
label = "Lava produce sparks",
|
label = "Lava produce sparks",
|
||||||
nodenames = {"group:lava"},
|
nodenames = {"group:lava"},
|
||||||
neighbors = {"air"},
|
neighbors = {"air"},
|
||||||
interval = 1,
|
interval = LAVA_SPARK_ABM_INTERVAL,
|
||||||
chance = 100,
|
chance = 18,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
local above = minetest.get_node(vector.new(pos.x, pos.y + 1, pos.z))
|
local above = minetest.get_node(vector.new(pos.x, pos.y + 1, pos.z))
|
||||||
if above.name ~= "air" then return end
|
if above.name ~= "air" then return end
|
||||||
|
|
||||||
|
lava_spark_abm_census = lava_spark_abm_census + 1
|
||||||
|
|
||||||
|
if lava_spark_census >= lava_spark_limit then return end
|
||||||
|
if math.random() > lava_spark_chance then return end
|
||||||
|
|
||||||
|
lava_spark_census = lava_spark_census + 1
|
||||||
|
minetest.after(math.random() * LAVA_SPARK_ABM_INTERVAL, mcl_core.lava_spark_add, pos)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function mcl_core.lava_spark_add(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
if minetest.get_node_group(node.name, "lava") == 0 then return end
|
||||||
|
|
||||||
|
local above = minetest.get_node(vector.new(pos.x, pos.y + 1, pos.z))
|
||||||
|
if above.name ~= "air" then return end
|
||||||
|
|
||||||
local pos_addend = vector.new(
|
local pos_addend = vector.new(
|
||||||
(math.random() - 0.5) * 0.8,
|
(math.random() - 0.5) * 0.8,
|
||||||
(math.random() - 0.5) * 0.8,
|
(math.random() - 0.5) * 0.8,
|
||||||
|
@ -94,7 +137,6 @@ minetest.register_abm({
|
||||||
if not luaentity then return end
|
if not luaentity then return end
|
||||||
luaentity._life_timer = 0.4 + math.random()
|
luaentity._life_timer = 0.4 + math.random()
|
||||||
end
|
end
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_entity("mcl_core:lava_spark", {
|
minetest.register_entity("mcl_core:lava_spark", {
|
||||||
physical = true,
|
physical = true,
|
||||||
|
@ -117,7 +159,7 @@ minetest.register_entity("mcl_core:lava_spark", {
|
||||||
|
|
||||||
self._smoke_timer = self._smoke_timer - dtime
|
self._smoke_timer = self._smoke_timer - dtime
|
||||||
if self._smoke_timer > 0 then return end
|
if self._smoke_timer > 0 then return end
|
||||||
self._smoke_timer = math.random() * 0.4
|
self._smoke_timer = 0.2 + math.random() * 0.3
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ mcl_showDeathMessages (Show death messages) bool true
|
||||||
# If disabled, all recipes will be shown.
|
# If disabled, all recipes will be shown.
|
||||||
mcl_craftguide_progressive_mode (Learn crafting recipes progressively) bool true
|
mcl_craftguide_progressive_mode (Learn crafting recipes progressively) bool true
|
||||||
|
|
||||||
|
# Limit the number of sparks produced by lava per 5 seconds to this number.
|
||||||
|
# 0 will disable lava sparks altogeter with no ABM being registered.
|
||||||
|
mcl_core_lava_spark_limit (Number of sparks lava can produce per 5 seconds) int 10
|
||||||
|
|
||||||
[Mobs]
|
[Mobs]
|
||||||
# If enabled, mobs will spawn naturally. This does not affect
|
# If enabled, mobs will spawn naturally. This does not affect
|
||||||
# affect mob spawners.
|
# affect mob spawners.
|
||||||
|
|
Loading…
Reference in New Issue