realtest/mods/instruments/buckets.lua

81 lines
2.3 KiB
Lua
Raw Normal View History

buckets = {}
buckets.liquids = {}
2012-10-15 16:38:08 +06:00
function buckets.register_liquid(name, source, flowing, itemname, inventory_image)
2012-10-15 16:38:08 +06:00
buckets.liquids[source] = {
name = name,
2012-10-15 16:38:08 +06:00
source = source,
flowing = flowing,
itemname = itemname,
}
buckets.liquids[flowing] = buckets.liquids[source]
2012-10-15 16:38:08 +06:00
if itemname ~= nil then
for i = 1,#metals.list do
minetest.register_craftitem(itemname.."_"..metals.list[i], {
description = metals.desc_list[i] .. " Bucket with " .. name,
inventory_image = "instruments_bucket_"..metals.list[i]..".png^"..inventory_image,
2012-10-15 16:38:08 +06:00
stack_max = 1,
liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to node
if pointed_thing.type ~= "node" then
return
end
n = minetest.env:get_node(pointed_thing.under)
if minetest.registered_nodes[n.name].buildable_to then
minetest.env:add_node(pointed_thing.under, {name=source})
else
n = minetest.env:get_node(pointed_thing.above)
if minetest.registered_nodes[n.name].buildable_to then
2012-10-15 16:38:08 +06:00
minetest.env:add_node(pointed_thing.above, {name=source})
else
return
end
2012-10-15 16:38:08 +06:00
end
return {name="instruments:bucket_empty_"..metals.list[i]}
2012-10-15 16:38:08 +06:00
end
})
end
end
end
for i = 1,#metals.list do
minetest.register_craftitem("instruments:bucket_empty_"..metals.list[i], {
2012-11-02 23:10:51 +06:00
description = "Empty " .. metals.desc_list[i] .. " Bucket",
inventory_image = "instruments_bucket_"..metals.list[i]..".png",
2012-10-15 16:38:08 +06:00
stack_max = 1,
liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to node
if pointed_thing.type ~= "node" then
return
end
-- Check if pointing to a liquid source
n = minetest.env:get_node(pointed_thing.under)
liquiddef = buckets.liquids[n.name]
2012-10-15 16:38:08 +06:00
if liquiddef ~= nil and liquiddef.source == n.name and liquiddef.itemname ~= nil then
minetest.env:add_node(pointed_thing.under, {name="air"})
return {name=liquiddef.itemname.."_"..metals.list[i]}
2012-10-15 16:38:08 +06:00
end
end,
})
end
buckets.register_liquid(
"Water",
2012-10-15 16:38:08 +06:00
"default:water_source",
"default:water_flowing",
"instruments:bucket_water",
"instruments_water.png"
2012-10-15 16:38:08 +06:00
)
buckets.register_liquid(
"Lava",
2012-10-15 16:38:08 +06:00
"default:lava_source",
"default:lava_flowing",
"instruments:bucket_lava",
"instruments_lava.png"
2012-10-15 16:38:08 +06:00
)