mirror of
https://github.com/minetest-mods/item_drop.git
synced 2025-06-30 13:50:34 +02:00
Compare commits
93 Commits
soundpitch
...
master
Author | SHA1 | Date | |
---|---|---|---|
8bebf6324e | |||
d19d00d690 | |||
1545f82cb7 | |||
de38b20fa6 | |||
f015cc1631 | |||
72f4225058 | |||
7cb8086a25 | |||
8ef6ba3c0f | |||
682a345495 | |||
871be4048e | |||
95e89b1c94 | |||
faf6d9236d | |||
c943cf2042 | |||
666ff41136 | |||
1157ec15df | |||
765bb0a405 | |||
aef629f5b3 | |||
6637bbb813 | |||
f8b60b0b05 | |||
0aa32c1fed | |||
4c0a23855a | |||
0cee07b9d5 | |||
97158f7fac | |||
dd01ddf5ff | |||
d3687f027a | |||
62dbd6bc0d | |||
02683056e5 | |||
1d2e42eaab | |||
0112f1f9ec | |||
5f3e6e6b1b | |||
13be42cd39 | |||
e2d370a17a | |||
50b976748d | |||
1901524074 | |||
608b5dfe6e | |||
1e5718cbac | |||
c57d3c1514 | |||
cce81f6fe9 | |||
88897d9049 | |||
b6b1a8e95b | |||
08ba364510 | |||
b576e882a7 | |||
15968a0240 | |||
f1fcc478a1 | |||
3d88b7b5c6 | |||
70068fd307 | |||
2577b99556 | |||
d5b28e01b0 | |||
41e93d3bf6 | |||
124e3588e5 | |||
464fce9a87 | |||
cbd717b549 | |||
609d441ef4 | |||
3a9a985cfc | |||
b5c7fbaa38 | |||
8543bad2aa | |||
f811009c80 | |||
ac2da1689e | |||
35786b597c | |||
1e2287a672 | |||
06c1212d5b | |||
253cc75c51 | |||
88df92b125 | |||
6de1402ebc | |||
b06129c3a3 | |||
c86bc605bd | |||
c21158ffab | |||
9de8d39af6 | |||
f2e3338265 | |||
31229760e8 | |||
fced0590c6 | |||
f91c73d2e3 | |||
8c3a470690 | |||
ce059ad5ad | |||
ac3386a402 | |||
0eace77417 | |||
bfcc14bb4b | |||
04c441768f | |||
31e8c9b0cc | |||
a88fa5f1b7 | |||
ad4e83d243 | |||
07eb65bb31 | |||
c63a4ee2a3 | |||
5aed10c3e7 | |||
dbd9538a78 | |||
1091537584 | |||
a7cdd68cc9 | |||
dbb43c2ed1 | |||
67025939e7 | |||
7f38ae5261 | |||
a523b5a574 | |||
04f75caeb3 | |||
2d42301d85 |
11
.github/workflows/build.yml
vendored
Normal file
11
.github/workflows/build.yml
vendored
Normal 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
19
.luacheckrc
Normal 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",
|
||||||
|
}
|
@ -1,15 +1,14 @@
|
|||||||
# item_drop
|
# Item Drop [](https://github.com/minetest-mods/item_drop/actions) [](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),
|
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
|
|
||||||
A highly configurable mod providing item magnet and in-world node drops
|
|
||||||
|
|
||||||
## 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. Particle code from WCILA mod by Aurailus, originally licensed MIT.
|
||||||
|
|
||||||
## 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
|
||||||
|
81
init.lua
81
init.lua
@ -1,5 +1,4 @@
|
|||||||
local load_time_start = minetest.get_us_time()
|
local load_time_start = minetest.get_us_time()
|
||||||
math.randomseed(os.time())
|
|
||||||
|
|
||||||
-- Functions which can be overridden by mods
|
-- Functions which can be overridden by mods
|
||||||
item_drop = {
|
item_drop = {
|
||||||
@ -94,35 +93,46 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
|||||||
flowingliquid = 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)
|
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,
|
||||||
pitch = (100 - (math.random(-2, 2)) * 10) / 100,
|
}, 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 item.tiles and item.tiles[1] then
|
if item and item.tiles and item.tiles[1] then
|
||||||
if inventorycube_drawtypes[item.drawtype] then
|
if inventorycube_drawtypes[item.drawtype] then
|
||||||
local tiles = item.tiles
|
local tiles = item.tiles
|
||||||
|
-- color in the tile definition is handled by tile_to_image.
|
||||||
local top = tiles[1]
|
-- color in the node definition is not yet supported here.
|
||||||
if type(top) == "table" then
|
local top = tile_to_image(tiles[1])
|
||||||
top = top.name
|
local left = tile_to_image(tiles[3], top)
|
||||||
end
|
local right = tile_to_image(tiles[5], left)
|
||||||
local left = tiles[3] or top
|
|
||||||
if type(left) == "table" then
|
|
||||||
left = left.name
|
|
||||||
end
|
|
||||||
local right = tiles[5] or left
|
|
||||||
if type(right) == "table" then
|
|
||||||
right = right.name
|
|
||||||
end
|
|
||||||
|
|
||||||
image = minetest.inventorycube(top, left, right)
|
image = minetest.inventorycube(top, left, right)
|
||||||
else
|
else
|
||||||
image = item.inventory_image or item.tiles[1]
|
image = item.inventory_image or item.tiles[1]
|
||||||
@ -203,9 +213,9 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
|||||||
local itemdef = minetest.registered_entities["__builtin:item"]
|
local itemdef = minetest.registered_entities["__builtin:item"]
|
||||||
local old_on_step = itemdef.on_step
|
local old_on_step = itemdef.on_step
|
||||||
local function do_nothing() end
|
local function do_nothing() end
|
||||||
function itemdef.on_step(self, dtime)
|
function itemdef.on_step(self, ...)
|
||||||
if not self.is_magnet_item then
|
if not self.is_magnet_item then
|
||||||
return old_on_step(self, dtime)
|
return old_on_step(self, ...)
|
||||||
end
|
end
|
||||||
ObjectRef = ObjectRef or getmetatable(self.object)
|
ObjectRef = ObjectRef or getmetatable(self.object)
|
||||||
local old_funcs = {}
|
local old_funcs = {}
|
||||||
@ -214,7 +224,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
|||||||
old_funcs[method] = ObjectRef[method]
|
old_funcs[method] = ObjectRef[method]
|
||||||
ObjectRef[method] = do_nothing
|
ObjectRef[method] = do_nothing
|
||||||
end
|
end
|
||||||
old_on_step(self, dtime)
|
old_on_step(self, ...)
|
||||||
for i = 1, #blocked_methods do
|
for i = 1, #blocked_methods do
|
||||||
local method = blocked_methods[i]
|
local method = blocked_methods[i]
|
||||||
ObjectRef[method] = old_funcs[method]
|
ObjectRef[method] = old_funcs[method]
|
||||||
@ -254,6 +264,13 @@ 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)
|
||||||
@ -263,8 +280,12 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
|||||||
end
|
end
|
||||||
|
|
||||||
local pos = player:get_pos()
|
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
|
pos.y = pos.y+0.5
|
||||||
local inv
|
local inv = player:get_inventory()
|
||||||
|
|
||||||
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)
|
||||||
@ -273,14 +294,6 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
|||||||
local ent = opt_get_ent(object)
|
local ent = opt_get_ent(object)
|
||||||
if ent
|
if ent
|
||||||
and item_drop.can_pickup(ent, player) 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
|
||||||
@ -375,7 +388,13 @@ and not minetest.settings:get_bool("creative_mode") then
|
|||||||
end
|
end
|
||||||
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 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
|
for i = 1,#drops do
|
||||||
local item = drops[i]
|
local item = drops[i]
|
||||||
if type(item) == "string" then
|
if type(item) == "string" then
|
||||||
|
BIN
sounds/item_drop_pickup.2.ogg
Normal file
BIN
sounds/item_drop_pickup.2.ogg
Normal file
Binary file not shown.
BIN
sounds/item_drop_pickup.3.ogg
Normal file
BIN
sounds/item_drop_pickup.3.ogg
Normal file
Binary file not shown.
BIN
sounds/item_drop_pickup.4.ogg
Normal file
BIN
sounds/item_drop_pickup.4.ogg
Normal file
Binary file not shown.
Reference in New Issue
Block a user