init.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. --
  2. -- Tool definitions
  3. --
  4. --[[ TOOLS SUMMARY:
  5. Tool types:
  6. * Hand: basic tool/weapon (special capabilities in creative mode)
  7. * Pickaxe: dig cracky
  8. * Axe: dig choppy
  9. * Shovel: dig crumbly
  10. * Shears: dig snappy
  11. * Sword: deal damage
  12. * Dagger: deal damage, but faster
  13. Tool materials:
  14. * Wood: dig nodes of rating 3
  15. * Stone: dig nodes of rating 3 or 2
  16. * Steel: dig nodes of rating 3, 2 or 1
  17. * Mese: dig "everything" instantly
  18. * n-Uses: can be used n times before breaking
  19. ]]
  20. -- The hand
  21. if core.settings:get_bool("creative_mode") then
  22. local digtime = 42
  23. local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256}
  24. core.register_item(":", {
  25. type = "none",
  26. wield_image = "wieldhand.png",
  27. wield_scale = {x = 1, y = 1, z = 2.5},
  28. range = 10,
  29. tool_capabilities = {
  30. full_punch_interval = 0.5,
  31. max_drop_level = 3,
  32. groupcaps = {
  33. crumbly = caps,
  34. cracky = caps,
  35. snappy = caps,
  36. choppy = caps,
  37. oddly_breakable_by_hand = caps,
  38. -- dig_immediate group doesn't use value 1. Value 3 is instant dig
  39. dig_immediate =
  40. {times = {[2] = digtime, [3] = 0}, uses = 0, maxlevel = 256},
  41. },
  42. damage_groups = {fleshy = 10},
  43. }
  44. })
  45. else
  46. core.register_item(":", {
  47. type = "none",
  48. wield_image = "wieldhand.png",
  49. wield_scale = {x = 1, y = 1, z = 2.5},
  50. tool_capabilities = {
  51. full_punch_interval = 0.9,
  52. max_drop_level = 0,
  53. groupcaps = {
  54. crumbly = {times = {[2] = 3.00, [3] = 0.70}, uses = 0, maxlevel = 1},
  55. snappy = {times = {[3] = 0.40}, uses = 0, maxlevel = 1},
  56. oddly_breakable_by_hand =
  57. {times = {[1] = 3.50, [2] = 2.00, [3] = 0.70}, uses = 0}
  58. },
  59. damage_groups = {fleshy = 1},
  60. }
  61. })
  62. end
  63. -- Mese Pickaxe: special tool that digs "everything" instantly
  64. core.register_tool("basetools:pick_mese", {
  65. description = "Mese Pickaxe".."\n"..
  66. "Digs diggable nodes instantly.",
  67. inventory_image = "basetools_mesepick.png",
  68. tool_capabilities = {
  69. full_punch_interval = 1.0,
  70. max_drop_level=3,
  71. groupcaps={
  72. cracky={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255},
  73. crumbly={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255},
  74. snappy={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255},
  75. choppy={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255},
  76. dig_immediate={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255},
  77. },
  78. damage_groups = {fleshy=100},
  79. },
  80. })
  81. -- A variant of the mese pickaxe that is not affected by the 0.15s digging delay
  82. core.register_tool("basetools:pick_mese_no_delay", {
  83. description = "Mese Pickaxe (no delay)".."\n"..
  84. "Digs diggable nodes instantly.".."\n"..
  85. "There is no delay between digging each node,\n"..
  86. 'but the "repeat_dig_time" setting is still respected.',
  87. inventory_image = "basetools_mesepick_no_delay.png",
  88. tool_capabilities = {
  89. full_punch_interval = 1.0,
  90. max_drop_level=3,
  91. groupcaps={
  92. cracky={times={[1]=0.001, [2]=0.001, [3]=0.001}, maxlevel=255},
  93. crumbly={times={[1]=0.001, [2]=0.001, [3]=0.001}, maxlevel=255},
  94. snappy={times={[1]=0.001, [2]=0.001, [3]=0.001}, maxlevel=255},
  95. choppy={times={[1]=0.001, [2]=0.001, [3]=0.001}, maxlevel=255},
  96. dig_immediate={times={[1]=0.001, [2]=0.001, [3]=0.001}, maxlevel=255},
  97. },
  98. damage_groups = {fleshy=100},
  99. },
  100. })
  101. --
  102. -- Pickaxes: Dig cracky
  103. --
  104. core.register_tool("basetools:pick_wood", {
  105. description = "Wooden Pickaxe".."\n"..
  106. "Digs cracky=3",
  107. inventory_image = "basetools_woodpick.png",
  108. tool_capabilities = {
  109. max_drop_level=0,
  110. groupcaps={
  111. cracky={times={[3]=2.00}, uses=30, maxlevel=0}
  112. },
  113. },
  114. })
  115. core.register_tool("basetools:pick_stone", {
  116. description = "Stone Pickaxe".."\n"..
  117. "Digs cracky=2..3",
  118. inventory_image = "basetools_stonepick.png",
  119. tool_capabilities = {
  120. max_drop_level=0,
  121. groupcaps={
  122. cracky={times={[2]=1.20, [3]=0.80}, uses=60, maxlevel=0}
  123. },
  124. },
  125. })
  126. core.register_tool("basetools:pick_steel", {
  127. description = "Steel Pickaxe".."\n"..
  128. "Digs cracky=1..3",
  129. inventory_image = "basetools_steelpick.png",
  130. tool_capabilities = {
  131. max_drop_level=1,
  132. groupcaps={
  133. cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=0}
  134. },
  135. },
  136. })
  137. core.register_tool("basetools:pick_steel_l1", {
  138. description = "Steel Pickaxe Level 1".."\n"..
  139. "Digs cracky=1..3".."\n"..
  140. "maxlevel=1",
  141. inventory_image = "basetools_steelpick_l1.png",
  142. tool_capabilities = {
  143. max_drop_level=1,
  144. groupcaps={
  145. cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=1}
  146. },
  147. },
  148. })
  149. core.register_tool("basetools:pick_steel_l2", {
  150. description = "Steel Pickaxe Level 2".."\n"..
  151. "Digs cracky=1..3".."\n"..
  152. "maxlevel=2",
  153. inventory_image = "basetools_steelpick_l2.png",
  154. tool_capabilities = {
  155. max_drop_level=1,
  156. groupcaps={
  157. cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=2}
  158. },
  159. },
  160. })
  161. --
  162. -- Shovels (dig crumbly)
  163. --
  164. core.register_tool("basetools:shovel_wood", {
  165. description = "Wooden Shovel".."\n"..
  166. "Digs crumbly=3",
  167. inventory_image = "basetools_woodshovel.png",
  168. tool_capabilities = {
  169. max_drop_level=0,
  170. groupcaps={
  171. crumbly={times={[3]=0.50}, uses=30, maxlevel=0}
  172. },
  173. },
  174. })
  175. core.register_tool("basetools:shovel_stone", {
  176. description = "Stone Shovel".."\n"..
  177. "Digs crumbly=2..3",
  178. inventory_image = "basetools_stoneshovel.png",
  179. tool_capabilities = {
  180. max_drop_level=0,
  181. groupcaps={
  182. crumbly={times={[2]=0.50, [3]=0.30}, uses=60, maxlevel=0}
  183. },
  184. },
  185. })
  186. core.register_tool("basetools:shovel_steel", {
  187. description = "Steel Shovel".."\n"..
  188. "Digs crumbly=1..3",
  189. inventory_image = "basetools_steelshovel.png",
  190. tool_capabilities = {
  191. max_drop_level=1,
  192. groupcaps={
  193. crumbly={times={[1]=1.00, [2]=0.70, [3]=0.60}, uses=90, maxlevel=0}
  194. },
  195. },
  196. })
  197. --
  198. -- Axes (dig choppy)
  199. --
  200. core.register_tool("basetools:axe_wood", {
  201. description = "Wooden Axe".."\n"..
  202. "Digs choppy=3",
  203. inventory_image = "basetools_woodaxe.png",
  204. tool_capabilities = {
  205. max_drop_level=0,
  206. groupcaps={
  207. choppy={times={[3]=0.80}, uses=30, maxlevel=0},
  208. },
  209. },
  210. })
  211. core.register_tool("basetools:axe_stone", {
  212. description = "Stone Axe".."\n"..
  213. "Digs choppy=2..3",
  214. inventory_image = "basetools_stoneaxe.png",
  215. tool_capabilities = {
  216. max_drop_level=0,
  217. groupcaps={
  218. choppy={times={[2]=1.00, [3]=0.60}, uses=60, maxlevel=0},
  219. },
  220. },
  221. })
  222. core.register_tool("basetools:axe_steel", {
  223. description = "Steel Axe".."\n"..
  224. "Digs choppy=1..3",
  225. inventory_image = "basetools_steelaxe.png",
  226. tool_capabilities = {
  227. max_drop_level=1,
  228. groupcaps={
  229. choppy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=90, maxlevel=0},
  230. },
  231. },
  232. })
  233. --
  234. -- Shears (dig snappy)
  235. --
  236. core.register_tool("basetools:shears_wood", {
  237. description = "Wooden Shears".."\n"..
  238. "Digs snappy=3",
  239. inventory_image = "basetools_woodshears.png",
  240. tool_capabilities = {
  241. max_drop_level=0,
  242. groupcaps={
  243. snappy={times={[3]=1.00}, uses=30, maxlevel=0},
  244. },
  245. },
  246. })
  247. core.register_tool("basetools:shears_stone", {
  248. description = "Stone Shears".."\n"..
  249. "Digs snappy=2..3",
  250. inventory_image = "basetools_stoneshears.png",
  251. tool_capabilities = {
  252. max_drop_level=0,
  253. groupcaps={
  254. snappy={times={[2]=1.00, [3]=0.50}, uses=60, maxlevel=0},
  255. },
  256. },
  257. })
  258. core.register_tool("basetools:shears_steel", {
  259. description = "Steel Shears".."\n"..
  260. "Digs snappy=1..3",
  261. inventory_image = "basetools_steelshears.png",
  262. tool_capabilities = {
  263. max_drop_level=1,
  264. groupcaps={
  265. snappy={times={[1]=1.00, [2]=0.50, [3]=0.25}, uses=90, maxlevel=0},
  266. },
  267. },
  268. })
  269. --
  270. -- Swords (deal damage)
  271. --
  272. core.register_tool("basetools:sword_wood", {
  273. description = "Wooden Sword".."\n"..
  274. "Damage: fleshy=2",
  275. inventory_image = "basetools_woodsword.png",
  276. tool_capabilities = {
  277. full_punch_interval = 1.0,
  278. damage_groups = {fleshy=2},
  279. }
  280. })
  281. core.register_tool("basetools:sword_stone", {
  282. description = "Stone Sword".."\n"..
  283. "Damage: fleshy=5",
  284. inventory_image = "basetools_stonesword.png",
  285. tool_capabilities = {
  286. full_punch_interval = 1.0,
  287. max_drop_level=0,
  288. damage_groups = {fleshy=5},
  289. }
  290. })
  291. core.register_tool("basetools:sword_steel", {
  292. description = "Steel Sword".."\n"..
  293. "Damage: fleshy=10",
  294. inventory_image = "basetools_steelsword.png",
  295. tool_capabilities = {
  296. full_punch_interval = 1.0,
  297. max_drop_level=1,
  298. damage_groups = {fleshy=10},
  299. }
  300. })
  301. core.register_tool("basetools:sword_titanium", {
  302. description = "Titanium Sword".."\n"..
  303. "Damage: fleshy=100",
  304. inventory_image = "basetools_titaniumsword.png",
  305. tool_capabilities = {
  306. full_punch_interval = 1.0,
  307. max_drop_level=1,
  308. damage_groups = {fleshy=100},
  309. }
  310. })
  311. core.register_tool("basetools:sword_blood", {
  312. description = "Blood Sword".."\n"..
  313. "Damage: fleshy=1000",
  314. inventory_image = "basetools_bloodsword.png",
  315. tool_capabilities = {
  316. full_punch_interval = 1.0,
  317. max_drop_level=1,
  318. damage_groups = {fleshy=1000},
  319. }
  320. })
  321. -- Max. damage sword
  322. core.register_tool("basetools:sword_mese", {
  323. description = "Mese Sword".."\n"..
  324. "Damage: fleshy=32767, fiery=32767, icy=32767".."\n"..
  325. "Full Punch Interval: 0.0s",
  326. inventory_image = "basetools_mesesword.png",
  327. tool_capabilities = {
  328. full_punch_interval = 0.0,
  329. max_drop_level=1,
  330. damage_groups = {fleshy=32767, fiery=32767, icy=32767},
  331. }
  332. })
  333. -- Fire/Ice sword: Deal damage to non-fleshy damage groups
  334. core.register_tool("basetools:sword_fire", {
  335. description = "Fire Sword".."\n"..
  336. "Damage: icy=10",
  337. inventory_image = "basetools_firesword.png",
  338. tool_capabilities = {
  339. full_punch_interval = 1.0,
  340. max_drop_level=0,
  341. damage_groups = {icy=10},
  342. }
  343. })
  344. core.register_tool("basetools:sword_ice", {
  345. description = "Ice Sword".."\n"..
  346. "Damage: fiery=10",
  347. inventory_image = "basetools_icesword.png",
  348. tool_capabilities = {
  349. full_punch_interval = 1.0,
  350. max_drop_level=0,
  351. damage_groups = {fiery=10},
  352. }
  353. })
  354. core.register_tool("basetools:sword_elemental", {
  355. description = "Elemental Sword".."\n"..
  356. "Damage: fiery=10, icy=10",
  357. inventory_image = "basetools_elementalsword.png",
  358. tool_capabilities = {
  359. full_punch_interval = 1.0,
  360. max_drop_level=0,
  361. damage_groups = {fiery=10, icy=10},
  362. }
  363. })
  364. -- Healing weapons: heal HP
  365. core.register_tool("basetools:dagger_heal", {
  366. description = "Healing Dagger".."\n"..
  367. "Heal: fleshy=1".."\n"..
  368. "Full Punch Interval: 0.5s",
  369. inventory_image = "basetools_healdagger.png",
  370. tool_capabilities = {
  371. full_punch_interval = 0.5,
  372. damage_groups = {fleshy=-1},
  373. }
  374. })
  375. core.register_tool("basetools:sword_heal", {
  376. description = "Healing Sword".."\n"..
  377. "Heal: fleshy=10",
  378. inventory_image = "basetools_healsword.png",
  379. tool_capabilities = {
  380. full_punch_interval = 1.0,
  381. damage_groups = {fleshy=-10},
  382. }
  383. })
  384. core.register_tool("basetools:sword_heal_super", {
  385. description = "Super Healing Sword".."\n"..
  386. "Heal: fleshy=32768, fiery=32768, icy=32768",
  387. inventory_image = "basetools_superhealsword.png",
  388. tool_capabilities = {
  389. full_punch_interval = 1.0,
  390. damage_groups = {fleshy=-32768, fiery=-32768, icy=-32768},
  391. }
  392. })
  393. --
  394. -- Dagger: Low damage, fast punch interval
  395. --
  396. core.register_tool("basetools:dagger_wood", {
  397. description = "Wooden Dagger".."\n"..
  398. "Damage: fleshy=1".."\n"..
  399. "Full Punch Interval: 0.5s",
  400. inventory_image = "basetools_wooddagger.png",
  401. tool_capabilities = {
  402. full_punch_interval = 0.5,
  403. max_drop_level=0,
  404. damage_groups = {fleshy=1},
  405. }
  406. })
  407. core.register_tool("basetools:dagger_steel", {
  408. description = "Steel Dagger".."\n"..
  409. "Damage: fleshy=2".."\n"..
  410. "Full Punch Interval: 0.5s",
  411. inventory_image = "basetools_steeldagger.png",
  412. tool_capabilities = {
  413. full_punch_interval = 0.5,
  414. max_drop_level=0,
  415. damage_groups = {fleshy=2},
  416. }
  417. })
  418. -- Test tool uses, punch_attack_uses, and wear bar coloring
  419. local tool_params = {
  420. {uses = 1},
  421. {uses = 2},
  422. {uses = 3},
  423. {
  424. uses = 5,
  425. wear_color = "#5865f2",
  426. wear_description = "Solid color: #5865f2",
  427. },
  428. {
  429. uses = 10,
  430. wear_color = "slateblue",
  431. wear_description = "Solid color: slateblue",
  432. },
  433. {
  434. uses = 50,
  435. wear_color = {
  436. color_stops = {
  437. [0] = "red",
  438. [0.5] = "yellow",
  439. [1.0] = "blue"
  440. },
  441. blend = "linear"
  442. },
  443. wear_description = "Ranges from blue to yellow to red",
  444. },
  445. {
  446. uses = 100,
  447. wear_color = {
  448. color_stops = {
  449. [0] = "#ffff00",
  450. [0.2] = "#ff00ff",
  451. [0.3] = "#ffff00",
  452. [0.45] = "#c0ffee",
  453. [0.6] = {r=255, g=255, b=0, a=100}, -- continues until the end
  454. },
  455. blend = "constant"
  456. },
  457. wear_description = "Misc. colors, constant interpolation",
  458. },
  459. {uses = 1e3},
  460. {uses = 1e4},
  461. {uses = 65535},
  462. }
  463. for i, params in ipairs(tool_params) do
  464. local uses = params.uses
  465. local ustring = uses.."-Use"..(uses == 1 and "" or "s")
  466. local color = string.format("#FF00%02X", math.floor(((i-1)/#tool_params) * 255))
  467. core.register_tool("basetools:pick_uses_"..string.format("%05d", uses), {
  468. description = ustring.." Pickaxe".."\n"..
  469. "Digs cracky=3"..
  470. (params.wear_description and "\n".."Wear bar: " .. params.wear_description or ""),
  471. inventory_image = "basetools_usespick.png^[colorize:"..color..":127",
  472. tool_capabilities = {
  473. max_drop_level=0,
  474. groupcaps={
  475. cracky={times={[3]=0.1, [2]=0.2, [1]=0.3}, uses=uses, maxlevel=0}
  476. },
  477. },
  478. wear_color = params.wear_color
  479. })
  480. core.register_tool("basetools:sword_uses_"..string.format("%05d", uses), {
  481. description = ustring.." Sword".."\n"..
  482. "Damage: fleshy=1",
  483. inventory_image = "basetools_usessword.png^[colorize:"..color..":127",
  484. tool_capabilities = {
  485. damage_groups = {fleshy=1},
  486. punch_attack_uses = uses,
  487. },
  488. })
  489. end
  490. core.register_chatcommand("wear_color", {
  491. params = "[idx]",
  492. description = "Set wear bar color override",
  493. func = function(player_name, param)
  494. local player = core.get_player_by_name(player_name)
  495. if not player then return end
  496. local wear_color = nil
  497. local wear_desc = "Reset override"
  498. if param ~= "" then
  499. local params = tool_params[tonumber(param)]
  500. if not params then
  501. return false, "idx out of bounds"
  502. end
  503. wear_color = params.wear_color
  504. wear_desc = "Set override: "..(params.wear_description or "Default behavior")
  505. end
  506. local tool = player:get_wielded_item()
  507. if tool:get_count() == 0 then
  508. return false, "Tool not found"
  509. end
  510. tool:get_meta():set_wear_bar_params(wear_color)
  511. player:set_wielded_item(tool)
  512. return true, wear_desc
  513. end
  514. })
  515. -- Punch handler to set random color & wear
  516. local wear_on_use = function(itemstack, user, pointed_thing)
  517. local meta = itemstack:get_meta()
  518. local color = math.random(0, 0xFFFFFF)
  519. local colorstr = string.format("#%06x", color)
  520. meta:set_wear_bar_params(colorstr)
  521. core.log("action", "[basetool] Wear bar color of "..itemstack:get_name().." changed to "..colorstr)
  522. itemstack:set_wear(math.random(0, 65535))
  523. return itemstack
  524. end
  525. -- Place handler to clear item metadata color
  526. local wear_on_place = function(itemstack, user, pointed_thing)
  527. local meta = itemstack:get_meta()
  528. meta:set_wear_bar_params(nil)
  529. return itemstack
  530. end
  531. core.register_tool("basetools:random_wear_bar", {
  532. description = "Wear Bar Color Test\n" ..
  533. "Punch: Set random color & wear\n" ..
  534. "Place: Clear color",
  535. -- Base texture: A grayscale square (can be colorized)
  536. inventory_image = "basetools_usespick.png^[colorize:#FFFFFF:127",
  537. tool_capabilities = {
  538. max_drop_level=0,
  539. groupcaps={
  540. cracky={times={[3]=0.1, [2]=0.2, [1]=0.3}, uses=1000, maxlevel=0}
  541. },
  542. },
  543. on_use = wear_on_use,
  544. on_place = wear_on_place,
  545. on_secondary_use = wear_on_place,
  546. })