Advertisement
Doyousketch2

guide.lua

Jul 6th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.20 KB | None | 0 0
  1. local cube = minetest.inventorycube
  2.  
  3. -- the content of the guide
  4. local guide_infos = {
  5.     {
  6.         description = "mushroom",
  7.         {"text", "You can find the nether mushroom on the ground of the nether and on netherrack soil, it can be dug by hand."},
  8.         {"y", -0.3},
  9.         {"image", {1, 1, "riesenpilz_nether_shroom_side.png"}},
  10.         {"y", 0.2},
  11.         {"text", "If you drop it without holding aux1 (the fast key), you can split it into its stem and head:"},
  12.         {"image", {1, 1, "nether_shroom_top.png", 1}},
  13.         {"image", {1, 1, "nether_shroom_stem.png"}},
  14.         {"y", 0.2},
  15.         {"text", "You can get more mushrooms by using netherrack soil:\n"..
  16.             "1. search a dark place and, if necessary, place netherrack with air about it\n"..
  17.             "2. right click with cooked blood onto the netherrack to make it soiled\n"..
  18.             "3. right click onto the netherrack soil with a nether mushroom head to add some spores\n"..
  19.             "4. dig the mushroom which grew after some time to make place for another one"},
  20.         {"image", {1, 1, "riesenpilz_nether_shroom_side.png", 6, 0.12}},
  21.         {"y", 1},
  22.         {"image", {1, 1, "nether_netherrack.png^nether_netherrack_soil.png", 1.8}},
  23.         {"image", {1, 1, "nether_hotbed.png", 1.3, -0.4}},
  24.         {"image", {1, 1, "nether_netherrack.png^nether_netherrack_soil.png", 3.6}},
  25.         {"image", {1, 1, "nether_shroom_top.png", 3.1, -0.5}},
  26.         {"image", {1, 1, "nether_netherrack.png^nether_netherrack_soil.png", 6}},
  27.         {"image", {1, 1, "nether_netherrack.png"}},
  28.     },
  29.     {
  30.         description = "tools",
  31.         {"text", "You can craft 5 types of tools in the nether, which (except the mushroom pick) require sticks to be crafted:"},
  32.         {"y", 0.4},
  33.         {"image", {1, 1, "nether_pick_mushroom.png"}},
  34.         {"text", "strength: 1\n"..
  35.             "The mushroom pick needs mushroom stems and heads to be crafted."},
  36.         {"y", 0.2},
  37.         {"image", {1, 1, "nether_pick_wood.png"}},
  38.         {"text", "strength: 2\n"..
  39.             "The nether wood pick can be crafted with cooked nether blood wood."},
  40.         {"y", 0.2},
  41.         {"image", {1, 1, "nether_axe_netherrack.png", 1}},
  42.         {"image", {1, 1, "nether_shovel_netherrack.png", 2}},
  43.         {"image", {1, 1, "nether_sword_netherrack.png", 3}},
  44.         {"image", {1, 1, "nether_pick_netherrack.png"}},
  45.         {"text", "strength: 3\n"..
  46.             "The red netherrack tools can be crafted with usual netherrack."},
  47.         {"y", 0.2},
  48.         {"image", {1, 1, "nether_axe_netherrack_blue.png", 1}},
  49.         {"image", {1, 1, "nether_shovel_netherrack_blue.png", 2}},
  50.         {"image", {1, 1, "nether_sword_netherrack_blue.png", 3}},
  51.         {"image", {1, 1, "nether_pick_netherrack_blue.png"}},
  52.         {"text", "strength: 3\n"..
  53.             "The blue netherrack tools can be crafted with blue netherrack."},
  54.         {"y", 0.2},
  55.         {"image", {1, 1, "nether_axe_white.png", 1}},
  56.         {"image", {1, 1, "nether_shovel_white.png", 2}},
  57.         {"image", {1, 1, "nether_sword_white.png", 3}},
  58.         {"image", {1, 1, "nether_pick_white.png"}},
  59.         {"text", "strength: 3\n"..
  60.             "The siwtonic tools can be crafted with the siwtonic ore."},
  61.     },
  62.     {
  63.         description = "blood structures",
  64.         {"text", "You can find blood structures on the ground and dig their nodes even with the bare hand."},
  65.         {"y", 0.2},
  66.         {"text", "One contains 4 kinds of blocks:"},
  67.         {"image", {1, 1, cube("nether_blood.png"), 1}},
  68.         {"image", {1, 1,
  69.             cube("nether_blood_top.png", "nether_blood.png^nether_blood_side.png", "nether_blood.png^nether_blood_side.png"),
  70.             2}},
  71.         {"image", {1, 1, "nether_fruit.png", 3}},
  72.         {"image", {1, 1, cube("nether_blood_stem_top.png", "nether_blood_stem.png", "nether_blood_stem.png")}},
  73.         {"text", "the blood stem, blood, blood head and nether fruit"},
  74.         {"y", 0.2},
  75.         {"text", "You can craft the stem to 4 blood wood:"},
  76.         {"image", {1, 1, cube("nether_wood.png")}},
  77.         {"y", 0.2},
  78.         {"text", "The 4 blood nodes can be cooked and, except blood wood, their blood can be extracted."},
  79.     },
  80.     {
  81.         description = "fruit",
  82.         {"text", "You can find the nether fruit at blood structures and dig it even with the bare hand."},
  83.         {"y", 0.05},
  84.         {"image", {1, 1, "nether_fruit.png"}},
  85.         {"text", "You can eat it to get a bit blood because of its acid effect:"},
  86.         {"image", {1, 1, "nether_blood_extracted.png"}},
  87.         {"y", 0.2},
  88.         {"text", "If you eat it at the right place inside a portal, you teleport instead of getting blood."},
  89.         {"y", 0.2},
  90.         {"text", "If you drop it without holding aux1 (the fast key), you can split it into its fruit and leaf:"},
  91.         {"image", {1, 1, "nether_fruit_leaf.png", 1}},
  92.         {"image", {1, 1, "nether_fruit_no_leaf.png"}},
  93.         {"y", 0.2},
  94.         {"text", "9 fruit leaves can be crafted to a fruit leaves block and the fruit without leaf can be used for crafting a nether pearl."},
  95.         {"y", 0.2},
  96.         {"image", {1, 1, cube("nether_fruit_leaves.png")}},
  97.         {"text", "fruit leaves block"},
  98.     },
  99.     {
  100.         description = "cooking",
  101.         {"text", "To get a furnace you need to dig at least 8 netherrack bricks.\n"..
  102.             "They can be found at pyramid like constructions and require at least a strength 1 nether pick to be dug.\n"..
  103.             "For crafting the furnace, use the netherrack bricks like cobble:"},
  104.         {"y", 0.2},
  105.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 0.5}},
  106.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 1}},
  107.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png")}},
  108.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 1}},
  109.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png")}},
  110.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 0.5}},
  111.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 1}},
  112.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png")}},
  113.         {"y", 0.2},
  114.         {"text", "To begin cooking stuff, you can use a mushroom or fruit.\n"..
  115.             "After that it's recommended to use cooked blood nodes."},
  116.         {"y", 0.2},
  117.         {"text", "Some nether items can be cooked:"},
  118.         {"y", 0.1},
  119.         {"image", {1, 1, cube("nether_blood_stem_top_cooked.png", "nether_blood_stem_cooked.png", "nether_blood_stem_cooked.png"), 0.35}},
  120.         {"image", {1, 1, cube("nether_blood_cooked.png"), 1.6}},
  121.         {"image", {1, 1,
  122.             cube("nether_blood_top_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png"),
  123.             2.9}},
  124.         {"image", {1, 1, cube("nether_wood_cooked.png"), 4.3}},
  125.         {"y", 1},
  126.         {"text", "cooked blood stem, cooked blood, cooked blood head, cooked blood wood,"},
  127.         {"y", 0.2},
  128.         {"image", {1, 1, "nether_hotbed.png", 0.3}},
  129.         {"image", {1, 1, "nether_pearl.png", 2}},
  130.         {"y", 1},
  131.         {"text", "cooked extracted blood and nether pearl"},
  132.     },
  133.     {
  134.         description = "extractor",
  135.         {"text", "Here you can find out information about the nether extractor."},
  136.         {"y", 0.4},
  137.         {"text", "Here you can see its craft recipe:"},
  138.         {"y", 0.2},
  139.         {"image", {0.5, 0.5, cube("nether_blood_top_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png", "nether_blood_cooked.png^nether_blood_side_cooked.png"), 0.5}},
  140.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 1}},
  141.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png")}},
  142.         {"image", {0.5, 0.5, cube("nether_blood_extractor.png"), 2.5}},
  143.         {"image", {0.5, 0.5, "nether_shroom_stem.png", 0.5}},
  144.         {"image", {0.5, 0.5, cube("nether_blood_cooked.png"), 1}},
  145.         {"image", {0.5, 0.5, cube("nether_blood_cooked.png")}},
  146.         {"image", {0.5, 0.5, cube("nether_blood_stem_top_cooked.png", "nether_blood_stem_cooked.png", "nether_blood_stem_cooked.png"), 0.5}},
  147.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png"), 1}},
  148.         {"image", {0.5, 0.5, cube("nether_netherrack_brick.png")}},
  149.         {"y", 0.2},
  150.         {"text", "You can extract blood from the blood nodes you get from the blood structure.\n"..
  151.             "You can also get blood with a nether fruit."},
  152.         {"y", 0.2},
  153.         {"text", "So you can use it:\n"..
  154.             "1. place it somewhere\n"..
  155.             "2. place blood blocks next to it (4 or less)\n"..
  156.             "3. right click with extracted blood onto it to power it\n"..
  157.             "4. take the new extracted blood and dig the extracted nodes"},
  158.         {"y", 0.2},
  159.         {"text", "Example (view from the top):"},
  160.         {"y", 0.88},
  161.         {"image", {1, 1, "nether_blood_stem_top.png", 0.82, -0.88}},
  162.         {"image", {1, 1, "nether_blood.png", 1.63}},
  163.         {"image", {1, 1, "nether_blood_extractor.png", 0.82}},
  164.         {"image", {1, 1, "nether_blood_stem_top_empty.png", 3.82, -0.88}},
  165.         {"image", {1, 1, "nether_blood_empty.png", 4.63}},
  166.         {"image", {1, 1, "nether_blood_empty.png", 3.001}},
  167.         {"image", {1, 1, "nether_blood_extractor.png", 3.82}},
  168.         {"image", {1, 1, "nether_blood.png"}},
  169.         {"image", {1, 1, "nether_blood.png", 0.82, -0.12}},
  170.         {"image", {1, 1, "nether_blood_empty.png", 3.82, -0.12}},
  171.         {"y", 1.2},
  172.         {"text", "The empty blood stem can be crafted to empty nether wood, which can be crafted to nether sticks."},
  173.     },
  174.     {
  175.         description = "ores",
  176.         {"text", "You can find 5 types of ores:"},
  177.         {"y", 0.4},
  178.         {"image", {1, 1, cube("nether_netherrack_black.png"), 4}},
  179.         {"image", {1, 1, cube("nether_netherrack.png")}},
  180.         {"text", "The red netherrack is generated like stone and the black netherrack is generated like gravel.\n"..
  181.             "Both require at least a strength 2 nether pick to be dug."},
  182.         {"y", 0.2},
  183.         {"image", {1, 1, cube("nether_white.png"), 4}},
  184.         {"image", {1, 1, cube("nether_netherrack_blue.png")}},
  185.         {"text", "The blue netherrack is generated like diamond ore and the siwtonic ore is generated like mese blocks.\n"..
  186.             "Both require at least a strength 3 nether pick to be dug."},
  187.         {"y", 0.2},
  188.         {"image", {1, 1, cube("nether_netherrack_tiled.png"), 4}},
  189.         {"image", {1, 1, cube("glow_stone.png")}},
  190.         {"text", "The glow stone can be used for lighting and the tiled netherrack is generated like coal ore.\n"..
  191.             "Glow stone requires at least a strength 1 pick to be dug.\n"..
  192.             "Tiled netherrack requires at least a strength 2 nether pick to be dug."},
  193.     },
  194.     {
  195.         description = "vines",
  196.         {"text", "The nether vines can be fed with blood.\n"..
  197.             "They can be dug by hand and drop nether children."},
  198.         {"image", {1, 1, "nether_vine.png"}},
  199.         {"y", 0.2},
  200.         {"text", "To let a nether child grow to a blood structure, place it at a dark place onto a blood structure head node."},
  201.         {"image", {1, 1, "nether_sapling.png"}},
  202.         {"y", -0.11},
  203.         {"image", {1, 1, "nether_blood.png^nether_blood_side.png"}},
  204.     },
  205.     {
  206.         description = "pearl",
  207.         {"text", "The nether pearl can be thrown for teleporting.\n"..
  208.             "So cou can get one:"},
  209.         {"y", 0.4},
  210.         {"text", "At first you need to craft 2 mushroom heads and 1 nether fruit without leaf together:"},
  211.         {"image", {1, 1, "nether_shroom_top.png"}},
  212.         {"image", {1, 1, "nether_fim.png", 3}},
  213.         {"image", {1, 1, "nether_fruit_no_leaf.png"}},
  214.         {"image", {1, 1, "nether_shroom_top.png"}},
  215.         {"y", 0.2},
  216.         {"text", "Then you need to put the result into the furnance to cook it to a nether pearl:"},
  217.         {"image", {1, 1, "nether_pearl.png"}},
  218.     },
  219.     {
  220.         description = "bricks",
  221.         {"text", "You can craft bricks of red, black and blue netherrack."},
  222.         {"y", 0.4},
  223.         {"image", {1, 1, cube("nether_netherrack_brick_black.png"), 1}},
  224.         {"image", {1, 1, cube("nether_netherrack_brick_blue.png"), 2}},
  225.         {"image", {1, 1, cube("nether_netherrack_brick.png")}},
  226.         {"y", 0.2},
  227.         {"text", "These bricks require at least a strength 1 nether pick to be dug."},
  228.         {"y", 0.2},
  229.         {"text", "Because the crafing recipe of bricks is well known, it's not shown here."},
  230.     },
  231.     {
  232.         description = "portal",
  233.         {"text", "Here you can find out how to build the nether portal."},
  234.         {"y", 0.4},
  235.         {"text", "A nether portal requires following nodes:"},
  236.         {"y", 0.05},
  237.         {"text", "21 empty nether wooden planks\n"..
  238.             "12 blue netherrack bricks\n"..
  239.             "12 black netherrack\n"..
  240.             "8 red netherrack\n"..
  241.             "8 cooked nether wood\n"..
  242.             "4 nether fruits\n"..
  243.             "2 siwtonic blocks"},
  244.         {"y", 0.2},
  245.         {"text", "It should look approximately like this one:"},
  246.         {"image", {5.625, 6, "nether_teleporter.png", 0, -1.5}},
  247.         {"y", 5.5},
  248.         {"text", "You can activate it by standing in the middle on a siwtonic block and eating a nether fruit.\n"..
  249.             "Don't forget to take enough stuff with you to be able to build a portal back."},
  250.     },
  251.     {
  252.         description = "nether forest",
  253.         {"text", "The nether forest is generated in caves above the usual nether."},
  254.         {"y", 0.2},
  255.         {"text", "There you can find some plants:"},
  256.         {"y", 0.2},
  257.         {"image", {1, 1, "nether_grass_middle.png", 1}},
  258.         {"image", {1, 1, "nether_grass_big.png", 2}},
  259.         {"image", {1, 1, "nether_grass_small.png"}},
  260.         {"y", 0.2},
  261.         {"text", "The nether forest grass can be used to get paper.\n"..
  262.             "Just dig it, put the grass into the furnace and craft paper out of the dried grass.\n"..
  263.             "The recipe is similar to the one of crafting paper with papyrus."},
  264.         {"y", 0.2},
  265.         {"image", {1, 1, cube("nether_tree_top.png", "nether_tree.png", "nether_tree.png")}},
  266.         {"text", "Nether trunks can be found at nether trees, you can craft nether wood out of them."},
  267.         {"y", 0.2},
  268.         {"image", {1, 1, "nether_glowflower.png"}},
  269.         {"text", "Currently this flower can be used for lighting and decoration."},
  270.     },
  271. }
  272.  
  273. -- the size of guide pages
  274. local guide_size = {x=20, y=10, cx=0.1, cy=-0.2}
  275.  
  276. -- informations about settings and ...
  277. local formspec_offset = {x=0.25, y=0.55}
  278. local font_size
  279. if minetest.is_singleplayer() then
  280.     font_size = tonumber(minetest.setting_get("font_size")) or 14
  281. else
  282.     font_size = 14
  283. end
  284. guide_size.fx = 70
  285. -- math.floor((guide_size.x-2*(guide_size.cx+formspec_offset.x))*font_size)
  286. guide_size.fy = font_size/50
  287.  
  288. -- the default guide formspecs
  289. local guide_forms = {
  290.     contents = "size[3,"..(#guide_infos+1)*0.5 ..";]label["..guide_size.cx+0.8 ..","..guide_size.cy..";Contents:]",
  291. }
  292.  
  293. -- change the infos to formspecs
  294. for n,data in ipairs(guide_infos) do
  295.     local form = ""
  296.     local y = 0
  297.     local x = guide_size.cx
  298.     for _,i in ipairs(data) do
  299.         local typ, content = unpack(i)
  300.         if typ == "y" then
  301.             y = y+content
  302.         elseif typ == "x" then
  303.             x = math.max(x, content)
  304.         elseif typ == "text" then
  305.             local tab = minetest.splittext(content, guide_size.fx)
  306.             local l = guide_size.cx
  307.             for _,str in ipairs(tab) do
  308.                 form = form.."label["..guide_size.cx..","..guide_size.cy+y..";"..str.."]"
  309.                 y = y+guide_size.fy
  310.                 l = math.max(l, #str)
  311.             end
  312.             x = math.max(x+0.8, l/font_size)
  313.         elseif typ == "image" then
  314.             local w, h, texture_name, px, py = unpack(content)
  315.             if not px then
  316.                 form = form.."image["..guide_size.cx..","..guide_size.cy+y+h*0.3 ..";"..w..","..h..";"..texture_name.."]"
  317.                 y = y+h
  318.             else
  319.                 px = guide_size.cx+px
  320.                 py = py or 0
  321.                 form = form.."image["..px..","..
  322.                     guide_size.cy+y+h*0.3+py ..";"..w..","..h..";"..texture_name.."]"
  323.                 x = math.max(x+0.5, px+w)
  324.             end
  325.         end
  326.     end
  327.     form = "size["..x..","..y+1 ..";]"..form.."button["..x/2-0.5 ..","..y ..";1,2;quit;back]"
  328.     guide_forms[n] = {data.description, form}
  329. end
  330.  
  331. local desc_tab = {}
  332. for n,i in ipairs(guide_forms) do
  333.     desc_tab[i[1]] = n
  334. end
  335.  
  336. -- creates contents formspec
  337. local y = 0
  338. for y,i in ipairs(guide_forms) do
  339.     local desc, form = unpack(i)
  340.     local s = #desc/font_size+1.2
  341.     guide_forms.contents = guide_forms.contents.."button["..guide_size.cx+math.random()..","..guide_size.cy+y/2 ..";"..s..",1;name;"..desc.."]"
  342. end
  343.  
  344. -- shows the contents of the formspec
  345. local function show_guide(pname)
  346.     minetest.show_formspec(pname, "nether_guide_contents", guide_forms["contents"])
  347. end
  348.  
  349. minetest.register_on_player_receive_fields(function(player, formname, fields)
  350.     if formname == "nether_guide_contents" then
  351.         local fname = fields.name
  352.         local pname = player:get_player_name()
  353.         if fname
  354.         and pname then
  355.             minetest.show_formspec(pname, "nether_guide", guide_forms[desc_tab[fname]][2])
  356.         end
  357.     elseif formname == "nether_guide" then
  358.         local fname = fields.quit
  359.         local pname = player:get_player_name()
  360.         if fname
  361.         and pname then
  362.             minetest.show_formspec(pname, "nether_guide_contents", guide_forms["contents"])
  363.         end
  364.     end
  365. end)
  366.  
  367. minetest.register_chatcommand("nether_help", {
  368.     params = "",
  369.     description = "Shows a nether guide",
  370.     func = function(name)
  371.         local player = minetest.get_player_by_name(name)
  372.         if not player then
  373.             minetest.chat_send_player(name, "Something went wrong.")
  374.             return false
  375.         end
  376.         if player:getpos().y > nether.start then
  377.             minetest.chat_send_player(name, "Usually you don't neet this guide here. You can view it in the nether.")
  378.             return false
  379.         end
  380.         minetest.chat_send_player(name, "Showing guide...")
  381.         show_guide(name)
  382.         return true
  383.     end
  384. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement