item.lua 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. -- Minetest: builtin/item.lua
  2. local builtin_shared = ...
  3. local function copy_pointed_thing(pointed_thing)
  4. return {
  5. type = pointed_thing.type,
  6. above = vector.new(pointed_thing.above),
  7. under = vector.new(pointed_thing.under),
  8. ref = pointed_thing.ref,
  9. }
  10. end
  11. --
  12. -- Item definition helpers
  13. --
  14. function core.inventorycube(img1, img2, img3)
  15. img2 = img2 or img1
  16. img3 = img3 or img1
  17. return "[inventorycube"
  18. .. "{" .. img1:gsub("%^", "&")
  19. .. "{" .. img2:gsub("%^", "&")
  20. .. "{" .. img3:gsub("%^", "&")
  21. end
  22. function core.get_pointed_thing_position(pointed_thing, above)
  23. if pointed_thing.type == "node" then
  24. if above then
  25. -- The position where a node would be placed
  26. return pointed_thing.above
  27. end
  28. -- The position where a node would be dug
  29. return pointed_thing.under
  30. elseif pointed_thing.type == "object" then
  31. return pointed_thing.ref and pointed_thing.ref:get_pos()
  32. end
  33. end
  34. function core.dir_to_facedir(dir, is6d)
  35. --account for y if requested
  36. if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
  37. --from above
  38. if dir.y < 0 then
  39. if math.abs(dir.x) > math.abs(dir.z) then
  40. if dir.x < 0 then
  41. return 19
  42. else
  43. return 13
  44. end
  45. else
  46. if dir.z < 0 then
  47. return 10
  48. else
  49. return 4
  50. end
  51. end
  52. --from below
  53. else
  54. if math.abs(dir.x) > math.abs(dir.z) then
  55. if dir.x < 0 then
  56. return 15
  57. else
  58. return 17
  59. end
  60. else
  61. if dir.z < 0 then
  62. return 6
  63. else
  64. return 8
  65. end
  66. end
  67. end
  68. --otherwise, place horizontally
  69. elseif math.abs(dir.x) > math.abs(dir.z) then
  70. if dir.x < 0 then
  71. return 3
  72. else
  73. return 1
  74. end
  75. else
  76. if dir.z < 0 then
  77. return 2
  78. else
  79. return 0
  80. end
  81. end
  82. end
  83. -- Table of possible dirs
  84. local facedir_to_dir = {
  85. {x= 0, y=0, z= 1},
  86. {x= 1, y=0, z= 0},
  87. {x= 0, y=0, z=-1},
  88. {x=-1, y=0, z= 0},
  89. {x= 0, y=-1, z= 0},
  90. {x= 0, y=1, z= 0},
  91. }
  92. -- Mapping from facedir value to index in facedir_to_dir.
  93. local facedir_to_dir_map = {
  94. [0]=1, 2, 3, 4,
  95. 5, 2, 6, 4,
  96. 6, 2, 5, 4,
  97. 1, 5, 3, 6,
  98. 1, 6, 3, 5,
  99. 1, 4, 3, 2,
  100. }
  101. function core.facedir_to_dir(facedir)
  102. return facedir_to_dir[facedir_to_dir_map[facedir % 32]]
  103. end
  104. function core.dir_to_wallmounted(dir)
  105. if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then
  106. if dir.y < 0 then
  107. return 1
  108. else
  109. return 0
  110. end
  111. elseif math.abs(dir.x) > math.abs(dir.z) then
  112. if dir.x < 0 then
  113. return 3
  114. else
  115. return 2
  116. end
  117. else
  118. if dir.z < 0 then
  119. return 5
  120. else
  121. return 4
  122. end
  123. end
  124. end
  125. -- table of dirs in wallmounted order
  126. local wallmounted_to_dir = {
  127. [0] = {x = 0, y = 1, z = 0},
  128. {x = 0, y = -1, z = 0},
  129. {x = 1, y = 0, z = 0},
  130. {x = -1, y = 0, z = 0},
  131. {x = 0, y = 0, z = 1},
  132. {x = 0, y = 0, z = -1},
  133. }
  134. function core.wallmounted_to_dir(wallmounted)
  135. return wallmounted_to_dir[wallmounted % 8]
  136. end
  137. function core.dir_to_yaw(dir)
  138. return -math.atan2(dir.x, dir.z)
  139. end
  140. function core.yaw_to_dir(yaw)
  141. return {x = -math.sin(yaw), y = 0, z = math.cos(yaw)}
  142. end
  143. function core.is_colored_paramtype(ptype)
  144. return (ptype == "color") or (ptype == "colorfacedir") or
  145. (ptype == "colorwallmounted")
  146. end
  147. function core.strip_param2_color(param2, paramtype2)
  148. if not core.is_colored_paramtype(paramtype2) then
  149. return nil
  150. end
  151. if paramtype2 == "colorfacedir" then
  152. param2 = math.floor(param2 / 32) * 32
  153. elseif paramtype2 == "colorwallmounted" then
  154. param2 = math.floor(param2 / 8) * 8
  155. end
  156. -- paramtype2 == "color" requires no modification.
  157. return param2
  158. end
  159. function core.get_node_drops(node, toolname)
  160. -- Compatibility, if node is string
  161. local nodename = node
  162. local param2 = 0
  163. -- New format, if node is table
  164. if (type(node) == "table") then
  165. nodename = node.name
  166. param2 = node.param2
  167. end
  168. local def = core.registered_nodes[nodename]
  169. local drop = def and def.drop
  170. local ptype = def and def.paramtype2
  171. -- get color, if there is color (otherwise nil)
  172. local palette_index = core.strip_param2_color(param2, ptype)
  173. if drop == nil then
  174. -- default drop
  175. if palette_index then
  176. local stack = ItemStack(nodename)
  177. stack:get_meta():set_int("palette_index", palette_index)
  178. return {stack:to_string()}
  179. end
  180. return {nodename}
  181. elseif type(drop) == "string" then
  182. -- itemstring drop
  183. return drop ~= "" and {drop} or {}
  184. elseif drop.items == nil then
  185. -- drop = {} to disable default drop
  186. return {}
  187. end
  188. -- Extended drop table
  189. local got_items = {}
  190. local got_count = 0
  191. for _, item in ipairs(drop.items) do
  192. local good_rarity = true
  193. local good_tool = true
  194. if item.rarity ~= nil then
  195. good_rarity = item.rarity < 1 or math.random(item.rarity) == 1
  196. end
  197. if item.tools ~= nil then
  198. good_tool = false
  199. end
  200. if item.tools ~= nil and toolname then
  201. for _, tool in ipairs(item.tools) do
  202. if tool:sub(1, 1) == '~' then
  203. good_tool = toolname:find(tool:sub(2)) ~= nil
  204. else
  205. good_tool = toolname == tool
  206. end
  207. if good_tool then
  208. break
  209. end
  210. end
  211. end
  212. if good_rarity and good_tool then
  213. got_count = got_count + 1
  214. for _, add_item in ipairs(item.items) do
  215. -- add color, if necessary
  216. if item.inherit_color and palette_index then
  217. local stack = ItemStack(add_item)
  218. stack:get_meta():set_int("palette_index", palette_index)
  219. add_item = stack:to_string()
  220. end
  221. got_items[#got_items+1] = add_item
  222. end
  223. if drop.max_items ~= nil and got_count == drop.max_items then
  224. break
  225. end
  226. end
  227. end
  228. return got_items
  229. end
  230. local function user_name(user)
  231. return user and user:get_player_name() or ""
  232. end
  233. -- Returns a logging function. For empty names, does not log.
  234. local function make_log(name)
  235. return name ~= "" and core.log or function() end
  236. end
  237. function core.item_place_node(itemstack, placer, pointed_thing, param2,
  238. prevent_after_place)
  239. local def = itemstack:get_definition()
  240. if def.type ~= "node" or pointed_thing.type ~= "node" then
  241. return itemstack, nil
  242. end
  243. local under = pointed_thing.under
  244. local oldnode_under = core.get_node_or_nil(under)
  245. local above = pointed_thing.above
  246. local oldnode_above = core.get_node_or_nil(above)
  247. local playername = user_name(placer)
  248. local log = make_log(playername)
  249. if not oldnode_under or not oldnode_above then
  250. log("info", playername .. " tried to place"
  251. .. " node in unloaded position " .. core.pos_to_string(above))
  252. return itemstack, nil
  253. end
  254. local olddef_under = core.registered_nodes[oldnode_under.name]
  255. olddef_under = olddef_under or core.nodedef_default
  256. local olddef_above = core.registered_nodes[oldnode_above.name]
  257. olddef_above = olddef_above or core.nodedef_default
  258. if not olddef_above.buildable_to and not olddef_under.buildable_to then
  259. log("info", playername .. " tried to place"
  260. .. " node in invalid position " .. core.pos_to_string(above)
  261. .. ", replacing " .. oldnode_above.name)
  262. return itemstack, nil
  263. end
  264. -- Place above pointed node
  265. local place_to = {x = above.x, y = above.y, z = above.z}
  266. -- If node under is buildable_to, place into it instead (eg. snow)
  267. if olddef_under.buildable_to then
  268. log("info", "node under is buildable to")
  269. place_to = {x = under.x, y = under.y, z = under.z}
  270. end
  271. if core.is_protected(place_to, playername) then
  272. log("action", playername
  273. .. " tried to place " .. def.name
  274. .. " at protected position "
  275. .. core.pos_to_string(place_to))
  276. core.record_protection_violation(place_to, playername)
  277. return itemstack, nil
  278. end
  279. local oldnode = core.get_node(place_to)
  280. local newnode = {name = def.name, param1 = 0, param2 = param2 or 0}
  281. -- Calculate direction for wall mounted stuff like torches and signs
  282. if def.place_param2 ~= nil then
  283. newnode.param2 = def.place_param2
  284. elseif (def.paramtype2 == "wallmounted" or
  285. def.paramtype2 == "colorwallmounted") and not param2 then
  286. local dir = {
  287. x = under.x - above.x,
  288. y = under.y - above.y,
  289. z = under.z - above.z
  290. }
  291. newnode.param2 = core.dir_to_wallmounted(dir)
  292. -- Calculate the direction for furnaces and chests and stuff
  293. elseif (def.paramtype2 == "facedir" or
  294. def.paramtype2 == "colorfacedir") and not param2 then
  295. local placer_pos = placer and placer:get_pos()
  296. if placer_pos then
  297. local dir = {
  298. x = above.x - placer_pos.x,
  299. y = above.y - placer_pos.y,
  300. z = above.z - placer_pos.z
  301. }
  302. newnode.param2 = core.dir_to_facedir(dir)
  303. log("info", "facedir: " .. newnode.param2)
  304. end
  305. end
  306. local metatable = itemstack:get_meta():to_table().fields
  307. -- Transfer color information
  308. if metatable.palette_index and not def.place_param2 then
  309. local color_divisor = nil
  310. if def.paramtype2 == "color" then
  311. color_divisor = 1
  312. elseif def.paramtype2 == "colorwallmounted" then
  313. color_divisor = 8
  314. elseif def.paramtype2 == "colorfacedir" then
  315. color_divisor = 32
  316. end
  317. if color_divisor then
  318. local color = math.floor(metatable.palette_index / color_divisor)
  319. local other = newnode.param2 % color_divisor
  320. newnode.param2 = color * color_divisor + other
  321. end
  322. end
  323. -- Check if the node is attached and if it can be placed there
  324. if core.get_item_group(def.name, "attached_node") ~= 0 and
  325. not builtin_shared.check_attached_node(place_to, newnode) then
  326. log("action", "attached node " .. def.name ..
  327. " can not be placed at " .. core.pos_to_string(place_to))
  328. return itemstack, nil
  329. end
  330. log("action", playername .. " places node "
  331. .. def.name .. " at " .. core.pos_to_string(place_to))
  332. -- Add node and update
  333. core.add_node(place_to, newnode)
  334. -- Play sound if it was done by a player
  335. if playername ~= "" and def.sounds and def.sounds.place then
  336. core.sound_play(def.sounds.place, {
  337. pos = place_to,
  338. exclude_player = playername,
  339. }, true)
  340. end
  341. local take_item = true
  342. -- Run callback
  343. if def.after_place_node and not prevent_after_place then
  344. -- Deepcopy place_to and pointed_thing because callback can modify it
  345. local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
  346. local pointed_thing_copy = copy_pointed_thing(pointed_thing)
  347. if def.after_place_node(place_to_copy, placer, itemstack,
  348. pointed_thing_copy) then
  349. take_item = false
  350. end
  351. end
  352. -- Run script hook
  353. for _, callback in ipairs(core.registered_on_placenodes) do
  354. -- Deepcopy pos, node and pointed_thing because callback can modify them
  355. local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
  356. local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2}
  357. local oldnode_copy = {name=oldnode.name, param1=oldnode.param1, param2=oldnode.param2}
  358. local pointed_thing_copy = copy_pointed_thing(pointed_thing)
  359. if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack, pointed_thing_copy) then
  360. take_item = false
  361. end
  362. end
  363. if take_item then
  364. itemstack:take_item()
  365. end
  366. return itemstack, place_to
  367. end
  368. -- deprecated, item_place does not call this
  369. function core.item_place_object(itemstack, placer, pointed_thing)
  370. local pos = core.get_pointed_thing_position(pointed_thing, true)
  371. if pos ~= nil then
  372. local item = itemstack:take_item()
  373. core.add_item(pos, item)
  374. end
  375. return itemstack
  376. end
  377. function core.item_place(itemstack, placer, pointed_thing, param2)
  378. -- Call on_rightclick if the pointed node defines it
  379. if pointed_thing.type == "node" and placer and
  380. not placer:get_player_control().sneak then
  381. local n = core.get_node(pointed_thing.under)
  382. local nn = n.name
  383. if core.registered_nodes[nn] and core.registered_nodes[nn].on_rightclick then
  384. return core.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
  385. placer, itemstack, pointed_thing) or itemstack, nil
  386. end
  387. end
  388. -- Place if node, otherwise do nothing
  389. if itemstack:get_definition().type == "node" then
  390. return core.item_place_node(itemstack, placer, pointed_thing, param2)
  391. end
  392. return itemstack, nil
  393. end
  394. function core.item_secondary_use(itemstack, placer)
  395. return itemstack
  396. end
  397. function core.item_drop(itemstack, dropper, pos)
  398. local dropper_is_player = dropper and dropper:is_player()
  399. local p = table.copy(pos)
  400. local cnt = itemstack:get_count()
  401. if dropper_is_player then
  402. p.y = p.y + 1.2
  403. end
  404. local item = itemstack:take_item(cnt)
  405. local obj = core.add_item(p, item)
  406. if obj then
  407. if dropper_is_player then
  408. local dir = dropper:get_look_dir()
  409. dir.x = dir.x * 2.9
  410. dir.y = dir.y * 2.9 + 2
  411. dir.z = dir.z * 2.9
  412. obj:set_velocity(dir)
  413. obj:get_luaentity().dropped_by = dropper:get_player_name()
  414. end
  415. return itemstack
  416. end
  417. -- If we reach this, adding the object to the
  418. -- environment failed
  419. end
  420. function core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
  421. for _, callback in pairs(core.registered_on_item_eats) do
  422. local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing)
  423. if result then
  424. return result
  425. end
  426. end
  427. local def = itemstack:get_definition()
  428. if itemstack:take_item() ~= nil then
  429. user:set_hp(user:get_hp() + hp_change)
  430. if def and def.sound and def.sound.eat then
  431. core.sound_play(def.sound.eat, {
  432. pos = user:get_pos(),
  433. max_hear_distance = 16
  434. }, true)
  435. end
  436. if replace_with_item then
  437. if itemstack:is_empty() then
  438. itemstack:add_item(replace_with_item)
  439. else
  440. local inv = user:get_inventory()
  441. -- Check if inv is null, since non-players don't have one
  442. if inv and inv:room_for_item("main", {name=replace_with_item}) then
  443. inv:add_item("main", replace_with_item)
  444. else
  445. local pos = user:get_pos()
  446. pos.y = math.floor(pos.y + 0.5)
  447. core.add_item(pos, replace_with_item)
  448. end
  449. end
  450. end
  451. end
  452. return itemstack
  453. end
  454. function core.item_eat(hp_change, replace_with_item)
  455. return function(itemstack, user, pointed_thing) -- closure
  456. if user then
  457. return core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
  458. end
  459. end
  460. end
  461. function core.node_punch(pos, node, puncher, pointed_thing)
  462. -- Run script hook
  463. for _, callback in ipairs(core.registered_on_punchnodes) do
  464. -- Copy pos and node because callback can modify them
  465. local pos_copy = vector.new(pos)
  466. local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
  467. local pointed_thing_copy = pointed_thing and copy_pointed_thing(pointed_thing) or nil
  468. callback(pos_copy, node_copy, puncher, pointed_thing_copy)
  469. end
  470. end
  471. function core.handle_node_drops(pos, drops, digger)
  472. -- Add dropped items to object's inventory
  473. local inv = digger and digger:get_inventory()
  474. local give_item
  475. if inv then
  476. give_item = function(item)
  477. return inv:add_item("main", item)
  478. end
  479. else
  480. give_item = function(item)
  481. -- itemstring to ItemStack for left:is_empty()
  482. return ItemStack(item)
  483. end
  484. end
  485. for _, dropped_item in pairs(drops) do
  486. local left = give_item(dropped_item)
  487. if not left:is_empty() then
  488. local p = {
  489. x = pos.x + math.random()/2-0.25,
  490. y = pos.y + math.random()/2-0.25,
  491. z = pos.z + math.random()/2-0.25,
  492. }
  493. core.add_item(p, left)
  494. end
  495. end
  496. end
  497. function core.node_dig(pos, node, digger)
  498. local diggername = user_name(digger)
  499. local log = make_log(diggername)
  500. local def = core.registered_nodes[node.name]
  501. -- Copy pos because the callback could modify it
  502. if def and (not def.diggable or
  503. (def.can_dig and not def.can_dig(vector.new(pos), digger))) then
  504. log("info", diggername .. " tried to dig "
  505. .. node.name .. " which is not diggable "
  506. .. core.pos_to_string(pos))
  507. return false
  508. end
  509. if core.is_protected(pos, diggername) then
  510. log("action", diggername
  511. .. " tried to dig " .. node.name
  512. .. " at protected position "
  513. .. core.pos_to_string(pos))
  514. core.record_protection_violation(pos, diggername)
  515. return false
  516. end
  517. log('action', diggername .. " digs "
  518. .. node.name .. " at " .. core.pos_to_string(pos))
  519. local wielded = digger and digger:get_wielded_item()
  520. local drops = core.get_node_drops(node, wielded and wielded:get_name())
  521. if wielded then
  522. local wdef = wielded:get_definition()
  523. local tp = wielded:get_tool_capabilities()
  524. local dp = core.get_dig_params(def and def.groups, tp)
  525. if wdef and wdef.after_use then
  526. wielded = wdef.after_use(wielded, digger, node, dp) or wielded
  527. else
  528. -- Wear out tool
  529. if not core.is_creative_enabled(diggername) then
  530. wielded:add_wear(dp.wear)
  531. if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then
  532. core.sound_play(wdef.sound.breaks, {
  533. pos = pos,
  534. gain = 0.5
  535. }, true)
  536. end
  537. end
  538. end
  539. digger:set_wielded_item(wielded)
  540. end
  541. -- Check to see if metadata should be preserved.
  542. if def and def.preserve_metadata then
  543. local oldmeta = core.get_meta(pos):to_table().fields
  544. -- Copy pos and node because the callback can modify them.
  545. local pos_copy = {x=pos.x, y=pos.y, z=pos.z}
  546. local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
  547. local drop_stacks = {}
  548. for k, v in pairs(drops) do
  549. drop_stacks[k] = ItemStack(v)
  550. end
  551. drops = drop_stacks
  552. def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
  553. end
  554. -- Handle drops
  555. core.handle_node_drops(pos, drops, digger)
  556. local oldmetadata = nil
  557. if def and def.after_dig_node then
  558. oldmetadata = core.get_meta(pos):to_table()
  559. end
  560. -- Remove node and update
  561. core.remove_node(pos)
  562. -- Play sound if it was done by a player
  563. if diggername ~= "" and def and def.sounds and def.sounds.dug then
  564. core.sound_play(def.sounds.dug, {
  565. pos = pos,
  566. exclude_player = diggername,
  567. }, true)
  568. end
  569. -- Run callback
  570. if def and def.after_dig_node then
  571. -- Copy pos and node because callback can modify them
  572. local pos_copy = {x=pos.x, y=pos.y, z=pos.z}
  573. local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
  574. def.after_dig_node(pos_copy, node_copy, oldmetadata, digger)
  575. end
  576. -- Run script hook
  577. for _, callback in ipairs(core.registered_on_dignodes) do
  578. local origin = core.callback_origins[callback]
  579. if origin then
  580. core.set_last_run_mod(origin.mod)
  581. end
  582. -- Copy pos and node because callback can modify them
  583. local pos_copy = {x=pos.x, y=pos.y, z=pos.z}
  584. local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
  585. callback(pos_copy, node_copy, digger)
  586. end
  587. return true
  588. end
  589. function core.itemstring_with_palette(item, palette_index)
  590. local stack = ItemStack(item) -- convert to ItemStack
  591. stack:get_meta():set_int("palette_index", palette_index)
  592. return stack:to_string()
  593. end
  594. function core.itemstring_with_color(item, colorstring)
  595. local stack = ItemStack(item) -- convert to ItemStack
  596. stack:get_meta():set_string("color", colorstring)
  597. return stack:to_string()
  598. end
  599. -- This is used to allow mods to redefine core.item_place and so on
  600. -- NOTE: This is not the preferred way. Preferred way is to provide enough
  601. -- callbacks to not require redefining global functions. -celeron55
  602. local function redef_wrapper(table, name)
  603. return function(...)
  604. return table[name](...)
  605. end
  606. end
  607. --
  608. -- Item definition defaults
  609. --
  610. local default_stack_max = tonumber(core.settings:get("default_stack_max")) or 99
  611. core.nodedef_default = {
  612. -- Item properties
  613. type="node",
  614. -- name intentionally not defined here
  615. description = "",
  616. groups = {},
  617. inventory_image = "",
  618. wield_image = "",
  619. wield_scale = {x=1,y=1,z=1},
  620. stack_max = default_stack_max,
  621. usable = false,
  622. liquids_pointable = false,
  623. tool_capabilities = nil,
  624. node_placement_prediction = nil,
  625. -- Interaction callbacks
  626. on_place = redef_wrapper(core, 'item_place'), -- core.item_place
  627. on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
  628. on_use = nil,
  629. can_dig = nil,
  630. on_punch = redef_wrapper(core, 'node_punch'), -- core.node_punch
  631. on_rightclick = nil,
  632. on_dig = redef_wrapper(core, 'node_dig'), -- core.node_dig
  633. on_receive_fields = nil,
  634. -- Node properties
  635. drawtype = "normal",
  636. visual_scale = 1.0,
  637. -- Don't define these because otherwise the old tile_images and
  638. -- special_materials wouldn't be read
  639. --tiles ={""},
  640. --special_tiles = {
  641. -- {name="", backface_culling=true},
  642. -- {name="", backface_culling=true},
  643. --},
  644. post_effect_color = {a=0, r=0, g=0, b=0},
  645. paramtype = "none",
  646. paramtype2 = "none",
  647. is_ground_content = true,
  648. sunlight_propagates = false,
  649. walkable = true,
  650. pointable = true,
  651. diggable = true,
  652. climbable = false,
  653. buildable_to = false,
  654. floodable = false,
  655. liquidtype = "none",
  656. liquid_alternative_flowing = "",
  657. liquid_alternative_source = "",
  658. liquid_viscosity = 0,
  659. drowning = 0,
  660. light_source = 0,
  661. damage_per_second = 0,
  662. selection_box = {type="regular"},
  663. legacy_facedir_simple = false,
  664. legacy_wallmounted = false,
  665. }
  666. core.craftitemdef_default = {
  667. type="craft",
  668. -- name intentionally not defined here
  669. description = "",
  670. groups = {},
  671. inventory_image = "",
  672. wield_image = "",
  673. wield_scale = {x=1,y=1,z=1},
  674. stack_max = default_stack_max,
  675. liquids_pointable = false,
  676. tool_capabilities = nil,
  677. -- Interaction callbacks
  678. on_place = redef_wrapper(core, 'item_place'), -- core.item_place
  679. on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
  680. on_secondary_use = redef_wrapper(core, 'item_secondary_use'),
  681. on_use = nil,
  682. }
  683. core.tooldef_default = {
  684. type="tool",
  685. -- name intentionally not defined here
  686. description = "",
  687. groups = {},
  688. inventory_image = "",
  689. wield_image = "",
  690. wield_scale = {x=1,y=1,z=1},
  691. stack_max = 1,
  692. liquids_pointable = false,
  693. tool_capabilities = nil,
  694. -- Interaction callbacks
  695. on_place = redef_wrapper(core, 'item_place'), -- core.item_place
  696. on_secondary_use = redef_wrapper(core, 'item_secondary_use'),
  697. on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
  698. on_use = nil,
  699. }
  700. core.noneitemdef_default = { -- This is used for the hand and unknown items
  701. type="none",
  702. -- name intentionally not defined here
  703. description = "",
  704. groups = {},
  705. inventory_image = "",
  706. wield_image = "",
  707. wield_scale = {x=1,y=1,z=1},
  708. stack_max = default_stack_max,
  709. liquids_pointable = false,
  710. tool_capabilities = nil,
  711. -- Interaction callbacks
  712. on_place = redef_wrapper(core, 'item_place'),
  713. on_secondary_use = redef_wrapper(core, 'item_secondary_use'),
  714. on_drop = nil,
  715. on_use = nil,
  716. }