init.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. creative = {}
  2. local creative_mode_cache = minetest.settings:get_bool("creative_mode")
  3. function creative.is_enabled_for(name)
  4. return creative_mode_cache
  5. end
  6. dofile(minetest.get_modpath("creative") .. "/inventory.lua")
  7. if creative_mode_cache then
  8. -- Dig time is modified according to difference (leveldiff) between tool
  9. -- 'maxlevel' and node 'level'. Digtime is divided by the larger of
  10. -- leveldiff and 1.
  11. -- To speed up digging in creative, hand 'maxlevel' and 'digtime' have been
  12. -- increased such that nodes of differing levels have an insignificant
  13. -- effect on digtime.
  14. local digtime = 42
  15. local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256}
  16. minetest.register_item(":", {
  17. type = "none",
  18. wield_image = "wieldhand.png",
  19. wield_scale = {x = 1, y = 1, z = 2.5},
  20. range = 10,
  21. tool_capabilities = {
  22. full_punch_interval = 0.5,
  23. max_drop_level = 3,
  24. groupcaps = {
  25. crumbly = caps,
  26. cracky = caps,
  27. snappy = caps,
  28. choppy = caps,
  29. oddly_breakable_by_hand = caps,
  30. },
  31. damage_groups = {fleshy = 10},
  32. }
  33. })
  34. end
  35. -- Unlimited node placement
  36. minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
  37. return creative.is_enabled_for(placer:get_player_name())
  38. end)
  39. -- Don't pick up if the item is already in the inventory
  40. local old_handle_node_drops = minetest.handle_node_drops
  41. function minetest.handle_node_drops(pos, drops, digger)
  42. if not digger or not digger:is_player() then
  43. return
  44. end
  45. if not creative.is_enabled_for(digger:get_player_name()) then
  46. return old_handle_node_drops(pos, drops, digger)
  47. end
  48. local inv = digger:get_inventory()
  49. if inv then
  50. for _, item in ipairs(drops) do
  51. if not inv:contains_item("main", item, true) then
  52. inv:add_item("main", item)
  53. end
  54. end
  55. end
  56. end