forked from minetest-mods/technic
Add vacuum cleaner tool (by Phvli)
This commit is contained in:
parent
e16a39b385
commit
46f3f8ec7d
BIN
technic/sounds/vacuumcleaner.ogg
Normal file
BIN
technic/sounds/vacuumcleaner.ogg
Normal file
Binary file not shown.
BIN
technic/textures/technic_vacuum.png
Normal file
BIN
technic/textures/technic_vacuum.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 705 B |
@ -14,6 +14,7 @@ dofile(path.."/chainsaw.lua")
|
||||
dofile(path.."/tree_tap.lua")
|
||||
dofile(path.."/sonic_screwdriver.lua")
|
||||
dofile(path.."/prospector.lua")
|
||||
dofile(path.."/vacuum.lua")
|
||||
|
||||
if minetest.get_modpath("screwdriver") then
|
||||
-- compatibility alias
|
||||
|
61
technic/tools/vacuum.lua
Normal file
61
technic/tools/vacuum.lua
Normal file
@ -0,0 +1,61 @@
|
||||
-- Configuration
|
||||
local vacuum_max_charge = 10000 -- 10000 - Maximum charge of the vacuum cleaner
|
||||
local vacuum_charge_per_object = 100 -- 100 - Capable of picking up 50 objects
|
||||
local vacuum_range = 8 -- 8 - Area in which to pick up objects
|
||||
|
||||
local S = technic.getter
|
||||
|
||||
technic.register_power_tool("technic:vacuum", vacuum_max_charge)
|
||||
|
||||
minetest.register_tool("technic:vacuum", {
|
||||
description = S("Vacuum Cleaner"),
|
||||
inventory_image = "technic_vacuum.png",
|
||||
stack_max = 1,
|
||||
wear_represents = "technic_RE_charge",
|
||||
on_refill = technic.refill_RE_charge,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge > vacuum_charge_per_object then
|
||||
minetest.sound_play("vacuumcleaner", {
|
||||
to_player = user:get_player_name(),
|
||||
gain = 0.4,
|
||||
})
|
||||
end
|
||||
local pos = user:getpos()
|
||||
local inv = user:get_inventory()
|
||||
for _, object in ipairs(minetest.env:get_objects_inside_radius(pos, vacuum_range)) do
|
||||
local luaentity = object:get_luaentity()
|
||||
if not object:is_player() and luaentity and luaentity.name == "__builtin:item" and luaentity.itemstring ~= "" then
|
||||
if inv and inv:room_for_item("main", ItemStack(luaentity.itemstring)) then
|
||||
meta.charge = meta.charge - vacuum_charge_per_object
|
||||
if meta.charge < vacuum_charge_per_object then
|
||||
return
|
||||
end
|
||||
inv:add_item("main", ItemStack(luaentity.itemstring))
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
to_player = user:get_player_name(),
|
||||
gain = 0.4,
|
||||
})
|
||||
luaentity.itemstring = ""
|
||||
object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
technic.set_RE_wear(itemstack, meta.charge, vacuum_max_charge)
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic:vacuum',
|
||||
recipe = {
|
||||
{'pipeworks:tube_1', 'pipeworks:filter', 'technic:battery'},
|
||||
{'pipeworks:tube_1', 'technic:motor', 'technic:battery'},
|
||||
{'technic:stainless_steel_ingot', '', ''},
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user