aboutsummaryrefslogtreecommitdiff
path: root/data/mods/bucket
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2012-01-12 06:10:39 +0100
committerKahrl <kahrl@gmx.net>2012-01-12 06:10:39 +0100
commit6a76c226e10e92c3e3339096f07f8ab065e2098b (patch)
tree396d9083f5f76ebb5ba96df113ba68046c2487df /data/mods/bucket
parent569156b01302ea4ba45d11ff5524b62dbc6a9aa0 (diff)
downloadminetest-6a76c226e10e92c3e3339096f07f8ab065e2098b.tar.gz
minetest-6a76c226e10e92c3e3339096f07f8ab065e2098b.tar.bz2
minetest-6a76c226e10e92c3e3339096f07f8ab065e2098b.zip
The huge item definition and item namespace unification patch (itemdef), see http://c55.me/minetest/wiki/doku.php?id=changes:itemdef
Diffstat (limited to 'data/mods/bucket')
-rw-r--r--data/mods/bucket/init.lua139
1 files changed, 77 insertions, 62 deletions
diff --git a/data/mods/bucket/init.lua b/data/mods/bucket/init.lua
index 639a614d4..8ed9da522 100644
--- a/data/mods/bucket/init.lua
+++ b/data/mods/bucket/init.lua
@@ -1,80 +1,95 @@
-- bucket (Minetest 0.4 mod)
-- A bucket, which can pick up water and lava
-minetest.alias_craftitem("bucket", "bucket:bucket_empty")
-minetest.alias_craftitem("bucket_water", "bucket:bucket_water")
-minetest.alias_craftitem("bucket_lava", "bucket:bucket_lava")
+minetest.register_alias("bucket", "bucket:bucket_empty")
+minetest.register_alias("bucket_water", "bucket:bucket_water")
+minetest.register_alias("bucket_lava", "bucket:bucket_lava")
minetest.register_craft({
- output = 'craft "bucket:bucket_empty" 1',
+ output = 'bucket:bucket_empty 1',
recipe = {
- {'craft "steel_ingot"', '', 'craft "steel_ingot"'},
- {'', 'craft "steel_ingot"', ''},
+ {'default:steel_ingot', '', 'default:steel_ingot'},
+ {'', 'default:steel_ingot', ''},
}
})
-minetest.register_craftitem("bucket:bucket_empty", {
- image = "bucket.png",
- stack_max = 1,
- liquids_pointable = true,
- on_place_on_ground = minetest.craftitem_place_item,
- on_use = function(item, player, pointed_thing)
- if pointed_thing.type == "node" then
- n = minetest.env:get_node(pointed_thing.under)
- if n.name == "default:water_source" then
- minetest.env:add_node(pointed_thing.under, {name="air"})
- player:add_to_inventory_later('craft "bucket:bucket_water" 1')
- return true
- elseif n.name == "default:lava_source" then
- minetest.env:add_node(pointed_thing.under, {name="air"})
- player:add_to_inventory_later('craft "bucket:bucket_lava" 1')
- return true
+bucket = {}
+bucket.liquids = {}
+
+-- Register a new liquid
+-- source = name of the source node
+-- flowing = name of the flowing node
+-- itemname = name of the new bucket item (or nil if liquid is not takeable)
+-- inventory_image = texture of the new bucket item (ignored if itemname == nil)
+-- This function can be called from any mod (that depends on bucket).
+function bucket.register_liquid(source, flowing, itemname, inventory_image)
+ bucket.liquids[source] = {
+ source = source,
+ flowing = flowing,
+ itemname = itemname,
+ }
+ bucket.liquids[flowing] = bucket.liquids[source]
+
+ if itemname ~= nil then
+ minetest.register_craftitem(itemname, {
+ inventory_image = inventory_image,
+ 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
+ n = minetest.env:get_node(pointed_thing.under)
+ if bucket.liquids[n.name] == nil then
+ -- Not a liquid
+ minetest.env:add_node(pointed_thing.above, {name=source})
+ elseif n.name ~= source then
+ -- It's a liquid
+ minetest.env:add_node(pointed_thing.under, {name=source})
+ end
+ return {name="bucket:bucket_empty"}
end
- end
- return false
- end,
-})
+ })
+ end
+end
-minetest.register_craftitem("bucket:bucket_water", {
- image = "bucket_water.png",
+minetest.register_craftitem("bucket:bucket_empty", {
+ inventory_image = "bucket.png",
stack_max = 1,
liquids_pointable = true,
- on_place_on_ground = minetest.craftitem_place_item,
- on_use = function(item, player, pointed_thing)
- if pointed_thing.type == "node" then
- n = minetest.env:get_node(pointed_thing.under)
- if n.name == "default:water_source" then
- -- unchanged
- elseif n.name == "default:water_flowing" or n.name == "default:lava_source" or n.name == "default:lava_flowing" then
- minetest.env:add_node(pointed_thing.under, {name="default:water_source"})
- else
- minetest.env:add_node(pointed_thing.above, {name="default:water_source"})
- end
- player:add_to_inventory_later('craft "bucket:bucket_empty" 1')
- return 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 = bucket.liquids[n.name]
+ 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}
end
- return false
end,
})
-minetest.register_craftitem("bucket:bucket_lava", {
- image = "bucket_lava.png",
- stack_max = 1,
- liquids_pointable = true,
- on_place_on_ground = minetest.craftitem_place_item,
- on_use = function(item, player, pointed_thing)
- if pointed_thing.type == "node" then
- n = minetest.env:get_node(pointed_thing.under)
- if n.name == "default:lava_source" then
- -- unchanged
- elseif n.name == "default:water_source" or n.name == "default:water_flowing" or n.name == "default:lava_flowing" then
- minetest.env:add_node(pointed_thing.under, {name="default:lava_source"})
- else
- minetest.env:add_node(pointed_thing.above, {name="default:lava_source"})
- end
- player:add_to_inventory_later('craft "bucket:bucket_empty" 1')
- return true
- end
- return false
- end,
+bucket.register_liquid(
+ "default:water_source",
+ "default:water_flowing",
+ "bucket:bucket_water",
+ "bucket_water.png"
+)
+
+bucket.register_liquid(
+ "default:lava_source",
+ "default:lava_flowing",
+ "bucket:bucket_lava",
+ "bucket_lava.png"
+)
+
+minetest.register_craft({
+ type = "fuel",
+ recipe = "default:bucket_lava",
+ burntime = 60,
})