Custom dropped items for Minetest

TenPlus1 3efaf333da fix readme examples 11 months ago
sounds 06fcfa8d1a 1st commit 4 years ago
textures 06fcfa8d1a 1st commit 4 years ago
.gitignore 06fcfa8d1a 1st commit 4 years ago
README.md 3efaf333da fix readme examples 11 months ago
depends.txt 43a3e7ad66 updated readme 2 years ago
init.lua db14f55e5f add dtime to custom on_step 11 months ago
init.lua_ a20158a059 added 'dropped_step' check for dropped items 11 months ago
mod.conf d1f7c4e54b added mod.conf and tweaked particle 2 years ago

README.md

item_entity.lua replacement

edited by TenPlus1

Features:

  • Items are destroyed by lava
  • Items are pushed along by flowing water (thanks to QwertyMine3)
  • Items are removed after 900 seconds or the time that is specified by remove_items in minetest.conf (-1 disables it)
  • Particle effects added
  • Dropped items slide on nodes with {slippery} groups
  • Items stuck inside solid nodes move to nearest empty space
  • Added 'dropped_step(self, pos, dtime)' custom on_step for dropped items 'self.node_inside' contains node table that item is inside 'self.def_inside' contains node definition for above 'self.node_under' contains node table that is below item 'self.def_under' contains node definition for above 'self.age' holds age of dropped item in seconds 'self.itemstring' contains itemstring e.g. "default:dirt", "default:ice 20" 'pos' holds position of dropped item 'dtime' used for timers

return false to skip further checks by builtin_item

License: MIT

dropped_step() examples:

-- if gunpowder dropped on burning tnt or gunpowder then remove

if minetest.registered_items["tnt:gunpowder"] then

minetest.override_item("tnt:gunpowder", {

    dropped_step = function(self, pos)

        if (self.node_inside
        and self.node_inside.name == "tnt:gunpowder_burning")
        or (self.node_under
        and self.node_under.name == "tnt:tnt_burning") then

            minetest.sound_play("builtin_item_lava", {
                pos = pos,
                max_hear_distance = 6,
                gain = 0.5
            })

            self.itemstring = ""
            self.object:remove()

            return false -- return with no further action
        end
    end
})

end

-- if 2x mese crystal and 2x crystal spike dropped in pool of water_source -- then merge into a single crystal_ingot.

if minetest.registered_items["ethereal:crystal_spike"] then

minetest.override_item("ethereal:crystal_spike", {

    dropped_step = function(self, pos, dtime)

        self.ctimer = (self.ctimer or 0) + dtime
        if self.ctimer < 5.0 then return end
        self.ctimer = 0

        if self.node_inside
        and self.node_inside.name ~= "default:water_source" then
            return
        end

        local objs = core.get_objects_inside_radius(pos, 0.8)

        if not objs or #objs < 2 or #objs > 2 then return end

        local crystal, mese, ent = nil, nil, nil

        for k, obj in pairs(objs) do

            ent = obj:get_luaentity()

            if ent and ent.name == "__builtin:item" then

                if ent.itemstring == "default:mese_crystal 2"
                and not mese then

                    mese = obj

                elseif ent.itemstring == "ethereal:crystal_spike 2"
                and not crystal then

                    crystal = obj
                end
            end
        end

        if mese and crystal then

            mese:remove()
            crystal:remove()

            core.add_item(pos, "ethereal:crystal_ingot")

            return false -- return with no further action
        end
    end
})

end