6 Commits

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

View File

@ -93,13 +93,34 @@ 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)
if pickup_particle then
local item = minetest.registered_nodes[
ent.itemstring:gsub("(.*)%s.*$", "%1")]
@ -107,20 +128,11 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
if item and item.tiles and item.tiles[1] then
if inventorycube_drawtypes[item.drawtype] then
local tiles = item.tiles
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
-- 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 = item.inventory_image or item.tiles[1]
@ -378,7 +390,7 @@ and not minetest.settings:get_bool("creative_mode") then
local old_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, player)
if player.is_fake_player then
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)