129 Commits
dev ... master

Author SHA1 Message Date
88ca34203d Merge remote-tracking branch 'upstream/master' 2023-06-07 21:32:30 +02:00
8bebf6324e Fix error when picking up a node with deprecated tile definition (#40)
If `image` instead of `tile` was used, the mod passed nil to minetest.inventorycube.
The color field of a tile is now also supported (the code is used only for the particle image calculation).
2022-10-06 18:36:50 +02:00
cae46704eb Merge remote-tracking branch 'upstream/master' 2021-09-21 23:00:00 +02:00
d19d00d690 Mark pickup sound as ephemeral 2021-09-02 23:42:56 +02:00
900614a74c Merge remote-tracking branch 'upstream/master' 2020-09-28 20:52:45 +02:00
1545f82cb7 Fix error for 'nil' player in minetest.handle_node_drops (#36) 2020-09-27 19:15:57 +02:00
29983259ee Merge remote-tracking branch 'upstream/master' into nalc-1.2-dev 2020-06-16 22:54:09 +02:00
de38b20fa6 Add GitHub workflow and LuaCheck (#34)
* Add GitHub workflow and LuaCheck

* Fix LuaCheck warnings

* Improve README.md
2020-05-25 20:42:09 +02:00
f015cc1631 Ignore players which are outside the map 2020-05-17 21:12:57 +02:00
72f4225058 Support the moveresult parameter of on_step
The parameter is available in Minetest 5.3.0-dev.
thanks to sofar and VanessaE for the fix and report
2020-05-08 11:54:33 +02:00
7cb8086a25 Get player inventory before looping (#30)
This prevents the inventory check on each object in the loop and thus shortens the code.
Additionally, the inventory existence check is removed because get_inventory never returns nil for player objects.
2020-04-15 20:21:48 +02:00
c6a80bd4fa Merge branch 'master' of yunohost.local:minetest-mods/item_drop into nalc-1.2-dev 2019-12-22 13:35:07 +01:00
8ef6ba3c0f Do not drop items when a Node Breaker digs a node 2019-09-05 12:00:13 +02:00
fadfbf7e05 Do not drop items when a Node Breaker digs a node 2019-09-05 12:00:13 +02:00
682a345495 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
2019-07-01 15:46:06 +02:00
5611b4d639 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
2019-07-01 15:46:06 +02:00
871be4048e Replace another deprecated function 2019-06-15 13:26:24 +02:00
26d0532cbd Replace another deprecated function 2019-06-15 13:26:24 +02:00
95e89b1c94 Merge pull request #24 from Panquesito7/master
Replace deprecated functions with newer ones
2019-06-15 02:51:01 +02:00
becdfd113a Merge pull request #24 from Panquesito7/master
Replace deprecated functions with newer ones
2019-06-15 02:51:01 +02:00
faf6d9236d Replace deprecated functions with newer ones 2019-06-14 17:47:21 -05:00
934ebff45a Replace deprecated functions with newer ones 2019-06-14 17:47:21 -05:00
c943cf2042 Enable pickup_keyinvert by default 2019-06-04 16:44:46 +02:00
5069afa834 Enable pickup_keyinvert by default 2019-06-04 16:44:46 +02:00
666ff41136 Allow disabling the pickup key
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.
2019-05-29 20:44:59 +02:00
70b3386322 Allow disabling the pickup key
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.
2019-05-29 20:44:59 +02:00
1157ec15df Update description.txt 2019-05-27 09:21:59 +02:00
1e9e73e978 Update description.txt 2019-05-27 09:21:59 +02:00
765bb0a405 Update mod.conf 2019-05-27 09:21:28 +02:00
f7d62113ff Update mod.conf 2019-05-27 09:21:28 +02:00
aef629f5b3 Fix crash due to a missing function
I accidentally wrote can_pickup instead of item_drop.can_pickup in a previous commit.
2019-05-26 14:13:54 +02:00
3a9a506011 Fix crash due to a missing function
I accidentally wrote can_pickup instead of item_drop.can_pickup in a previous commit.
2019-05-26 14:13:54 +02:00
6637bbb813 Fix missing ore drops 2019-05-16 11:36:15 +02:00
427117d786 Fix missing ore drops 2019-05-16 11:36:15 +02:00
c1637b1975 Corrige crash à cause d'un mauvais appel de fonction 2019-05-10 11:54:20 +02:00
e10486d2aa Merge branch 'master' into nalc-1.2 2019-05-10 00:12:36 +02:00
f8b60b0b05 Update readme 2019-02-13 02:54:58 +01:00
532a3cb0d0 Update readme 2019-02-13 02:54:58 +01:00
0aa32c1fed Remove unneeded variable assertion, fix #20 2019-02-12 13:25:34 +01:00
56d2eeda5c Remove unneeded variable assertion, fix #20 2019-02-12 13:25:34 +01:00
4c0a23855a Add a screenshot 2019-02-12 05:37:14 +01:00
c52ff0ea55 Add a screenshot 2019-02-12 05:37:14 +01:00
0cee07b9d5 Add setting for disabling manual item pickups by mouse 2019-02-12 01:12:59 +01:00
8e89c148be Add setting for disabling manual item pickups by mouse 2019-02-12 01:12:59 +01:00
97158f7fac Ignore items where picking failed
tested with item_helpers
2019-02-05 19:29:40 +01:00
726b5f4872 Ignore items where picking failed
tested with item_helpers
2019-02-05 19:29:40 +01:00
dd01ddf5ff Fix crash when trying to spawn an unknown item 2019-02-01 17:55:12 +01:00
8e1878d101 Fix crash when trying to spawn an unknown item 2019-02-01 17:55:12 +01:00
d3687f027a Add three functions which can be used by other mods 2019-01-05 13:54:12 +01:00
f6b8bcd7a7 Add three functions which can be used by other mods 2019-01-05 13:54:12 +01:00
62dbd6bc0d Fix a legacy setting support 2019-01-05 13:26:29 +01:00
6b7ed8e7ca Fix a legacy setting support 2019-01-05 13:26:29 +01:00
2730deca16 Déplace le message de chargement du mod vers le journal "action" 2018-12-26 00:05:48 +01:00
02683056e5 Fix item magnet
There is no field named physical_state, so the item didn't lose the physical property, but it happily hopped towards me after I dropped it.
Disabling physical looked quite wrong, because the item flew through mountains. Instead, it gets zero acceleration now.
To avoid resetting the acceleration in the on_step function, it is overridden to disable acceleration and velocity changes during executing the original on_step.
Small code fix: Add underscores in set_velocity and set_acceleration
2018-10-03 17:58:58 +02:00
fc89b2d2b4 Fix item magnet
There is no field named physical_state, so the item didn't lose the physical property, but it happily hopped towards me after I dropped it.
Disabling physical looked quite wrong, because the item flew through mountains. Instead, it gets zero acceleration now.
To avoid resetting the acceleration in the on_step function, it is overridden to disable acceleration and velocity changes during executing the original on_step.
Small code fix: Add underscores in set_velocity and set_acceleration
2018-10-03 17:58:58 +02:00
1d2e42eaab Fix crash when a node texture is a table 2018-08-12 10:33:55 +02:00
f5187108f1 Fix crash when a node texture is a table 2018-08-12 10:33:55 +02:00
0112f1f9ec Tidy up pickup_particle code 2018-08-12 10:33:49 +02:00
902daba7cf Tidy up pickup_particle code 2018-08-12 10:33:49 +02:00
5f3e6e6b1b Merge branch 'master' of https://github.com/minetest-mods/item_drop 2018-06-23 18:39:36 +02:00
3c9c0e34e3 Merge branch 'master' of https://github.com/minetest-mods/item_drop 2018-06-23 18:39:36 +02:00
13be42cd39 Reflect particle feature setting in readme 2018-06-23 18:39:29 +02:00
eaa44e2a36 Reflect particle feature setting in readme 2018-06-23 18:39:29 +02:00
e2d370a17a Reflect particle feature setting in readme 2018-06-23 18:39:17 +02:00
a69bdd2275 Reflect particle feature setting in readme 2018-06-23 18:39:17 +02:00
50b976748d Add WCILA code origin and license 2018-06-23 10:15:40 +02:00
1b0bc8461c Add WCILA code origin and license 2018-06-23 10:15:40 +02:00
1901524074 Merge pull request #14 from minetest-mods/dev
Bug fixes
2018-06-23 10:13:55 +02:00
b42a64cfa4 Merge pull request #14 from minetest-mods/dev
Bug fixes
2018-06-23 10:13:55 +02:00
608b5dfe6e Simplify inventorycube code (again) 2018-06-23 10:09:02 +02:00
1e5718cbac Fix settings bug 2018-06-23 10:02:04 +02:00
c57d3c1514 Fix crash on no drops (@HybridDog) 2018-06-23 10:01:40 +02:00
cce81f6fe9 Fix settings bug 2018-06-18 20:54:59 +02:00
760acbc593 Fix settings bug 2018-06-18 20:54:59 +02:00
88897d9049 Merge pull request #13 from minetest-mods/pickerparticle
Pickup particle feature
2018-06-18 10:31:33 +02:00
b6b1a8e95b Complete pickup particle feature 2018-06-18 10:18:06 +02:00
08ba364510 Look for legacy setting names 2018-06-17 09:27:43 +02:00
b576e882a7 Merge pull request #11 from minetest-mods/rewrite
Rewrite
2018-06-17 07:41:43 +02:00
15968a0240 Update readme 2018-06-17 07:35:06 +02:00
f1fcc478a1 Rename the key press test function 2017-09-16 13:18:20 +02:00
3d88b7b5c6 Disable item pickup age if the player has to hold a key for taking items 2017-09-16 12:59:28 +02:00
70068fd307 Typo 2017-09-15 18:40:11 +02:00
2577b99556 Update CONTRIBUTING.md 2017-09-15 16:25:53 +02:00
d5b28e01b0 Fix missing division for dropped item velocity calculation 2017-09-15 10:27:28 +02:00
41e93d3bf6 Merge pull request #6 from minetest-mods/no_pop
Always collect items one by one
2017-09-12 13:15:19 +02:00
124e3588e5 Merge pull request #7 from minetest-mods/readmeup
Update README
2017-09-12 13:14:58 +02:00
464fce9a87 Create CONTRIBUTING.md 2017-09-12 13:12:23 +02:00
cbd717b549 Update README 2017-09-12 10:49:57 +02:00
609d441ef4 Always collect items one by one 2017-09-12 10:13:49 +02:00
3a9a985cfc Revert "Adjust default key settings"
This reverts commit 3bc3a4bd25.
2017-09-12 09:55:16 +02:00
b5c7fbaa38 Reflect pickup sound gain in readme 2017-09-11 14:51:02 +02:00
8543bad2aa Call on_punch to pick items (DS) 2017-09-11 14:44:31 +02:00
f811009c80 Don't override handle_node_drops in creative mode 2017-09-11 14:35:55 +02:00
ac2da1689e Update item dropping code 2017-09-11 14:22:17 +02:00
35786b597c Update mod load logging
There's no official setting called log_mods
2017-09-11 14:09:24 +02:00
1e2287a672 Do not pick items if the player has no interact 2017-09-11 14:08:01 +02:00
06c1212d5b Lower pickup sound gain 2017-09-11 13:09:11 +02:00
253cc75c51 Higher update delay if no item was found
avoid loud pop noise (in zero velocity mode)
2017-09-08 21:26:08 +02:00
88df92b125 Fix key triggering disabling 2017-09-08 20:57:05 +02:00
6de1402ebc Remove damage setting test 2017-09-08 20:46:36 +02:00
b06129c3a3 Fix redundant minetest.after invocations 2017-09-08 20:43:30 +02:00
c86bc605bd Add item flight time setting, set it to 5 seconds by default 2017-09-08 20:42:28 +02:00
c21158ffab Adjust default key settings 2017-09-08 20:38:20 +02:00
9de8d39af6 Add keyinvert setting 2017-09-08 20:36:36 +02:00
f2e3338265 Add magnet_radius setting 2017-09-08 20:32:48 +02:00
31229760e8 Play the pickup sound positional to all players 2017-09-07 21:22:23 +02:00
fced0590c6 Add code for zero velocity mode 2017-09-07 21:13:10 +02:00
f91c73d2e3 Fix multiplayer support 2017-09-07 21:00:55 +02:00
8c3a470690 Move item flight code 2017-09-07 20:57:02 +02:00
ce059ad5ad Simplify velocity calculation 2017-09-07 20:44:08 +02:00
ac3386a402 Add item pickup age 2017-09-07 20:39:49 +02:00
0eace77417 Add item_drop. prefix to settings 2017-09-06 15:56:04 +02:00
bfcc14bb4b Use tabs for indentation 2017-09-06 15:51:34 +02:00
04c441768f Use minetest.after instead of globalstep 2017-09-06 13:29:48 +02:00
31e8c9b0cc Load settings only if they are used 2017-09-06 13:27:21 +02:00
a88fa5f1b7 Short code a bit 2017-09-02 23:58:29 +02:00
ad4e83d243 Add description and conf file 2017-08-31 21:33:28 +02:00
07eb65bb31 Create LICENSE 2017-08-31 21:27:22 +02:00
c63a4ee2a3 New readme 2017-08-31 21:21:15 +02:00
5aed10c3e7 Code touch-up 2017-08-30 21:13:33 +02:00
dbd9538a78 Pickup radius, new keytypes, limited globalstep (#1)
Thank you @LouisCyfer 🌮 🎉
2017-08-03 22:42:53 +02:00
1091537584 Use ctrl var 2017-07-11 23:29:18 +02:00
a7cdd68cc9 Fix var bug 2017-07-09 18:38:44 +02:00
dbb43c2ed1 Proper global settingtypes 2017-07-09 17:33:22 +02:00
67025939e7 Remove remove_items, superseded by item_entity_ttl 2017-07-09 16:25:11 +02:00
7f38ae5261 Fix global settings bool fallbacks 2017-07-09 16:12:57 +02:00
a523b5a574 Add optional pickup key, either sneak, use or a+d key. Add settable sound gain. 2017-06-26 15:57:23 +02:00
04f75caeb3 Add settings for pickups and drops 2017-06-26 15:24:56 +02:00
2d42301d85 Replace deprecated calls 2017-06-26 15:15:48 +02:00
8 changed files with 301 additions and 107 deletions

11
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,11 @@
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

19
.luacheckrc Normal file
View File

@ -0,0 +1,19 @@
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,15 +1,14 @@
# item_drop
# 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)
A highly configurable mod providing item magnet and in-world node drops\
By [PilzAdam](https://github.com/PilzAdam),
[texmex](https://github.com/tacotexmex/), [hybriddog](https://github.com/hybriddog/).
## Description
This mod adds Minecraft like drop/pick up of items to Minetest.
## Licensing
LGPLv2.1/CC BY-SA 3.0.
LGPLv2.1/CC BY-SA 3.0. Particle code from WCILA mod by Aurailus, originally licensed MIT.
## 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).
## List of features
@ -19,6 +18,8 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
`true` (true by default) It does nothing in creative mode.
* Puts dropped items to the player's inventory if `item_drop.enable_item_pickup`
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),
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
@ -29,6 +30,8 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
items between these radii are flying to the player for
`item_drop.magnet_time` seconds, after this time, they're picked or stop
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
`item_drop.pickup_sound_gain` (default 0.2)
* Requires a key to be pressed in order to pick items if
@ -39,8 +42,11 @@ 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)
## Known issues

View File

@ -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

324
init.lua
View File

@ -1,26 +1,63 @@
local load_time_start = minetest.get_us_time()
pickup_radius = tonumber(minetest.settings:get("item_pickup_radius"))
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
-- Functions which can be overridden by mods
item_drop = {
-- This function is executed before picking up an item or making it fly to
-- the player. If it does not return true, the item is ignored.
-- It is also executed before collecting the item after it flew to
-- 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 =
minetest.settings:get_bool("item_drop.pickup_particle") ~= false
local pickup_radius = tonumber(
minetest.settings:get("item_drop.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
"item_drop.pickup_keyinvert") ~= false
local keytype
if key_triggered then
keytype = minetest.settings:get("item_drop.pickup_keytype") or
@ -30,6 +67,11 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
pickup_age = math.min(pickup_age, 0)
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 zero_velocity_mode = pickup_age == -1
@ -38,37 +80,62 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
error"zero velocity mode can't be used together with magnet mode"
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
local function collect_item(ent, pos, player)
item_drop.before_collect(ent, pos, player)
minetest.sound_play("item_drop_pickup", {
pos = pos,
gain = pickup_gain,
})
}, true)
if pickup_particle then
local item = minetest.registered_nodes[ent.itemstring:gsub("(.*)%s.*$","%1")]
local image = ""
if item and minetest.registered_items[item.name] and minetest.registered_items[item.name].tiles then
if minetest.registered_items[item.name].tiles[1] then
local dt = minetest.registered_items[item.name].drawtype
if dt == "normal" or dt == "allfaces" or dt == "allfaces_optional"
or dt == "glasslike" or dt =="glasslike_framed" or dt == "glasslike_framed_optional"
or dt == "liquid" or dt == "flowingliquid" then
local tiles = minetest.registered_items[item.name].tiles
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
local item = minetest.registered_nodes[
ent.itemstring:gsub("(.*)%s.*$", "%1")]
local image
if item and item.tiles and item.tiles[1] then
if inventorycube_drawtypes[item.drawtype] then
local tiles = item.tiles
-- color in the tile definition is handled by tile_to_image.
-- color in the node definition is not yet supported here.
local top = tile_to_image(tiles[1])
local left = tile_to_image(tiles[3], top)
local right = tile_to_image(tiles[5], left)
image = minetest.inventorycube(top, left, right)
else
image = minetest.registered_items[item.name].inventory_image
if not image then image = minetest.registered_items[item.name].tiles[1] end
end
image = item.inventory_image or item.tiles[1]
end
minetest.add_particle({
pos = {x = pos.x, y = pos.y + 1.5, z = pos.z},
@ -82,6 +149,7 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
end
end
ent:on_punch(player)
item_drop.after_collect(ent, pos, player)
end
-- opt_get_ent gets the object's luaentity if it can be collected
@ -89,7 +157,7 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
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()
@ -127,16 +195,42 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
end
local item = ItemStack(ent.itemstring)
if inv
and inv:room_for_item("main", item) then
and inv:room_for_item("main", item)
and item_drop.can_pickup(ent, player) then
collect_item(ent, object:get_pos(), player)
else
object:setvelocity({x=0,y=0,z=0})
ent.physical_state = true
ent.object:set_properties({
physical = true
})
-- the acceleration will be reset by the object's on_step
object:set_velocity({x=0,y=0,z=0})
ent.is_magnet_item = false
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
-- set keytype to the key name if possible
@ -170,6 +264,13 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
return keys_pressed ~= key_invert
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
local function pickupfunc(player)
if not has_keys_pressed(player)
@ -178,46 +279,43 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
return
end
local pos = player:getpos()
local pos = player:get_pos()
if not is_inside_map(pos) then
-- get_objects_inside_radius crashes for too far positions
return
end
pos.y = pos.y+0.5
local inv
local inv = player:get_inventory()
local objectlist = minetest.get_objects_inside_radius(pos,
magnet_mode and magnet_radius or pickup_radius)
for i = 1,#objectlist do
local object = objectlist[i]
local ent = opt_get_ent(object)
if ent 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
if ent
and item_drop.can_pickup(ent, player) then
local item = ItemStack(ent.itemstring)
if inv:room_for_item("main", item) then
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
-- collect one item at a time to avoid the loud pop
-- The item is near enough to pick it
collect_item(ent, pos, player)
-- Collect one item at a time to avoid the loud pop
return true
end
local vel = vector.multiply(
vector.subtract(pos, pos2), 3)
-- The item is not too far a way but near enough to be
-- magnetised, make it fly to the player
local vel = vector.multiply(vector.subtract(pos, pos2), 3)
vel.y = vel.y + 0.6
object:setvelocity(vel)
if ent.physical_state then
ent.physical_state = false
ent.object:set_properties({
physical = false
})
object:set_velocity(vel)
if not ent.is_magnet_item then
ent.object:set_acceleration({x=0, y=0, z=0})
ent.is_magnet_item = true
minetest.after(magnet_time, afterflight,
object, inv, player)
@ -245,33 +343,37 @@ 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
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()
-- 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
if name == "" then
-- Sometimes nothing should be dropped
count = 0
-- 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
for _ = 1,count do
local obj = minetest.add_item(pos, name)
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))
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
@ -282,17 +384,69 @@ and not minetest.settings:get_bool("creative_mode") then
z = z+1
end
vel.z = 1 / z
obj:setvelocity(vel)
obj:set_velocity(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
local function pickup_step()
local got_item
local players = minetest.get_connected_players()
for i = 1,#players do
got_item = got_item or pickupfunc(players[i])
end
-- lower step if takeable item(s) were found
local time
if got_item then
time = 0.02
else
time = 0.2
end
minetest.after(time, pickup_step)
end
minetest.after(3.0, pickup_step)
end
local time = (minetest.get_us_time() - load_time_start) / 1000000
local msg = "[item_drop] loaded after ca. " .. time .. " seconds."
if time > 0.01 then
print(msg)
else
minetest.log("info", msg)
minetest.log("action", msg)
end

View File

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

BIN
screenshot.png Normal file

Binary file not shown.

After

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
#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
@ -33,3 +33,6 @@ item_drop.magnet_time (Magnet time) float 5.0
#Time delay in seconds after autopicking an item if it's dropped by a player
item_drop.pickup_age (Pickup age) float 0.5
#Enable manual item pickups by mouse
item_drop.mouse_pickup (Mouse pickup) bool true