chisel.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. local USES = 200
  2. local mode = {}
  3. local function parti(pos)
  4. minetest.add_particlespawner(25, 0.3,
  5. pos, pos,
  6. {x=2, y=0.2, z=2}, {x=-2, y=2, z=-2},
  7. {x=0, y=-6, z=0}, {x=0, y=-10, z=0},
  8. 0.2, 1,
  9. 0.2, 2,
  10. true, "mychisel_parti.png")
  11. end
  12. mode = "1"
  13. minetest.register_tool( "mychisel:chisel",{
  14. description = "Chisel",
  15. inventory_image = "mychisel_chisel.png",
  16. wield_image = "mychisel_chisel.png",
  17. on_use = function(itemstack, user, pointed_thing)
  18. if pointed_thing.type ~= "node" then
  19. return
  20. end
  21. local pos = pointed_thing.under
  22. local node = minetest.get_node(pos)
  23. local default_material = {
  24. {"default:cobble", "default_cobble", "Cobble"},
  25. {"default:sandstone","default_sandstone", "Sandstone"},
  26. {"default:clay","default_clay", "Clay"},
  27. {"default:coalblock","default_coal_block", "Coal Block"},
  28. {"default:stone","default_stone", "Stone"},
  29. {"default:desert_stone","default_desert_stone", "Desert Stone"},
  30. {"default:wood","default_wood", "Wood"},
  31. {"default:acacia_wood","default_acacia_wood", "Acacia Wood"},
  32. {"default:aspen_wood","default_aspen_wood", "Aspen Wood"},
  33. {"default:pine_wood","default_pine_wood", "Pine Wood"},
  34. {"default:desert_cobble","default_desert_cobble", "Desert Cobble"},
  35. {"default:junglewood","default_junglewood", "Jungle Wood"},
  36. {"default:sandstonebrick","default_sandstone_brick", "Sandstone Brick"},
  37. {"default:stonebrick","default_stone_brick", "Stone Brick"},
  38. {"default:desert_stonebrick","default_desert_stone_brick", "Desert Stone Brick"},
  39. }
  40. for i in ipairs (default_material) do
  41. local item = default_material [i][1]
  42. local mat = default_material [i][2]
  43. local desc = default_material [i][3]
  44. if pointed_thing.type ~= "node" then
  45. return
  46. end
  47. if minetest.is_protected(pos, user:get_player_name()) then
  48. minetest.record_protection_violation(pos, user:get_player_name())
  49. return
  50. end
  51. if mode == "1" then
  52. if node.name == item then
  53. minetest.set_node(pos,{name = "mychisel:chiseled_"..mat.."1", param2=minetest.dir_to_facedir(user:get_look_dir())})
  54. parti(pos)
  55. end
  56. if node.name == "mychisel:chiseled_"..mat.."1" then
  57. minetest.set_node(pos,{name = "mychisel:chiseled_"..mat.."2", param2=minetest.dir_to_facedir(user:get_look_dir())})
  58. parti(pos)
  59. end
  60. if node.name == "mychisel:chiseled_"..mat.."2" then
  61. minetest.set_node(pos,{name = "mychisel:chiseled_"..mat.."3", param2=minetest.dir_to_facedir(user:get_look_dir())})
  62. parti(pos)
  63. end
  64. if node.name == "mychisel:chiseled_"..mat.."3" then
  65. minetest.set_node(pos,{name = "mychisel:chiseled_"..mat.."4", param2=minetest.dir_to_facedir(user:get_look_dir())})
  66. parti(pos)
  67. end
  68. end
  69. if mode == "2" then
  70. if node.name == item then
  71. minetest.set_node(pos,{name = "mychisel:horizontal_"..mat.."1", param2=minetest.dir_to_facedir(user:get_look_dir())})
  72. parti(pos)
  73. end
  74. if node.name == "mychisel:horizontal_"..mat.."1" then
  75. minetest.set_node(pos,{name = "mychisel:horizontal_"..mat.."2", param2=minetest.dir_to_facedir(user:get_look_dir())})
  76. parti(pos)
  77. end
  78. if node.name == "mychisel:horizontal_"..mat.."2" then
  79. minetest.set_node(pos,{name = "mychisel:horizontal_"..mat.."3", param2=minetest.dir_to_facedir(user:get_look_dir())})
  80. parti(pos)
  81. end
  82. if node.name == "mychisel:horizontal_"..mat.."3" then
  83. minetest.set_node(pos,{name = "mychisel:horizontal_"..mat.."4", param2=minetest.dir_to_facedir(user:get_look_dir())})
  84. parti(pos)
  85. end
  86. end
  87. if mode == "3" then
  88. if node.name == item then
  89. minetest.set_node(pos,{name = "mychisel:vertical_"..mat.."1", param2=minetest.dir_to_facedir(user:get_look_dir())})
  90. parti(pos)
  91. end
  92. if node.name == "mychisel:vertical_"..mat.."1" then
  93. minetest.set_node(pos,{name = "mychisel:vertical_"..mat.."2", param2=minetest.dir_to_facedir(user:get_look_dir())})
  94. parti(pos)
  95. end
  96. if node.name == "mychisel:vertical_"..mat.."2" then
  97. minetest.set_node(pos,{name = "mychisel:vertical_"..mat.."3", param2=minetest.dir_to_facedir(user:get_look_dir())})
  98. parti(pos)
  99. end
  100. if node.name == "mychisel:vertical_"..mat.."3" then
  101. minetest.set_node(pos,{name = "mychisel:vertical_"..mat.."4", param2=minetest.dir_to_facedir(user:get_look_dir())})
  102. parti(pos)
  103. end
  104. end
  105. if mode == "4" then
  106. if node.name == item then
  107. minetest.set_node(pos,{name = "mychisel:cross_"..mat.."1", param2=minetest.dir_to_facedir(user:get_look_dir())})
  108. parti(pos)
  109. end
  110. if node.name == "mychisel:cross_"..mat.."1" then
  111. minetest.set_node(pos,{name = "mychisel:cross_"..mat.."2", param2=minetest.dir_to_facedir(user:get_look_dir())})
  112. parti(pos)
  113. end
  114. if node.name == "mychisel:cross_"..mat.."2" then
  115. minetest.set_node(pos,{name = "mychisel:cross_"..mat.."3", param2=minetest.dir_to_facedir(user:get_look_dir())})
  116. parti(pos)
  117. end
  118. if node.name == "mychisel:cross_"..mat.."3" then
  119. minetest.set_node(pos,{name = "mychisel:cross_"..mat.."4", param2=minetest.dir_to_facedir(user:get_look_dir())})
  120. parti(pos)
  121. end
  122. end
  123. if mode == "5" then
  124. if node.name == item then
  125. minetest.set_node(pos,{name = "mychisel:square_"..mat.."1", param2=minetest.dir_to_facedir(user:get_look_dir())})
  126. parti(pos)
  127. end
  128. if node.name == "mychisel:square_"..mat.."1" then
  129. minetest.set_node(pos,{name = "mychisel:square_"..mat.."2", param2=minetest.dir_to_facedir(user:get_look_dir())})
  130. parti(pos)
  131. end
  132. if node.name == "mychisel:square_"..mat.."2" then
  133. minetest.set_node(pos,{name = "mychisel:square_"..mat.."3", param2=minetest.dir_to_facedir(user:get_look_dir())})
  134. parti(pos)
  135. end
  136. if node.name == "mychisel:square_"..mat.."3" then
  137. minetest.set_node(pos,{name = "mychisel:square_"..mat.."4", param2=minetest.dir_to_facedir(user:get_look_dir())})
  138. parti(pos)
  139. end
  140. end
  141. if mode == "6" then
  142. -- on_place = function(itemstack, placer, pointed_thing)
  143. local pt = pointed_thing
  144. if ( minetest.get_node({x=pt.under.x, y=pt.under.y+1, z=pt.under.z}).name == "air" ) then
  145. local wear = itemstack:get_wear()
  146. local direction = minetest.dir_to_facedir(user:get_look_dir())
  147. local meta1 = minetest.env:get_meta({x=pt.under.x, y=pt.under.y , z=pt.under.z})
  148. local meta2 = minetest.env:get_meta({x=pt.under.x, y=pt.under.y+1, z=pt.under.z})
  149. minetest.set_node({x=pt.under.x, y=pt.under.y+1, z=pt.under.z}, {name="mychisel:chisel_deco", param2=direction})
  150. meta1:set_int("wear", wear)
  151. meta2:set_int("wear", wear)
  152. itemstack:take_item()
  153. return itemstack
  154. end
  155. end
  156. end
  157. if not minetest.setting_getbool("creative_mode") then
  158. itemstack:add_wear(65535 / (USES - 1))
  159. end
  160. return itemstack
  161. end,
  162. on_place = function(itemstack, user, pointed_thing)
  163. local usr = user:get_player_name()
  164. if mode == "1" then
  165. mode = "2"
  166. minetest.chat_send_player(usr,"Horizontal Groove")
  167. elseif mode == "2" then
  168. mode = "3"
  169. minetest.chat_send_player(usr,"Vertical Groove")
  170. elseif mode == "3" then
  171. mode = "4"
  172. minetest.chat_send_player(usr,"Cross Grooves")
  173. elseif mode == "4" then
  174. mode = "5"
  175. minetest.chat_send_player(usr,"Square")
  176. elseif mode == "5" then
  177. mode = "6"
  178. minetest.chat_send_player(usr,"Place Tool")
  179. elseif mode == "6" then
  180. mode = "1"
  181. minetest.chat_send_player(usr,"Chisel 4 Edges")
  182. end
  183. if not minetest.setting_getbool("creative_mode") then
  184. itemstack:add_wear(65535 / (USES - 1))
  185. end
  186. return itemstack
  187. end
  188. })
  189. minetest.register_craft({
  190. output = "mychisel:chisel",
  191. recipe = {
  192. {"default:steel_ingot"},
  193. {"wool:brown"},
  194. },
  195. })