From f925fd956868cdc2b25da60b31b3ead142e875ea Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 16 Aug 2024 22:28:33 +0200 Subject: [PATCH] Maintenance: fix deprecation warnings --- abms.lua | 22 +++++++++++----------- init.lua | 29 ++++++++++++----------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/abms.lua b/abms.lua index a5536be..302e057 100644 --- a/abms.lua +++ b/abms.lua @@ -11,26 +11,26 @@ minetest.register_abm({ end local inv = minetest.get_meta(pos):get_inventory() - local posob + if not inv then + return + end for _,object in pairs(minetest.get_objects_inside_radius(pos, 1)) do - if not object:is_player() - and object:get_luaentity() - and object:get_luaentity().name == "__builtin:item" - and inv - and inv:room_for_item("main", - ItemStack(object:get_luaentity().itemstring)) then + local entity = not object:is_player() and object:get_luaentity() - posob = object:getpos() + if entity + and entity.name == "__builtin:item" + and inv:room_for_item("main", ItemStack(entity.itemstring)) then + + local posob = object:get_pos() if math.abs(posob.x - pos.x) <= 0.5 and posob.y - pos.y <= 0.85 and posob.y - pos.y >= 0.3 then - inv:add_item("main", - ItemStack(object:get_luaentity().itemstring)) + inv:add_item("main", ItemStack(entity.itemstring)) - object:get_luaentity().itemstring = "" + entity.itemstring = "" object:remove() end end diff --git a/init.lua b/init.lua index 2148fa0..7f22098 100644 --- a/init.lua +++ b/init.lua @@ -30,25 +30,20 @@ dofile(MP.."/abms.lua") -- Formspec handling minetest.register_on_player_receive_fields(function(player, formname, fields) - if "hopper_formspec:" == string.sub(formname, 1, 16) then - local pos = minetest.string_to_pos(string.sub(formname, 17, -1)) - local meta = minetest.get_meta(pos) + if string.sub(formname, 1, 16) ~= "hopper_formspec:" then + return + end + + local pos = minetest.string_to_pos(string.sub(formname, 17, -1)) + local meta = minetest.get_meta(pos) + if fields.eject then local eject_setting = meta:get_string("eject") == "true" + -- "" deletes the key + meta:set_string("eject", eject_setting and "" or "true") + end + if fields.filter_all then local filter_all_setting = meta:get_string("filter_all") == "true" - if fields.eject then - if eject_setting then - meta:set_string("eject", nil) - else - meta:set_string("eject", "true") - end - end - if fields.filter_all then - if filter_all_setting then - meta:set_string("filter_all", nil) - else - meta:set_string("filter_all", "true") - end - end + meta:set_string("filter_all", filter_all_setting and "" or "true") end end)