hoes.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. local function create_soil(pos, inv, p)
  2. if pos == nil then
  3. return false
  4. end
  5. local node = minetest.env:get_node(pos)
  6. local name = node.name
  7. local above = minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z})
  8. if name == "default:dirt" or name == "default:dirt_with_grass" then
  9. if above.name == "air" then
  10. node.name = "farming:soil"
  11. minetest.env:set_node(pos, node)
  12. if inv and p and name == "default:dirt_with_grass" then
  13. for name,rarity in pairs(farming.seeds) do
  14. if math.random(1, rarity-p) == 1 then
  15. inv:add_item("main", ItemStack(name))
  16. end
  17. end
  18. end
  19. return true
  20. end
  21. end
  22. return false
  23. end
  24. print("kajldkalkwdhalwkjd")
  25. minetest.register_tool("farming:hoe_wood", {
  26. description = "Wood Hoe",
  27. inventory_image = "farming_hoe_wood.png",
  28. on_use = function(itemstack, user, pointed_thing)
  29. if create_soil(pointed_thing.under, user:get_inventory(), 0) then
  30. if not minetest.setting_getbool("creative_mode") then
  31. itemstack:add_wear(65535/30)
  32. end
  33. return itemstack
  34. end
  35. end
  36. })
  37. minetest.register_craft({
  38. output = "farming:hoe_wood",
  39. recipe = {
  40. {"group:wood", "group:wood"},
  41. {"", "group:wood"},
  42. {"", "group:wood"}
  43. }
  44. })
  45. minetest.register_tool("farming:hoe_stone", {
  46. description = "Stone Hoe",
  47. inventory_image = "farming_hoe_stone.png",
  48. on_use = function(itemstack, user, pointed_thing)
  49. if create_soil(pointed_thing.under, user:get_inventory(), 5) then
  50. if not minetest.setting_getbool("creative_mode") then
  51. itemstack:add_wear(65535/50)
  52. end
  53. return itemstack
  54. end
  55. end
  56. })
  57. minetest.register_craft({
  58. output = "farming:hoe_stone",
  59. recipe = {
  60. {"group:stone", "group:stone"},
  61. {"", "group:wood"},
  62. {"", "group:wood"}
  63. }
  64. })
  65. minetest.register_tool("farming:hoe_steel", {
  66. description = "Steel Hoe",
  67. inventory_image = "farming_hoe_steel.png",
  68. on_use = function(itemstack, user, pointed_thing)
  69. if create_soil(pointed_thing.under, user:get_inventory(), 10) then
  70. if not minetest.setting_getbool("creative_mode") then
  71. itemstack:add_wear(65535/80)
  72. end
  73. return itemstack
  74. end
  75. end
  76. })
  77. minetest.register_craft({
  78. output = "farming:hoe_steel",
  79. recipe = {
  80. {"default:steel_ingot", "default:steel_ingot"},
  81. {"", "group:wood"},
  82. {"", "group:wood"}
  83. }
  84. })