diff options
Diffstat (limited to 'item_drop/item_entity.lua')
-rw-r--r-- | item_drop/item_entity.lua | 92 |
1 files changed, 79 insertions, 13 deletions
diff --git a/item_drop/item_entity.lua b/item_drop/item_entity.lua index 6e479a1..5da8285 100644 --- a/item_drop/item_entity.lua +++ b/item_drop/item_entity.lua @@ -24,7 +24,7 @@ minetest.register_entity(":__builtin:item", { itemstring = '', physical_state = true, timer = 0, - + set_item = function(self, itemstring) self.itemstring = itemstring local stack = ItemStack(itemstring) @@ -62,15 +62,21 @@ minetest.register_entity(":__builtin:item", { return minetest.serialize({ itemstring = self.itemstring, always_collect = self.always_collect, + timer = self.timer, }) end, - on_activate = function(self, staticdata) + on_activate = function(self, staticdata, dtime_s) if string.sub(staticdata, 1, string.len("return")) == "return" then local data = minetest.deserialize(staticdata) if data and type(data) == "table" then self.itemstring = data.itemstring self.always_collect = data.always_collect + self.timer = data.timer + if not self.timer then + self.timer = 0 + end + self.timer = self.timer+dtime_s end else self.itemstring = staticdata @@ -80,18 +86,79 @@ minetest.register_entity(":__builtin:item", { self.object:setacceleration({x=0, y=-10, z=0}) self:set_item(self.itemstring) end, - + on_step = function(self, dtime) + local time = minetest.setting_get("remove_items") + if not time then + time = 300 + end + if not self.timer then + self.timer = 0 + end self.timer = self.timer + dtime - if (self.timer > 300) then + if time ~= 0 and (self.timer > time) then self.object:remove() end + local p = self.object:getpos() + + local name = minetest.env:get_node(p).name + if name == "default:lava_flowing" or name == "default:lava_source" then + minetest.sound_play("builtin_item_lava", {pos=self.object:getpos(),gain = 1.0, max_hear_distance = 10}) + self.object:remove() + return + end + + if minetest.registered_nodes[name] and minetest.registered_nodes[name].liquidtype == "flowing" then + get_flowing_dir = function(self) + local pos = self.object:getpos() + local param2 = minetest.env:get_node(pos).param2 + for i,d in ipairs({-1, 1, -1, 1}) do + if i<3 then + pos.x = pos.x+d + else + pos.z = pos.z+d + end + + local name = minetest.env:get_node(pos).name + local par2 = minetest.env:get_node(pos).param2 + if name == "default:water_flowing" and par2 < param2 then + return pos + end + + if i<3 then + pos.x = pos.x-d + else + pos.z = pos.z-d + end + end + end + + local vec = get_flowing_dir(self) + if vec then + local v = self.object:getvelocity() + if vec and vec.x-p.x > 0 then + self.object:setvelocity({x=0.5,y=v.y,z=0}) + elseif vec and vec.x-p.x < 0 then + self.object:setvelocity({x=-0.5,y=v.y,z=0}) + elseif vec and vec.z-p.z > 0 then + self.object:setvelocity({x=0,y=v.y,z=0.5}) + elseif vec and vec.z-p.z < 0 then + self.object:setvelocity({x=0,y=v.y,z=-0.5}) + end + self.object:setacceleration({x=0, y=-10, z=0}) + self.physical_state = true + self.object:set_properties({ + physical = true + }) + return + end + end + p.y = p.y - 0.3 local nn = minetest.env:get_node(p).name - -- If node is not registered or node is walkably solid and resting on nodebox - local v = self.object:getvelocity() - if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and v.y == 0 then + -- If node is not registered or node is walkably solid + if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable then if self.physical_state then self.object:setvelocity({x=0,y=0,z=0}) self.object:setacceleration({x=0, y=0, z=0}) @@ -114,13 +181,12 @@ minetest.register_entity(":__builtin:item", { on_punch = function(self, hitter) if self.itemstring ~= '' then - local left = hitter:get_inventory():add_item("main", self.itemstring) - if not left:is_empty() then - self.itemstring = left:to_string() - return - end + hitter:get_inventory():add_item("main", self.itemstring) end self.object:remove() end, }) -print("ITEM ENTITY LOADED") + +if minetest.setting_get("log_mods") then + minetest.log("action", "builtin_item loaded") +end |