Guest User

Untitled

a guest
Jun 29th, 2012
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Mod Name: Uranium Mod
  2. --Author: LandMine
  3. --Last Edit: 06.29.2012
  4. --About Mod: Adds various items to Minetest
  5. --MineTest Version: MineTest-C55 0.4.dev-20120606-c57e508
  6.  
  7.  
  8. --
  9. -- Fuels
  10. --
  11.  
  12. minetest.register_craft({
  13.     type = "fuel",
  14.     recipe = "uranium:uranium_dust",
  15.     burntime = 40,
  16. })
  17.  
  18. minetest.register_craft({
  19.     type = "fuel",
  20.     recipe = "uranium:radioactive_coal",
  21.     burntime = 80,
  22. })
  23.  
  24. ---------------------------------------------------------------------------------------------------------
  25.  
  26. --01. Uranium Ore:
  27.  
  28. minetest.register_node( "uranium:uranium_ore", {
  29.     description = "Uranium Ore",
  30.     tile_images = { "default_stone.png^uranium_ore.png" },
  31.     is_ground_content = true,
  32.     groups = {cracky=3},
  33.     sounds = default.node_sound_stone_defaults(),
  34.     drop = 'craft "uranium:uranium_dust" 3',
  35. })
  36.  
  37. ---------------------------------------------------------------------------------------------------------
  38.  
  39. --02.Uranium Dust:
  40.  
  41. minetest.register_craftitem( "uranium:uranium_dust", {
  42.     description = "Uranium Dust",
  43.     inventory_image = "uranium_dust.png",
  44.     on_place_on_ground = minetest.craftitem_place_item,
  45. })
  46.  
  47. ---------------------------------------------------------------------------------------------------------
  48.  
  49. --03.Uranium Block:
  50.  
  51. minetest.register_node( "uranium:uranium_block", {
  52.     description = "Uranium Block",
  53.     tile_images = { "uranium_block.png" },
  54.     light_propagates = true,
  55.     paramtype = "light",
  56.     sunlight_propagates = true,
  57.     light_source = 15,
  58.     is_ground_content = true,
  59.     groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
  60.     sounds = default.node_sound_stone_defaults(),
  61. })
  62.  
  63.  
  64. minetest.register_craft( {
  65.     output = 'node "uranium:uranium_block" 1',
  66.     recipe = {
  67.         { 'uranium:uranium_dust', 'uranium:uranium_dust', 'uranium:uranium_dust' },
  68.         { 'uranium:uranium_dust', 'uranium:uranium_dust', 'uranium:uranium_dust' },
  69.         { 'uranium:uranium_dust', 'uranium:uranium_dust', 'uranium:uranium_dust' },
  70.     }
  71. })
  72. ---------------------------------------------------------------------------------------------------------
  73.  
  74. --04.Radioactive Coal:
  75.  
  76. minetest.register_craftitem( "uranium:radioactive_coal", {
  77.     description = "Radioactive Coal",
  78.     inventory_image = "uranium_coal.png",
  79.     on_place_on_ground = minetest.craftitem_place_item,
  80. })
  81.  
  82. ---------------------------------------------------------------------------------------------------------
  83.  
  84. --05.Uranium Gem:
  85.  
  86. minetest.register_craftitem( "uranium:uranium_gem", {
  87.     description = "Uranium Gem",
  88.     inventory_image = "uranium_gem.png",
  89.     on_place_on_ground = minetest.craftitem_place_item,
  90. })
  91.  
  92.  
  93. ---------------------------------------------------------------------------------------------------------
  94.  
  95. --05.Uranium Tools:
  96.  
  97. --Uranium Pick
  98. minetest.register_tool("uranium:uranium_pick", {
  99.     description = "Uranium Pickaxe",
  100.     inventory_image = "uranium_pickaxe.png",
  101.     tool_capabilities = {
  102.         max_drop_level=3,
  103.         groupcaps={
  104.             cracky={times={[1]=2.25, [2]=0.55, [3]=0.35}, uses=200, maxlevel=1}
  105.         }
  106.     },
  107. })
  108.  
  109. minetest.register_craft( {
  110.     output = 'craft "uranium:uranium_pick" 1',
  111.     recipe = {
  112.         { 'uranium:uranium_gem', 'uranium:uranium_gem', 'uranium:uranium_gem' },
  113.         { '', 'Stick', '' },
  114.         { '', 'Stick', '' },
  115.     }
  116. })
  117.  
  118. --Uranium Shovel
  119. minetest.register_tool("uranium:uranium_shovel", {
  120.     description = "Uranium Shovel",
  121.     inventory_image = "uranium_shovel.png",
  122.     tool_capabilities = {
  123.         max_drop_level=3,
  124.         groupcaps={
  125.             crumbly={times={[1]=0.70, [2]=0.35, [3]=0.20}, uses=200, maxlevel=1}
  126.         }
  127.     },
  128. })
  129.  
  130. minetest.register_craft( {
  131.     output = 'craft "uranium:uranium_shovel" 1',
  132.     recipe = {
  133.         { '', 'uranium:uranium_gem', '' },
  134.         { '', 'Stick', '' },
  135.         { '', 'Stick', '' },
  136.     }
  137. })
  138.  
  139. --Uranium Axe
  140. minetest.register_tool("uranium:uranium_axe", {
  141.     description = "Uranium Axe",
  142.     inventory_image = "uranium_axe.png",
  143.     tool_capabilities = {
  144.         max_drop_level=3,
  145.         groupcaps={
  146.             choppy={times={[1]=1.75, [2]=0.45, [3]=0.45}, uses=200, maxlevel=1},
  147.             fleshy={times={[2]=0.95, [3]=0.30}, uses=200, maxlevel=1}
  148.         }
  149.     },
  150. })
  151.  
  152. minetest.register_craft( {
  153.     output = 'craft "uranium:uranium_axe" 1',
  154.     recipe = {
  155.         { 'uranium:uranium_gem', 'uranium:uranium_gem', '' },
  156.         { 'uranium:uranium_gem', 'Stick', '' },
  157.         { '', 'Stick', '' },
  158.     }
  159. })
  160.  
  161. --Uranium Sword
  162. minetest.register_tool("uranium:uranium_sword", {
  163.     description = "Uranium Sword",
  164.     inventory_image = "uranium_sword.png",
  165.     tool_capabilities = {
  166.         full_punch_interval = 0.45,
  167.         max_drop_level=3,
  168.         groupcaps={
  169.             fleshy={times={[2]=0.65, [3]=0.25}, uses=200, maxlevel=1},
  170.             snappy={times={[2]=0.70, [3]=0.25}, uses=200, maxlevel=1},
  171.             choppy={times={[3]=0.65}, uses=200, maxlevel=0}
  172.         }
  173.     }
  174. })
  175.  
  176. minetest.register_craft( {
  177.     output = 'craft "uranium:uranium_sword" 1',
  178.     recipe = {
  179.         { '', 'uranium:uranium_gem', '' },
  180.         { '', 'uranium:uranium_gem', '' },
  181.         { '', 'Stick', '' },
  182.     }
  183. })
  184.  
  185. --Uranium Paxel
  186.  
  187. minetest.register_tool("uranium:uranium_paxel", {
  188.     description = "Uranium Paxel",
  189.     inventory_image = "uranium_paxel.png",
  190.     tool_capabilities = {
  191.         full_punch_interval = 0.45,
  192.         max_drop_level=3,
  193.         groupcaps={
  194.             fleshy={times={[2]=0.65, [3]=0.25}, uses=200, maxlevel=1},
  195.             snappy={times={[2]=0.70, [3]=0.25}, uses=200, maxlevel=1},
  196.             choppy={times={[3]=0.65}, uses=200, maxlevel=0}
  197.         }
  198.     }
  199. })
  200.  
  201. minetest.register_craft( {
  202.     output = 'craft "uranium:uranium_paxel" 1',
  203.     recipe = {
  204.         { 'uranium:uranium_shovel', 'uranium:uranium_pick', 'uranium:uranium_axe' },
  205.         { '', 'Stick', '' },
  206.         { '', 'Stick', '' },
  207.     }
  208. })
  209.  
  210. ---------------------------------------------------------------------------------------------------------
  211.  
  212. --06.Reactor:
  213.  
  214. uranium.uranium:reactor_inactive_formspec =
  215.     "invsize[8,9;]"..
  216.     "image[2,2;1,1;default_furnace_fire_bg.png]"..
  217.     "list[current_name;fuel;2,3;1,1;]"..
  218.     "list[current_name;src;2,1;1,1;]"..
  219.     "list[current_name;dst;5,1;2,2;]"..
  220.     "list[current_player;main;0,5;8,4;]"
  221.  
  222. minetest.register_node("uranium:reactor", {
  223.     description = "Reactor",
  224.     tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
  225.         "default_furnace_side.png", "default_furnace_side.png", "default_furnace_front.png"},
  226.     paramtype2 = "facedir",
  227.     groups = {cracky=2},
  228.     sounds = default.node_sound_stone_defaults(),
  229.     on_construct = function(pos)
  230.         local meta = minetest.env:get_meta(pos)
  231.         meta:set_string("formspec", uranium.uranium:reactor_inactive_formspec)
  232.         meta:set_string("infotext", "Reactor")
  233.         local inv = meta:get_inventory()
  234.         inv:set_size("fuel", 1)
  235.         inv:set_size("src", 1)
  236.         inv:set_size("dst", 4)
  237.     end,
  238.     can_dig = function(pos,player)
  239.         local meta = minetest.env:get_meta(pos);
  240.         local inv = meta:get_inventory()
  241.         if not inv:is_empty("fuel") then
  242.             return false
  243.         elseif not inv:is_empty("dst") then
  244.             return false
  245.         elseif not inv:is_empty("src") then
  246.             return false
  247.         end
  248.         return true
  249.     end,
  250. })
  251.  
  252. minetest.register_node("uranium:reactor_active", {
  253.     description = "Reactor",
  254.     tiles = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
  255.         "default_furnace_side.png", "default_furnace_side.png", "default_furnace_front_active.png"},
  256.     paramtype2 = "facedir",
  257.     light_source = 8,
  258.     drop = "uranium:reactor",
  259.     groups = {cracky=2},
  260.     sounds = default.node_sound_stone_defaults(),
  261.     on_construct = function(pos)
  262.         local meta = minetest.env:get_meta(pos)
  263.         meta:set_string("formspec", uranium.uranium:reactor_inactive_formspec)
  264.         meta:set_string("infotext", "Furnace");
  265.         local inv = meta:get_inventory()
  266.         inv:set_size("fuel", 1)
  267.         inv:set_size("src", 1)
  268.         inv:set_size("dst", 4)
  269.     end,
  270.     can_dig = function(pos,player)
  271.         local meta = minetest.env:get_meta(pos);
  272.         local inv = meta:get_inventory()
  273.         if not inv:is_empty("fuel") then
  274.             return false
  275.         elseif not inv:is_empty("dst") then
  276.             return false
  277.         elseif not inv:is_empty("src") then
  278.             return false
  279.         end
  280.         return true
  281.     end,
  282. })
  283.  
  284. function hacky_swap_node(pos,name)
  285.     local node = minetest.env:get_node(pos)
  286.     local meta = minetest.env:get_meta(pos)
  287.     local meta0 = meta:to_table()
  288.     if node.name == name then
  289.         return
  290.     end
  291.     node.name = name
  292.     local meta0 = meta:to_table()
  293.     minetest.env:set_node(pos,node)
  294.     meta = minetest.env:get_meta(pos)
  295.     meta:from_table(meta0)
  296. end
  297.  
  298. minetest.register_abm({
  299.     nodenames = {"uranium:reactor","uranium:reactor_active"},
  300.     interval = 1.0,
  301.     chance = 1,
  302.     action = function(pos, node, active_object_count, active_object_count_wider)
  303.         local meta = minetest.env:get_meta(pos)
  304.         for i, name in ipairs({
  305.                 "fuel_totaltime",
  306.                 "fuel_time",
  307.                 "src_totaltime",
  308.                 "src_time"
  309.         }) do
  310.             if meta:get_string(name) == "" then
  311.                 meta:set_float(name, 0.0)
  312.             end
  313.         end
  314.  
  315.         local inv = meta:get_inventory()
  316.  
  317.         local srclist = inv:get_list("src")
  318.         local cooked = nil
  319.        
  320.         if srclist then
  321.             cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
  322.         end
  323.        
  324.         local was_active = false
  325.        
  326.         if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
  327.             was_active = true
  328.             meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
  329.             meta:set_float("src_time", meta:get_float("src_time") + 1)
  330.             if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
  331.                 -- check if there's room for output in "dst" list
  332.                 if inv:room_for_item("dst",cooked.item) then
  333.                     -- Put result in "dst" list
  334.                     inv:add_item("dst", cooked.item)
  335.                     -- take stuff from "src" list
  336.                     srcstack = inv:get_stack("src", 1)
  337.                     srcstack:take_item()
  338.                     inv:set_stack("src", 1, srcstack)
  339.                 else
  340.                     print("Could not insert '"..cooked.item.."'")
  341.                 end
  342.                 meta:set_string("src_time", 0)
  343.             end
  344.         end
  345.        
  346.         if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
  347.             local percent = math.floor(meta:get_float("fuel_time") /
  348.                     meta:get_float("fuel_totaltime") * 100)
  349.             meta:set_string("infotext","Reactor active: "..percent.."%")
  350.             hacky_swap_node(pos,"uranium:reactor_active")
  351.             meta:set_string("formspec",
  352.                 "invsize[8,9;]"..
  353.                 "image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
  354.                         (100-percent)..":default_furnace_fire_fg.png]"..
  355.                 "list[current_name;fuel;2,3;1,1;]"..
  356.                 "list[current_name;src;2,1;1,1;]"..
  357.                 "list[current_name;dst;5,1;2,2;]"..
  358.                 "list[current_player;main;0,5;8,4;]")
  359.             return
  360.         end
  361.  
  362.         local fuel = nil
  363.         local cooked = nil
  364.         local fuellist = inv:get_list("fuel")
  365.         local srclist = inv:get_list("src")
  366.        
  367.         if srclist then
  368.             cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
  369.         end
  370.         if fuellist then
  371.             fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
  372.         end
  373.  
  374.         if fuel.time <= 0 then
  375.             meta:set_string("infotext","Reactor out of fuel")
  376.             hacky_swap_node(pos,"uranium:reactor")
  377.             meta:set_string("formspec", uranium.uranium:reactor_inactive_formspec)
  378.             return
  379.         end
  380.  
  381.         if cooked.item:is_empty() then
  382.             if was_active then
  383.                 meta:set_string("infotext","Reactor is empty")
  384.                 hacky_swap_node(pos,"uranium:reactor")
  385.                 meta:set_string("formspec", uranium.uranium:reactor_inactive_formspec)
  386.             end
  387.             return
  388.         end
  389.  
  390.         meta:set_string("fuel_totaltime", fuel.time)
  391.         meta:set_string("fuel_time", 0)
  392.        
  393.         local stack = inv:get_stack("fuel", 1)
  394.         stack:take_item()
  395.         inv:set_stack("fuel", 1, stack)
  396.     end,
  397. })
  398.  
  399.  
  400. -------------------------------------------    
  401. -- Ore generation
  402.  
  403. local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max)
  404.     if maxp.y < height_min or minp.y > height_max then
  405.         return
  406.     end
  407.     local y_min = math.max(minp.y, height_min)
  408.     local y_max = math.min(maxp.y, height_max)
  409.     local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
  410.     local pr = PseudoRandom(seed)
  411.     local num_chunks = math.floor(chunks_per_volume * volume)
  412.     local chunk_size = 3
  413.     if ore_per_chunk <= 4 then
  414.         chunk_size = 2
  415.     end
  416.     local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
  417.     --print("generate_ore num_chunks: "..dump(num_chunks))
  418.     for i=1,num_chunks do
  419.     if (y_max-chunk_size+1 <= y_min) then return end
  420.         local y0 = pr:next(y_min, y_max-chunk_size+1)
  421.         if y0 >= height_min and y0 <= height_max then
  422.             local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
  423.             local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
  424.             local p0 = {x=x0, y=y0, z=z0}
  425.             for x1=0,chunk_size-1 do
  426.             for y1=0,chunk_size-1 do
  427.             for z1=0,chunk_size-1 do
  428.                 if pr:next(1,inverse_chance) == 1 then
  429.                     local x2 = x0+x1
  430.                     local y2 = y0+y1
  431.                     local z2 = z0+z1
  432.                     local p2 = {x=x2, y=y2, z=z2}
  433.                     if minetest.env:get_node(p2).name == wherein then
  434.                         minetest.env:set_node(p2, {name=name})
  435.                     end
  436.                 end
  437.             end
  438.             end
  439.             end
  440.         end
  441.     end
  442.     --print("generate_ore done")
  443. end
  444.  
  445. minetest.register_on_generated(function(minp, maxp, seed)
  446. generate_ore("uranium:uranium_ore", "default:stone", minp, maxp, seed+21,   1/13/13/13,    5, -31000,  -150)
  447.  
  448. end)
RAW Paste Data