forked from minetest-mods/item_drop
Compare commits
3 Commits
nalc-1.2.0
...
master
Author | SHA1 | Date | |
---|---|---|---|
8bebf6324e | |||
d19d00d690 | |||
1545f82cb7 |
64
init.lua
64
init.lua
@ -93,13 +93,34 @@ 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,
|
||||||
})
|
}, 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")]
|
||||||
@ -107,20 +128,11 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
|
|||||||
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]
|
||||||
@ -378,7 +390,7 @@ and not minetest.settings:get_bool("creative_mode") then
|
|||||||
|
|
||||||
local old_handle_node_drops = minetest.handle_node_drops
|
local old_handle_node_drops = minetest.handle_node_drops
|
||||||
function minetest.handle_node_drops(pos, drops, player)
|
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
|
-- Node Breaker or similar machines should receive items in the
|
||||||
-- inventory
|
-- inventory
|
||||||
return old_handle_node_drops(pos, drops, player)
|
return old_handle_node_drops(pos, drops, player)
|
||||||
@ -412,29 +424,13 @@ and not minetest.settings:get_bool("creative_mode") then
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
local time = (minetest.get_us_time() - load_time_start) / 1000000
|
local time = (minetest.get_us_time() - load_time_start) / 1000000
|
||||||
local msg = "[item_drop] loaded after ca. " .. time .. " seconds."
|
local msg = "[item_drop] loaded after ca. " .. time .. " seconds."
|
||||||
if time > 0.01 then
|
if time > 0.01 then
|
||||||
print(msg)
|
print(msg)
|
||||||
else
|
else
|
||||||
minetest.log("action", msg)
|
minetest.log("info", msg)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user