Gábriel
2024-07-07 6731db14e580ddccace186f5a8ac03dad0661e0c
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)
a08ba2 17         local meta = technic.get_stack_meta(itemstack)
C 18         local charge = meta:get_int("technic:charge")
19         if charge < vacuum_charge_per_object then
46f3f8 20             return
R 21         end
a08ba2 22         minetest.sound_play("vacuumcleaner", {
C 23             to_player = user:get_player_name(),
24             gain = 0.4,
25         })
d5df30 26         local pos = user:get_pos()
46f3f8 27         local inv = user:get_inventory()
4cc124 28         for _, object in ipairs(minetest.get_objects_inside_radius(pos, vacuum_range)) do
46f3f8 29             local luaentity = object:get_luaentity()
R 30             if not object:is_player() and luaentity and luaentity.name == "__builtin:item" and luaentity.itemstring ~= "" then
31                 if inv and inv:room_for_item("main", ItemStack(luaentity.itemstring)) then
a08ba2 32                     charge = charge - vacuum_charge_per_object
C 33                     if charge < vacuum_charge_per_object then
46f3f8 34                         return
R 35                     end
36                     inv:add_item("main", ItemStack(luaentity.itemstring))
37                     minetest.sound_play("item_drop_pickup", {
38                         to_player = user:get_player_name(),
39                         gain = 0.4,
40                     })
41                     luaentity.itemstring = ""
42                     object:remove()
43                 end
44             end
45         end
a8daa4 46
a08ba2 47         meta:set_int("technic:charge", charge)
C 48         technic.set_RE_wear(itemstack, charge, vacuum_max_charge)
46f3f8 49         return itemstack
R 50     end,
51 })
52
53 minetest.register_craft({
54     output = 'technic:vacuum',
55     recipe = {
56         {'pipeworks:tube_1',              'pipeworks:filter', 'technic:battery'},
44cb8d 57         {'pipeworks:tube_1',              'basic_materials:motor',    'technic:battery'},
46f3f8 58         {'technic:stainless_steel_ingot', '',                 ''},
R 59     }
60 })