mirror of
https://github.com/minetest-mods/item_drop.git
synced 2025-06-29 21:31:03 +02:00
Compare commits
86 Commits
master
...
soundpitch
Author | SHA1 | Date | |
---|---|---|---|
49fb82d4e9 | |||
5611b4d639 | |||
26d0532cbd | |||
becdfd113a | |||
934ebff45a | |||
5069afa834 | |||
70b3386322 | |||
1e9e73e978 | |||
f7d62113ff | |||
3a9a506011 | |||
427117d786 | |||
532a3cb0d0 | |||
56d2eeda5c | |||
c52ff0ea55 | |||
8e89c148be | |||
726b5f4872 | |||
8e1878d101 | |||
f6b8bcd7a7 | |||
6b7ed8e7ca | |||
fc89b2d2b4 | |||
f5187108f1 | |||
902daba7cf | |||
3c9c0e34e3 | |||
eaa44e2a36 | |||
a69bdd2275 | |||
1b0bc8461c | |||
b42a64cfa4 | |||
d51b468428 | |||
293fd77614 | |||
3e6a731cab | |||
760acbc593 | |||
d282d1ab0c | |||
8e6b386fe3 | |||
31bdc51b42 | |||
c688119069 | |||
376439b214 | |||
49b7bb19ef | |||
4c66b76937 | |||
29df36b2af | |||
2aff58ee02 | |||
92d68aa48a | |||
7afe3723e4 | |||
69f0c08561 | |||
6f8a37bd10 | |||
19ad20305f | |||
e7b8d02922 | |||
0f903cd0b0 | |||
bf9931d6db | |||
739a62a6c6 | |||
271a577881 | |||
729397b6c9 | |||
4912d3c828 | |||
057966141a | |||
78ef2a50f6 | |||
c4365cd4de | |||
bf0bb807fb | |||
22763d3b06 | |||
169d83840f | |||
da2fb1df20 | |||
3bc3a4bd25 | |||
55e89d3710 | |||
4b5e362395 | |||
bc5ef09e21 | |||
bab3c733fa | |||
69a68cb247 | |||
b56c1792de | |||
544381bbfe | |||
9f54694931 | |||
fb2c076b92 | |||
46959e79d2 | |||
e84433d41c | |||
884824989f | |||
962d0a3889 | |||
81d32527f3 | |||
8a14503372 | |||
a7b7c71d50 | |||
5a6f79a5d2 | |||
363b56fc03 | |||
189fea5eff | |||
1f9ceb3eb3 | |||
6befa68ef8 | |||
d336a226cd | |||
16210c79f7 | |||
2c60ac7ab0 | |||
a666252f1c | |||
d9581ec795 |
11
.github/workflows/build.yml
vendored
11
.github/workflows/build.yml
vendored
@ -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
|
19
.luacheckrc
19
.luacheckrc
@ -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",
|
||||
}
|
@ -1,14 +1,15 @@
|
||||
# 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\
|
||||
# item_drop
|
||||
By [PilzAdam](https://github.com/PilzAdam),
|
||||
[texmex](https://github.com/tacotexmex/), [hybriddog](https://github.com/hybriddog/).
|
||||
|
||||
## Description
|
||||
A highly configurable mod providing item magnet and in-world node drops
|
||||
|
||||
## Licensing
|
||||
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
|
||||
|
81
init.lua
81
init.lua
@ -1,4 +1,5 @@
|
||||
local load_time_start = minetest.get_us_time()
|
||||
math.randomseed(os.time())
|
||||
|
||||
-- Functions which can be overridden by mods
|
||||
item_drop = {
|
||||
@ -93,46 +94,35 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
||||
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)
|
||||
pitch = (100 - (math.random(-2, 2)) * 10) / 100,
|
||||
})
|
||||
if pickup_particle then
|
||||
local item = minetest.registered_nodes[
|
||||
ent.itemstring:gsub("(.*)%s.*$", "%1")]
|
||||
local image
|
||||
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)
|
||||
|
||||
local top = tiles[1]
|
||||
if type(top) == "table" then
|
||||
top = top.name
|
||||
end
|
||||
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)
|
||||
else
|
||||
image = item.inventory_image or item.tiles[1]
|
||||
@ -213,9 +203,9 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
||||
local itemdef = minetest.registered_entities["__builtin:item"]
|
||||
local old_on_step = itemdef.on_step
|
||||
local function do_nothing() end
|
||||
function itemdef.on_step(self, ...)
|
||||
function itemdef.on_step(self, dtime)
|
||||
if not self.is_magnet_item then
|
||||
return old_on_step(self, ...)
|
||||
return old_on_step(self, dtime)
|
||||
end
|
||||
ObjectRef = ObjectRef or getmetatable(self.object)
|
||||
local old_funcs = {}
|
||||
@ -224,7 +214,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
||||
old_funcs[method] = ObjectRef[method]
|
||||
ObjectRef[method] = do_nothing
|
||||
end
|
||||
old_on_step(self, ...)
|
||||
old_on_step(self, dtime)
|
||||
for i = 1, #blocked_methods do
|
||||
local method = blocked_methods[i]
|
||||
ObjectRef[method] = old_funcs[method]
|
||||
@ -264,13 +254,6 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
||||
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)
|
||||
@ -280,12 +263,8 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
||||
end
|
||||
|
||||
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 = player:get_inventory()
|
||||
local inv
|
||||
|
||||
local objectlist = minetest.get_objects_inside_radius(pos,
|
||||
magnet_mode and magnet_radius or pickup_radius)
|
||||
@ -294,6 +273,14 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
||||
local ent = opt_get_ent(object)
|
||||
if ent
|
||||
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)
|
||||
if inv:room_for_item("main", item) then
|
||||
local flying_item
|
||||
@ -388,13 +375,7 @@ and not minetest.settings:get_bool("creative_mode") then
|
||||
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
|
||||
function minetest.handle_node_drops(pos, drops)
|
||||
for i = 1,#drops do
|
||||
local item = drops[i]
|
||||
if type(item) == "string" then
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user