From f0b8e8ea1192511585974cb049769060b8647974 Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Fri, 15 Apr 2022 13:56:49 -0500 Subject: [PATCH 1/2] Lava produce sparks --- mods/ITEMS/mcl_core/README.txt | 8 ++ mods/ITEMS/mcl_core/functions.lua | 89 ++++++++++++++++++ .../mcl_core/textures/mcl_core_lava_spark.png | Bin 0 -> 1520 bytes 3 files changed, 97 insertions(+) create mode 100644 mods/ITEMS/mcl_core/textures/mcl_core_lava_spark.png diff --git a/mods/ITEMS/mcl_core/README.txt b/mods/ITEMS/mcl_core/README.txt index 6c48d74fd..88da2f88d 100644 --- a/mods/ITEMS/mcl_core/README.txt +++ b/mods/ITEMS/mcl_core/README.txt @@ -21,6 +21,14 @@ MIT License. The textures are taken from the Minecraft resource pack “Faithful 1.11” by Vattic and xMrVizzy and contributers. + +CC BY-SA 4.0 + +mcl_core_lava_spark.png is based on the Pixel Perfection resource pack for Minecraft 1.11, +authored by XSSheep. +Source: +License: [CC BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/) + Sounds ====== All sounds included in this mod are under the MIT License. diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 20978e26f..43ddbcce5 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -54,6 +54,95 @@ minetest.register_abm({ end, }) +-- Production of sparks from lava +minetest.register_abm({ + label = "Lava produce sparks", + nodenames = {"group:lava"}, + neighbors = {"air"}, + interval = 1, + chance = 100, + action = function(pos, node) + 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( + (math.random() - 0.5) * 0.8, + (math.random() - 0.5) * 0.8, + (math.random() - 0.5) * 0.8 + ) + local spark_pos = vector.add(pos, pos_addend) + local spark = minetest.add_entity(spark_pos, "mcl_core:lava_spark") + if not spark then return end + + local velocity = vector.new( + (math.random() - 0.5) * 3, + (math.random() + 2) * 2, + (math.random() - 0.5) * 3 + ) + spark:set_velocity(velocity) + + spark:set_acceleration(vector.new(0, -9, 0)) + + -- Set a random size + local size = 0.2 + math.random() * 0.2 + local props = spark:get_properties() + if not props then return end + props.visual_size = vector.new(size, size, size) + spark:set_properties(props) + + local luaentity = spark:get_luaentity() + if not luaentity then return end + luaentity._life_timer = 0.4 + math.random() + end +}) + +minetest.register_entity("mcl_core:lava_spark", { + physical = true, + visual = "sprite", + collide_with_objects = true, + textures = {"mcl_core_lava_spark.png"}, + glow = 10, + static_save = false, + _smoke_timer = 0.1, + _life_timer = 1, + on_step = function(self, dtime) + if not self or not self.object then return end + + self._life_timer = self._life_timer - dtime + if self._life_timer <= 0 then + self.object:remove() + return + end + + + self._smoke_timer = self._smoke_timer - dtime + if self._smoke_timer > 0 then return end + self._smoke_timer = math.random() * 0.4 + + local pos = self.object:get_pos() + + -- Add smoke + minetest.add_particlespawner({ + amount = 3, + time = 0.001, + minpos = pos, + maxpos = pos, + minvel = vector.new(-0.1, 1, -0.1), + maxvel = vector.new(0.1, 1.5, 0.1), + minexptime = 0.1, + maxexptime = 0.6, + minsize = 0.5, + maxsize = 1.5, + texture = "mcl_particles_smoke_anim.png", + animation = { + type = "vertical_frames", + aspect_w = 8, + aspect_h = 8, + } + }) + end +}) + -- -- Papyrus and cactus growing -- diff --git a/mods/ITEMS/mcl_core/textures/mcl_core_lava_spark.png b/mods/ITEMS/mcl_core/textures/mcl_core_lava_spark.png new file mode 100644 index 0000000000000000000000000000000000000000..079f7730ec909c78b339f81d57748a5a7ed576da GIT binary patch literal 1520 zcmV zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=HGlI$i7hTmC5mVhKKVmVx^vV$x?Kj3zEdpeVu zp7WB_vC9^gu_XQv=r;YYKZp4P2U~H*`KTd-=n;s{!0V8idA8e8&=E*@`{{T#>G&XrhtiLW>k;+{ zetmWkVlR;nn`apwrjT%q;!sYFg(Wg>9%q`}dEMiT{( z3UUHBpS94+n`S;FQ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[PATCH 2/2] Lava sparks: performance improvement --- mods/ITEMS/mcl_core/functions.lua | 118 ++++++++++++++++++++---------- settingtypes.txt | 4 + 2 files changed, 84 insertions(+), 38 deletions(-) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 43ddbcce5..407766d08 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -54,47 +54,89 @@ minetest.register_abm({ end, }) + +-- -- Production of sparks from lava -minetest.register_abm({ - label = "Lava produce sparks", - nodenames = {"group:lava"}, - neighbors = {"air"}, - interval = 1, - chance = 100, - action = function(pos, node) - local above = minetest.get_node(vector.new(pos.x, pos.y + 1, pos.z)) - if above.name ~= "air" then return end +-- + +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({ + label = "Lava produce sparks", + nodenames = {"group:lava"}, + neighbors = {"air"}, + interval = LAVA_SPARK_ABM_INTERVAL, + chance = 18, + action = function(pos, node) + 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( - (math.random() - 0.5) * 0.8, - (math.random() - 0.5) * 0.8, - (math.random() - 0.5) * 0.8 - ) - local spark_pos = vector.add(pos, pos_addend) - local spark = minetest.add_entity(spark_pos, "mcl_core:lava_spark") - if not spark then return end + lava_spark_abm_census = lava_spark_abm_census + 1 - local velocity = vector.new( - (math.random() - 0.5) * 3, - (math.random() + 2) * 2, - (math.random() - 0.5) * 3 - ) - spark:set_velocity(velocity) + if lava_spark_census >= lava_spark_limit then return end + if math.random() > lava_spark_chance then return end - spark:set_acceleration(vector.new(0, -9, 0)) - - -- Set a random size - local size = 0.2 + math.random() * 0.2 - local props = spark:get_properties() - if not props then return end - props.visual_size = vector.new(size, size, size) - spark:set_properties(props) - - local luaentity = spark:get_luaentity() - if not luaentity then return end - luaentity._life_timer = 0.4 + math.random() - 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( + (math.random() - 0.5) * 0.8, + (math.random() - 0.5) * 0.8, + (math.random() - 0.5) * 0.8 + ) + local spark_pos = vector.add(pos, pos_addend) + local spark = minetest.add_entity(spark_pos, "mcl_core:lava_spark") + if not spark then return end + + local velocity = vector.new( + (math.random() - 0.5) * 3, + (math.random() + 2) * 2, + (math.random() - 0.5) * 3 + ) + spark:set_velocity(velocity) + + spark:set_acceleration(vector.new(0, -9, 0)) + + -- Set a random size + local size = 0.2 + math.random() * 0.2 + local props = spark:get_properties() + if not props then return end + props.visual_size = vector.new(size, size, size) + spark:set_properties(props) + + local luaentity = spark:get_luaentity() + if not luaentity then return end + luaentity._life_timer = 0.4 + math.random() +end minetest.register_entity("mcl_core:lava_spark", { physical = true, @@ -117,7 +159,7 @@ minetest.register_entity("mcl_core:lava_spark", { self._smoke_timer = self._smoke_timer - dtime 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() diff --git a/settingtypes.txt b/settingtypes.txt index dca03b7e1..fd3f6114a 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -51,6 +51,10 @@ mcl_showDeathMessages (Show death messages) bool true # If disabled, all recipes will be shown. 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] # If enabled, mobs will spawn naturally. This does not affect # affect mob spawners.