init.lua 2.0 KB

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