init.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ----------------------------------------------------------
  2. ---- ____ _ _ ----
  3. ---- / ___| ___ _ __ ___ | | | ----
  4. ---- \___ \ / __| '__/ _ \| | | ----
  5. ---- ___) | (__| | | (_) | | | ----
  6. ---- |____/ \___|_| \___/|_|_| ----
  7. ---- ----
  8. ---- Converts Spawn egg to Summon scroll ----
  9. ---- ----
  10. ---- All Graphics and Code Creative Commons 0 ----
  11. ---- Sirrob Zeroone ----
  12. ---- Version: 20181012 ----
  13. ----------------------------------------------------------
  14. ----------------------------------------------------------
  15. ---- "o1" = Cartoon ----
  16. ---Inspiration from: www.how-to-draw-funny-cartoons.com---
  17. ---- "o2" = Simple Stencils ----
  18. ---- Inspiration from: All over the Internet ----
  19. ---- Any img name starting c1_ ----
  20. ---- will override o1/o2 ----
  21. ----------------------------------------------------------
  22. usr_iop = minetest.settings:get_bool("o1_enbled_o2_disabled")-- get user option from UI settings
  23. if usr_iop == true then
  24. img_option = "o1"
  25. elseif usr_iop == false then
  26. img_option = "o2"
  27. else
  28. img_option = "o1" -- even with a default this can resolve to nil so error protection
  29. end
  30. usr_pre = minetest.settings:get("mod_scroll_pre") -- get user tooltip prefix from UI setting, default is "Summon"
  31. if usr_pre == nil then
  32. desc_prefix = "Summon" -- even with a default this can be nil so error protection
  33. else
  34. desc_prefix = minetest.settings:get("mod_scroll_pre") -- Tooltip prefix
  35. end
  36. ----------------------------------------------------------
  37. ---- Scroll Graphic Elements ----
  38. ---- Created by: evandromyller ----
  39. ---- www.openclipart.org/detail/17299/papyrus ----
  40. ---- Modded by: Sirrob Zeroone ----
  41. ----------------------------------------------------------
  42. scroll_bg = "aa_scroll_blank.png"
  43. scroll_overlay = "aa_scroll_blank_overlay.png" -- Currently a blank image as preferred it, left in incase anyone wishes to Customise
  44. scroll_top = "aa_scroll_blank_top.png"
  45. fp_scrolls = minetest.get_modpath("mobs_scroll") -- path for mobs scroll
  46. scrolls = {} -- table store for mobs_ spawn egg item
  47. ----------------------------------------------------------
  48. ---- Populate loaded mod mobs item list ----
  49. ---- by looking for items specific to mobs spawn_egg ----
  50. ---- also workarounds for NSSM, Goblines, Mineclone2 ----
  51. ----------------------------------------------------------
  52. if mobs then
  53. for skey,value in pairs(minetest.registered_items) do
  54. if minetest.registered_items[skey]
  55. ["groups"]["spawn_egg"] ~= nil then -- Only add named items which are in the group spawn_egg
  56. scrolls[skey] = value -- Build new table of relevant item names and values
  57. elseif string.find(tostring(minetest.registered_items[skey]
  58. ["image"]),"_egg") or -- NSSM egg workaround, note to workout-should use pattern match "nssm" .. .* .. "_egg"
  59. string.find(tostring(minetest.registered_items[skey]
  60. ["description"]),"goblin egg") or -- Goblins egg workaround
  61. string.find(tostring(minetest.registered_items[skey]
  62. ["image"]),"mobs_mc_spawn_icon_") -- Mineclone2 egg workaround
  63. then
  64. scrolls[skey] = value
  65. scrolls[skey]["description"] = string.gsub(scrolls[skey]["description"]," Egg","") -- NSSM remove egg from end of description
  66. scrolls[skey]["description"] = string.gsub(scrolls[skey]["description"]," egg","") -- Goblin remove egg from end of description
  67. else
  68. end
  69. end
  70. else
  71. --scrolls_error = "nil" -- no mob entity items would be registered ie no mob spawn eggs
  72. end
  73. --[[ old code
  74. if mobs then
  75. for skey,value in pairs(minetest.registered_items) do
  76. if minetest.registered_items[skey]
  77. ["groups"]["spawn_egg"] ~= nil then -- Only add named items which are in the group spawn_egg
  78. scrolls[skey] = value -- Build new table of relevant item names and values
  79. --i = i+1
  80. else
  81. end
  82. end
  83. else
  84. --scrolls_error = "nil" -- no mob entity items would be registered ie no mob spawn eggs
  85. end
  86. ]]--
  87. ----------------------------------------------------------
  88. ---- Replace the eggs with scrolls and selected ----
  89. ---- graphic option/custom ----
  90. ----------------------------------------------------------
  91. if scrolls then
  92. for k,va in pairs(scrolls) do
  93. local img_e = "c1_"..scrolls[k]["description"] .. ".png" -- Create inital image string assuming a c1 (custom) image eg c1_White Sheep(Tamed).png
  94. img_ex = string.gsub(img_e, "[%s()]", "") -- Image strings can't contain spaces or brackets so remove these eg c1_WhiteSheepTamed.png
  95. local img_ex_co, err = io.open(fp_scrolls .."/textures/".. img_ex, "rb"); -- Try to open the constructed Image string to confirm Image exists
  96. if err then -- If theres an error then c1 (custom) image dosen't exist for that spawn egg item
  97. local img_e = img_option .."_".. scrolls[k]["description"] .. ".png" -- Create image string using option selected - o1/o2 eg o1_White Sheep(Tamed).png
  98. img_ex = string.gsub(img_e, "[%s()]", "") -- Image strings can't contain spaces or brackets so remove these eg o1_WhiteSheepTamed.png
  99. local img_ex_co, err2 = io.open(fp_scrolls .."/textures/".. img_ex, "rb"); -- Try to open the constructed Image string to confirm Image exists
  100. if err2 then -- If theres an error than o1/o2 dosent exist for this spawn egg item
  101. img_ex = img_option.."_aa_noimage".. ".png" -- Resort to no image avaliable image and create working img string eg o1_aa_noimage.png
  102. else
  103. img_ex_co:close() -- Outcome here is if there is no err2 created and img string will equal o1_WhiteSheepTamed.png
  104. end -- Also close the image file that was opened.
  105. else
  106. img_ex_co:close() -- Outcome here is if there is no err created and img string will equal c1_WhiteSheepTamed.png
  107. end -- Also close the image file that was opened.
  108. minetest.override_item(k,{ -- Standard override item using the key in scrolls (scrolls[k]) eg mobs_animal:sheep_white
  109. description = desc_prefix .. " " .. scrolls[k]["description"], -- Adjust the description of spawn item so it includes the prefix eg Summon White Sheep
  110. inventory_image = scroll_bg .. "^" .. -- Build the Scroll Inventory image using the 3 scroll elements and our created image string
  111. img_ex .. "^" .. -- eg "aa_scroll_blank.png"^"o1_WhiteSheepTamed.png"^"aa_scroll_blank_overlay.png"^"aa_scroll_blank_top.png"
  112. scroll_overlay .. "^" ..
  113. scroll_top,
  114. })
  115. end
  116. end