58 Commits
master ... dev

Author SHA1 Message Date
d51b468428 Simplify inventorycube code (again) 2018-06-23 10:09:02 +02:00
293fd77614 Fix settings bug 2018-06-23 10:02:04 +02:00
3e6a731cab Fix crash on no drops (@HybridDog) 2018-06-23 10:01:40 +02:00
d282d1ab0c Merge pull request #13 from minetest-mods/pickerparticle
Pickup particle feature
2018-06-18 10:31:33 +02:00
8e6b386fe3 Complete pickup particle feature 2018-06-18 10:18:06 +02:00
31bdc51b42 Look for legacy setting names 2018-06-17 09:27:43 +02:00
c688119069 Merge pull request #11 from minetest-mods/rewrite
Rewrite
2018-06-17 07:41:43 +02:00
376439b214 Update readme 2018-06-17 07:35:06 +02:00
49b7bb19ef Rename the key press test function 2017-09-16 13:18:20 +02:00
4c66b76937 Disable item pickup age if the player has to hold a key for taking items 2017-09-16 12:59:28 +02:00
29df36b2af Typo 2017-09-15 18:40:11 +02:00
2aff58ee02 Update CONTRIBUTING.md 2017-09-15 16:25:53 +02:00
92d68aa48a Fix missing division for dropped item velocity calculation 2017-09-15 10:27:28 +02:00
7afe3723e4 Merge pull request #6 from minetest-mods/no_pop
Always collect items one by one
2017-09-12 13:15:19 +02:00
69f0c08561 Merge pull request #7 from minetest-mods/readmeup
Update README
2017-09-12 13:14:58 +02:00
6f8a37bd10 Create CONTRIBUTING.md 2017-09-12 13:12:23 +02:00
19ad20305f Update README 2017-09-12 10:49:57 +02:00
e7b8d02922 Always collect items one by one 2017-09-12 10:13:49 +02:00
0f903cd0b0 Revert "Adjust default key settings"
This reverts commit 3bc3a4bd25.
2017-09-12 09:55:16 +02:00
bf9931d6db Reflect pickup sound gain in readme 2017-09-11 14:51:02 +02:00
739a62a6c6 Call on_punch to pick items (DS) 2017-09-11 14:44:31 +02:00
271a577881 Don't override handle_node_drops in creative mode 2017-09-11 14:35:55 +02:00
729397b6c9 Update item dropping code 2017-09-11 14:22:17 +02:00
4912d3c828 Update mod load logging
There's no official setting called log_mods
2017-09-11 14:09:24 +02:00
057966141a Do not pick items if the player has no interact 2017-09-11 14:08:01 +02:00
78ef2a50f6 Lower pickup sound gain 2017-09-11 13:09:11 +02:00
c4365cd4de Higher update delay if no item was found
avoid loud pop noise (in zero velocity mode)
2017-09-08 21:26:08 +02:00
bf0bb807fb Fix key triggering disabling 2017-09-08 20:57:05 +02:00
22763d3b06 Remove damage setting test 2017-09-08 20:46:36 +02:00
169d83840f Fix redundant minetest.after invocations 2017-09-08 20:43:30 +02:00
da2fb1df20 Add item flight time setting, set it to 5 seconds by default 2017-09-08 20:42:28 +02:00
3bc3a4bd25 Adjust default key settings 2017-09-08 20:38:20 +02:00
55e89d3710 Add keyinvert setting 2017-09-08 20:36:36 +02:00
4b5e362395 Add magnet_radius setting 2017-09-08 20:32:48 +02:00
bc5ef09e21 Play the pickup sound positional to all players 2017-09-07 21:22:23 +02:00
bab3c733fa Add code for zero velocity mode 2017-09-07 21:13:10 +02:00
69a68cb247 Fix multiplayer support 2017-09-07 21:00:55 +02:00
b56c1792de Move item flight code 2017-09-07 20:57:02 +02:00
544381bbfe Simplify velocity calculation 2017-09-07 20:44:08 +02:00
9f54694931 Add item pickup age 2017-09-07 20:39:49 +02:00
fb2c076b92 Add item_drop. prefix to settings 2017-09-06 15:56:04 +02:00
46959e79d2 Use tabs for indentation 2017-09-06 15:51:34 +02:00
e84433d41c Use minetest.after instead of globalstep 2017-09-06 13:29:48 +02:00
884824989f Load settings only if they are used 2017-09-06 13:27:21 +02:00
962d0a3889 Short code a bit 2017-09-02 23:58:29 +02:00
81d32527f3 Add description and conf file 2017-08-31 21:33:28 +02:00
8a14503372 Create LICENSE 2017-08-31 21:27:22 +02:00
a7b7c71d50 New readme 2017-08-31 21:21:15 +02:00
5a6f79a5d2 Code touch-up 2017-08-30 21:13:33 +02:00
363b56fc03 Pickup radius, new keytypes, limited globalstep (#1)
Thank you @LouisCyfer 🌮 🎉
2017-08-03 22:42:53 +02:00
189fea5eff Use ctrl var 2017-07-11 23:29:18 +02:00
1f9ceb3eb3 Fix var bug 2017-07-09 18:38:44 +02:00
6befa68ef8 Proper global settingtypes 2017-07-09 17:33:22 +02:00
d336a226cd Remove remove_items, superseded by item_entity_ttl 2017-07-09 16:25:11 +02:00
16210c79f7 Fix global settings bool fallbacks 2017-07-09 16:12:57 +02:00
2c60ac7ab0 Add optional pickup key, either sneak, use or a+d key. Add settable sound gain. 2017-06-26 15:57:23 +02:00
a666252f1c Add settings for pickups and drops 2017-06-26 15:24:56 +02:00
d9581ec795 Replace deprecated calls 2017-06-26 15:15:48 +02:00
8 changed files with 102 additions and 280 deletions

View File

@ -1,11 +0,0 @@
on: [push, pull_request]
name: build
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: lint
uses: Roang-zero1/factorio-mod-luacheck@master
with:
luacheckrc_url: https://raw.githubusercontent.com/minetest-mods/item_drop/master/.luacheckrc

View File

@ -1,19 +0,0 @@
unused_args = false
allow_defined_top = true
max_line_length = 999
ignore = {
"name", "drops", "i",
}
globals = {
"minetest",
}
read_globals = {
string = {fields = {"split", "trim"}},
table = {fields = {"copy", "getn"}},
"vector", "ItemStack",
"dump",
}

View File

@ -1,14 +1,15 @@
# Item Drop [![](https://github.com/minetest-mods/item_drop/workflows/build/badge.svg)](https://github.com/minetest-mods/item_drop/actions) [![License](https://img.shields.io/badge/license-LGPLv2.1%2B-blue.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html) # item_drop
A highly configurable mod providing item magnet and in-world node drops\
By [PilzAdam](https://github.com/PilzAdam), By [PilzAdam](https://github.com/PilzAdam),
[texmex](https://github.com/tacotexmex/), [hybriddog](https://github.com/hybriddog/). [texmex](https://github.com/tacotexmex/), [hybriddog](https://github.com/hybriddog/).
## Description
This mod adds Minecraft like drop/pick up of items to Minetest.
## Licensing ## Licensing
LGPLv2.1/CC BY-SA 3.0. Particle code from WCILA mod by Aurailus, originally licensed MIT. LGPLv2.1/CC BY-SA 3.0.
## Notes ## Notes
`item_drop` can be played with Minetest 0.4.16 or above. It was originally item_drop can be played with Minetest 0.4.16 or above. It was originally
developed by [PilzAdam](https://github.com/PilzAdam/item_drop). developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
## List of features ## List of features
@ -18,8 +19,6 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
`true` (true by default) It does nothing in creative mode. `true` (true by default) It does nothing in creative mode.
* Puts dropped items to the player's inventory if `item_drop.enable_item_pickup` * Puts dropped items to the player's inventory if `item_drop.enable_item_pickup`
is `true` (true by default) is `true` (true by default)
* Multiple items are picked in a quick succession instead of all at once which
is indicated by the pickup sound.
* It uses a node radius set in `item_drop.pickup_radius` (default 0.75), * It uses a node radius set in `item_drop.pickup_radius` (default 0.75),
if items are within this radius around the player's belt, they're picked. if items are within this radius around the player's belt, they're picked.
* If `item_drop.pickup_age` is something positive, items dropped by players * If `item_drop.pickup_age` is something positive, items dropped by players
@ -30,8 +29,6 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
items between these radii are flying to the player for items between these radii are flying to the player for
`item_drop.magnet_time` seconds, after this time, they're picked or stop `item_drop.magnet_time` seconds, after this time, they're picked or stop
flying. flying.
* Enable manual item pickups by mouse only if `item_drop.mouse_pickup` is
`true` (true by default)
* Plays a sound when the items are picked up with the gain level set to * Plays a sound when the items are picked up with the gain level set to
`item_drop.pickup_sound_gain` (default 0.2) `item_drop.pickup_sound_gain` (default 0.2)
* Requires a key to be pressed in order to pick items if * Requires a key to be pressed in order to pick items if
@ -42,11 +39,8 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
* Left and Right keys combined (`LeftAndRight`) * Left and Right keys combined (`LeftAndRight`)
* Right mouse button (`RMB`) * Right mouse button (`RMB`)
* Sneak key and right mouse button combined (`SneakAndRMB`) * Sneak key and right mouse button combined (`SneakAndRMB`)
* If `item_drop.pickup_keyinvert` is `true`, items are * If `item_drop.pickup_keyinvert` is `true` (false by default), items are
collected when the key is not pressed instead of when it's pressed. 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)
## Known issues ## Known issues

View File

@ -1 +1 @@
A highly configurable mod providing item magnet and in-world node drops This mod adds Minecraft like drop/pick up of items to Minetest.

306
init.lua
View File

@ -1,63 +1,26 @@
local load_time_start = minetest.get_us_time() local load_time_start = minetest.get_us_time()
pickup_radius = tonumber(minetest.settings:get("item_pickup_radius"))
-- Functions which can be overridden by mods if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false and
item_drop = { minetest.settings:get_bool("enable_item_pickup") ~= false then
-- This function is executed before picking up an item or making it fly to local pickup_gain = tonumber(
-- the player. If it does not return true, the item is ignored. minetest.settings:get("item_drop.pickup_sound_gain")) or
-- It is also executed before collecting the item after it flew to tonumber(minetest.settings:get("item_pickup_gain")) or 0.2
-- the player and did not reach him/her for magnet_time seconds.
can_pickup = function(entity, player)
if entity.item_drop_picked then
-- Ignore items where picking has already failed
return false
end
return true
end,
-- before_collect and after_collect are executed before and after an item
-- is collected by a player
before_collect = function(entity, pos, player)
end,
after_collect = function(entity, pos, player)
entity.item_drop_picked = true
end,
}
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 = local pickup_particle =
minetest.settings:get_bool("item_drop.pickup_particle", true) minetest.settings:get_bool("item_drop.pickup_particle") ~= false
local pickup_radius = legacy_setting_getnumber("item_drop.pickup_radius", local pickup_radius = tonumber(
"item_pickup_radius", 0.75) minetest.settings:get("item_drop.pickup_radius")) or 0.75
local magnet_radius = tonumber( local magnet_radius = tonumber(
minetest.settings:get("item_drop.magnet_radius")) or -1 minetest.settings:get("item_drop.magnet_radius")) or -1
local magnet_time = tonumber( local magnet_time = tonumber(
minetest.settings:get("item_drop.magnet_time")) or 5.0 minetest.settings:get("item_drop.magnet_time")) or 5.0
local pickup_age = tonumber( local pickup_age = tonumber(
minetest.settings:get("item_drop.pickup_age")) or 0.5 minetest.settings:get("item_drop.pickup_age")) or 0.5
local key_triggered = legacy_setting_getbool("item_drop.enable_pickup_key", local key_triggered = minetest.settings:get_bool(
"enable_item_pickup_key", true) "item_drop.enable_pickup_key") or
minetest.settings:get_bool("enable_item_pickup_key") ~= false
local key_invert = minetest.settings:get_bool( local key_invert = minetest.settings:get_bool(
"item_drop.pickup_keyinvert") ~= false "item_drop.pickup_keyinvert") or false
local keytype local keytype
if key_triggered then if key_triggered then
keytype = minetest.settings:get("item_drop.pickup_keytype") or keytype = minetest.settings:get("item_drop.pickup_keytype") or
@ -67,11 +30,6 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
pickup_age = math.min(pickup_age, 0) pickup_age = math.min(pickup_age, 0)
end end
end end
local mouse_pickup = minetest.settings:get_bool(
"item_drop.mouse_pickup") ~= false
if not mouse_pickup then
minetest.registered_entities["__builtin:item"].pointable = false
end
local magnet_mode = magnet_radius > pickup_radius local magnet_mode = magnet_radius > pickup_radius
local zero_velocity_mode = pickup_age == -1 local zero_velocity_mode = pickup_age == -1
@ -80,62 +38,37 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
error"zero velocity mode can't be used together with magnet mode" error"zero velocity mode can't be used together with magnet mode"
end end
-- tells whether an inventorycube should be shown as pickup_particle or not
-- for known drawtypes
local inventorycube_drawtypes = {
normal = true,
allfaces = true,
allfaces_optional = true,
glasslike = true,
glasslike_framed = true,
glasslike_framed_optional = true,
liquid = true,
flowingliquid = true,
}
-- Get an image string from a tile definition
local function tile_to_image(tile, fallback_image)
if not tile then
return fallback_image
end
local tile_type = type(tile)
if tile_type == "string" then
return tile
end
assert(tile_type == "table", "Tile definition is not a string or table")
local image = tile.name or tile.image
assert(image, "Tile definition has no image file specified")
if tile.color then
local colorstr = minetest.colorspec_to_colorstring(tile.color)
if colorstr then
return image .. "^[multiply:" .. colorstr
end
end
return image
end
-- adds the item to the inventory and removes the object -- adds the item to the inventory and removes the object
local function collect_item(ent, pos, player) local function collect_item(ent, pos, player)
item_drop.before_collect(ent, pos, player)
minetest.sound_play("item_drop_pickup", { minetest.sound_play("item_drop_pickup", {
pos = pos, pos = pos,
gain = pickup_gain, gain = pickup_gain,
}, true) })
if pickup_particle then if pickup_particle then
local item = minetest.registered_nodes[ local item = minetest.registered_nodes[ent.itemstring:gsub("(.*)%s.*$","%1")]
ent.itemstring:gsub("(.*)%s.*$", "%1")] local image = ""
local image if item and minetest.registered_items[item.name] and minetest.registered_items[item.name].tiles then
if item and item.tiles and item.tiles[1] then if minetest.registered_items[item.name].tiles[1] then
if inventorycube_drawtypes[item.drawtype] then local dt = minetest.registered_items[item.name].drawtype
local tiles = item.tiles if dt == "normal" or dt == "allfaces" or dt == "allfaces_optional"
-- color in the tile definition is handled by tile_to_image. or dt == "glasslike" or dt =="glasslike_framed" or dt == "glasslike_framed_optional"
-- color in the node definition is not yet supported here. or dt == "liquid" or dt == "flowingliquid" then
local top = tile_to_image(tiles[1]) local tiles = minetest.registered_items[item.name].tiles
local left = tile_to_image(tiles[3], top)
local right = tile_to_image(tiles[5], left) local top = tiles[1]
if (type(top) == "table") then top = top.item end
local left = tiles[3]
if not left then left = top end
if (type(left) == "table") then left = left.item end
local right = tiles[5]
if not right then right = left end
if (type(right) == "table") then right = right.item end
image = minetest.inventorycube(top, left, right) image = minetest.inventorycube(top, left, right)
else else
image = item.inventory_image or item.tiles[1] image = minetest.registered_items[item.name].inventory_image
if not image then image = minetest.registered_items[item.name].tiles[1] end
end
end end
minetest.add_particle({ minetest.add_particle({
pos = {x = pos.x, y = pos.y + 1.5, z = pos.z}, pos = {x = pos.x, y = pos.y + 1.5, z = pos.z},
@ -149,7 +82,6 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
end end
end end
ent:on_punch(player) ent:on_punch(player)
item_drop.after_collect(ent, pos, player)
end end
-- opt_get_ent gets the object's luaentity if it can be collected -- opt_get_ent gets the object's luaentity if it can be collected
@ -157,7 +89,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
if zero_velocity_mode then if zero_velocity_mode then
function opt_get_ent(object) function opt_get_ent(object)
if object:is_player() if object:is_player()
or not vector.equals(object:get_velocity(), {x=0, y=0, z=0}) then or not vector.equals(object:getvelocity(), {x=0, y=0, z=0}) then
return return
end end
local ent = object:get_luaentity() local ent = object:get_luaentity()
@ -195,42 +127,16 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
end end
local item = ItemStack(ent.itemstring) local item = ItemStack(ent.itemstring)
if inv if inv
and inv:room_for_item("main", item) and inv:room_for_item("main", item) then
and item_drop.can_pickup(ent, player) then
collect_item(ent, object:get_pos(), player) collect_item(ent, object:get_pos(), player)
else else
-- the acceleration will be reset by the object's on_step object:setvelocity({x=0,y=0,z=0})
object:set_velocity({x=0,y=0,z=0}) ent.physical_state = true
ent.is_magnet_item = false ent.object:set_properties({
physical = true
})
end end
end end
-- disable velocity and acceleration changes of items flying to players
minetest.after(0, function()
local ObjectRef
local blocked_methods = {"set_acceleration", "set_velocity",
"setacceleration", "setvelocity"}
local itemdef = minetest.registered_entities["__builtin:item"]
local old_on_step = itemdef.on_step
local function do_nothing() end
function itemdef.on_step(self, ...)
if not self.is_magnet_item then
return old_on_step(self, ...)
end
ObjectRef = ObjectRef or getmetatable(self.object)
local old_funcs = {}
for i = 1, #blocked_methods do
local method = blocked_methods[i]
old_funcs[method] = ObjectRef[method]
ObjectRef[method] = do_nothing
end
old_on_step(self, ...)
for i = 1, #blocked_methods do
local method = blocked_methods[i]
ObjectRef[method] = old_funcs[method]
end
end
end)
end end
-- set keytype to the key name if possible -- set keytype to the key name if possible
@ -264,13 +170,6 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
return keys_pressed ~= key_invert return keys_pressed ~= key_invert
end end
local function is_inside_map(pos)
local bound = 31000
return -bound < pos.x and pos.x < bound
and -bound < pos.y and pos.y < bound
and -bound < pos.z and pos.z < bound
end
-- called for each player to possibly collect an item, returns true if so -- called for each player to possibly collect an item, returns true if so
local function pickupfunc(player) local function pickupfunc(player)
if not has_keys_pressed(player) if not has_keys_pressed(player)
@ -279,43 +178,46 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
return return
end end
local pos = player:get_pos() local pos = player:getpos()
if not is_inside_map(pos) then
-- get_objects_inside_radius crashes for too far positions
return
end
pos.y = pos.y+0.5 pos.y = pos.y+0.5
local inv = player:get_inventory() local inv
local objectlist = minetest.get_objects_inside_radius(pos, local objectlist = minetest.get_objects_inside_radius(pos,
magnet_mode and magnet_radius or pickup_radius) magnet_mode and magnet_radius or pickup_radius)
for i = 1,#objectlist do for i = 1,#objectlist do
local object = objectlist[i] local object = objectlist[i]
local ent = opt_get_ent(object) local ent = opt_get_ent(object)
if ent if ent then
and item_drop.can_pickup(ent, player) then if not inv then
inv = player:get_inventory()
if not inv then
minetest.log("error", "[item_drop] Couldn't " ..
"get inventory")
return
end
end
local item = ItemStack(ent.itemstring) local item = ItemStack(ent.itemstring)
if inv:room_for_item("main", item) then if inv:room_for_item("main", item) then
local flying_item local flying_item
local pos2 local pos2
if magnet_mode then if magnet_mode then
pos2 = object:get_pos() pos2 = object:getpos()
flying_item = vector.distance(pos, pos2) > pickup_radius flying_item = vector.distance(pos, pos2) > pickup_radius
end end
if not flying_item then if not flying_item then
-- The item is near enough to pick it -- collect one item at a time to avoid the loud pop
collect_item(ent, pos, player) collect_item(ent, pos, player)
-- Collect one item at a time to avoid the loud pop
return true return true
end end
-- The item is not too far a way but near enough to be local vel = vector.multiply(
-- magnetised, make it fly to the player vector.subtract(pos, pos2), 3)
local vel = vector.multiply(vector.subtract(pos, pos2), 3)
vel.y = vel.y + 0.6 vel.y = vel.y + 0.6
object:set_velocity(vel) object:setvelocity(vel)
if not ent.is_magnet_item then if ent.physical_state then
ent.object:set_acceleration({x=0, y=0, z=0}) ent.physical_state = false
ent.is_magnet_item = true ent.object:set_properties({
physical = false
})
minetest.after(magnet_time, afterflight, minetest.after(magnet_time, afterflight,
object, inv, player) object, inv, player)
@ -343,37 +245,33 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
minetest.after(3.0, pickup_step) minetest.after(3.0, pickup_step)
end end
if legacy_setting_getbool("item_drop.enable_item_drop", "enable_item_drop", true) if minetest.settings:get_bool("item_drop.enable_item_drop") ~= false and
minetest.settings:get_bool("enable_item_drop") ~= false
and not minetest.settings:get_bool("creative_mode") then and not minetest.settings:get_bool("creative_mode") then
-- Workaround to test if an item metadata (ItemStackMetaRef) is empty function minetest.handle_node_drops(pos, drops)
local function itemmeta_is_empty(meta) for i = 1,#drops do
local t = meta:to_table() local item = drops[i]
for k, v in pairs(t) do local count, name
if k ~= "fields" then if type(item) == "string" then
return false count = 1
end name = item
assert(type(v) == "table") else
if next(v) ~= nil then count = item:get_count()
return false name = item:get_name()
end
end
return true
end end
-- Tests if the item has special information such as metadata if name == "" then
local function can_split_item(item) -- Sometimes nothing should be dropped
return item:get_wear() == 0 and itemmeta_is_empty(item:get_meta()) count = 0
end end
local function spawn_items(pos, items_to_spawn) for _ = 1,count do
for i = 1,#items_to_spawn do local obj = minetest.add_item(pos, name)
local obj = minetest.add_item(pos, items_to_spawn[i])
if not obj then if not obj then
error("Couldn't spawn item " .. name .. ", drops: " error("Couldn't spawn item " .. name .. ", drops: " .. dump(drops))
.. dump(drops))
end end
local vel = obj:get_velocity() local vel = obj:getvelocity()
local x = math.random(-5, 4) local x = math.random(-5, 4)
if x >= 0 then if x >= 0 then
x = x+1 x = x+1
@ -384,43 +282,7 @@ and not minetest.settings:get_bool("creative_mode") then
z = z+1 z = z+1
end end
vel.z = 1 / z vel.z = 1 / z
obj:set_velocity(vel) obj:setvelocity(vel)
end
end
local old_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, player)
if not player or 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
-- 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 == ""
or not minetest.registered_items[name] then
count = 0
end
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
spawn_items(pos, items_to_spawn)
end end
end end
end end

View File

@ -1,2 +1 @@
name = item_drop name = item_drop
description = A highly configurable mod providing item magnet and in-world node drops

Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 KiB

View File

@ -8,7 +8,7 @@ item_drop.enable_item_drop (Enable item drops) bool true
item_drop.enable_pickup_key (Use pickup key) 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 #Collect items when the key is not pressed instead of when it is pressed
item_drop.pickup_keyinvert (Invert pickup key) bool true item_drop.pickup_keyinvert (Invert pickup key) bool false
#What keytype to use as pickup key #What keytype to use as pickup key
item_drop.pickup_keytype (Pickup keytype) enum Use Use,Sneak,LeftAndRight,RMB,SneakAndRMB item_drop.pickup_keytype (Pickup keytype) enum Use Use,Sneak,LeftAndRight,RMB,SneakAndRMB
@ -33,6 +33,3 @@ item_drop.magnet_time (Magnet time) float 5.0
#Time delay in seconds after autopicking an item if it's dropped by a player #Time delay in seconds after autopicking an item if it's dropped by a player
item_drop.pickup_age (Pickup age) float 0.5 item_drop.pickup_age (Pickup age) float 0.5
#Enable manual item pickups by mouse
item_drop.mouse_pickup (Mouse pickup) bool true