Advertisement
Guest User

Gems Rewrite

a guest
Nov 6th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.32 KB | None | 0 0
  1. dofile(minetest.get_modpath("gems").."/config.lua")
  2.  
  3. minetest.register_node("gems:mineral_ruby", {
  4.     description = "Ruby Ore",
  5.     tiles = {"default_stone.png^gems_mineral_ore.png"},
  6.     is_ground_content = true,
  7.     groups = {cracky=3},
  8.     drop = 'gems:ruby',
  9.     sounds = default.node_sound_stone_defaults(),
  10. })
  11. minetest.register_node("gems:mineral_sapphire", {
  12.     description = "Sapphire Ore",
  13.     tiles = {"default_stone.png^gems_mineral_sapphire.png"},
  14.     is_ground_content = true,
  15.     groups = {cracky=3},
  16.     drop = 'gems:sapphire',
  17.     sounds = default.node_sound_stone_defaults(),
  18. })
  19. minetest.register_node("gems:mineral_emerald", {
  20.     description = "Emerald Ore",
  21.     tiles = {"default_stone.png^gems_mineral_emerald.png"},
  22.     is_ground_content = true,
  23.     groups = {cracky=3},
  24.     drop = 'gems:emerald',
  25.     sounds = default.node_sound_stone_defaults(),
  26. })
  27. minetest.register_node("gems:mineral_diamond", {
  28.     description = "Amethyst Ore",
  29.     tiles = {"default_stone.png^gems_mineral_diamond.png"},
  30.     is_ground_content = true,
  31.     groups = {cracky=3},
  32.     drop = 'gems:diamond',
  33.     sounds = default.node_sound_stone_defaults(),
  34. })
  35. minetest.register_node("gems:mineral_topaz", {
  36.     description = "Topaz Ore",
  37.     tiles = {"default_stone.png^gems_mineral_topaz.png"},
  38.     is_ground_content = true,
  39.     groups = {cracky=3},
  40.     drop = 'gems:topaz',
  41.     sounds = default.node_sound_stone_defaults(),
  42. })
  43.  
  44. minetest.register_craftitem("gems:ruby", {
  45.     description = "Ruby",
  46.     inventory_image = "gems_ruby.png",
  47. })
  48. minetest.register_craftitem("gems:sapphire", {
  49.     description = "Sapphire",
  50.     inventory_image = "gems_sapphire.png",
  51. })
  52. minetest.register_craftitem("gems:emerald", {
  53.     description = "Emerald",
  54.     inventory_image = "gems_emerald.png",
  55. })
  56. minetest.register_craftitem("gems:amethyst", {
  57.     description = "Amethyst",
  58.     inventory_image = "gems_amethyst.png",
  59. })
  60. minetest.register_craftitem("gems:topaz", {
  61.     description = "Topaz",
  62.     inventory_image = "gems_topaz.png",
  63. })
  64.  
  65. encrust_a_tool = function(result,crafttool,craftgem)
  66.     minetest.register_craft( {
  67.        type = "shapeless",
  68.        output = result,
  69.        recipe = {
  70.                crafttool,
  71.                craftgem,
  72.         },
  73.     })
  74. end
  75.  
  76. mods = {}
  77. metals = {}
  78. metalname = {}
  79. gems = {"ruby","sapphire","emerald","amethyst","topaz"}
  80. gemname = {"Ruby","Sapphire","Emerald","Amethyst","Topaz"}
  81.  
  82. gembenefitspeed = {0.75,1.00,0.85,1.15,0.60}
  83. gembenefitwear = {1.00,1.35,1.25,1.50,0.80}
  84.  
  85. if encrust_steel == true then
  86.     table.insert(mods,"default")
  87.     table.insert(metals,"steel")
  88.     table.insert(metalname,"Steel")
  89. end
  90.  
  91. if encrust_bronze == true then
  92.     table.insert(mods,"moreores")
  93.     table.insert(metals,"bronze")
  94.     table.insert(metalname,"Bronze")
  95. end
  96.  
  97. if encrust_silver == true then
  98.     table.insert(mods,"moreores")
  99.     table.insert(metals,"silver")
  100.     table.insert(metalname,"Silver")
  101. end
  102.  
  103. if encrust_gold == true then
  104.     table.insert(mods,"moreores")
  105.     table.insert(metals,"gold")
  106.     table.insert(metalname,"Gold")
  107. end
  108.  
  109. if encrust_mithril == true then
  110.     table.insert(mods,"moreores")
  111.     table.insert(metals,"mithril")
  112.     table.insert(metalname,"Mithril")
  113. end
  114.  
  115. if encrust_alatro == true then
  116.     table.insert(mods,"gloopores")
  117.     table.insert(metals,"alatro")
  118.     table.insert(metalname,"Alatro")
  119. end
  120.  
  121. if encrust_arol == true then
  122.     table.insert(mods,"gloopores")
  123.     table.insert(metals,"arol")
  124.     table.insert(metalname,"Arol")
  125. end
  126.  
  127. for j,k in ipairs(metals) do
  128.     modis = mods[j]
  129.     metalis = metals[j]
  130.     pickdef = minetest.registered_tools[modis..":pick_"..metals[j]]
  131.     axedef = minetest.registered_tools[modis..":axe_"..metals[j]]
  132.     shoveldef = minetest.registered_tools[modis..":shovel_"..metals[j]]
  133.     sworddef = minetest.registered_tools[modis..":sword_"..metals[j]]
  134.     pickdig = pickdef.tool_capabilities.groupcaps.cracky
  135.     axedigc = axedef.tool_capabilities.groupcaps.choppy
  136.     axedigf = axedef.tool_capabilities.groupcaps.fleshy
  137.     shoveldig = shoveldef.tool_capabilities.groupcaps.crumbly
  138.     sworddigf = sworddef.tool_capabilities.groupcaps.fleshy
  139.     sworddigs = sworddef.tool_capabilities.groupcaps.snappy
  140.     sworddigc = sworddef.tool_capabilities.groupcaps.choppy
  141.     for i,l in gems do
  142.         npickdig = {}
  143.         naxedigc = {}
  144.         naxedigf = {}
  145.         nshoveldig = {}
  146.         nsworddigf = {}
  147.         nsworddigs = {}
  148.         nsworddigc = {}
  149.        
  150.         npickdig.times[1] = pickdig.times[1]*gembenefitspeed[i]
  151.         npickdig.times[2] = pickdig.times[2]*gembenefitspeed[i]
  152.         npickdig.times[3] = pickdig.times[3]*gembenefitspeed[i]
  153.         npickdig.uses = pickdig.uses*gembenefitwear[i]
  154.        
  155.         naxedigc.times[1] = axedigc.times[1]*gembenefitspeed[i]
  156.         naxedigc.times[2] = axedigc.times[2]*gembenefitspeed[i]
  157.         naxedigc.times[3] = axedigc.times[3]*gembenefitspeed[i]
  158.         naxedigc.uses = axedigc.uses*gembenefitwear[i]
  159.        
  160.         naxedigf.times[1] = axedigf.times[1]*gembenefitspeed[i]
  161.         naxedigf.times[2] = axedigf.times[2]*gembenefitspeed[i]
  162.         naxedigf.times[3] = axedigf.times[3]*gembenefitspeed[i]
  163.         naxedigf.uses = axedigf.uses*gembenefitwear[i]
  164.        
  165.         nshoveldig.times[1] = shoveldig.times[1]*gembenefitspeed[i]
  166.         nshoveldig.times[2] = shoveldig.times[2]*gembenefitspeed[i]
  167.         nshoveldig.times[3] = shoveldig.times[3]*gembenefitspeed[i]
  168.         nshoveldig.uses = shoveldig.uses*gembenefitwear[i]
  169.        
  170.         nsworddigf.times[1] = sworddigf.times[1]*gembenefitspeed[i]
  171.         nsworddigf.times[2] = sworddigf.times[2]*gembenefitspeed[i]
  172.         nsworddigf.times[3] = sworddigf.times[3]*gembenefitspeed[i]
  173.         nsworddigf.uses = sworddigf.uses*gembenefitwear[i]
  174.        
  175.         nsworddigs.times[1] = sworddigs.times[1]*gembenefitspeed[i]
  176.         nsworddigs.times[2] = sworddigs.times[2]*gembenefitspeed[i]
  177.         nsworddigs.times[3] = sworddigs.times[3]*gembenefitspeed[i]
  178.         nsworddigs.uses = sworddigs.uses*gembenefitwear[i]
  179.        
  180.         nsworddigc.times[1] = sworddigc.times[1]*gembenefitspeed[i]
  181.         nsworddigc.times[2] = sworddigc.times[2]*gembenefitspeed[i]
  182.         nsworddigc.times[3] = sworddigc.times[3]*gembenefitspeed[i]
  183.         nsworddigc.uses = sworddigc.uses*gembenefitwear[i]
  184.        
  185.         minetest.register_tool("gems:pick_"..k.."_"..l, {
  186.             description = gemname[i].."Encrusted "..metalname[j].." Pickaxe",
  187.             inventory_image = mods[j].."_tool_"..metals[j].."pick.png^gems_pick_"..gems[i],
  188.             tool_capabilities = {
  189.                 max_drop_level = pickdef.tool_capabilities.max_drop_level,
  190.                 groupcaps = {
  191.                     npickdig,
  192.                 }
  193.             }
  194.         })
  195.         minetest.register_tool("gems:axe_"..k.."_"..i, {
  196.             description = gemname[i].."Encrusted "..metalname[j].." Axe",
  197.             inventory_image = mods[j].."_tool_"..metals[j].."axe.png^gems_axe_"..gems[i],
  198.             tool_capabilities = {
  199.                 max_drop_level = axedef.tool_capabilities.max_drop_level,
  200.                 groupcaps = {
  201.                     naxedigc,
  202.                     naxedigf,
  203.                 }
  204.             }
  205.         })
  206.         minetest.register_tool("gems:shovel_"..k.."_"..l, {
  207.             description = gemname[i].."Encrusted "..metalname[j].." Shovel",
  208.             inventory_image = mods[j].."_tool_"..metals[j].."shovel.png^gems_shovel_"..gems[i],
  209.             tool_capabilities = {
  210.                 max_drop_level = shoveldef.tool_capabilities.max_drop_level,
  211.                 groupcaps = {
  212.                     nshoveldig,
  213.                 }
  214.             }
  215.         })
  216.         minetest.register_tool("gems:sword_"..k.."_"..l, {
  217.             description = gemname[i].."Encrusted "..metalname[j].." Sword",
  218.             inventory_image = mods[j].."_tool_"..metals[j].."sword.png^gems_sword_"..gems[i],
  219.             tool_capabilities = {
  220.                 max_drop_level = sworddef.tool_capabilities.max_drop_level,
  221.                 groupcaps = {
  222.                     nsworddigf,
  223.                     nsworddigs,
  224.                     nsworddigc,
  225.                 }
  226.             }
  227.         })
  228.         minetest.register_craft({
  229.             type = "shapeless",
  230.             output = "gems:pick_"..k.."_"..l,
  231.             recipe = {
  232.                 "gems:"..i,
  233.                 mods[j]..":pick_"..k,
  234.             }
  235.         })
  236.         minetest.register_craft({
  237.             type = "shapeless",
  238.             output = "gems:axe_"..k.."_"..l,
  239.             recipe = {
  240.                 "gems:"..i,
  241.                 mods[j]..":axe_"..k,
  242.             }
  243.         })
  244.         minetest.register_craft({
  245.             type = "shapeless",
  246.             output = "gems:shovel_"..k.."_"..l,
  247.             recipe = {
  248.                 "gems:"..i,
  249.                 mods[j]..":shovel_"..k,
  250.             }
  251.         })
  252.         minetest.register_craft({
  253.             type = "shapeless",
  254.             output = "gems:sword_"..k.."_"..l,
  255.             recipe = {
  256.                 "gems:"..i,
  257.                 mods[j]..":sword_"..k,
  258.             }
  259.         })
  260.     end
  261. end
  262.  
  263. local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max)
  264.     if maxp.y < height_min or minp.y > height_max then
  265.         return
  266.     end
  267.     local y_min = math.max(minp.y, height_min)
  268.     local y_max = math.min(maxp.y, height_max)
  269.     local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
  270.     local pr = PseudoRandom(seed)
  271.     local num_chunks = math.floor(chunks_per_volume * volume)
  272.     local chunk_size = 3
  273.     if ore_per_chunk <= 4 then
  274.         chunk_size = 2
  275.     end
  276.     local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
  277.     --print("generate_ore num_chunks: "..dump(num_chunks))
  278.     for i=1,num_chunks do
  279.     if (y_max-chunk_size+1 <= y_min) then return end
  280.         local y0 = pr:next(y_min, y_max-chunk_size+1)
  281.         if y0 >= height_min and y0 <= height_max then
  282.             local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
  283.             local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
  284.             local p0 = {x=x0, y=y0, z=z0}
  285.             for x1=0,chunk_size-1 do
  286.             for y1=0,chunk_size-1 do
  287.             for z1=0,chunk_size-1 do
  288.                 if pr:next(1,inverse_chance) == 1 then
  289.                     local x2 = x0+x1
  290.                     local y2 = y0+y1
  291.                     local z2 = z0+z1
  292.                     local p2 = {x=x2, y=y2, z=z2}
  293.                     if minetest.env:get_node(p2).name == wherein then
  294.                         minetest.env:set_node(p2, {name=name})
  295.                     end
  296.                 end
  297.             end
  298.             end
  299.             end
  300.         end
  301.     end
  302.     --print("generate_ore done")
  303. end
  304.  
  305. minetest.register_on_generated(function(minp, maxp, seed)
  306.     math.randomseed(os.time())
  307.     local current_seed = seed + math.random(10,100)
  308.     local function get_next_seed()
  309.         current_seed = current_seed + 1
  310.         return current_seed
  311.     end
  312.     generate_ore("gems:mineral_ruby", "default:stone", minp, maxp, get_next_seed(), 1/7/7/7, 1, -31000, -50)
  313.     generate_ore("gems:mineral_sapphire", "default:stone", minp, maxp, get_next_seed(), 1/7/7/7, 1, -31000, -100)
  314.     generate_ore("gems:mineral_emerald", "default:stone", minp, maxp, get_next_seed(), 1/7/7/7, 1, -31000, -150)
  315.     generate_ore("gems:mineral_amethyst", "default:stone", minp, maxp, get_next_seed(), 1/7/7/7, 1, -31000, -200)
  316.     generate_ore("gems:mineral_topaz", "default:stone", minp, maxp, get_next_seed(), 1/7/7/7, 1, -31000, -250)
  317. end)
  318.  
  319. minetest.register_alias("gems:mineral_garnet","default:stone")
  320. minetest.register_alias("gems:mineral_aquamarine","default:stone")
  321. minetest.register_alias("gems:mineral_diamond","default:stone")
  322. minetest.register_alias("gems:mineral_opal","default:stone")
  323.  
  324. print("[Gems] Loaded!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement