chisel.lua.diff 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. 2,11c2
  2. < local color = '#FF6700'
  3. < local TechnicMaxCharge = 300000
  4. < chisel = {}
  5. <
  6. < chisel.materials = {}
  7. < chisel.mods = {}
  8. < chisel.selected = {}
  9. < chisel.active = {}
  10. < chisel.program = {}
  11. < chisel.mode = {}
  12. ---
  13. > local mode = {}
  14. 12a4,12
  15. > local function parti(pos)
  16. > minetest.add_particlespawner(25, 0.3,
  17. > pos, pos,
  18. > {x=2, y=0.2, z=2}, {x=-2, y=2, z=-2},
  19. > {x=0, y=-6, z=0}, {x=0, y=-10, z=0},
  20. > 0.2, 1,
  21. > 0.2, 2,
  22. > true, "mychisel_parti.png")
  23. > end
  24. 13a14
  25. > mode = "1"
  26. 14a16,19
  27. > minetest.register_tool( "mychisel:chisel",{
  28. > description = "Chisel",
  29. > inventory_image = "mychisel_chisel.png",
  30. > wield_image = "mychisel_chisel.png",
  31. 16c21
  32. < local wehavetechnic = minetest.get_modpath("technic")
  33. ---
  34. > on_use = function(itemstack, user, pointed_thing)
  35. 17a23,25
  36. > if pointed_thing.type ~= "node" then
  37. > return
  38. > end
  39. 19,20c27,28
  40. <
  41. <
  42. ---
  43. > local pos = pointed_thing.under
  44. > local node = minetest.get_node(pos)
  45. 22c30
  46. < local default_material = {
  47. ---
  48. > local default_material = {
  49. 40,185d47
  50. < -- Chatcommand to show loaded mods with names and number of styles
  51. <
  52. < minetest.register_chatcommand("chisel", {
  53. < params = "",
  54. < description = "Shows supported mods in mychisel",
  55. < privs = {interact = true},
  56. < func = function(name, poi_name)
  57. <
  58. < for i in ipairs (chisel.mods) do
  59. <
  60. < minetest.chat_send_player(name,core.colorize(color,i..") modname :"..chisel.mods[i][1].." styles: "..chisel.mods[i][2]))
  61. < end
  62. <
  63. < end,
  64. < })
  65. <
  66. < -- global API
  67. <
  68. < function chisel.register_node(modname, prefix, raw, design) -- global function to register new stuff
  69. < local counter = chisel.count_stuff() +1
  70. < chisel.materials [counter] = {}
  71. < chisel.materials [counter][1] = modname
  72. < chisel.materials [counter][2] = prefix
  73. < chisel.materials [counter][3] = raw
  74. < chisel.materials [counter][4] = design
  75. < end
  76. <
  77. <
  78. < function chisel.add_mod(modname,number) -- global function to init a new mod for the chisel.
  79. < local counter = chisel.count_mods() +1
  80. < chisel.mods [counter] = {}
  81. < chisel.mods [counter][1] = modname
  82. < chisel.mods [counter][2] = number
  83. < minetest.log("action","[CHISEL] Added mod "..modname .. " with " .. number.." styles to mychisel") -- log loaded mods to debug.txt
  84. < end
  85. <
  86. <
  87. <
  88. < function chisel.count_stuff() -- how many materials have been registered already ?
  89. < local counter = 0
  90. < for i in ipairs (chisel.materials) do counter = counter +1 end
  91. < return counter
  92. < end
  93. <
  94. <
  95. <
  96. < function chisel.count_mods() -- how many different mods are registered ?
  97. <
  98. < local counter = 0
  99. < for i in ipairs (chisel.mods) do counter = counter +1 end
  100. < return counter
  101. < end
  102. <
  103. <
  104. <
  105. <
  106. < -- init chisel for each player joining
  107. <
  108. < local function chiselinit(name)
  109. < chisel.selected[name] = 1
  110. < chisel.active[name] = "default"
  111. < chisel.program[name] = 1
  112. < chisel.mode[name] = "1"
  113. < end
  114. <
  115. < minetest.register_on_joinplayer(function(player)
  116. < chiselinit(player:get_player_name())
  117. < end)
  118. <
  119. < -- end init
  120. <
  121. <
  122. <
  123. <
  124. < local function parti(pos)
  125. < minetest.add_particlespawner(25, 0.3,
  126. < pos, pos,
  127. < {x=2, y=0.2, z=2}, {x=-2, y=2, z=-2},
  128. < {x=0, y=-6, z=0}, {x=0, y=-10, z=0},
  129. < 0.2, 1,
  130. < 0.2, 2,
  131. < true, "mychisel_parti.png")
  132. < end
  133. <
  134. <
  135. <
  136. <
  137. < local function chiselcut(pos,user,node)
  138. < local name = user:get_player_name()
  139. <
  140. < for i in ipairs (chisel.materials) do
  141. <
  142. < if chisel.materials[i][1] == chisel.active[name] then
  143. < if node.name == chisel.materials[i][3] and chisel.materials[i][4] == chisel.materials[chisel.program[name]][4] then
  144. <
  145. < minetest.set_node(pos, {name=chisel.materials[i][1]..":"..chisel.materials[i][2].."_"..chisel.materials[i][4], param2=minetest.dir_to_facedir(user:get_look_dir())})
  146. < end
  147. < end
  148. < end
  149. < end
  150. <
  151. <
  152. < local function change_mode(user, choice)
  153. <
  154. < local name = user:get_player_name()
  155. <
  156. <
  157. < if choice then
  158. < if chisel.mode[name] == "1" then
  159. < chisel.mode[name] = "2"
  160. < minetest.chat_send_player(name,core.colorize(color, "Horizontal Groove"))
  161. <
  162. < elseif chisel.mode[name] == "2" then
  163. < chisel.mode[name] = "3"
  164. < minetest.chat_send_player(name,core.colorize(color, "Vertical Groove"))
  165. <
  166. < elseif chisel.mode[name] == "3" then
  167. < chisel.mode[name] = "4"
  168. < minetest.chat_send_player(name, core.colorize(color, "Cross Grooves"))
  169. <
  170. < elseif chisel.mode[name] == "4" then
  171. < chisel.mode[name] = "5"
  172. < minetest.chat_send_player(name, core.colorize(color, "Square"))
  173. <
  174. < elseif chisel.mode[name] == "5" then
  175. < chisel.mode[name] = "1"
  176. < minetest.chat_send_player(name, core.colorize(color, "Chisel 4 Edges"))
  177. < end
  178. < else
  179. < chisel.program[name] = chisel.program[name] +1
  180. < if chisel.program[name] > chisel.mods [chisel.selected[name]][2] then chisel.program[name] = 1 end
  181. < minetest.chat_send_player(name, core.colorize(color, chisel.materials [chisel.program[name]][4]))
  182. < end
  183. <
  184. < end
  185. <
  186. <
  187. <
  188. <
  189. < local function chiselme(pos, user, node)
  190. <
  191. <
  192. < local name = user:get_player_name()
  193. <
  194. <
  195. <
  196. 190d51
  197. <
  198. 192c53,62
  199. < if chisel.mode[name] == "1" then
  200. ---
  201. > if pointed_thing.type ~= "node" then
  202. > return
  203. > end
  204. >
  205. > if minetest.is_protected(pos, user:get_player_name()) then
  206. > minetest.record_protection_violation(pos, user:get_player_name())
  207. > return
  208. > end
  209. >
  210. > if mode == "1" then
  211. 197d66
  212. <
  213. 203d71
  214. <
  215. 209d76
  216. <
  217. 215d81
  218. <
  219. 217,218d82
  220. <
  221. <
  222. 221c85
  223. < if chisel.mode[name] == "2" then
  224. ---
  225. > if mode == "2" then
  226. 226d89
  227. <
  228. 232d94
  229. <
  230. 238d99
  231. <
  232. 244d104
  233. <
  234. 246d105
  235. <
  236. 249c108
  237. < if chisel.mode[name] == "3" then
  238. ---
  239. > if mode == "3" then
  240. 254d112
  241. <
  242. 260d117
  243. <
  244. 266d122
  245. <
  246. 272d127
  247. <
  248. 274d128
  249. <
  250. 277c131
  251. < if chisel.mode[name] == "4" then
  252. ---
  253. > if mode == "4" then
  254. 282d135
  255. <
  256. 288d140
  257. <
  258. 294d145
  259. <
  260. 300d150
  261. <
  262. 302d151
  263. <
  264. 305c154
  265. < if chisel.mode[name] == "5" then
  266. ---
  267. > if mode == "5" then
  268. 310d158
  269. <
  270. 316d163
  271. <
  272. 322d168
  273. <
  274. 328d173
  275. <
  276. 330d174
  277. <
  278. 332a177,192
  279. > if mode == "6" then
  280. > -- on_place = function(itemstack, placer, pointed_thing)
  281. > local pt = pointed_thing
  282. > if ( minetest.get_node({x=pt.under.x, y=pt.under.y+1, z=pt.under.z}).name == "air" ) then
  283. > local wear = itemstack:get_wear()
  284. > local direction = minetest.dir_to_facedir(user:get_look_dir())
  285. > local meta1 = minetest.env:get_meta({x=pt.under.x, y=pt.under.y , z=pt.under.z})
  286. > local meta2 = minetest.env:get_meta({x=pt.under.x, y=pt.under.y+1, z=pt.under.z})
  287. > minetest.set_node({x=pt.under.x, y=pt.under.y+1, z=pt.under.z}, {name="mychisel:chisel_deco", param2=direction})
  288. > meta1:set_int("wear", wear)
  289. > meta2:set_int("wear", wear)
  290. > itemstack:take_item()
  291. > return itemstack
  292. > end
  293. > end
  294. >
  295. 334,335d193
  296. <
  297. < end
  298. 337,338c195,197
  299. <
  300. < if not wehavetechnic then
  301. ---
  302. > if not minetest.setting_getbool("creative_mode") then
  303. > itemstack:add_wear(65535 / (USES - 1))
  304. > end
  305. 340,531c199,221
  306. < minetest.register_tool( "mychisel:chisel",{
  307. < description = "Chisel",
  308. < inventory_image = "mychisel_chisel.png",
  309. < wield_image = "mychisel_chisel.png",
  310. <
  311. < on_use = function(itemstack, user, pointed_thing)
  312. <
  313. < if pointed_thing.type ~= "node" then
  314. < return
  315. < end
  316. <
  317. < local pos = pointed_thing.under
  318. < local node = minetest.get_node(pos)local feedback = false
  319. < local name = user:get_player_name()
  320. <
  321. <
  322. <
  323. <
  324. < if minetest.is_protected(pos, user:get_player_name()) then
  325. < minetest.record_protection_violation(pos, user:get_player_name())
  326. < return
  327. < end
  328. <
  329. <
  330. < if chisel.active[name] == "default" then
  331. < chiselme(pos,user,node)
  332. <
  333. < else
  334. <
  335. < chiselcut(pos,user,node)
  336. <
  337. < end
  338. <
  339. <
  340. < if not minetest.setting_getbool("creative_mode") then
  341. < itemstack:add_wear(65535 / (USES - 1))
  342. < end
  343. <
  344. < return itemstack
  345. <
  346. < end,
  347. <
  348. < on_place = function(itemstack, user, pointed_thing)
  349. <
  350. <
  351. < local number = chisel.count_mods()
  352. < local keys = user:get_player_control()
  353. < local name = user:get_player_name()
  354. <
  355. <
  356. <
  357. < -- change design mode of chisel by pressing sneak while right-clicking
  358. < if( not( keys["sneak"] )) then
  359. < if chisel.active[name] == "default" then
  360. < change_mode(user,true)
  361. < else
  362. <
  363. < change_mode(user,false)
  364. <
  365. < end
  366. < else
  367. < chisel.selected[name] = chisel.selected[name] +1
  368. < if chisel.selected[name] > chisel.count_mods() then chisel.selected[name] = 1 end
  369. <
  370. < chisel.active[name] = chisel.mods[chisel.selected[name]][1]
  371. < minetest.chat_send_player(user:get_player_name(), core.colorize(color, " ***>>> switched to mod: "..chisel.active[name]))
  372. <
  373. < end
  374. <
  375. < return itemstack
  376. <
  377. < end
  378. <
  379. < })
  380. <
  381. < minetest.register_craft({
  382. < output = "mychisel:chisel",
  383. < recipe = {
  384. < {"default:steel_ingot"},
  385. < {"wool:brown"},
  386. < },
  387. < })
  388. <
  389. <
  390. <
  391. <
  392. < else
  393. <
  394. <
  395. < local S = technic.getter
  396. <
  397. < technic.register_power_tool("mychisel:chisel",TechnicMaxCharge)
  398. < local chisel_charge_per_node =math.floor( TechnicMaxCharge / USES )
  399. <
  400. <
  401. < minetest.register_tool("mychisel:chisel", {
  402. < description = S("Chisel"),
  403. < inventory_image = "mychisel_chisel.png",
  404. < stack_max = 1,
  405. < wear_represents = "technic_RE_charge",
  406. < on_refill = technic.refill_RE_charge,
  407. < on_use = function(itemstack, user, pointed_thing)
  408. <
  409. <
  410. < if pointed_thing.type ~= "node" then
  411. < return
  412. < end
  413. <
  414. < local pos = pointed_thing.under
  415. < local node = minetest.get_node(pos)
  416. < local name = user:get_player_name()
  417. <
  418. <
  419. <
  420. < if minetest.is_protected(pos, user:get_player_name()) then
  421. < minetest.record_protection_violation(pos, user:get_player_name())
  422. < return
  423. < end
  424. <
  425. < --
  426. <
  427. < local meta = minetest.deserialize(itemstack:get_metadata())
  428. < if not meta or not meta.charge or
  429. < meta.charge < chisel_charge_per_node then
  430. < return
  431. < end
  432. <
  433. < if chisel.active[name] == "default" then
  434. < chiselme(pos,user,node)
  435. < meta.charge = meta.charge - chisel_charge_per_node
  436. < else
  437. <
  438. < chiselcut(pos,user,node)
  439. < meta.charge = meta.charge - chisel_charge_per_node
  440. < end
  441. <
  442. <
  443. <
  444. < if not technic.creative_mode then
  445. < technic.set_RE_wear(itemstack, meta.charge, TechnicMaxCharge)
  446. < itemstack:set_metadata(minetest.serialize(meta))
  447. < end
  448. <
  449. < return itemstack
  450. <
  451. <
  452. < end,
  453. <
  454. < on_place = function(itemstack, user, pointed_thing)
  455. <
  456. < local number = chisel.count_mods()
  457. < local keys = user:get_player_control()
  458. < local name = user:get_player_name()
  459. <
  460. <
  461. <
  462. < -- change design mode of chisel by pressing sneak while right-clicking
  463. < if( not( keys["sneak"] )) then
  464. < if chisel.active[name] == "default" then
  465. < change_mode(user,true)
  466. < else
  467. <
  468. < change_mode(user,false)
  469. <
  470. < end
  471. < else
  472. < chisel.selected[name] = chisel.selected[name] +1
  473. < if chisel.selected[name] > chisel.count_mods() then chisel.selected[name] = 1 end
  474. <
  475. < chisel.active[name] = chisel.mods[chisel.selected[name]][1]
  476. < minetest.chat_send_player(user:get_player_name(),core.colorize(color, " ***>>> switched to mod: "..chisel.active[name]))
  477. <
  478. < end
  479. <
  480. < return itemstack
  481. <
  482. < end
  483. < })
  484. <
  485. <
  486. < minetest.register_craft({
  487. < output = "mychisel:chisel",
  488. < recipe = {
  489. < {"default:diamond", "default:diamond" , "default:diamond" },
  490. < {"", "technic:stainless_steel_ingot", ""},
  491. < {"", "technic:battery", ""},
  492. < }
  493. < })
  494. <
  495. <
  496. <
  497. < end
  498. ---
  499. > return itemstack
  500. >
  501. > end,
  502. >
  503. > on_place = function(itemstack, user, pointed_thing)
  504. >
  505. > local usr = user:get_player_name()
  506. >
  507. > if mode == "1" then
  508. > mode = "2"
  509. > minetest.chat_send_player(usr,"Horizontal Groove")
  510. >
  511. > elseif mode == "2" then
  512. > mode = "3"
  513. > minetest.chat_send_player(usr,"Vertical Groove")
  514. >
  515. > elseif mode == "3" then
  516. > mode = "4"
  517. > minetest.chat_send_player(usr,"Cross Grooves")
  518. >
  519. > elseif mode == "4" then
  520. > mode = "5"
  521. > minetest.chat_send_player(usr,"Square")
  522. 533c223,247
  523. < chisel.add_mod("default",5)
  524. \ No newline at end of file
  525. ---
  526. > elseif mode == "5" then
  527. > mode = "6"
  528. > minetest.chat_send_player(usr,"Place Tool")
  529. > elseif mode == "6" then
  530. > mode = "1"
  531. > minetest.chat_send_player(usr,"Chisel 4 Edges")
  532. > end
  533. >
  534. > if not minetest.setting_getbool("creative_mode") then
  535. > itemstack:add_wear(65535 / (USES - 1))
  536. > end
  537. >
  538. > return itemstack
  539. >
  540. > end
  541. >
  542. > })
  543. >
  544. > minetest.register_craft({
  545. > output = "mychisel:chisel",
  546. > recipe = {
  547. > {"default:steel_ingot"},
  548. > {"wool:brown"},
  549. > },
  550. > })