Advertisement
Guest User

wood bucket

a guest
Oct 16th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. bucket = {}
  2. bucket.liquids = {}
  3.  
  4. minetest.register_craft({
  5.     output = 'alternative:wood_bucket 1',
  6.     recipe = {
  7.         {'default:wood', '', 'default:wood'},
  8.         {'', 'default:wood', ''},
  9.     }
  10. })
  11.  
  12. function bucket.register_liquid(source, flowing, itemname, inventory_image)
  13.     bucket.liquids[source] = {
  14.         source = source,
  15.         flowing = flowing,
  16.         itemname = itemname,
  17.     }
  18.     bucket.liquids[flowing] = bucket.liquids[source]
  19.  
  20.     if itemname ~= nil then
  21.         minetest.register_craftitem(itemname, {
  22.             inventory_image = inventory_image,
  23.             stack_max = 1,
  24.             liquids_pointable = true,
  25.             on_use = function(itemstack, user, pointed_thing)
  26.                 -- Must be pointing to node
  27.                 if pointed_thing.type ~= "node" then
  28.                     return
  29.                 end
  30.                 -- Check if pointing to a liquid
  31.                 n = minetest.env:get_node(pointed_thing.under)
  32.                 if bucket.liquids[n.name] == nil then
  33.                     -- Not a liquid
  34.                     minetest.env:add_node(pointed_thing.above, {name=water_source})
  35.                 elseif n.name ~= source then
  36.                     -- It's a liquid
  37.                     minetest.env:add_node(pointed_thing.under, {name=water_source})
  38.                 end
  39.                 return {name="alternative:wood_bucket"}
  40.             end
  41.         })
  42.     end
  43. end
  44.  
  45. minetest.register_craftitem("alternative:wood_bucket", {
  46.     description = "Wood bucket",
  47.     inventory_image = "alternative_wood_bucket.png",
  48.     stack_max = 1,
  49.     liquids_pointable = true,
  50.     on_use = function(itemstack, user, pointed_thing)
  51.         -- Must be pointing to node
  52.         if pointed_thing.type ~= "node" then
  53.             return
  54.         end
  55.         -- Check if pointing to a liquid source
  56.         n = minetest.env:get_node(pointed_thing.under)
  57.         liquiddef = bucket.liquids[n.name]
  58.         if liquiddef ~= nil and liquiddef.source == n.name and liquiddef.itemname ~= nil then
  59.             minetest.env:add_node(pointed_thing.under, {name="air"})
  60.             return {name=liquiddef.itemname}
  61.         end
  62.     end,
  63. })
  64.  
  65. bucket.register_liquid(
  66.     "default:water_source",
  67.     "default:water_flowing",
  68.     "alternative:wood_bucket_water",
  69.     "alternative_wood_bucket_water.png"
  70. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement