Vanessa Dannenberg
2018-10-31 44cb8df048e09b64214f59db73a3fd23cfe12e77
commit | author | age
46f3f8 1 -- Configuration
R 2 local vacuum_max_charge        = 10000 -- 10000 - Maximum charge of the vacuum cleaner
3 local vacuum_charge_per_object = 100   -- 100   - Capable of picking up 50 objects
4 local vacuum_range             = 8     -- 8     - Area in which to pick up objects
5
6 local S = technic.getter
7
8 technic.register_power_tool("technic:vacuum", vacuum_max_charge)
9
10 minetest.register_tool("technic:vacuum", {
11     description = S("Vacuum Cleaner"),
12     inventory_image = "technic_vacuum.png",
13     stack_max = 1,
14     wear_represents = "technic_RE_charge",
15     on_refill = technic.refill_RE_charge,
16     on_use = function(itemstack, user, pointed_thing)
17         local meta = minetest.deserialize(itemstack:get_metadata())
18         if not meta or not meta.charge then
19             return
20         end
21         if meta.charge > vacuum_charge_per_object then
22             minetest.sound_play("vacuumcleaner", {
23                 to_player = user:get_player_name(),
24                 gain = 0.4,
25             })
26         end
27         local pos = user:getpos()
28         local inv = user:get_inventory()
4cc124 29         for _, object in ipairs(minetest.get_objects_inside_radius(pos, vacuum_range)) do
46f3f8 30             local luaentity = object:get_luaentity()
R 31             if not object:is_player() and luaentity and luaentity.name == "__builtin:item" and luaentity.itemstring ~= "" then
32                 if inv and inv:room_for_item("main", ItemStack(luaentity.itemstring)) then
33                     meta.charge = meta.charge - vacuum_charge_per_object
34                     if meta.charge < vacuum_charge_per_object then
35                         return
36                     end
37                     inv:add_item("main", ItemStack(luaentity.itemstring))
38                     minetest.sound_play("item_drop_pickup", {
39                         to_player = user:get_player_name(),
40                         gain = 0.4,
41                     })
42                     luaentity.itemstring = ""
43                     object:remove()
44                 end
45             end
46         end
47         
48         technic.set_RE_wear(itemstack, meta.charge, vacuum_max_charge)
49         itemstack:set_metadata(minetest.serialize(meta))
50         return itemstack
51     end,
52 })
53
54 minetest.register_craft({
55     output = 'technic:vacuum',
56     recipe = {
57         {'pipeworks:tube_1',              'pipeworks:filter', 'technic:battery'},
44cb8d 58         {'pipeworks:tube_1',              'basic_materials:motor',    'technic:battery'},
46f3f8 59         {'technic:stainless_steel_ingot', '',                 ''},
R 60     }
61 })