Default: Destroy flammable items when in fire or lava
authorFernando Carmona Varo <ferkiwi@gmail.com>
Sun, 11 Sep 2016 15:24:02 +0000 (17:24 +0200)
committerparamat <mat.gregory@virginmedia.com>
Sun, 23 Oct 2016 02:48:37 +0000 (03:48 +0100)
The check for igniters (fire/lava) will be performed every 10 secs
if the item is flammable.

if the item is found to be in lava it will then burn up and
disappear in a smoke puff.

If a non-lava igniter node is found, a combination of `flammable`
value of the item and `igniter` group value of the node will be used
to determine the chance for the item to be removed.

mods/default/README.txt
mods/default/init.lua
mods/default/item_entity.lua [new file with mode: 0644]
mods/default/sounds/default_item_smoke.ogg [new file with mode: 0644]
mods/default/textures/default_item_smoke.png [new file with mode: 0644]

index bf7481b63bf0e37ab78680cf0aee049d58da9d3e..06739977ec8dbe495831e4442e309dba1e7ba926 100644 (file)
@@ -183,6 +183,10 @@ Pithydon (CC BY-SA 3.0)
   default_coral_orange.png
   default_coral_skeleton.png
 
+Ferk (CC0 1.0)
+  default_item_smoke.png
+  default_item_smoke.ogg, based on sound by http://opengameart.org/users/bart
+
 Glass breaking sounds (CC BY 3.0):
   1: http://www.freesound.org/people/cmusounddesign/sounds/71947/
   2: http://www.freesound.org/people/Tomlija/sounds/97669/
index 594ea36ad0389319219f282838cbcd25178301b9..08e9efe4964017d5d677a077e02739db44ef2b78 100644 (file)
@@ -42,6 +42,7 @@ dofile(default_path.."/trees.lua")
 dofile(default_path.."/nodes.lua")
 dofile(default_path.."/furnace.lua")
 dofile(default_path.."/tools.lua")
+dofile(default_path.."/item_entity.lua")
 dofile(default_path.."/craftitems.lua")
 dofile(default_path.."/crafting.lua")
 dofile(default_path.."/mapgen.lua")
diff --git a/mods/default/item_entity.lua b/mods/default/item_entity.lua
new file mode 100644 (file)
index 0000000..c34e60e
--- /dev/null
@@ -0,0 +1,74 @@
+-- mods/default/item_entity.lua
+
+local builtin_item = minetest.registered_entities["__builtin:item"]
+
+local item = {
+       set_item = function(self, itemstring)
+               builtin_item.set_item(self, itemstring)
+
+               local stack = ItemStack(itemstring)
+               local itemdef = minetest.registered_items[stack:get_name()]
+               if itemdef and itemdef.groups.flammable ~= 0 then
+                       self.flammable = itemdef.groups.flammable
+               end
+       end,
+
+       burn_up = function(self)
+               -- disappear in a smoke puff
+               self.object:remove()
+               local p = self.object:getpos()
+               minetest.sound_play("default_item_smoke", {
+                       pos = p,
+                       max_hear_distance = 8,
+               })
+               minetest.add_particlespawner({
+                       amount = 3,
+                       time = 0.1,
+                       minpos = {x = p.x - 0.1, y = p.y + 0.1, z = p.z - 0.1 },
+                       maxpos = {x = p.x + 0.1, y = p.y + 0.2, z = p.z + 0.1 },
+                       minvel = {x = 0, y = 2.5, z = 0},
+                       maxvel = {x = 0, y = 2.5, z = 0},
+                       minacc = {x = -0.15, y = -0.02, z = -0.15},
+                       maxacc = {x = 0.15, y = -0.01, z = 0.15},
+                       minexptime = 4,
+                       maxexptime = 6,
+                       minsize = 5,
+                       maxsize = 5,
+                       collisiondetection = true,
+                       texture = "default_item_smoke.png"
+               })
+       end,
+
+       on_step = function(self, dtime)
+               builtin_item.on_step(self, dtime)
+
+               if self.flammable then
+                       -- flammable, check for igniters
+                       self.ignite_timer = (self.ignite_timer or 0) + dtime
+                       if self.ignite_timer > 10 then
+                               self.ignite_timer = 0
+
+                               local node = minetest.get_node_or_nil(self.object:getpos())
+                               if not node then
+                                       return
+                               end
+
+                               -- Immediately burn up flammable items in lava
+                               if minetest.get_item_group(node.name, "lava") > 0 then
+                                       self:burn_up()
+                               else
+                                       --  otherwise there'll be a chance based on its igniter value
+                                       local burn_chance = self.flammable
+                                               * minetest.get_item_group(node.name, "igniter")
+                                       if burn_chance > 0 and math.random(0, burn_chance) ~= 0 then
+                                               self:burn_up()
+                                       end
+                               end
+                       end
+               end
+       end,
+}
+
+-- set defined item as new __builtin:item, with the old one as fallback table
+setmetatable(item, builtin_item)
+minetest.register_entity(":__builtin:item", item)
diff --git a/mods/default/sounds/default_item_smoke.ogg b/mods/default/sounds/default_item_smoke.ogg
new file mode 100644 (file)
index 0000000..e1c8407
Binary files /dev/null and b/mods/default/sounds/default_item_smoke.ogg differ
diff --git a/mods/default/textures/default_item_smoke.png b/mods/default/textures/default_item_smoke.png
new file mode 100644 (file)
index 0000000..d62fb3b
Binary files /dev/null and b/mods/default/textures/default_item_smoke.png differ