saw.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. local S = minetest.get_translator("wood_and_saws")
  2. crafting.register_recipe(
  3. {
  4. output = "saw",
  5. type = "inv",
  6. items = {"cobble 4", "iron_ingot"},
  7. always_known = true,
  8. })
  9. local function saw(itemstack)
  10. local def = itemstack:get_definition()
  11. if def and def._sawing_result
  12. then
  13. itemstack:take_item()
  14. minetest.sound_play("wood_and_saws_saw",
  15. {
  16. gain = 0.3,
  17. pos = pos,
  18. pitch = 1 + ((math.random() - 0.5) / 8)
  19. })
  20. return ItemStack(def._sawing_result)
  21. else
  22. return ItemStack(nil)
  23. end
  24. end
  25. local function saw_rightclick(pos, node, clicker, itemstack)
  26. local result = saw(itemstack)
  27. local inv = clicker:get_inventory()
  28. local ret = inv:add_item("main", result)
  29. return itemstack
  30. end
  31. local function set_infotext(pos)
  32. local meta = minetest.get_meta(pos)
  33. meta:set_string("infotext", S("Saw\n@1", S("Use with logs or planks to saw")))
  34. end
  35. minetest.register_node("wood_and_saws:saw",
  36. {
  37. description = S("Saw@n@1",
  38. minetest.colorize("#90FFFF", S("Cuts logs to planks and planks to sticks"))),
  39. drawtype = "mesh",
  40. mesh = "wood_and_saws_saw.obj",
  41. on_rightclick = saw_rightclick,
  42. tiles =
  43. {
  44. {
  45. name = "wood_and_saws_saw_blade.png",
  46. animation =
  47. {
  48. type = "vertical_frames",
  49. aspect_w = 16,
  50. aspect_h = 16,
  51. length = 0.5,
  52. },
  53. },
  54. "wood_and_saws_saw_base.png"
  55. },
  56. groups = {cracky = 3,},
  57. sounds = generic_media.node_sound_metal_defaults(),
  58. sunlight_propagates = true,
  59. inventory_image = "wood_and_saws_saw_inventory.png",
  60. wield_image = "wood_and_saws_saw_inventory.png",
  61. is_ground_content = false,
  62. paramtype2 = "facedir",
  63. collision_box =
  64. {
  65. type = "fixed",
  66. fixed = {
  67. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  68. },
  69. },
  70. selection_box =
  71. {
  72. type = "fixed",
  73. fixed = {
  74. {-0.5, 0, 0, 0.5, 0.5, 0},
  75. {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
  76. },
  77. },
  78. damage_per_second = 5,
  79. on_construct = set_infotext,
  80. stack_max = 1,
  81. })
  82. minetest.register_alias("saw", "wood_and_saws:saw")
  83. --https://freesound.org/people/180007/sounds/445526/