From 427117d7868c099d7f3088ddcb88a2c7b76c9add Mon Sep 17 00:00:00 2001 From: HybridDog Date: Thu, 16 May 2019 11:36:15 +0200 Subject: [PATCH 01/10] Fix missing ore drops --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index bd19bb2..e263ce5 100644 --- a/init.lua +++ b/init.lua @@ -331,7 +331,7 @@ and not minetest.settings:get_bool("creative_mode") then -- Sometimes nothing should be dropped if name == "" - or not minetest.registered_nodes[name] then + or not minetest.registered_items[name] then count = 0 end From 3a9a506011cd7336a7585ed911bc4f75d77046ef Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sun, 26 May 2019 14:13:54 +0200 Subject: [PATCH 02/10] Fix crash due to a missing function I accidentally wrote can_pickup instead of item_drop.can_pickup in a previous commit. --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index e263ce5..da0bca6 100644 --- a/init.lua +++ b/init.lua @@ -170,7 +170,7 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then local item = ItemStack(ent.itemstring) if inv and inv:room_for_item("main", item) - and can_pickup(ent, player) then + and item_drop.can_pickup(ent, player) then collect_item(ent, object:get_pos(), player) else -- the acceleration will be reset by the object's on_step From f7d62113ffae6136d2110b403bbbf2f97623d5a0 Mon Sep 17 00:00:00 2001 From: texmex Date: Mon, 27 May 2019 09:21:28 +0200 Subject: [PATCH 03/10] Update mod.conf --- mod.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/mod.conf b/mod.conf index 7a095b1..8966913 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,2 @@ name = item_drop +description = A highly configurable mod providing item magnet and in-world node drops From 1e9e73e978dc8ea2cb16292fc8f6f152ed13dd0b Mon Sep 17 00:00:00 2001 From: texmex Date: Mon, 27 May 2019 09:21:59 +0200 Subject: [PATCH 04/10] Update description.txt --- description.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/description.txt b/description.txt index 4488941..ef32f14 100644 --- a/description.txt +++ b/description.txt @@ -1 +1 @@ -This mod adds Minecraft like drop/pick up of items to Minetest. +A highly configurable mod providing item magnet and in-world node drops From 70b33863223743783fa8b8d16204bcfa9ebd58d0 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Wed, 29 May 2019 20:44:40 +0200 Subject: [PATCH 05/10] Allow disabling the pickup key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To support lecagy setting names, I added two functions. They use the old setting only if the new one is not set. (I'm not sure if enable_item_pickup_key is a valid legacy setting…) I did not test this commit thoroughly. --- init.lua | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/init.lua b/init.lua index da0bca6..8a30465 100644 --- a/init.lua +++ b/init.lua @@ -23,25 +23,39 @@ item_drop = { end, } -if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false and -minetest.settings:get_bool("enable_item_pickup") ~= false then - local pickup_gain = tonumber( - minetest.settings:get("item_drop.pickup_sound_gain")) or - tonumber(minetest.settings:get("item_pickup_gain")) or 0.2 +local function legacy_setting_getbool(name_new, name_old, default) + local v = minetest.settings:get_bool(name_new) + if v == nil then + v = minetest.settings:get_bool(name_new) + end + if default then + return v ~= false + end + return v +end + +local function legacy_setting_getnumber(name_new, name_old, default) + return tonumber(minetest.settings:get(name_new)) + or tonumber(minetest.settings:get(name_old)) + or default +end + +if legacy_setting_getbool("item_drop.enable_item_pickup", + "enable_item_pickup", true) then + local pickup_gain = legacy_setting_getnumber("item_drop.pickup_sound_gain", + "item_pickup_gain", 0.2) local pickup_particle = - minetest.settings:get_bool("item_drop.pickup_particle") ~= false - local pickup_radius = tonumber( - minetest.settings:get("item_drop.pickup_radius")) or - tonumber(minetest.settings:get("item_pickup_radius")) or 0.75 + minetest.settings:get_bool("item_drop.pickup_particle", true) + local pickup_radius = legacy_setting_getnumber("item_drop.pickup_radius", + "item_pickup_radius", 0.75) local magnet_radius = tonumber( minetest.settings:get("item_drop.magnet_radius")) or -1 local magnet_time = tonumber( minetest.settings:get("item_drop.magnet_time")) or 5.0 local pickup_age = tonumber( minetest.settings:get("item_drop.pickup_age")) or 0.5 - local key_triggered = minetest.settings:get_bool( - "item_drop.enable_pickup_key") or - minetest.settings:get_bool("enable_item_pickup_key") ~= false + local key_triggered = legacy_setting_getbool("item_drop.enable_pickup_key", + "enable_item_pickup_key", true) local key_invert = minetest.settings:get_bool( "item_drop.pickup_keyinvert") or false local keytype @@ -314,8 +328,7 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then minetest.after(3.0, pickup_step) end -if minetest.settings:get_bool("item_drop.enable_item_drop") ~= false and -minetest.settings:get_bool("enable_item_drop") ~= false +if legacy_setting_getbool("item_drop.enable_item_drop", "enable_item_drop", true) and not minetest.settings:get_bool("creative_mode") then function minetest.handle_node_drops(pos, drops) for i = 1,#drops do From 5069afa83443ffed2ae980773b09725bd8fb5696 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Tue, 4 Jun 2019 16:44:46 +0200 Subject: [PATCH 06/10] Enable pickup_keyinvert by default --- README.md | 2 +- init.lua | 2 +- settingtypes.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7136f76..3fa0895 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop). * Left and Right keys combined (`LeftAndRight`) * Right mouse button (`RMB`) * Sneak key and right mouse button combined (`SneakAndRMB`) - * If `item_drop.pickup_keyinvert` is `true` (false by default), items are + * If `item_drop.pickup_keyinvert` is `true`, items are collected when the key is not pressed instead of when it's pressed. * Displays a particle of the picked item above the player if `item_drop.pickup_particle` is `true` (true by default) diff --git a/init.lua b/init.lua index 8a30465..e89a78e 100644 --- a/init.lua +++ b/init.lua @@ -57,7 +57,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", local key_triggered = legacy_setting_getbool("item_drop.enable_pickup_key", "enable_item_pickup_key", true) local key_invert = minetest.settings:get_bool( - "item_drop.pickup_keyinvert") or false + "item_drop.pickup_keyinvert") ~= false local keytype if key_triggered then keytype = minetest.settings:get("item_drop.pickup_keytype") or diff --git a/settingtypes.txt b/settingtypes.txt index 4896788..14df02c 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -8,7 +8,7 @@ item_drop.enable_item_drop (Enable item drops) bool true item_drop.enable_pickup_key (Use pickup key) bool true #Collect items when the key is not pressed instead of when it is pressed -item_drop.pickup_keyinvert (Invert pickup key) bool false +item_drop.pickup_keyinvert (Invert pickup key) bool true #What keytype to use as pickup key item_drop.pickup_keytype (Pickup keytype) enum Use Use,Sneak,LeftAndRight,RMB,SneakAndRMB From 934ebff45a105910b10689181844b19f4326bcec Mon Sep 17 00:00:00 2001 From: Panquesito7 <51391473+Panquesito7@users.noreply.github.com> Date: Fri, 14 Jun 2019 17:47:21 -0500 Subject: [PATCH 07/10] Replace deprecated functions with newer ones --- init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index e89a78e..47b1c6f 100644 --- a/init.lua +++ b/init.lua @@ -145,7 +145,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", if zero_velocity_mode then function opt_get_ent(object) if object:is_player() - or not vector.equals(object:getvelocity(), {x=0, y=0, z=0}) then + or not vector.equals(object:get_velocity(), {x=0, y=0, z=0}) then return end local ent = object:get_luaentity() @@ -284,7 +284,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", local flying_item local pos2 if magnet_mode then - pos2 = object:getpos() + pos2 = object:get_pos() flying_item = vector.distance(pos, pos2) > pickup_radius end if not flying_item then @@ -354,7 +354,7 @@ and not minetest.settings:get_bool("creative_mode") then error("Couldn't spawn item " .. name .. ", drops: " .. dump(drops)) end - local vel = obj:getvelocity() + local vel = obj:get_velocity() local x = math.random(-5, 4) if x >= 0 then x = x+1 From 26d0532cbda53416b278472edc3296d85ee97496 Mon Sep 17 00:00:00 2001 From: texmex Date: Sat, 15 Jun 2019 13:26:24 +0200 Subject: [PATCH 08/10] Replace another deprecated function --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 47b1c6f..16084bd 100644 --- a/init.lua +++ b/init.lua @@ -260,7 +260,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", return end - local pos = player:getpos() + local pos = player:get_pos() pos.y = pos.y+0.5 local inv From 5611b4d639a0a77cc8a6f32ba0a50622bc3cb749 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Mon, 1 Jul 2019 15:37:04 +0200 Subject: [PATCH 09/10] Handle item drops more carefully Do not ignore itemstrings which contain more than just the name; fixes missing clay drops Support dropped items with toolwear and/or metadata --- init.lua | 78 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/init.lua b/init.lua index 16084bd..d05726d 100644 --- a/init.lua +++ b/init.lua @@ -330,17 +330,59 @@ end if legacy_setting_getbool("item_drop.enable_item_drop", "enable_item_drop", true) and not minetest.settings:get_bool("creative_mode") then + -- Workaround to test if an item metadata (ItemStackMetaRef) is empty + local function itemmeta_is_empty(meta) + local t = meta:to_table() + for k, v in pairs(t) do + if k ~= "fields" then + return false + end + assert(type(v) == "table") + if next(v) ~= nil then + return false + end + end + return true + end + + -- Tests if the item has special information such as metadata + local function can_split_item(item) + return item:get_wear() == 0 and itemmeta_is_empty(item:get_meta()) + end + + local function spawn_items(pos, items_to_spawn) + for i = 1,#items_to_spawn do + local obj = minetest.add_item(pos, items_to_spawn[i]) + if not obj then + error("Couldn't spawn item " .. name .. ", drops: " + .. dump(drops)) + end + + local vel = obj:get_velocity() + local x = math.random(-5, 4) + if x >= 0 then + x = x+1 + end + vel.x = 1 / x + local z = math.random(-5, 4) + if z >= 0 then + z = z+1 + end + vel.z = 1 / z + obj:set_velocity(vel) + end + end + function minetest.handle_node_drops(pos, drops) for i = 1,#drops do local item = drops[i] - local count, name if type(item) == "string" then - count = 1 - name = item - else - count = item:get_count() - name = item:get_name() + -- The string is not necessarily only the item name, + -- so always convert it to ItemStack + item = ItemStack(item) end + local count = item:get_count() + local name = item:get_name() -- Sometimes nothing should be dropped if name == "" @@ -348,24 +390,16 @@ and not minetest.settings:get_bool("creative_mode") then count = 0 end - for _ = 1,count do - local obj = minetest.add_item(pos, name) - if not obj then - error("Couldn't spawn item " .. name .. ", drops: " .. dump(drops)) + if count > 0 then + -- Split items if possible + local items_to_spawn = {item} + if can_split_item(item) then + for i = 1,count do + items_to_spawn[i] = name + end end - local vel = obj:get_velocity() - local x = math.random(-5, 4) - if x >= 0 then - x = x+1 - end - vel.x = 1 / x - local z = math.random(-5, 4) - if z >= 0 then - z = z+1 - end - vel.z = 1 / z - obj:set_velocity(vel) + spawn_items(pos, items_to_spawn) end end end From fadfbf7e0563f58fadd7b3b7c9e9aedd83c9adca Mon Sep 17 00:00:00 2001 From: HybridDog Date: Wed, 4 Sep 2019 18:30:49 +0200 Subject: [PATCH 10/10] Do not drop items when a Node Breaker digs a node --- init.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index d05726d..25145b1 100644 --- a/init.lua +++ b/init.lua @@ -373,7 +373,13 @@ and not minetest.settings:get_bool("creative_mode") then end end - function minetest.handle_node_drops(pos, drops) + local old_handle_node_drops = minetest.handle_node_drops + function minetest.handle_node_drops(pos, drops, player) + if player.is_fake_player then + -- Node Breaker or similar machines should receive items in the + -- inventory + return old_handle_node_drops(pos, drops, player) + end for i = 1,#drops do local item = drops[i] if type(item) == "string" then