Zefram
2014-05-16 68b7bcc28e39bdf0926072b834eeeeec0ee6c721
commit | author | age
ee5c6c 1 local water_can_max_load = 16
K 2 local lava_can_max_load = 8
82cba9 3
be2f30 4 local S = technic.getter
S 5
82cba9 6 minetest.register_craft({
R 7     output = 'technic:water_can 1',
8     recipe = {
9         {'technic:zinc_ingot', 'technic:rubber','technic:zinc_ingot'},
68b7bc 10         {'technic:carbon_steel_ingot', '', 'technic:carbon_steel_ingot'},
Z 11         {'technic:zinc_ingot', 'technic:carbon_steel_ingot', 'technic:zinc_ingot'},
82cba9 12     }
R 13 })
14
15 minetest.register_craft({
16     output = 'technic:lava_can 1',
17     recipe = {
18         {'technic:zinc_ingot', 'technic:stainless_steel_ingot','technic:zinc_ingot'},
19         {'technic:stainless_steel_ingot', '', 'technic:stainless_steel_ingot'},
20         {'technic:zinc_ingot', 'technic:stainless_steel_ingot', 'technic:zinc_ingot'},
21     }
22 })
23
03a537 24 local function set_can_wear(itemstack, level, max_level)
Z 25     local temp
26     if level == 0 then
27         temp = 0
28     else
29         temp = 65536 - math.floor(level / max_level * 65535)
30         if temp > 65535 then temp = 65535 end
31         if temp < 1 then temp = 1 end
32     end
33     itemstack:set_wear(temp)
34 end
82cba9 35
R 36 minetest.register_tool("technic:water_can", {
be2f30 37     description = S("Water Can"),
82cba9 38     inventory_image = "technic_water_can.png",
R 39     stack_max = 1,
99fd5d 40     wear_represents = "content_level",
82cba9 41     liquids_pointable = true,
R 42     on_use = function(itemstack, user, pointed_thing)
43         if pointed_thing.type ~= "node" then
eac484 44             return
82cba9 45         end
eac484 46         node = minetest.get_node(pointed_thing.under)
82cba9 47
eac484 48         local charge = nil
S 49         if itemstack:get_metadata() == "" then
50             charge = 0
51         else
52             charge = tonumber(itemstack:get_metadata())
53         end
54         if node.name == "default:water_source" then
ef70cb 55             if charge < water_can_max_load then
eac484 56                 minetest.remove_node(pointed_thing.under)
S 57                 charge = charge + 1
58                 itemstack:set_metadata(tostring(charge))
03a537 59                 set_can_wear(itemstack, charge, water_can_max_load)
eac484 60             end
82cba9 61             return itemstack
eac484 62         end
S 63         if charge == 0 then
64             return
65         end
66
67         if node.name == "default:water_flowing" then
68             minetest.set_node(pointed_thing.under, {name="default:water_source"})
69             charge = charge - 1
70             itemstack:set_metadata(tostring(charge))
03a537 71             set_can_wear(itemstack, charge, water_can_max_load)
eac484 72             return itemstack
S 73         end
74
75         node = minetest.get_node(pointed_thing.above)
76         if node.name == "air" then
77             minetest.set_node(pointed_thing.above, {name="default:water_source"})
78             charge = charge - 1;
79             itemstack:set_metadata(tostring(charge))
03a537 80             set_can_wear(itemstack, charge, water_can_max_load)
eac484 81             return itemstack
S 82         end        
82cba9 83     end,
00d7c9 84     on_refill = function(stack)
Z 85         stack:set_metadata(tostring(water_can_max_load))
86         set_can_wear(stack, water_can_max_load, water_can_max_load)
87         return stack
88     end,
82cba9 89 })
R 90
91 minetest.register_tool("technic:lava_can", {
be2f30 92     description = S("Lava Can"),
82cba9 93     inventory_image = "technic_lava_can.png",
R 94     stack_max = 1,
99fd5d 95     wear_represents = "content_level",
82cba9 96     liquids_pointable = true,
R 97     on_use = function(itemstack, user, pointed_thing)
eac484 98         if pointed_thing.type ~= "node" then
S 99             return
82cba9 100         end
eac484 101         node = minetest.get_node(pointed_thing.under)
S 102         local charge = 0
103         if itemstack:get_metadata() == "" then
104             charge = 0
105         else
106             charge = tonumber(itemstack:get_metadata())
82cba9 107         end
R 108
eac484 109         if node.name == "default:lava_source" then
ef70cb 110             if charge < lava_can_max_load then
eac484 111                 minetest.remove_node(pointed_thing.under)
S 112                 charge = charge + 1
113                 itemstack:set_metadata(tostring(charge))
03a537 114                 set_can_wear(itemstack, charge, lava_can_max_load)
eac484 115             end
82cba9 116             return itemstack
eac484 117         end
S 118         if charge == 0 then
119             return
120         end
121
122         if node.name == "default:lava_flowing" then
123             minetest.set_node(pointed_thing.under, {name="default:lava_source"})
124             charge = charge - 1    
125             itemstack:set_metadata(tostring(charge))
03a537 126             set_can_wear(itemstack, charge, lava_can_max_load)
eac484 127             return itemstack
S 128         end
129
130         node = minetest.get_node(pointed_thing.above)
131         if node.name == "air" then
132             minetest.set_node(pointed_thing.above, {name="default:lava_source"})
133             charge = charge - 1
134             itemstack:set_metadata(tostring(charge))
03a537 135             set_can_wear(itemstack, charge, lava_can_max_load)
eac484 136             return itemstack
S 137         end
82cba9 138     end,
00d7c9 139     on_refill = function(stack)
Z 140         stack:set_metadata(tostring(lava_can_max_load))
141         set_can_wear(stack, lava_can_max_load, lava_can_max_load)
142         return stack
143     end,
82cba9 144 })
be2f30 145