├── LICENSE ├── README.md ├── bower.json ├── craft_guide ├── api_craft_guide.lua ├── depends.txt ├── init.lua ├── register_craft.lua ├── register_node.lua ├── screenshot.png └── textures │ ├── craft_guide_pc_black.png │ ├── craft_guide_pc_grey.png │ ├── craft_guide_pc_screen.png │ └── craft_guide_sign.png └── modpack.txt /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Brett O'Donnell http://cornernote.github.io 2 | All rights reserved. 3 | _____ _____ _____ _____ _____ _____ 4 | | |___| __ | | |___| __ | | |___|_ _|___ 5 | | --| . | -| | | | -_| -| | | | . | | | | -_| 6 | |_____|___|__|__|_|___|___|__|__|_|___|___| |_| |___| 7 | 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | * Redistributions of source code must retain the above copyright notice, this 13 | list of conditions and the following disclaimer. 14 | 15 | * Redistributions in binary form must reproduce the above copyright notice, this 16 | list of conditions and the following disclaimer in the documentation and/or 17 | other materials provided with the distribution. 18 | 19 | * Neither the name of the organization nor the names of its 20 | contributors may be used to endorse or promote products derived from 21 | this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Craft Guide for Minetest 2 | 3 | [![home](https://img.shields.io/badge/craft_guide-home-blue.svg?style=flat-square)](http://cornernote.github.io/minetest-craft_guide) 4 | [![download](https://img.shields.io/github/tag/cornernote/minetest-craft_guide.svg?style=flat-square&label=release)](https://github.com/cornernote/minetest-craft_guide/archive/master.zip) 5 | [![git](https://img.shields.io/badge/git-project-green.svg?style=flat-square)](https://github.com/cornernote/minetest-craft_guide) 6 | [![forum](https://img.shields.io/badge/minetest-mod-green.svg?style=flat-square)](https://forum.minetest.net/viewtopic.php?t=2334) 7 | [![bower](https://img.shields.io/badge/bower-mod-green.svg?style=flat-square)](https://minetest-bower.herokuapp.com/mods/craft_guide) 8 | 9 | 10 | ## Description 11 | 12 | Provides items that will show you how to craft any craftable or cookable item. 13 | 14 | 15 | ## Features 16 | 17 | - Provides craftable items that can be placed. 18 | - Placed items open like a chest, but instead of containing items, it contains a list of craftable items . 19 | - Items can be dragged into the `Output` slot, and the craft recipe will be displayed. 20 | 21 | 22 | ## Project Resources 23 | 24 | * [Home](http://cornernote.github.io/minetest-craft_guide) 25 | * [Download](https://github.com/cornernote/minetest-craft_guide/archive/master.zip) 26 | * [Project](https://github.com/cornernote/minetest-craft_guide) 27 | * [Forum](https://forum.minetest.net/viewtopic.php?t=2334) 28 | * [Bower](https://minetest-bower.herokuapp.com/mods/craft_guide) 29 | * 30 | 31 | ## Support 32 | 33 | - Does this README need improvement? Go ahead and [suggest a change](https://github.com/cornernote/minetest-craft_guide/edit/master/README.md). 34 | - Found a bug, or need help using this project? Check the [open issues](https://github.com/cornernote/minetest-craft_guide/issues) or [create an issue](https://github.com/cornernote/minetest-craft_guide/issues/new). 35 | 36 | 37 | ## About 38 | 39 | This module is open source, so it's distributed freely. If you find it useful then I ask not for your wealth, but simply to spare your time to consider the world we share by watching [Earthlings](http://earthlings.com/), a multi-award winning film available to watch online for free. A must-see for anyone who wishes to make the world a better place. 40 | 41 | 42 | ## License 43 | 44 | [BSD-3-Clause](https://raw.github.com/cornernote/minetest-craft_guide/master/LICENSE), Copyright © 2013-2014 [Brett O'Donnell](http://cornernote.github.io/) 45 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "craft_guide", 3 | "description": "Provides items that will show you how to craft any craftable or cookable item.", 4 | "keywords": [ 5 | "craft_guide" 6 | ], 7 | "homepage": "http://cornernote.github.io/minetest-craft_guide", 8 | "forum": "https://forum.minetest.net/viewtopic.php?t=2334", 9 | "screenshots": [ 10 | "http://cornernote.github.io/minetest-craft_guide/img/screenshot.png" 11 | ], 12 | "authors": [ 13 | "cornernote" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /craft_guide/api_craft_guide.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Craft Guide for Minetest 4 | 5 | Copyright (c) 2012 cornernote, Brett O'Donnell 6 | Source Code: https://github.com/cornernote/minetest-craft_guide 7 | License: BSD-3-Clause https://raw.github.com/cornernote/minetest-craft_guide/master/LICENSE 8 | 9 | CRAFT GUIDE API 10 | 11 | ]]-- 12 | 13 | 14 | 15 | 16 | 17 | -- expose object to other modules 18 | craft_guide = {} 19 | 20 | 21 | -- vvv INTERNAL SETTINGS vvv 22 | 23 | -- enable or disable you need feature 24 | 25 | craft_guide.you_need=true 26 | 27 | -- enable or disable copy craft recipe to crafting grid feature 28 | 29 | craft_guide.copy_button=true 30 | 31 | 32 | -- show items which only have have craft recipes of type "fuel". This are for example: tree trunks, saplings, .. etc. 33 | --Don't matter when craft_guide.show_fuel=false 34 | 35 | craft_guide.show_all_fuel_crafts=false 36 | 37 | 38 | -- don't show any recipes of type fuel in craft guide 39 | 40 | craft_guide.show_fuel=true 41 | 42 | 43 | --shows crafts other then normal crafts in crafting grid or of type "cooking" or "fuel". 44 | --at the moment this are crafts for machines from technic mod 45 | 46 | craft_guide.other_crafting_types=true 47 | 48 | 49 | --don't show crafts which are registered in moreblocks mod to get the original item back from its slabs, panels, microblocks, etc... 50 | --and don't show all ingots, dusts and blocks of uranium with different percentages 51 | craft_guide.remove_cluttering_crafts=true 52 | 53 | 54 | -- here you can define base items for "you need" feature 55 | 56 | --all items with this prefix are base items: 57 | 58 | craft_guide.basic_item_prefixes = { 59 | 60 | "dye:", 61 | 62 | } 63 | 64 | --all items which belong to this groups are base items 65 | 66 | craft_guide.basic_item_groups = { 67 | 68 | "wood", 69 | "stone", 70 | "stick", 71 | "tree", 72 | "sand", 73 | "glass", 74 | 75 | } 76 | 77 | --all items which end with these strings are base items 78 | 79 | craft_guide.basic_item_endings = { 80 | 81 | "ingot", 82 | "lump", 83 | "glass", 84 | "dust", 85 | 86 | } 87 | 88 | -- here you can define single items as base items. 89 | -- items without crafting recipe or items which match criterias from the tables above are base items too. 90 | 91 | craft_guide.basic_items = { 92 | 93 | "default:dirt", 94 | "default:sand", 95 | "default:cobble", 96 | "default:snowblock", 97 | "default:ice", 98 | "default:wood", 99 | "default:stone", 100 | "default:stick", 101 | "default:clay_brick", 102 | "default:gravel", 103 | "default:mossycobble", 104 | "default:desert_stone", 105 | "default:desert_cobble", 106 | "default:desert_sand", 107 | "default:diamond", 108 | "default:mese_crystal", 109 | "default:glass", 110 | "default:obsidian", 111 | "default:wheat", 112 | "bucket:bucket_water", 113 | "bucket:bucket_lava", 114 | "technic:uranium", 115 | "technic:raw_latex", 116 | "homedecor:roof_tile_terracotta", 117 | "homedecor:terracotta_base", 118 | "mesecons_materials:glue", 119 | "wool:white" 120 | } 121 | 122 | -- END OF SETTINGS SECTION 123 | 124 | 125 | 126 | 127 | -- define api variables 128 | craft_guide.crafts = {} 129 | 130 | craft_guide.alias = {} 131 | 132 | craft_guide.fuel = {} 133 | 134 | craft_guide.saved_you_need_lists = {} 135 | 136 | craft_guide.you_need_list = {} 137 | 138 | craft_guide.add_things=true 139 | 140 | craft_guide.fuel_to_add=false 141 | 142 | -- log 143 | craft_guide.log = function(message) 144 | --if not craft_guide.DEBUG then return end 145 | minetest.log("action", "[CraftGuide] "..message) 146 | end 147 | 148 | 149 | -- register_craft 150 | craft_guide.register_craft = function(options) 151 | if options.type == "fuel" and craft_guide.show_fuel and options.recipe~=nil then 152 | local itemstack = ItemStack(options.recipe) 153 | if itemstack:is_empty() then 154 | return 155 | end 156 | 157 | if craft_guide.fuel[itemstack:get_name()]==nil then 158 | craft_guide.fuel[itemstack:get_name()] = {} 159 | end 160 | table.insert(craft_guide.fuel[itemstack:get_name()],options) 161 | craft_guide.fuel_to_add=true 162 | return 163 | end 164 | 165 | if options.output == nil then 166 | return 167 | end 168 | local itemstack = ItemStack(options.output) 169 | if itemstack:is_empty() then 170 | return 171 | end 172 | --this should remove crafts which craft original item back from stairs, slabs, panels or micros, 173 | if craft_guide.remove_cluttering_crafts then 174 | local mod,_=string.find(itemstack:get_name(),":") 175 | if mod~=nil then 176 | mod=string.sub(itemstack:get_name(),1,mod) 177 | local recipestr="" 178 | if options.recipe[1]~=nil and type(options.recipe[1])=="string" then 179 | recipestr=" "..options.recipe[1] 180 | elseif options.recipe[1]~=nil and type(options.recipe[1][1])=="string" then 181 | recipestr=" "..options.recipe[1][1] 182 | elseif options.recipe[2]~=nil and type(options.recipe[2][1])=="string" then 183 | recipestr=" "..options.recipe[2][1] 184 | end 185 | if 186 | --dont show recipes for ingots, dusts and blocks of uranium with different percentages 187 | string.find(itemstack:get_name(),"technic:uranium._")==nil 188 | and string.find(itemstack:get_name(),"technic:uranium.._")==nil 189 | and 190 | 191 | (recipestr==""or (options.recipe~=nil and string.find(recipestr," "..mod.."panel_")==nil 192 | and string.find(recipestr," "..mod.."stair_")==nil 193 | and string.find(recipestr," "..mod.."micro_")==nil and string.find(recipestr," "..mod.."slab_")==nil 194 | and string.find(recipestr," moreblocks:panel_")==nil and string.find(recipestr," moreblocks:stair_")==nil 195 | and string.find(recipestr," moreblocks:micro_")==nil and string.find(recipestr," moreblocks:slab_")==nil)) then 196 | 197 | 198 | --craft_guide.log("registered craft for - "..itemstack:get_name()) 199 | if craft_guide.crafts[itemstack:get_name()]==nil then 200 | craft_guide.crafts[itemstack:get_name()] = {} 201 | end 202 | table.insert(craft_guide.crafts[itemstack:get_name()],options) 203 | end 204 | end 205 | 206 | end 207 | end 208 | 209 | 210 | -- register_alias 211 | craft_guide.register_alias = function(alias,convert_to) 212 | local count=#craft_guide.alias 213 | craft_guide.alias[count+1]=alias 214 | craft_guide.alias[count+2]=convert_to 215 | end 216 | 217 | -- get_craft_guide_formspec 218 | craft_guide.get_craft_guide_formspec = function(meta, search, page, alternate) 219 | if craft_guide.add_things then 220 | craft_guide.add_additional_crafts() 221 | end 222 | if search == nil then 223 | search = meta:get_string("search") 224 | end 225 | if meta:get_string("formspec")=="" then 226 | meta:set_string("owner","") 227 | meta:set_string("saved_search","|") 228 | meta:set_string("saved_page","1") 229 | meta:set_string("saved_pages","1") 230 | meta:set_string("switch","bookmarks") 231 | meta:set_string("poslist","down") 232 | meta:set_string("globalcount","1") 233 | meta:set_string("time","0") 234 | meta:set_string("method","Cook") 235 | meta:set_string("locked","0") 236 | meta:set_string("isowner","0") 237 | end 238 | if page == nil then 239 | page = craft_guide.get_current_page(meta) 240 | end 241 | if alternate == nil then 242 | alternate = craft_guide.get_current_alternate(meta) 243 | end 244 | local inv = meta:get_inventory() 245 | local size = inv:get_size("main") 246 | local start = (page-1) * (5*14) --was 1 too much before 247 | local pages = math.floor((size-1) / (5*14) + 1) 248 | local alternates = 0 249 | local stack = inv:get_stack("output",1) 250 | local crafts = craft_guide.crafts[stack:get_name()] 251 | if crafts ~= nil then 252 | alternates = #crafts 253 | end 254 | local backbutton="" 255 | if meta:get_string("saved_search")~="|" then 256 | backbutton="button[6.3,5.8;2.7,1;back_button;<--- Back]" 257 | end 258 | local changeable_part="" 259 | if meta:get_string("switch")=="youneed" and craft_guide.you_need then 260 | changeable_part="button[9.7,6.35;0.8,0.7;switch_to_bookmarks;>>]" 261 | .."tooltip[switch_to_bookmarks;Show your saved bookmarks]" 262 | if meta:get_string("poslist")=="down" then 263 | changeable_part= changeable_part.."label[8,6.5;You need:]" 264 | .."button[10.42,6.35;0.5,0.7;move_up;^]" 265 | .."tooltip[move_up;Move the list of needed items upwards]" 266 | .."label[11.4,6.0;Add to]" 267 | .."label[11.2,6.35;bookmarks]" 268 | .."label[12.6,6.05;->]" 269 | .."list[current_name;add;13,6;1,1;]" 270 | ..craft_guide.build_button_list(meta,inv,"youneed",12,29,8,7,6) 271 | 272 | else 273 | changeable_part= changeable_part.."button[10.42,6.35;0.5,0.7;move_down;v]" 274 | .."tooltip[move_down;Move the list of needed items downwards]" 275 | ..craft_guide.build_button_list(meta,inv,"youneed",12,29,0,1,14,0) 276 | end 277 | changeable_part= changeable_part..craft_guide.get_amounts(meta,inv,"youneed") 278 | 279 | end 280 | if meta:get_string("switch")=="bookmarks" or (not craft_guide.you_need) or meta:get_string("poslist")=="up" then 281 | 282 | changeable_part= changeable_part.."label[8,6.5;Bookmarks]" 283 | if craft_guide.you_need and meta:get_string("switch")=="bookmarks" then 284 | changeable_part= changeable_part.."button[9.7,6.35;0.8,0.7;switch_to_youneed;>>]" 285 | .."tooltip[switch_to_youneed;Show amount of basic items needed]" 286 | end 287 | changeable_part= changeable_part.."list[current_name;bookmark;8,7;6,3;]" 288 | .."label[12,6.1;Bin ->]" 289 | .."list[current_name;bin;13,6;1,1;]" 290 | end 291 | 292 | local formspec = "size[14,10;]" 293 | if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then 294 | formspec=formspec.."label[0.1,0.3;You need:]" 295 | else 296 | formspec=formspec.."list[current_name;main;0,0;14,5;"..tostring(start).."]" 297 | end 298 | formspec=formspec.."label[0,5;--== Learn to Craft ==--]" 299 | 300 | .."label[0,5.4;Drag any item to the Output box to see the]" 301 | .."label[0,5.8;craft. Save your favorite items in Bookmarks.]" 302 | 303 | .."field[6,5.4;2.3,1;craft_guide_search_box;;"..tostring(search).."]" 304 | .."button[7.8,5.1;1.2,1;craft_guide_search_button;Search]" 305 | ..backbutton 306 | .."label[9.1,5.2;page "..tostring(page).." of "..tostring(pages).."]" 307 | .."button[11,5;1.5,1;craft_guide_prev;<<]" 308 | .."button[12.5,5;1.5,1;craft_guide_next;>>]" 309 | 310 | if inv:get_stack("fuel",1)==nil or inv:get_stack("fuel",1):get_name()==nil or inv:get_stack("fuel",1):get_name()=="" then 311 | formspec=formspec.."label[0,6.5;Output]" 312 | end 313 | formspec=formspec.."list[current_name;output;0,7;1,1;]" 314 | 315 | .."label[2,6.5;Inventory Craft]" 316 | if not (inv:get_stack("additional",1)==nil or inv:get_stack("additional",1):get_name()==nil 317 | or inv:get_stack("additional",1):get_name()=="") then 318 | formspec=formspec.."list[current_name;additional;0.96,7;1,1;]" 319 | end 320 | formspec=formspec..craft_guide.build_button_list(meta,inv,"build",3,11,2,7,3) 321 | if not (inv:get_stack("cook",1)==nil or inv:get_stack("cook",1):get_name()==nil or inv:get_stack("cook",1):get_name()=="") 322 | or (inv:get_stack("fuel",1)==nil or inv:get_stack("fuel",1):get_name()==nil or inv:get_stack("fuel",1):get_name()=="") then 323 | formspec=formspec.."label["..tostring(6.22-string.len(meta:get_string("method"))*0.05)..",6.5;"..meta:get_string("method").."]" 324 | if not (inv:get_stack("cook",2)==nil or inv:get_stack("cook",2):get_name()==nil or inv:get_stack("cook",2):get_name()=="") then 325 | formspec=formspec..craft_guide.build_button_list(meta,inv,"cook",1,2,5.5,7,2) 326 | else 327 | formspec=formspec..craft_guide.build_button_list(meta,inv,"cook",1,1,6,7,1) 328 | end 329 | end 330 | --add flames from default mod for craft fuel 331 | if not (inv:get_stack("fuel",1)==nil or inv:get_stack("fuel",1):get_name()==nil or inv:get_stack("fuel",1):get_name()=="") then 332 | formspec=formspec.."label[6,6.5;Fuel]" 333 | ..craft_guide.build_button_list(meta,inv,"fuel",1,1,6,7,1) 334 | .."image[6.13,9.1;0.7,0.7;default_furnace_fire_fg.png]" 335 | if meta:get_string("time")~=nil and meta:get_string("time")~="nil" then 336 | formspec=formspec.."label[6.02,8.17;"..meta:get_string("time").." sec]" 337 | end 338 | end 339 | if not (inv:get_stack("cook",1)==nil or inv:get_stack("cook",1):get_name()==nil or inv:get_stack("cook",1):get_name()=="") then 340 | formspec=formspec.."list[current_name;machine;6,9;1,1;]" 341 | if meta:get_string("time")~=nil and meta:get_string("time")~="nil" then 342 | formspec=formspec.."label[6.02,8.17;"..meta:get_string("time").." sec]" 343 | end 344 | end 345 | if alternates > 1 then 346 | if alternate>alternates then 347 | alternate=1 348 | end 349 | formspec = formspec 350 | .."label[0,8;recipe "..tostring(alternate).." of "..tostring(alternates).."]" 351 | .."button[0,8.4;2,1;alternate;Alternate]" 352 | 353 | end 354 | 355 | if craft_guide.copy_button 356 | and inv:get_stack("output",1)~=nil and inv:get_stack("output",1):get_name()~=nil and inv:get_stack("output",1):get_name()~=nil then 357 | if craft_guide.crafts[inv:get_stack("output",1):get_name()]~=nil then 358 | if craft_guide.crafts[inv:get_stack("output",1):get_name()][alternate]~=nil then 359 | if (craft_guide.crafts[inv:get_stack("output",1):get_name()][alternate]).type==nil 360 | or (craft_guide.crafts[inv:get_stack("output",1):get_name()][alternate]).type=="shapeless" then 361 | formspec=formspec.."label[5.45,8.6;Prepare to craft:]" 362 | .."button[5.6,9.2;0.7,0.8;copy1;1]" 363 | .."button[6.2,9.2;0.7,0.8;copy10;10]" 364 | .."button[6.8,9.2;0.7,0.8;copy99;99]" 365 | end 366 | end 367 | end 368 | end 369 | formspec=formspec..changeable_part 370 | .."button_exit[0,9.2;1,0.8;close_mm;ESC]" 371 | 372 | 373 | meta:set_string("saved_formspec",formspec) 374 | --this needs to be added last, so it can be changed when restoring a locked formspec 375 | if meta:get_string("isowner")=="1" then 376 | if meta:get_string("locked")=="0" then 377 | formspec=formspec.."button[0.88,9.2;1.22,0.8;lock;Lock]" 378 | .."tooltip[lock;Lock Craft Guide in current state]" 379 | else 380 | formspec=formspec.."button[0.88,9.2;1.22,0.8;lock;Locked]" 381 | .."tooltip[lock;Craft Guide is locked - Press again to unlock]" 382 | end 383 | else 384 | if meta:get_string("locked")~="0" and meta:get_string("owner")~=nil and meta:get_string("owner")~="" then 385 | formspec=formspec.."label[0.88,9.2;Locked]" 386 | .."tooltip[close_mm; Owner: "..meta:get_string("owner").."]" 387 | end 388 | end 389 | 390 | 391 | return formspec 392 | end 393 | 394 | 395 | -- on_construct 396 | craft_guide.on_construct = function(pos) 397 | local meta = minetest.env:get_meta(pos) 398 | local inv = meta:get_inventory() 399 | inv:set_size("output", 1) 400 | inv:set_size("additional", 1) --here goes the second output of centrifuge recipe, just shown when needed 401 | inv:set_size("build", 3*3) 402 | inv:set_size("cook", 2*1) 403 | inv:set_size("fuel", 1) 404 | inv:set_size("machine", 1) 405 | inv:set_size("bookmark", 6*3) 406 | inv:set_size("youneed", 6*15) 407 | inv:set_size("bin", 1) 408 | inv:set_size("add", 1) 409 | inv:set_size("copylist", 9) 410 | inv:set_size("tempinv", 42) 411 | inv:set_size("tempmain", 32) 412 | inv:set_size("tempresult", 1) 413 | if meta:get_string("locked")~="1" then 414 | craft_guide.create_inventory(inv) 415 | end 416 | meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) 417 | meta:set_string("out","") 418 | meta:set_string("addindex","1") 419 | end 420 | 421 | 422 | -- on_receive_fields 423 | craft_guide.on_receive_fields = function(pos, formname, fields, player) 424 | local meta = minetest.env:get_meta(pos); 425 | if meta:get_string("locked")=="1" then 426 | craft_guide.save_meta(meta) 427 | end 428 | if minetest.get_node(pos).name=="craft_guide:sign_wall_locked" or minetest.get_node(pos).name=="craft_guide:lcd_pc_locked" then 429 | if meta:get_string("owner")=="" then 430 | meta:set_string("owner",player:get_player_name()) 431 | meta:set_string("isowner","1") 432 | elseif meta:get_string("owner")==player:get_player_name() then 433 | meta:set_string("isowner","1") 434 | end 435 | end 436 | local inv = meta:get_inventory() 437 | if inv:get_size("additional")==nil or inv:get_size("additional")~=1 then --old version, construct again 438 | local node=minetest.get_node(pos) 439 | minetest.set_node(pos, node) 440 | meta = minetest.env:get_meta(pos) 441 | inv = meta:get_inventory() 442 | end 443 | if inv:get_size("copylist")==nil or inv:get_size("copylist")~=9 then 444 | inv:set_size("copylist", 9) 445 | inv:set_size("tempinv", 42) 446 | inv:set_size("tempmain", 32) 447 | inv:set_size("tempresult", 1) 448 | end 449 | local size = inv:get_size("main",1) 450 | local stack = inv:get_stack("output",1) 451 | local crafts = craft_guide.crafts[stack:get_name()] 452 | local alternate = craft_guide.get_current_alternate(meta) 453 | local alternates = 0 454 | if crafts ~= nil then 455 | alternates = #crafts 456 | end 457 | 458 | local page = craft_guide.get_current_page(meta) 459 | local pages = math.floor((size-1) / (5*14) + 1) 460 | 461 | 462 | -- search 463 | local update_search=false 464 | local search 465 | search = fields.craft_guide_search_box 466 | if search~=nil then 467 | if string.lower(search)==string.upper(search) and tonumber(search)==nil and search~="*" then 468 | search="" 469 | end 470 | update_search=true 471 | else 472 | search=meta:get_string("search") 473 | end 474 | meta:set_string("search", search) 475 | if fields.craft_guide_search_button then 476 | if search==nil then 477 | meta:set_string("search", "") 478 | end 479 | if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then 480 | meta:set_string("switch","bookmarks") 481 | end 482 | meta:set_string("saved_search", "|") 483 | page = 1 484 | update_search=true 485 | end 486 | 487 | -- copy buttons: 488 | 489 | local copy=0 490 | if fields.copy99 then 491 | copy=99 492 | elseif fields.copy10 then 493 | copy=10 494 | elseif fields.copy1 then 495 | copy=1 496 | end 497 | if copy~=0 and player~=nil then 498 | local inv2=player:get_inventory() 499 | if inv2~=nil then 500 | for i=0,inv:get_size("copylist"),1 do 501 | inv:set_stack("copylist",i,ItemStack(nil)) 502 | end 503 | for i=0,inv:get_size("build"),1 do 504 | local stk=inv:get_stack("build", i) 505 | if stk:get_count()>0 then 506 | if string.sub(stk:get_name(),1,6)=="group:" then 507 | inv:set_stack("copylist",i,ItemStack(stk:get_name().."~|@q 1")) 508 | else 509 | inv:add_item("copylist",ItemStack(stk:get_name().."~|@q 1")) --trick, because stacksize of unknown items is 99 510 | end 511 | end 512 | end 513 | inv:set_list("tempinv",inv2:get_list("main")) 514 | for i=0,inv2:get_size("craft"),1 do 515 | local st=inv2:get_stack("craft",i) 516 | if st:get_count()>0 then 517 | inv:add_item("tempinv",st) 518 | end 519 | end 520 | local st=inv2:get_stack("craftresult",1) 521 | if st:get_count()>0 then 522 | inv:add_item("tempinv",st) 523 | end 524 | for i=0,inv:get_size("copylist"),1 do 525 | local stk=inv:get_stack("copylist", i) 526 | local stkcount=stk:get_count() 527 | if stkcount>0 then 528 | local stkname=stk:get_name() 529 | if string.sub(stkname,1,6)~="group:" then 530 | stk=ItemStack(string.sub(stkname,1,string.len(stkname)-4).." "..tostring(stkcount*copy)) 531 | inv:set_stack("copylist",i,ItemStack(nil)) 532 | local lastcheck=0 533 | local removed=0 534 | for x=1,9,1 do 535 | if stk:get_count()>stk:get_stack_max()+removed then 536 | stk=ItemStack(stk:get_name().." "..tostring(stk:get_stack_max())) 537 | else 538 | lastcheck=1 539 | end 540 | removed=removed+(inv:remove_item("tempinv",stk)):get_count() 541 | if lastcheck==1 or not (inv:contains_item("tempinv",ItemStack(stk:get_name().." 1"))) then 542 | break 543 | end 544 | end 545 | if copy>math.floor(removed/stkcount) then 546 | inv:add_item("tempinv",ItemStack(stk:get_name().." "..tostring(removed-(math.floor(removed/stkcount)*stkcount)))) 547 | for jj=0,i-1,1 do 548 | local oldstack=inv:get_stack("copylist", jj) 549 | if oldstack:get_count()>0 and string.sub(oldstack:get_name(),1,6)~="group:"then 550 | local newstack=ItemStack(oldstack:get_name().." "..tostring((copy-math.floor(removed/stkcount))*oldstack:get_count())) 551 | inv:add_item("tempinv", newstack) 552 | end 553 | end 554 | copy=math.floor(removed/stkcount) 555 | end 556 | lastcheck=0 557 | if copy<1 then 558 | break 559 | end 560 | 561 | end 562 | end 563 | end 564 | if copy>0 then 565 | for i=0,inv:get_size("copylist"),1 do 566 | local stk=inv:get_stack("copylist", i) 567 | local stkcount=stk:get_count() 568 | if stkcount>0 then 569 | local stkname=stk:get_name() 570 | if string.sub(stkname,1,6)=="group:" then 571 | local success=false 572 | local groups=string.sub(stkname,7,string.len(stkname)-4) 573 | for count=copy,0,-1 do 574 | for i2=0,inv:get_size("tempinv"),1 do 575 | local check=inv:get_stack("tempinv",i2) 576 | if check:get_count()>0 then 577 | local name=check:get_name() 578 | local hasgroup=1 579 | for group in string.gmatch(groups,"([^,]+)") do 580 | if minetest.get_item_group(name, group)==0 then 581 | hasgroup=0 582 | break 583 | end 584 | end 585 | if hasgroup==1 then 586 | 587 | if inv:contains_item("tempinv",ItemStack(name.." "..tostring(count))) then 588 | inv:remove_item("tempinv",ItemStack(name.." "..tostring(count))) 589 | inv:set_stack("copylist",i,ItemStack(name.." 1")) 590 | success=true 591 | break 592 | end 593 | end 594 | end 595 | end 596 | if copy>count then 597 | for jj=0,i-1,1 do 598 | local oldstack=inv:get_stack("copylist", jj) 599 | if oldstack:get_count()>0 and string.sub(oldstack:get_name(),1,6)~="group:" then 600 | local newstack=ItemStack(oldstack:get_name().." "..tostring((copy-count)*oldstack:get_count())) 601 | inv:add_item("tempinv", newstack) 602 | end 603 | end 604 | copy=count 605 | end 606 | if success or count<1 then 607 | break 608 | end 609 | 610 | end 611 | end 612 | end 613 | if copy<1 then 614 | break 615 | end 616 | end 617 | end 618 | if copy>0 then 619 | for i=0,inv:get_size("build"),1 do 620 | local stk=inv:get_stack("build", i) 621 | local stkcount=stk:get_count() 622 | if stkcount>0 then 623 | local stkname=stk:get_name() 624 | if string.sub(stkname,1,6)=="group:" then 625 | stk=inv:get_stack("copylist", i) 626 | stkname=stk:get_name() 627 | end 628 | 629 | stk=ItemStack(stkname.." "..tostring(copy)) 630 | inv:set_stack("copylist",i,stk) 631 | end 632 | end 633 | 634 | local clean=1 635 | if copy>0 then 636 | for i=0,inv:get_size("tempmain"),1 do 637 | inv:set_stack("tempmain",i,ItemStack(nil)) 638 | end 639 | 640 | local stk=inv2:get_stack("craftresult", 1) 641 | if stk:get_count()>0 then 642 | if inv:contains_item("tempinv",stk) then 643 | inv:remove_item("tempinv",stk) 644 | inv:add_item("tempresult",1,stk) 645 | else 646 | inv:add_item("tempresult",1,ItemStack(nil)) 647 | end 648 | end 649 | for i=0,inv2:get_size("main"),1 do --restore players main inventory 650 | local stk=inv2:get_stack("main", i) 651 | if stk:get_count()>0 then 652 | local removed=(inv:remove_item("tempinv",stk)):get_count() 653 | if removed>0 then 654 | inv:set_stack("tempmain",i,ItemStack(stk:get_name().." "..tostring(removed))) 655 | end 656 | end 657 | end 658 | for i=0,inv:get_size("tempinv"),1 do --check if items left in crafting grid can be moved to players inventory 659 | local stk=inv:get_stack("tempinv", i) 660 | if stk:get_count()>0 then 661 | if inv:room_for_item("tempmain",stk) then 662 | inv:add_item("tempmain",stk) 663 | inv:set_stack("tempinv",i,ItemStack(nil)) 664 | else 665 | clean=0 666 | end 667 | end 668 | end 669 | if clean==0 then 670 | local free=0 671 | for i=0,inv:get_size("tempmain"),1 do --check if two small stacks of same item can be joined to one big stack 672 | local stk=inv:get_stack("tempmain", i) 673 | if stk:get_count()>0 then 674 | if inv:room_for_item("tempmain",ItemStack(stk:get_name().." "..tostring(stk:get_stack_max()*(1+free)))) then 675 | inv:set_stack("tempmain",i,ItemStack(nil)) 676 | inv:add_item("tempmain",stk) 677 | free=free+1 678 | end 679 | end 680 | end 681 | for i=0,inv:get_size("build"),1 do --try to move more items to crafting grid 682 | local stk=inv:get_stack("build", i) 683 | local stkcount=stk:get_count() 684 | if stkcount>0 then 685 | local stkname=stk:get_name() 686 | stk=ItemStack(stkname.." 1") 687 | local stkmax=ItemStack(stkname.." "..tostring(stk:get_stack_max()-copy)) 688 | if inv:contains_item("tempinv",stk) then 689 | local removed=inv:remove_item("tempinv",stkmax) 690 | inv:set_stack("copylist",i,ItemStack(stkname.." "..tostring(removed:get_count()+copy))) 691 | elseif inv:contains_item("tempmain",stk) then 692 | local removed=inv:remove_item("tempmain",stkmax) 693 | inv:set_stack("copylist",i,ItemStack(stkname.." "..tostring(removed:get_count()+copy))) 694 | end 695 | end 696 | end 697 | 698 | for i=0,inv:get_size("tempinv"),1 do --last try to place all left items in main inventory 699 | local stk=inv:get_stack("tempinv", i) 700 | if stk:get_count()>0 then 701 | if inv:room_for_item("tempmain",stk) then 702 | inv:add_item("tempmain",stk) 703 | inv:set_stack("tempinv",i,ItemStack(nil)) 704 | else 705 | minetest.chat_send_player(player:get_player_name(), "Can't copy this recipe to crafting grid because your inventory is too full to move items around!") 706 | 707 | copy=0 708 | break 709 | end 710 | end 711 | end 712 | end 713 | if copy>0 then --we can successfully craft some of this item 714 | for i=0,inv:get_size("copylist"),1 do 715 | local stk=inv:get_stack("copylist", i) 716 | local stkcount=stk:get_count() 717 | if stkcount>copy then --if possible remove additional items back to inventory 718 | stk=ItemStack(stk:get_name().." 1") 719 | if inv:room_for_item("tempmain",stk) then 720 | local left=inv:add_item("tempmain",ItemStack(stk:get_name().." "..tostring(stkcount-copy))) 721 | if left~=nil and left~=0 then 722 | inv:set_stack("copylist", i,ItemStack(stk:get_name().." "..tostring(copy+left:get_count()))) 723 | end 724 | 725 | end 726 | end 727 | end 728 | 729 | --add wear and metadata to items again 730 | for t=0,42,1 do 731 | local tx=-10 732 | local invlist="tempmain" 733 | if t<=9 then 734 | invlist="copylist" 735 | tx=0 736 | end 737 | local itemStack=inv:get_stack(invlist, tx+t) 738 | if itemStack:get_count()==1 then 739 | if itemStack:get_stack_max()==1 then 740 | local itempos=t 741 | local found=false 742 | local itemStack2=ItemStack(nil) 743 | for slot=0,42,1 do 744 | if slot<=9 then 745 | itemStack2=inv2:get_stack("craft", slot) 746 | if itemStack2:get_name()==itemStack:get_name() then 747 | found=true 748 | end 749 | else 750 | itemStack2=inv2:get_stack("main", slot-10) 751 | if itemStack2:get_name()==itemStack:get_name() then 752 | found=true 753 | end 754 | end 755 | if found then 756 | found=false 757 | inv:set_stack(invlist, t+tx,itemStack2) 758 | for tt=itempos+1,42,1 do 759 | if tt<=9 then 760 | itemStack2=inv:get_stack("copylist", tt) 761 | if itemStack2:get_name()==itemStack:get_name() then 762 | itemStack=inv2:get_stack("copylist", tt) 763 | itempos=tt 764 | break 765 | end 766 | else 767 | itemStack2=inv:get_stack("tempmain",tt-10) 768 | if itemStack2:get_name()==itemStack:get_name() then 769 | itemStack=inv:get_stack("tempmain", tt-10) 770 | itempos=tt 771 | break 772 | end 773 | end 774 | end 775 | end 776 | end 777 | end 778 | end 779 | end 780 | --copy tempinventory to real inventory 781 | inv2:set_list("craft",inv:get_list("copylist")) 782 | inv2:set_list("main",inv:get_list("tempmain")) 783 | inv2:set_list("craftresult",inv:get_list("tempresult")) 784 | 785 | end 786 | end 787 | end 788 | end 789 | end 790 | 791 | 792 | -- change page 793 | if fields.craft_guide_prev then 794 | page = page - 1 795 | if page < 1 then 796 | page = pages 797 | end 798 | if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then 799 | meta:set_string("switch","bookmarks") 800 | end 801 | end 802 | 803 | if fields.craft_guide_next then 804 | page = page + 1 805 | if page > pages then 806 | page = 1 807 | end 808 | if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then 809 | meta:set_string("switch","bookmarks") 810 | end 811 | end 812 | 813 | if page > pages then 814 | page = pages 815 | end 816 | 817 | if page < 1 then 818 | page = 1 819 | end 820 | 821 | -- go back to search result 822 | if fields.back_button then 823 | if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then 824 | meta:set_string("switch","bookmarks") 825 | end 826 | local saved_search = meta:get_string("saved_search") 827 | if saved_search~="|" then 828 | search=saved_search 829 | meta:set_string("search", saved_search) 830 | page=tonumber(meta:get_string("saved_page")) 831 | pages=tonumber(meta:get_string("saved_pages")) 832 | meta:set_string("saved_search", "|") 833 | end 834 | update_search=true 835 | end 836 | 837 | --lock current state 838 | if fields.lock and meta:get_string("owner")==player:get_player_name() then 839 | if meta:get_string("locked")=="2" then 840 | meta:set_string("locked","0") 841 | else 842 | meta:set_string("locked","1") 843 | end 844 | end 845 | 846 | 847 | --toogle between bookmarks/you need 848 | if fields.switch_to_bookmarks then 849 | meta:set_string("switch","bookmarks") 850 | end 851 | 852 | if fields.switch_to_youneed then 853 | meta:set_string("switch","youneed") 854 | craft_guide.update_recipe(meta, player, stack, alternate) 855 | end 856 | 857 | --replacing bookmarks or main item list? 858 | if fields.move_up then 859 | if meta:get_string("switch")=="youneed" then 860 | meta:set_string("poslist","up") 861 | if meta:get_string("locked")~="0" then 862 | craft_guide.update_recipe(meta, player, stack, alternate) 863 | end 864 | end 865 | end 866 | 867 | if fields.move_down then 868 | if meta:get_string("switch")=="youneed" then 869 | meta:set_string("poslist","down") 870 | if meta:get_string("locked")~="0" then 871 | craft_guide.update_recipe(meta, player, stack, alternate) 872 | end 873 | end 874 | end 875 | 876 | 877 | -- get an alternate recipe 878 | if fields.alternate then 879 | alternate = alternate+1 880 | craft_guide.update_recipe(meta, player, stack, alternate) 881 | end 882 | if alternate > alternates then 883 | alternate = 1 884 | end 885 | 886 | --group buttons, finally a solution with a for loop 887 | local starts="" 888 | local ends="" 889 | local xx="" 890 | local formspec = meta:get_string("formspec") 891 | for button_number=1,29,1 do 892 | if fields[("t_758s"..tostring(button_number))] then 893 | --search the group name of pressed group button directly in formspec string 894 | xx,starts=string.find(formspec,"tooltip%[t_758s"..tostring(button_number)..";") 895 | if starts~=nil then 896 | ends,xx=string.find(formspec,"%]",starts+1) 897 | local group=string.lower(string.sub(formspec,starts+1,ends-2)) 898 | --displaying of items in a group is implemented in search function, just need to set search string 899 | meta:set_string("search", "group:"..group) 900 | --save old search string for restoring when "<-- back" is pressed 901 | if meta:get_string("saved_search")=="|" then 902 | meta:set_string("saved_search", search) 903 | meta:set_string("saved_page", tostring(page)) 904 | meta:set_string("saved_pages", tostring(pages)) 905 | end 906 | page = 1 907 | search="group:"..group 908 | update_search=true 909 | end 910 | break 911 | end 912 | end 913 | if starts~="" and meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then --button pressed, need to move back to bookmarks 914 | meta:set_string("switch","bookmarks") 915 | end 916 | -- update the formspec 917 | if meta:get_string("locked")=="2" and (fields["quit"] or fields.close_mm) then 918 | craft_guide.restore_meta(meta) 919 | else 920 | if update_search then 921 | craft_guide.create_inventory(inv, search) 922 | end 923 | meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta, search, page, alternate)) 924 | if meta:get_string("locked")=="1" then 925 | craft_guide.save_meta(meta) 926 | end 927 | end 928 | end 929 | 930 | 931 | -- returns formspec string of a inventory list with buttons for group items 932 | craft_guide.build_button_list = function(meta,inv,list,start_index,end_index,x,y,w,show_empty) 933 | --button numbers go from start_index to end_index 934 | --button numbers 1,(2)= cook or fuel 935 | --button numbers 3-11= inventory craft field 936 | --button numbers 12-29= you need items 937 | if show_empty~=0 then 938 | show_empty=1 939 | end 940 | local string="" 941 | for i=1,end_index-start_index+1,1 do 942 | local string_old=string 943 | local stack = inv:get_stack(list,i) 944 | if stack~=nil then 945 | local name=stack:get_name() 946 | if string.sub(name,1,6)=="group:" then 947 | local groups=string.sub(name,7) 948 | local saved="" 949 | for name,def in pairs(minetest.registered_items) do 950 | local hasgroup=1 951 | for group in string.gmatch(groups,"([^,]+)") do 952 | if minetest.get_item_group(name, group)==0 then 953 | hasgroup=0 954 | end 955 | end 956 | if hasgroup==1 then 957 | 958 | --prefer items from default mod 959 | if string.sub(name,1,8)=="default:" then 960 | --prefer items with simple short names, because cnc machines adds items under default prefix too 961 | if string.len(name)<20 then 962 | string=string.."item_image_button["..tostring(x+((i-1)%w)).."," 963 | ..tostring(y+math.floor((i-1)/w))..";1,1;" 964 | ..name..";t_758s"..tostring(i+start_index-1)..";group]" 965 | .."tooltip[t_758s"..tostring(i+start_index-1)..";" 966 | ..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]" 967 | 968 | saved="" 969 | break 970 | end 971 | elseif saved=="" then 972 | saved=name 973 | end 974 | end 975 | end 976 | if saved~="" then 977 | string=string.."item_image_button["..tostring(x+((i-1)%w)).."," 978 | ..tostring(y+math.floor((i-1)/w))..";1,1;"..saved..";t_758s"..tostring(i+start_index-1)..";group]" 979 | .."tooltip[t_758s"..tostring(i+start_index-1)..";" 980 | ..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]" 981 | end 982 | end 983 | end 984 | 985 | if string_old==string and ((stack~=nil and stack:get_name()~="") or show_empty==1) then 986 | string=string.."list[current_name;"..list..";"..tostring(x+((i-1)%w))..","..tostring(y+math.floor((i-1)/w)) 987 | ..";1,1;"..tostring(i-1).."]" 988 | end 989 | end 990 | return string 991 | end 992 | 993 | 994 | -- returns a formspec string with item amounts 995 | craft_guide.get_amounts = function(meta,inv,list) 996 | local amounts="" 997 | local xx=8.1 998 | local yy=7.45 999 | local w=6 1000 | local size=18 1001 | if meta:get_string("poslist")=="up" then 1002 | xx=0.1 1003 | yy=1.45 1004 | w=14 1005 | size=70 1006 | end 1007 | for jj=1,size,1 do 1008 | local item=string.lower(inv:get_stack(list,jj):get_name()) 1009 | local cnt=meta:get_string("globalcount") 1010 | if item==nil or item=="" then 1011 | break 1012 | end 1013 | local count=craft_guide.you_need_list[item] 1014 | if count~=nil then 1015 | cnt=math.floor(((count)/tonumber(meta:get_string("globalcount")))*1000+0.49)/1000 1016 | if cnt>1000 then 1017 | cnt=math.floor(cnt+0.49) 1018 | elseif cnt>100 then 1019 | cnt=math.floor(cnt*10+0.49)/10 1020 | elseif cnt>10 then 1021 | cnt=math.floor(cnt*100+0.49)/100 1022 | end 1023 | amounts=amounts.."label["..tostring(xx+((jj-1)%w))..","..tostring(yy+math.floor((jj-1)/w))..";"..tostring(cnt).."]" 1024 | end 1025 | jj=jj+1 1026 | if jj > size then 1027 | break 1028 | end 1029 | 1030 | end 1031 | return amounts 1032 | end 1033 | 1034 | 1035 | -- get_current_page 1036 | craft_guide.get_current_page = function(meta) 1037 | local formspec = meta:get_string("formspec") 1038 | local page = string.match(formspec, "label%[[%d.]+,[%d.]+;page (%d+) of [%d.]+%]") 1039 | page = tonumber(page) or 1 1040 | return page 1041 | end 1042 | 1043 | 1044 | -- get_current_alternate 1045 | craft_guide.get_current_alternate = function(meta) 1046 | local formspec = meta:get_string("formspec") 1047 | local alternate = string.match(formspec, "label%[[%d.]+,[%d.]+;recipe (%d+) of [%d.]+%]") 1048 | alternate = tonumber(alternate) or 1 1049 | return alternate 1050 | end 1051 | 1052 | 1053 | -- update_recipe 1054 | craft_guide.update_recipe = function(meta, player, stack, alternate) 1055 | local globalcount=1 1056 | local list={} 1057 | local list2={} 1058 | local test={} 1059 | local forlist={} 1060 | local inv = meta:get_inventory() 1061 | 1062 | for i=0,inv:get_size("build"),1 do 1063 | inv:set_stack("build", i, nil) 1064 | end 1065 | for i=0,inv:get_size("youneed"),1 do 1066 | inv:set_stack("youneed", i, nil) 1067 | end 1068 | 1069 | inv:set_stack("cook", 1, nil) 1070 | inv:set_stack("cook", 2, nil) 1071 | 1072 | inv:set_stack("fuel", 1, nil) 1073 | inv:set_stack("machine", 1, nil) 1074 | inv:set_stack("additional", 1, nil) 1075 | 1076 | meta:set_string("method","Cook") 1077 | 1078 | if stack==nil then return end 1079 | inv:set_stack("output", 1, stack:get_name()) 1080 | if alternate==nil then 1081 | alternate=craft_guide.get_current_alternate(meta) 1082 | end 1083 | alternate = tonumber(alternate) or 1 1084 | local crafts = craft_guide.crafts[stack:get_name()] 1085 | if crafts == nil then 1086 | if stack:get_name()~=nil and stack:get_name()~="" then 1087 | minetest.chat_send_player(player:get_player_name(), "no recipe available for "..stack:get_name()) 1088 | end 1089 | meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) 1090 | return 1091 | end 1092 | if alternate < 1 or alternate > #crafts then 1093 | alternate = 1 1094 | end 1095 | if stack:get_name()~=nil and stack:get_name()~="" then 1096 | if meta:get_string("switch")=="youneed" then 1097 | craft_guide.log(player:get_player_name().." shows needed items for recipe "..alternate.." for "..stack:get_name()) 1098 | else 1099 | craft_guide.log(player:get_player_name().." requests recipe "..alternate.." for "..stack:get_name()) 1100 | end 1101 | end 1102 | local craft = crafts[alternate] 1103 | 1104 | -- show me the unknown items 1105 | 1106 | --craft_guide.log(dump(craft)) 1107 | 1108 | --minetest.chat_send_player(player:get_player_name(), "recipe for "..stack:get_name()..": "..dump(craft)) 1109 | 1110 | local itemstack = ItemStack(craft.output) 1111 | inv:set_stack("output", 1, itemstack) 1112 | 1113 | if craft.type~=nil and craft.type~="shapeless" and craft.type~="fuel" then 1114 | -- cook 1115 | if craft.type=="cooking" then 1116 | if craft.cooktime==nil then 1117 | meta:set_string("time","3") 1118 | else 1119 | meta:set_string("time",tostring(craft.cooktime)) 1120 | end 1121 | inv:set_stack("cook", 1, craft.recipe) 1122 | if minetest.get_modpath("default") then 1123 | inv:set_stack("machine", 1, ItemStack("default:furnace")) 1124 | end 1125 | else 1126 | -- custom types added by technic mod 1127 | local input={} 1128 | if type(craft.input)~="table" or craft.input[1]==nil or craft.input[1]=="" then 1129 | table.insert(input,craft.input) 1130 | else 1131 | input=craft.input 1132 | end 1133 | if type(input)~="table" or input[1]==nil or input[1]=="" then 1134 | input={} 1135 | table.insert(input,craft.input) 1136 | end 1137 | 1138 | if craft.type=="Grinder" then 1139 | inv:set_stack("machine", 1, ItemStack("technic:lv_grinder")) 1140 | inv:set_stack("cook", 1, input[1]) 1141 | 1142 | elseif craft.type=="Extractor" then 1143 | inv:set_stack("machine", 1, ItemStack("technic:extractor")) 1144 | inv:set_stack("cook", 1, input[1]) 1145 | 1146 | elseif craft.type=="Compressor" then 1147 | inv:set_stack("machine", 1, ItemStack("technic:compressor")) 1148 | inv:set_stack("cook", 1, input[1]) 1149 | 1150 | elseif craft.type=="Alloy Furnace" then 1151 | inv:set_stack("machine", 1, ItemStack("technic:lv_alloy_furnace")) 1152 | inv:set_stack("cook", 1, craft.input[2]) 1153 | inv:set_stack("cook", 2, craft.input[1]) 1154 | 1155 | elseif craft.type=="Centrifuge" then 1156 | inv:set_stack("machine", 1, ItemStack("technic:mv_centrifuge")) 1157 | inv:set_stack("cook", 1, input[1]) 1158 | inv:set_stack("additional", 1, craft.output2) 1159 | end 1160 | 1161 | meta:set_string("method",craft.type) 1162 | meta:set_string("time",tostring(craft.time)) 1163 | meta:set_string("globalcount",tostring(ItemStack(craft.output):get_count())) 1164 | end 1165 | 1166 | else 1167 | -- fuel 1168 | if craft.type == "fuel" then 1169 | meta:set_string("time",tostring(craft.burntime)) 1170 | itemstack=ItemStack(craft.recipe) 1171 | inv:set_stack("output", 1, meta:get_string("out")) 1172 | inv:set_stack("fuel", 1, craft.recipe) 1173 | else 1174 | 1175 | -- build (shaped or shapeless) 1176 | if craft.recipe[1] then 1177 | if (type(craft.recipe[1]) == "string") then 1178 | inv:set_stack("build", 1, craft.recipe[1]) 1179 | else 1180 | if craft.recipe[1][1] then 1181 | inv:set_stack("build", 1, craft.recipe[1][1]) 1182 | end 1183 | if craft.recipe[1][2] then 1184 | inv:set_stack("build", 2, craft.recipe[1][2]) 1185 | end 1186 | if craft.recipe[1][3] then 1187 | inv:set_stack("build", 3, craft.recipe[1][3]) 1188 | end 1189 | end 1190 | end 1191 | if craft.recipe[2] then 1192 | if (type(craft.recipe[2]) == "string") then 1193 | inv:set_stack("build", 2, craft.recipe[2]) 1194 | else 1195 | if craft.recipe[2][1] then 1196 | inv:set_stack("build", 4, craft.recipe[2][1]) 1197 | end 1198 | if craft.recipe[2][2] then 1199 | inv:set_stack("build", 5, craft.recipe[2][2]) 1200 | end 1201 | if craft.recipe[2][3] then 1202 | inv:set_stack("build", 6, craft.recipe[2][3]) 1203 | end 1204 | end 1205 | end 1206 | if craft.recipe[3] then 1207 | if (type(craft.recipe[3]) == "string") then 1208 | inv:set_stack("build", 3, craft.recipe[3]) 1209 | else 1210 | if craft.recipe[3][1] then 1211 | inv:set_stack("build", 7, craft.recipe[3][1]) 1212 | end 1213 | if craft.recipe[3][2] then 1214 | inv:set_stack("build", 8, craft.recipe[3][2]) 1215 | end 1216 | if craft.recipe[3][3] then 1217 | inv:set_stack("build", 9, craft.recipe[3][3]) 1218 | end 1219 | end 1220 | end 1221 | if craft.recipe[4] then 1222 | if (type(craft.recipe[4]) == "string") then 1223 | inv:set_stack("build", 4, craft.recipe[4]) 1224 | end 1225 | end 1226 | if craft.recipe[5] then 1227 | if (type(craft.recipe[5]) == "string") then 1228 | inv:set_stack("build", 5, craft.recipe[5]) 1229 | end 1230 | end 1231 | if craft.recipe[6] then 1232 | if (type(craft.recipe[6]) == "string") then 1233 | inv:set_stack("build", 6, craft.recipe[6]) 1234 | end 1235 | end 1236 | if craft.recipe[7] then 1237 | if (type(craft.recipe[7]) == "string") then 1238 | inv:set_stack("build", 7, craft.recipe[7]) 1239 | end 1240 | end 1241 | if craft.recipe[8] then 1242 | if (type(craft.recipe[8]) == "string") then 1243 | inv:set_stack("build", 8, craft.recipe[8]) 1244 | end 1245 | end 1246 | if craft.recipe[9] then 1247 | if (type(craft.recipe[9]) == "string") then 1248 | inv:set_stack("build", 9, craft.recipe[9]) 1249 | end 1250 | end 1251 | end 1252 | end 1253 | if meta:get_string("switch")=="youneed" and craft_guide.you_need then 1254 | craft_guide.you_need_list=nil 1255 | craft_guide.you_need_list={} 1256 | local stack_name=stack:get_name() 1257 | -- get the saved list if we have it already, no need to calcalute all again 1258 | if craft_guide.saved_you_need_lists[stack_name.."@|²"..tostring(alternate)]~=nil then 1259 | craft_guide.you_need_list=craft_guide.saved_you_need_lists[stack_name.."@|²"..tostring(alternate)] 1260 | globalcount=tonumber(craft_guide.saved_you_need_lists[stack_name.."@|³"..tostring(alternate)]) 1261 | if globalcount==nil or globalcount<1 then 1262 | globalcount=1 1263 | end 1264 | local v=1 1265 | for _item,_ in pairs(craft_guide.you_need_list) do 1266 | inv:set_stack("youneed", v, _item) 1267 | v=v+1 1268 | end 1269 | else 1270 | list[stack_name] = {} 1271 | list[stack_name] = 1 1272 | for j=1,6,1 do --main iteration loop for resolving recipes into base items 1273 | local finished=1 1274 | local limit=inv:get_size("youneed") 1275 | local k=0 1276 | for name,count in pairs(list) do 1277 | if k>limit then 1278 | break 1279 | end 1280 | k=k+1 1281 | local isbase=0 1282 | if name==nil or name=="" or count==0 or string.sub(name,1,6)=="group:" then 1283 | isbase=1 1284 | elseif j>1 or k>1 then 1285 | for ii=1,999,1 do 1286 | if craft_guide.basic_item_prefixes[ii]==nil or craft_guide.basic_item_prefixes[ii]=="" then 1287 | break 1288 | elseif string.sub(name,1,string.len(craft_guide.basic_item_prefixes[ii]))== 1289 | string.lower(craft_guide.basic_item_prefixes[ii]) then 1290 | isbase=1 1291 | break 1292 | end 1293 | end 1294 | if isbase==0 then 1295 | for aa=1,999,1 do 1296 | if craft_guide.basic_item_groups[aa]==nil or craft_guide.basic_item_groups[aa]=="" then 1297 | break 1298 | elseif minetest.get_item_group(name, string.lower(craft_guide.basic_item_groups[aa]))>0 then 1299 | isbase=1 1300 | break 1301 | end 1302 | end 1303 | if isbase==0 then 1304 | for bb=1,999,1 do 1305 | if craft_guide.basic_item_endings[bb]==nil 1306 | or craft_guide.basic_item_endings[bb]=="" then 1307 | break 1308 | elseif string.sub(name,string.len(name)- 1309 | (string.len(craft_guide.basic_item_endings[bb])-1) )== 1310 | string.lower(craft_guide.basic_item_endings[bb]) then 1311 | isbase=1 1312 | break 1313 | end 1314 | end 1315 | if isbase==0 then 1316 | for cc=1,999,1 do 1317 | if craft_guide.basic_items[cc]==nil or craft_guide.basic_items[cc]=="" then 1318 | break 1319 | elseif name==string.lower(craft_guide.basic_items[cc]) then 1320 | isbase=1 1321 | break 1322 | end 1323 | end 1324 | end 1325 | end 1326 | end 1327 | end 1328 | crafts = craft_guide.crafts[name] 1329 | if crafts==nil or ((j>1 or k>1) and crafts[1].type~=nil 1330 | and crafts[1].type~="cooking" and crafts[1].type~="shapeless") then 1331 | isbase=1 1332 | end 1333 | if isbase==0 then 1334 | finished=0 1335 | if crafts ~= nil then 1336 | local istest=1 1337 | local bestcraft=1 1338 | local bestvalue=10 --lower is better 1339 | 1340 | 1341 | --too much tabs needed, starting here left again till this section is over 1342 | for craftnumber=1,#crafts+1,1 do 1343 | if craftnumber>49 then 1344 | craftnumber=#crafts+1 1345 | end 1346 | local index=craftnumber 1347 | if j>1 then 1348 | if #crafts==1 and index<=#crafts then 1349 | bestvalue=0 1350 | istest=0 1351 | elseif index>#crafts or bestvalue==0 then 1352 | index=bestcraft 1353 | bestvalue=0 1354 | istest=0 1355 | end 1356 | else 1357 | bestvalue=0 1358 | index=alternate 1359 | istest=0 1360 | end 1361 | local craft = crafts[index] 1362 | if craft~=nil and craft.type~="fuel" then 1363 | local amount=count 1364 | if istest==0 then 1365 | list[name]=0 1366 | local output_count=ItemStack(craft.output):get_count() 1367 | if output_count~=1 and (j>1 or k>1) then 1368 | if amount/output_count==math.floor(amount/output_count) then 1369 | amount=amount/output_count 1370 | else 1371 | globalcount=globalcount*output_count 1372 | for _name,_amount in pairs(list) do 1373 | if tonumber(amount)>0 then 1374 | list[_name]=tonumber(_amount)*output_count 1375 | end 1376 | end 1377 | end 1378 | end 1379 | end 1380 | if istest==1 then 1381 | list2=list 1382 | list=nil 1383 | list={} 1384 | list=test 1385 | end 1386 | if craft.type == "cooking" then 1387 | if list[craft.recipe]==nil then 1388 | list[(craft.recipe)]={} 1389 | list[(craft.recipe)]=amount 1390 | else 1391 | local add=amount+tonumber(list[(craft.recipe)]) 1392 | list[(craft.recipe)]=add 1393 | end 1394 | elseif craft.type ~=nil and craft.type ~= "fuel" and craft.type ~= "shapeless" then 1395 | local input=ItemStack(craft.input):get_name() 1396 | local _count=ItemStack(craft.input):get_count() 1397 | if input~=nil and input~="" then 1398 | if list[input]==nil then 1399 | list[input]={} 1400 | list[input]=amount*_count 1401 | else 1402 | local add=amount*_count+tonumber(list[input]) 1403 | list[input]=add 1404 | end 1405 | else 1406 | input=ItemStack(craft.input[1]):get_name() 1407 | _count=ItemStack(craft.input[1]):get_count() 1408 | if input~=nil and input~="" then 1409 | if list[input]==nil then 1410 | list[input]={} 1411 | list[input]=amount*_count 1412 | else 1413 | local add=amount*_count+tonumber(list[input]) 1414 | list[input]=add 1415 | end 1416 | input=ItemStack(craft.input[2]):get_name() 1417 | _count=ItemStack(craft.input[2]):get_count() 1418 | if input~=nil and input~="" then 1419 | if list[input]==nil then 1420 | list[input]={} 1421 | list[input]=amount*_count 1422 | else 1423 | local add=amount*_count+tonumber(list[input]) 1424 | list[input]=add 1425 | end 1426 | end 1427 | end 1428 | end 1429 | elseif craft.type==nil or craft.type=="shapeless" then 1430 | if craft.recipe[1] then 1431 | if (type(craft.recipe[1]) == "string") then 1432 | if list[craft.recipe[1]]==nil then 1433 | list[(craft.recipe[1])]={} 1434 | list[(craft.recipe[1])]=amount 1435 | else 1436 | local add =amount+tonumber(list[(craft.recipe[1])]) 1437 | list[(craft.recipe[1])]=add 1438 | end 1439 | else 1440 | if craft.recipe[1][1] then 1441 | if list[(craft.recipe[1][1])]==nil then 1442 | list[(craft.recipe[1][1])]={} 1443 | list[(craft.recipe[1][1])]=amount 1444 | else 1445 | local add =amount+tonumber(list[(craft.recipe[1][1])]) 1446 | list[(craft.recipe[1][1])]=add 1447 | end 1448 | end 1449 | if craft.recipe[1][2] then 1450 | if list[(craft.recipe[1][2])]==nil then 1451 | list[(craft.recipe[1][2])]={} 1452 | list[(craft.recipe[1][2])]=amount 1453 | else 1454 | local add =amount+tonumber(list[(craft.recipe[1][2])]) 1455 | list[(craft.recipe[1][2])]=add 1456 | end 1457 | end 1458 | if craft.recipe[1][3] then 1459 | if list[(craft.recipe[1][3])]==nil then 1460 | list[(craft.recipe[1][3])]={} 1461 | list[(craft.recipe[1][3])]=amount 1462 | else 1463 | local add =amount+tonumber(list[(craft.recipe[1][3])]) 1464 | list[(craft.recipe[1][3])]=add 1465 | end 1466 | end 1467 | end 1468 | end 1469 | if craft.recipe[2] then 1470 | if (type(craft.recipe[2]) == "string") then 1471 | if list[(craft.recipe[2])]==nil then 1472 | list[(craft.recipe[2])]={} 1473 | list[(craft.recipe[2])]=amount 1474 | else 1475 | local add =amount+tonumber(list[(craft.recipe[2])]) 1476 | list[(craft.recipe[2])]=add 1477 | end 1478 | else 1479 | if craft.recipe[2][1] then 1480 | if list[(craft.recipe[2][1])]==nil then 1481 | list[(craft.recipe[2][1])]={} 1482 | list[(craft.recipe[2][1])]=amount 1483 | else 1484 | local add =amount+tonumber(list[(craft.recipe[2][1])]) 1485 | list[(craft.recipe[2][1])]=add 1486 | end 1487 | end 1488 | if craft.recipe[2][2] then 1489 | if list[(craft.recipe[2][2])]==nil then 1490 | list[(craft.recipe[2][2])]={} 1491 | list[(craft.recipe[2][2])]=amount 1492 | else 1493 | local add =amount+tonumber(list[(craft.recipe[2][2])]) 1494 | list[(craft.recipe[2][2])]=add 1495 | end 1496 | end 1497 | if craft.recipe[2][3] then 1498 | if list[(craft.recipe[2][3])]==nil then 1499 | list[(craft.recipe[2][3])]={} 1500 | list[(craft.recipe[2][3])]=amount 1501 | else 1502 | local add =amount+tonumber(list[(craft.recipe[2][3])]) 1503 | list[(craft.recipe[2][3])]=add 1504 | end 1505 | end 1506 | end 1507 | end 1508 | if craft.recipe[3] then 1509 | if (type(craft.recipe[3]) == "string") then 1510 | if list[(craft.recipe[3])]==nil then 1511 | list[(craft.recipe[3])]={} 1512 | list[(craft.recipe[3])]=amount 1513 | else 1514 | local add =amount+tonumber(list[(craft.recipe[3])]) 1515 | list[(craft.recipe[3])]=add 1516 | end 1517 | else 1518 | if craft.recipe[3][1] then 1519 | if list[(craft.recipe[3][1])]==nil then 1520 | list[(craft.recipe[3][1])]={} 1521 | list[(craft.recipe[3][1])]=amount 1522 | else 1523 | local add =amount+tonumber(list[(craft.recipe[3][1])]) 1524 | list[(craft.recipe[3][1])]=add 1525 | end 1526 | end 1527 | if craft.recipe[3][2] then 1528 | if list[(craft.recipe[3][2])]==nil then 1529 | list[(craft.recipe[3][2])]={} 1530 | list[(craft.recipe[3][2])]=amount 1531 | else 1532 | local add =amount+tonumber(list[(craft.recipe[3][2])]) 1533 | list[(craft.recipe[3][2])]=add 1534 | end 1535 | end 1536 | if craft.recipe[3][3] then 1537 | if list[(craft.recipe[3][3])]==nil then 1538 | list[(craft.recipe[3][3])]={} 1539 | list[(craft.recipe[3][3])]=amount 1540 | else 1541 | local add =amount+tonumber(list[(craft.recipe[3][3])]) 1542 | list[(craft.recipe[3][3])]=add 1543 | end 1544 | end 1545 | end 1546 | end 1547 | if craft.recipe[4] then 1548 | if (type(craft.recipe[4]) == "string") then 1549 | if list[(craft.recipe[4])]==nil then 1550 | list[(craft.recipe[4])]={} 1551 | list[(craft.recipe[4])]=amount 1552 | else 1553 | local add =amount+tonumber(list[(craft.recipe[4])]) 1554 | list[(craft.recipe[4])]=add 1555 | end 1556 | end 1557 | end 1558 | if craft.recipe[5] then 1559 | if (type(craft.recipe[5]) == "string") then 1560 | if list[(craft.recipe[5])]==nil then 1561 | list[(craft.recipe[5])]={} 1562 | list[(craft.recipe[5])]=amount 1563 | else 1564 | local add =amount+tonumber(list[(craft.recipe[5])]) 1565 | list[(craft.recipe[5])]=add 1566 | end 1567 | end 1568 | end 1569 | if craft.recipe[6] then 1570 | if (type(craft.recipe[6]) == "string") then 1571 | if list[(craft.recipe[6])]==nil then 1572 | list[(craft.recipe[6])]={} 1573 | list[(craft.recipe[6])]=amount 1574 | else 1575 | local add =amount+tonumber(list[(craft.recipe[6])]) 1576 | list[(craft.recipe[6])]=add 1577 | end 1578 | end 1579 | end 1580 | if craft.recipe[7] then 1581 | if (type(craft.recipe[7]) == "string") then 1582 | if list[(craft.recipe[7])]==nil then 1583 | list[(craft.recipe[7])]={} 1584 | list[(craft.recipe[7])]=amount 1585 | else 1586 | local add =amount+tonumber(list[(craft.recipe[7])]) 1587 | list[(craft.recipe[7])]=add 1588 | end 1589 | end 1590 | end 1591 | if craft.recipe[8] then 1592 | if (type(craft.recipe[8]) == "string") then 1593 | if list[(craft.recipe[8])]==nil then 1594 | list[(craft.recipe[8])]={} 1595 | list[(craft.recipe[8])]=amount 1596 | else 1597 | local add =amount+tonumber(list[(craft.recipe[8])]) 1598 | list[(craft.recipe[8])]=add 1599 | end 1600 | end 1601 | end 1602 | if craft.recipe[9] then 1603 | if (type(craft.recipe[9]) == "string") then 1604 | if list[(craft.recipe[9])]==nil then 1605 | list[(craft.recipe[9])]={} 1606 | list[(craft.recipe[9])]=amount 1607 | else 1608 | local add =amount+tonumber(list[(craft.recipe[9])]) 1609 | list[(craft.recipe[9])]=add 1610 | end 1611 | end 1612 | end 1613 | end 1614 | if istest==1 then 1615 | test=list 1616 | list=nil 1617 | list={} 1618 | list=list2 1619 | end 1620 | end 1621 | 1622 | if istest==1 then 1623 | local value=0 1624 | local h=0 1625 | for name,testcount in pairs(test) do 1626 | h=h+1 1627 | if h>888 then 1628 | break 1629 | end 1630 | if testcount>0 then 1631 | if name.def==nil or (craft_guide.crafts[name]==nil 1632 | and string.sub(name,1,8)=="technic:") 1633 | then 1634 | bestvalue=10 1635 | h=999 1636 | else 1637 | local testcrafts = craft_guide.crafts[name] 1638 | local testcraft="" 1639 | if testcrafts~=nil then 1640 | testcraft=testcrafts[1] 1641 | end 1642 | local isbase=0 1643 | 1644 | 1645 | if name==nil or name=="" 1646 | or string.sub(name,1,6)=="group:" 1647 | or testcrafts==nil or testcraft==nil 1648 | or (testcraft.type~=nil and testcraft.type~="shapeless") 1649 | then 1650 | isbase=1 1651 | else 1652 | for ii=1,999,1 do 1653 | if craft_guide.basic_item_prefixes[ii]==nil or craft_guide.basic_item_prefixes[ii]=="" then 1654 | break 1655 | elseif string.sub(name,1,string.len(craft_guide.basic_item_prefixes[ii]))== 1656 | string.lower(craft_guide.basic_item_prefixes[ii]) then 1657 | isbase=1 1658 | break 1659 | end 1660 | end 1661 | if isbase==0 then 1662 | for aa=1,999,1 do 1663 | if craft_guide.basic_item_groups[aa]==nil or craft_guide.basic_item_groups[aa]=="" then 1664 | break 1665 | elseif minetest.get_item_group(name, string.lower(craft_guide.basic_item_groups[aa]))>0 then 1666 | isbase=1 1667 | break 1668 | end 1669 | end 1670 | if isbase==0 then 1671 | for bb=1,999,1 do 1672 | if craft_guide.basic_item_endings[bb]==nil or craft_guide.basic_item_endings[bb]=="" then 1673 | break 1674 | elseif string.sub(name,string.len(name)-(string.len(craft_guide.basic_item_endings[bb])-1))== 1675 | string.lower(craft_guide.basic_item_endings[bb]) then 1676 | isbase=1 1677 | break 1678 | end 1679 | end 1680 | if isbase==0 then 1681 | for cc=1,999,1 do 1682 | if craft_guide.basic_items[cc]==nil or craft_guide.basic_items[cc]=="" then 1683 | break 1684 | elseif name==string.lower(craft_guide.basic_items[cc]) then 1685 | isbase=1 1686 | break 1687 | end 1688 | end 1689 | end 1690 | end 1691 | end 1692 | end 1693 | 1694 | 1695 | if isbase==0 then 1696 | value=value+1 1697 | -- if string.find(name,"slab")~=nil 1698 | -- or string.find(name,"panel")~=nil 1699 | -- or string.find(name,"microblock")~=nil 1700 | -- or string.find(name,"stair")~=nil 1701 | -- then 1702 | -- value=value+5 1703 | -- end 1704 | end 1705 | end 1706 | end 1707 | end 1708 | 1709 | 1710 | --starting with correct tabs here again: 1711 | if value0 and string.lower(name)~=string.upper(name) then 1733 | local lower=string.lower(name) 1734 | if craft_guide.you_need_list[lower]~=nil and craft_guide.you_need_list[lower]>0 then 1735 | craft_guide.you_need_list[lower]=count+craft_guide.you_need_list[lower] 1736 | else 1737 | inv:add_item("youneed", lower) 1738 | if inv:get_stack("youneed",jj)==nil or inv:get_stack("youneed",jj):get_name()=="" then 1739 | for jjj=1,jj,1 do 1740 | if inv:get_stack("youneed",jjj):get_count()>1 then 1741 | local alias=string.lower(inv:get_stack("youneed",jjj):get_name()) 1742 | if craft_guide.you_need_list[alias]==nil then 1743 | craft_guide.you_need_list[alias]={} 1744 | craft_guide.you_need_list[alias]=count 1745 | inv:set_stack("youneed",jjj,alias) 1746 | else 1747 | craft_guide.you_need_list[alias]=craft_guide.you_need_list[alias]+count 1748 | inv:set_stack("youneed",jjj,alias) 1749 | end 1750 | end 1751 | end 1752 | inv:set_stack("youneed",jj,ItemStack(nil)) 1753 | duplicate=1 1754 | list[lower]=0 1755 | 1756 | elseif string.lower(inv:get_stack("youneed",jj):get_name())~=lower then 1757 | local alias=string.lower(inv:get_stack("youneed",jj):get_name()) 1758 | if craft_guide.you_need_list[alias]~=nil then 1759 | craft_guide.you_need_list[alias]=craft_guide.you_need_list[alias]+count 1760 | else 1761 | if list[alias]==nil then 1762 | craft_guide.you_need_list[alias]={} 1763 | craft_guide.you_need_list[alias]=count 1764 | inv:set_stack("youneed",jj,alias) 1765 | else 1766 | list[alias]=list[alias]+count 1767 | end 1768 | end 1769 | list[lower]=0 1770 | else 1771 | craft_guide.you_need_list[lower]={} 1772 | craft_guide.you_need_list[lower]=count 1773 | end 1774 | if duplicate==0 then 1775 | jj=jj+1 1776 | else 1777 | duplicate=0 1778 | end 1779 | if jj>inv:get_size("youneed") then 1780 | break 1781 | end 1782 | end 1783 | end 1784 | craft_guide.saved_you_need_lists[stack_name.."@|²"..tostring(alternate)]={} 1785 | craft_guide.saved_you_need_lists[stack_name.."@|²"..tostring(alternate)]=craft_guide.you_need_list 1786 | craft_guide.saved_you_need_lists[stack_name.."@|³"..tostring(alternate)]={} 1787 | craft_guide.saved_you_need_lists[stack_name.."@|³"..tostring(alternate)]=tostring(globalcount) 1788 | end 1789 | end 1790 | meta:set_string("globalcount",tostring(globalcount)) 1791 | meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) 1792 | end 1793 | 1794 | -- create_inventory 1795 | craft_guide.create_inventory = function(inv, search) 1796 | local craft_guide_list = {} 1797 | for name,def in pairs(minetest.registered_items) do 1798 | -- local craft_recipe = minetest.get_craft_recipe(name); 1799 | -- if craft_recipe.items ~= nil then 1800 | local craft = craft_guide.crafts[name]; 1801 | if (not def.groups.not_in_craft_guide or def.groups.not_in_craft_guide == 0) 1802 | and (craft ~= nil or (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)) 1803 | --and (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) 1804 | and def.description and def.description ~= "" then 1805 | if search and search~="" then 1806 | --search used to display groups of items 1807 | --if you enter something in search field it displays items without crafting recipes too 1808 | search=string.lower(search) 1809 | if string.sub(search,1,6)=="group:" then 1810 | local groups=string.sub(search,7) 1811 | local hasgroup=0 1812 | for group in string.gmatch(groups,"([^,]+)") do 1813 | if minetest.get_item_group(name, group)>0 then 1814 | hasgroup=1 1815 | else 1816 | hasgroup=0 1817 | break 1818 | end 1819 | end 1820 | if hasgroup==1 then 1821 | table.insert(craft_guide_list, name) 1822 | end 1823 | else 1824 | search=string.lower(search) 1825 | local test1=0 1826 | local test2=0 1827 | local test3=0 1828 | test1,test2=string.find(string.lower(def.name.." "), search) 1829 | test2,test3=string.find(string.lower(def.description.." "), search) 1830 | if (test1~=nil and test1>0) or (test2~=nil and test2>0) or search=="*" then 1831 | table.insert(craft_guide_list, name) 1832 | end 1833 | end 1834 | else 1835 | if craft~=nil and craft[1]~=nil and ((craft[1]).type~="fuel" or craft_guide.show_all_fuel_crafts) then 1836 | table.insert(craft_guide_list, name) 1837 | end 1838 | end 1839 | end 1840 | end 1841 | table.sort(craft_guide_list) 1842 | for i=0,inv:get_size("main"),1 do 1843 | inv:set_stack("main", i, nil) 1844 | end 1845 | inv:set_size("main", #craft_guide_list) 1846 | for _,itemstring in ipairs(craft_guide_list) do 1847 | inv:add_item("main", ItemStack(itemstring)) 1848 | end 1849 | end 1850 | 1851 | 1852 | -- add fuel recipes and recipes from technic machines to craft list 1853 | craft_guide.add_additional_crafts = function() 1854 | if craft_guide.other_crafting_types then 1855 | if minetest.get_modpath("technic") then 1856 | local oldversion=false 1857 | local recipelist={} 1858 | if technic.recipes==nil or technic.recipes["grinding"]==nil and technic.grinder_recipes~=nil then 1859 | oldversion=true 1860 | recipelist=technic.grinder_recipes 1861 | for t,recipe in pairs(recipelist) do 1862 | recipe.type="Grinder" 1863 | local name=ItemStack(recipe.output):get_name() 1864 | if name~=nil and name~="" then 1865 | if craft_guide.crafts[name]==nil then 1866 | craft_guide.crafts[name] = {} 1867 | end 1868 | recipe.time=recipe.time or 3 1869 | table.insert(craft_guide.crafts[name],recipe) 1870 | end 1871 | end 1872 | 1873 | else 1874 | recipelist=technic.recipes["grinding"].recipes 1875 | for t,recipe in pairs(recipelist) do 1876 | recipe.type="Grinder" 1877 | local name=ItemStack(recipe.output):get_name() 1878 | if name~=nil and name~="" and (not craft_guide.remove_cluttering_crafts 1879 | or (string.find(name,"technic:uranium._")==nil 1880 | and string.find(name,"technic:uranium.._")==nil)) then 1881 | if craft_guide.crafts[name]==nil then 1882 | craft_guide.crafts[name] = {} 1883 | end 1884 | local idx=1 1885 | for _name, _count in pairs(recipe.input) do 1886 | recipe.input[idx]=_name.." ".._count 1887 | break 1888 | end 1889 | recipe.time=recipe.time or 3 1890 | table.insert(craft_guide.crafts[name],recipe) 1891 | end 1892 | end 1893 | 1894 | end 1895 | 1896 | if oldversion then 1897 | for t,recipe in pairs(technic.compressor_recipes) do 1898 | recipe.type="Compressor" 1899 | local name=ItemStack(recipe.dst_name):get_name() 1900 | if name~=nil and name~="" then 1901 | if craft_guide.crafts[name]==nil then 1902 | craft_guide.crafts[name] = {} 1903 | end 1904 | recipe.input=t.." "..tostring(recipe.src_count) 1905 | recipe.output=recipe.dst_name.." "..tostring(recipe.dst_count) 1906 | recipe.time=recipe.time or 4 1907 | table.insert(craft_guide.crafts[name],recipe) 1908 | end 1909 | end 1910 | else 1911 | for t,recipe in pairs(technic.recipes["compressing"].recipes) do 1912 | recipe.type="Compressor" 1913 | local name=ItemStack(recipe.output):get_name() 1914 | if name~=nil and name~="" then 1915 | if craft_guide.crafts[name]==nil then 1916 | craft_guide.crafts[name] = {} 1917 | end 1918 | local idx=1 1919 | for _name, _count in pairs(recipe.input) do 1920 | recipe.input[idx]=_name.." ".._count 1921 | break 1922 | end 1923 | recipe.time=recipe.time or 4 1924 | table.insert(craft_guide.crafts[name],recipe) 1925 | end 1926 | end 1927 | 1928 | end 1929 | if oldversion then 1930 | for t,recipe in pairs(technic.extractor_recipes) do 1931 | recipe.type="Extractor" 1932 | local name=ItemStack(recipe.dst_name):get_name() 1933 | if name~=nil and name~="" then 1934 | if craft_guide.crafts[name]==nil then 1935 | craft_guide.crafts[name] = {} 1936 | end 1937 | recipe.input=t.." "..tostring(recipe.src_count) 1938 | recipe.output=recipe.dst_name.." "..tostring(recipe.dst_count) 1939 | recipe.time=recipe.time or 4 1940 | table.insert(craft_guide.crafts[name],recipe) 1941 | end 1942 | end 1943 | else 1944 | for t,recipe in pairs(technic.recipes["extracting"].recipes) do 1945 | recipe.type="Extractor" 1946 | local name=ItemStack(recipe.output):get_name() 1947 | if name~=nil and name~="" then 1948 | if craft_guide.crafts[name]==nil then 1949 | craft_guide.crafts[name] = {} 1950 | end 1951 | local idx=1 1952 | for _name, _count in pairs(recipe.input) do 1953 | recipe.input[idx]=_name.." ".._count 1954 | break 1955 | end 1956 | recipe.time=recipe.time or 4 1957 | table.insert(craft_guide.crafts[name],recipe) 1958 | end 1959 | end 1960 | 1961 | end 1962 | if oldversion then 1963 | recipelist=technic.alloy_recipes 1964 | for t,recipe in pairs(recipelist) do 1965 | recipe.type="Alloy Furnace" 1966 | local name=ItemStack(recipe.output):get_name() 1967 | if name~=nil and name~="" then 1968 | if craft_guide.crafts[name]==nil then 1969 | craft_guide.crafts[name] = {} 1970 | end 1971 | recipe.time=recipe.time or 6 1972 | table.insert(craft_guide.crafts[name],recipe) 1973 | end 1974 | end 1975 | else 1976 | recipelist=technic.recipes["alloy"].recipes 1977 | for t,recipe in pairs(recipelist) do 1978 | local rec={} 1979 | rec.type="Alloy Furnace" 1980 | local name=ItemStack(recipe.output):get_name() 1981 | if name~=nil and name~="" then 1982 | if craft_guide.crafts[name]==nil then 1983 | craft_guide.crafts[name] = {} 1984 | end 1985 | local idx=1 1986 | rec.output=recipe.output 1987 | rec.time=recipe.time or 6 1988 | rec.input={} 1989 | for _name, _count in pairs(recipe.input) do 1990 | rec.input[idx]=_name.." ".._count 1991 | idx=idx+1 1992 | if idx>2 then 1993 | break 1994 | end 1995 | end 1996 | table.insert(craft_guide.crafts[name],rec) 1997 | end 1998 | end 1999 | end 2000 | if not oldversion then 2001 | for t,recipe in pairs(technic.recipes["separating"].recipes) do 2002 | local rec={} 2003 | local rec2={} 2004 | 2005 | rec.type="Centrifuge" 2006 | rec2.type="Centrifuge" 2007 | local name=ItemStack(recipe.output[1]):get_name() 2008 | local name2=ItemStack(recipe.output[2]):get_name() 2009 | local count=ItemStack(recipe.output[1]):get_count() 2010 | local count2=ItemStack(recipe.output[2]):get_count() 2011 | if name~=nil and name~="" and (not craft_guide.remove_cluttering_crafts 2012 | or (string.find(name,"technic:uranium._")==nil 2013 | and string.find(name,"technic:uranium.._")==nil)) then 2014 | if craft_guide.crafts[name]==nil then 2015 | craft_guide.crafts[name] = {} 2016 | end 2017 | local idx=1 2018 | rec.input={} 2019 | rec2.input={} 2020 | for _name, _count in pairs(recipe.input) do 2021 | rec.input[idx]=_name.." ".._count 2022 | rec2.input[idx]=_name.." ".._count 2023 | break 2024 | end 2025 | rec.time=recipe.time or 10 2026 | rec2.time=recipe.time or 10 2027 | rec.output2=name2.." "..tostring(count2) 2028 | rec.output=name.." "..tostring(count) 2029 | table.insert(craft_guide.crafts[name],rec) 2030 | if name2~=nil and name2~="" and (not craft_guide.remove_cluttering_crafts 2031 | or (string.find(name2,"technic:uranium._")==nil 2032 | and string.find(name2,"technic:uranium.._")==nil)) then 2033 | if craft_guide.crafts[name2]==nil then 2034 | craft_guide.crafts[name2] = {} 2035 | end 2036 | rec2.output=name2.." "..tostring(count2) 2037 | rec2.output2=name.." "..tostring(count) 2038 | table.insert(craft_guide.crafts[name2],rec2) 2039 | end 2040 | end 2041 | end 2042 | 2043 | end 2044 | 2045 | end 2046 | end 2047 | 2048 | craft_guide.other_crafting_types = false 2049 | if craft_guide.fuel_to_add then 2050 | --add crafts with type "fuel" 2051 | for name,def in pairs(minetest.registered_items) do 2052 | if (not def.groups.not_in_craft_guide or def.groups.not_in_craft_guide == 0) then 2053 | if craft_guide.fuel[name]~=nil then 2054 | if craft_guide.crafts[name]==nil then 2055 | craft_guide.crafts[name] = {} 2056 | end 2057 | local fuels=craft_guide.fuel[name] 2058 | local fuel=fuels[1] 2059 | table.insert(craft_guide.crafts[name],fuel) 2060 | else 2061 | local best=0 2062 | local bestgroup="" 2063 | for group,_ in pairs(def.groups) do 2064 | if craft_guide.fuel["group:"..group]~=nil then 2065 | local fuels=craft_guide.fuel["group:"..group] 2066 | local fuel=fuels[1] 2067 | if fuel.burntime>best then 2068 | best=fuel.burntime 2069 | bestgroup=group 2070 | end 2071 | end 2072 | end 2073 | if bestgroup~="" then 2074 | if craft_guide.crafts[name]==nil then 2075 | craft_guide.crafts[name] = {} 2076 | end 2077 | local fuels=craft_guide.fuel["group:"..bestgroup] 2078 | local fuel=fuels[1] 2079 | table.insert(craft_guide.crafts[name],fuel) 2080 | end 2081 | end 2082 | end 2083 | end 2084 | end 2085 | 2086 | craft_guide.fuel_to_add=false 2087 | craft_guide.fuel=nil 2088 | craft_guide.fuel={} 2089 | -- all aliases should share the same crafting recipes 2090 | if craft_guide.add_things then 2091 | for i=1,9999,2 do 2092 | local alias=craft_guide.alias[i] 2093 | local convert_to=craft_guide.alias[i+1] 2094 | if alias~=nil and convert_to~=nil and (craft_guide.crafts[convert_to]~=nil or craft_guide.crafts[alias]~=nil) then 2095 | if craft_guide.crafts[convert_to]==nil and craft_guide.crafts[alias]~=nil then 2096 | craft_guide.crafts[convert_to]={} 2097 | elseif craft_guide.crafts[alias]==nil and craft_guide.crafts[convert_to]~=nil then 2098 | craft_guide.crafts[alias]={} 2099 | end 2100 | for ii=1,9999,1 do 2101 | local craft=(craft_guide.crafts[alias])[ii] 2102 | if craft==nil then 2103 | break 2104 | else 2105 | table.insert(craft_guide.crafts[convert_to],craft) 2106 | end 2107 | end 2108 | craft_guide.crafts[alias]={} 2109 | for ii=1,9999,1 do 2110 | local craft=(craft_guide.crafts[convert_to])[ii] 2111 | if craft==nil then 2112 | break 2113 | else 2114 | table.insert(craft_guide.crafts[alias],craft) 2115 | end 2116 | end 2117 | 2118 | end 2119 | end 2120 | end 2121 | craft_guide.add_things=false 2122 | end 2123 | 2124 | 2125 | -- allow_metadata_inventory_move 2126 | craft_guide.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) 2127 | local meta = minetest.env:get_meta(pos) 2128 | if meta:get_string("locked")=="1" then 2129 | craft_guide.save_meta(meta) 2130 | end 2131 | 2132 | local inv = meta:get_inventory() 2133 | if to_list == "bin" and from_list == "output" then 2134 | inv:set_stack(from_list,from_index,nil) 2135 | craft_guide.update_recipe(meta, player, inv:get_stack(from_list, from_index)) 2136 | end 2137 | if to_list == "bin" and from_list == "bookmark" then 2138 | inv:set_stack(from_list,from_index,nil) 2139 | inv:set_stack("add",1,nil)--clear this because bookmarks aren't full anymore 2140 | end 2141 | if to_list == "bookmark" and not inv:contains_item("bookmark",inv:get_stack(from_list, from_index):get_name()) then 2142 | inv:set_stack(to_list, to_index, inv:get_stack(from_list, from_index):get_name()) 2143 | if not inv:contains_item("bookmark",ItemStack(nil)) then 2144 | inv:set_stack("add", 1, inv:get_stack("bookmark", tonumber(meta:get_string("addindex"))):get_name()) 2145 | end 2146 | end 2147 | if to_list == "add" and not inv:contains_item("bookmark",inv:get_stack(from_list, from_index):get_name()) then 2148 | local index=tonumber(meta:get_string("addindex")) 2149 | local stack=inv:get_stack("bookmark",index) 2150 | local status=0 2151 | if stack~=nil and stack:get_name()~=nil and stack:get_name()~="" then 2152 | for i=1,inv:get_size("bookmark"),1 do 2153 | stack=inv:get_stack("bookmark",i) 2154 | if stack~=nil and stack:get_name()~=nil and stack:get_name()~="" then 2155 | else 2156 | if status==0 then 2157 | inv:set_stack("bookmark", i, inv:get_stack(from_list, from_index):get_name()) 2158 | meta:set_string("addindex",tostring(i)) 2159 | status=1 2160 | elseif status==1 then 2161 | status=2 2162 | end 2163 | end 2164 | end 2165 | if status==1 then --bookmarks are full now 2166 | inv:set_stack("add", to_index, inv:get_stack(from_list, from_index):get_name()) 2167 | elseif status==2 then --bookmarks has still empty slots after adding this stack 2168 | inv:set_stack("add", to_index, nil) 2169 | elseif status==0 then --bookmarks were already full, replace last added item 2170 | inv:set_stack("bookmark", index, inv:get_stack(from_list, from_index):get_name()) 2171 | inv:set_stack("add", to_index, inv:get_stack(from_list, from_index):get_name()) 2172 | end 2173 | else 2174 | inv:set_stack("bookmark", index, inv:get_stack(from_list, from_index):get_name()) 2175 | inv:set_stack("add", to_index, nil) 2176 | end 2177 | end 2178 | if to_list == "output" or from_list == "output" then 2179 | if from_list ~= "output" and to_list == "output" then 2180 | local name=inv:get_stack(from_list, from_index) 2181 | if name~=nil then 2182 | name=name:get_name() 2183 | end 2184 | if name~=nil then 2185 | meta:set_string("out",name) 2186 | inv:set_stack(to_list, to_index, nil) 2187 | end 2188 | end 2189 | if from_list == "output" and (to_list == "bin" or to_list=="add" ) then 2190 | meta:set_string("out","") 2191 | end 2192 | craft_guide.update_recipe(meta, player, inv:get_stack(from_list, from_index)) 2193 | end 2194 | if from_list == "bookmark" and to_list == "bookmark" then 2195 | return count 2196 | end 2197 | return 0 2198 | end 2199 | 2200 | 2201 | -- allow_metadata_inventory_put 2202 | craft_guide.allow_metadata_inventory_put = function(pos, listname, index, stack, player) 2203 | return 0 2204 | end 2205 | 2206 | 2207 | -- allow_metadata_inventory_take 2208 | craft_guide.allow_metadata_inventory_take = function(pos, listname, index, stack, player) 2209 | return 0 2210 | end 2211 | 2212 | craft_guide.save_meta = function (meta) 2213 | meta:set_string("saved_search2",meta:get_string("saved_search")) 2214 | meta:set_string("saved_page2",meta:get_string("saved_page")) 2215 | meta:set_string("saved_pages2",meta:get_string("saved_pages")) 2216 | meta:set_string("switch2",meta:get_string("switch")) 2217 | meta:set_string("poslist2",meta:get_string("poslist")) 2218 | meta:set_string("globalcount2",meta:get_string("globalcount")) 2219 | meta:set_string("time2",meta:get_string("time")) 2220 | meta:set_string("method2",meta:get_string("method")) 2221 | meta:set_string("out2",meta:get_string("out")) 2222 | meta:set_string("addindex2",meta:get_string("addindex")) 2223 | meta:set_string("search2",meta:get_string("search")) 2224 | local inv=meta:get_inventory() 2225 | inv:set_size("main2", inv:get_size("main")) 2226 | inv:set_size("output2", 1) 2227 | inv:set_size("additional2", 1) 2228 | inv:set_size("build2", 3*3) 2229 | inv:set_size("cook2", 2*1) 2230 | inv:set_size("fuel2", 1) 2231 | inv:set_size("machine2", 1) 2232 | inv:set_size("bookmark2", 6*3) 2233 | inv:set_size("youneed2", 6*15) 2234 | inv:set_size("bin2", 1) 2235 | inv:set_size("add2", 1) 2236 | for i=0,inv:get_size("main2"),1 do 2237 | inv:set_stack("main2", i, inv:get_stack("main",i)) 2238 | end 2239 | for i=0,inv:get_size("build2"),1 do 2240 | inv:set_stack("build2", i, inv:get_stack("build",i)) 2241 | end 2242 | for i=0,inv:get_size("bookmark2"),1 do 2243 | inv:set_stack("bookmark2", i, inv:get_stack("bookmark",i)) 2244 | end 2245 | for i=0,inv:get_size("youneed2"),1 do 2246 | inv:set_stack("youneed2", i, inv:get_stack("youneed",i)) 2247 | end 2248 | inv:set_stack("cook2", 1, inv:get_stack("cook",1)) 2249 | inv:set_stack("cook2", 2, inv:get_stack("cook",2)) 2250 | inv:set_stack("output2", 1, inv:get_stack("output",1)) 2251 | inv:set_stack("additional2", 1, inv:get_stack("additional",1)) 2252 | inv:set_stack("fuel2", 1, inv:get_stack("fuel",1)) 2253 | inv:set_stack("bin2", 1, inv:get_stack("bin",1)) 2254 | inv:set_stack("machine2", 1, inv:get_stack("machine",1)) 2255 | inv:set_stack("add2", 1, inv:get_stack("add",1)) 2256 | meta:set_string("locked","2") 2257 | meta:set_string("formspec2",meta:get_string("saved_formspec")) 2258 | 2259 | end 2260 | 2261 | craft_guide.restore_meta = function (meta) 2262 | meta:set_string("saved_search",meta:get_string("saved_search2")) 2263 | meta:set_string("saved_page",meta:get_string("saved_page2")) 2264 | meta:set_string("saved_pages",meta:get_string("saved_pages2")) 2265 | meta:set_string("switch",meta:get_string("switch2")) 2266 | meta:set_string("poslist",meta:get_string("poslist2")) 2267 | meta:set_string("globalcount",meta:get_string("globalcount2")) 2268 | meta:set_string("time",meta:get_string("time2")) 2269 | meta:set_string("method",meta:get_string("method2")) 2270 | meta:set_string("out",meta:get_string("out2")) 2271 | meta:set_string("addindex",meta:get_string("addindex2")) 2272 | meta:set_string("search",meta:get_string("search2")) 2273 | local inv=meta:get_inventory() 2274 | inv:set_size("main",inv:get_size("main2")) 2275 | for i=0,inv:get_size("main"),1 do 2276 | inv:set_stack("main", i, inv:get_stack("main2",i)) 2277 | end 2278 | for i=0,inv:get_size("build"),1 do 2279 | inv:set_stack("build", i, inv:get_stack("build2",i)) 2280 | end 2281 | for i=0,inv:get_size("bookmark"),1 do 2282 | inv:set_stack("bookmark", i, inv:get_stack("bookmark2",i)) 2283 | end 2284 | for i=0,inv:get_size("youneed"),1 do 2285 | inv:set_stack("youneed", i, inv:get_stack("youneed2",i)) 2286 | end 2287 | inv:set_stack("cook", 1, inv:get_stack("cook2",1)) 2288 | inv:set_stack("cook", 2, inv:get_stack("cook2",2)) 2289 | inv:set_stack("output", 1, inv:get_stack("output2",1)) 2290 | inv:set_stack("additional", 1, inv:get_stack("additional2",1)) 2291 | inv:set_stack("fuel", 1, inv:get_stack("fuel2",1)) 2292 | inv:set_stack("bin", 1, inv:get_stack("bin2",1)) 2293 | inv:set_stack("machine", 1, inv:get_stack("machine2",1)) 2294 | inv:set_stack("add", 1, inv:get_stack("add2",1)) 2295 | meta:set_string("isowner","0") 2296 | meta:set_string("locked","1") 2297 | local formspec= meta:get_string("formspec2") 2298 | meta:set_string("saved_formspec",formspec) 2299 | formspec=formspec.."label[0.88,9.2;Locked]" 2300 | .."tooltip[close_mm; Owner: "..meta:get_string("owner").."]" 2301 | meta:set_string("formspec",formspec) 2302 | 2303 | end 2304 | -------------------------------------------------------------------------------- /craft_guide/depends.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornernote/minetest-craft_guide/20520b5030f31a648b321f7a983b844efc3d52a9/craft_guide/depends.txt -------------------------------------------------------------------------------- /craft_guide/init.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Craft Guide for Minetest 4 | 5 | Copyright (c) 2012 cornernote, Brett O'Donnell 6 | Source Code: https://github.com/cornernote/minetest-craft_guide 7 | License: BSD-3-Clause https://raw.github.com/cornernote/minetest-craft_guide/master/LICENSE 8 | 9 | MAIN LOADER 10 | 11 | ]]-- 12 | 13 | -- load api 14 | dofile(minetest.get_modpath("craft_guide").."/api_craft_guide.lua") 15 | 16 | -- override minetest.register_craft 17 | local minetest_register_craft = minetest.register_craft 18 | minetest.register_craft = function (options) 19 | minetest_register_craft(options) 20 | craft_guide.register_craft(options) 21 | end 22 | 23 | -- override minetest.register_alias 24 | local minetest_register_alias = minetest.register_alias 25 | minetest.register_alias = function (name, convert_to) 26 | minetest_register_alias(name,convert_to) 27 | craft_guide.register_alias(name, convert_to) 28 | end 29 | 30 | -- register entities 31 | dofile(minetest.get_modpath("craft_guide").."/register_node.lua") 32 | dofile(minetest.get_modpath("craft_guide").."/register_craft.lua") 33 | 34 | -- log that we started 35 | minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded from "..minetest.get_modpath(minetest.get_current_modname())) 36 | -------------------------------------------------------------------------------- /craft_guide/register_craft.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Craft Guide for Minetest 4 | 5 | Copyright (c) 2012 cornernote, Brett O'Donnell 6 | Source Code: https://github.com/cornernote/minetest-craft_guide 7 | License: BSD-3-Clause https://raw.github.com/cornernote/minetest-craft_guide/master/LICENSE 8 | 9 | REGISTER CRAFTS 10 | 11 | ]]-- 12 | 13 | 14 | -- craft sign 15 | minetest.register_craft({ 16 | output = 'craft_guide:sign_wall', 17 | recipe = { 18 | {'group:stick', 'group:stick'}, 19 | {'group:stick', 'group:stick'}, 20 | {'group:stick', ''}, 21 | } 22 | }) 23 | 24 | 25 | -- craft pc 26 | minetest.register_craft({ 27 | output = 'craft_guide:lcd_pc', 28 | recipe = { 29 | {'craft_guide:sign_wall'}, 30 | {'default:glass'}, 31 | {'stairs:slab_stone'}, 32 | } 33 | }) 34 | 35 | -- craft sign 36 | minetest.register_craft({ 37 | type = 'shapeless', 38 | output = 'craft_guide:sign_wall_locked', 39 | recipe = { 40 | 'craft_guide:sign_wall', 41 | 'default:steel_ingot', 42 | } 43 | }) 44 | 45 | 46 | -- craft pc 47 | minetest.register_craft({ 48 | type = 'shapeless', 49 | output = 'craft_guide:lcd_pc_locked', 50 | recipe = { 51 | 'craft_guide:lcd_pc', 52 | 'default:steel_ingot', 53 | } 54 | }) 55 | 56 | minetest.register_craft({ 57 | output = 'craft_guide:lcd_pc_locked', 58 | recipe = { 59 | {'craft_guide:sign_wall_locked'}, 60 | {'default:glass'}, 61 | {'stairs:slab_stone'}, 62 | } 63 | }) 64 | 65 | -------------------------------------------------------------------------------- /craft_guide/register_node.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Craft Guide for Minetest 4 | 5 | Copyright (c) 2012 cornernote, Brett O'Donnell 6 | Source Code: https://github.com/cornernote/minetest-craft_guide 7 | License: BSD-3-Clause https://raw.github.com/cornernote/minetest-craft_guide/master/LICENSE 8 | 9 | REGISTER NODES 10 | 11 | ]]-- 12 | 13 | 14 | -- craft sign 15 | minetest.register_node("craft_guide:sign_wall", { 16 | description = "Craft Sign", 17 | drawtype = "signlike", 18 | tiles = {"craft_guide_sign.png"}, 19 | inventory_image = "craft_guide_sign.png", 20 | paramtype = 'light', 21 | paramtype2 = "wallmounted", 22 | sunlight_propagates = true, 23 | walkable = false, 24 | groups = {choppy=2,dig_immediate=2,book=1}, 25 | --sounds = default.node_sound_defaults(), 26 | selection_box = { 27 | type = "wallmounted", 28 | }, 29 | on_construct = craft_guide.on_construct, 30 | on_receive_fields = craft_guide.on_receive_fields, 31 | allow_metadata_inventory_move = craft_guide.allow_metadata_inventory_move, 32 | allow_metadata_inventory_put = craft_guide.allow_metadata_inventory_put, 33 | allow_metadata_inventory_take = craft_guide.allow_metadata_inventory_take, 34 | }) 35 | 36 | -- craft pc 37 | minetest.register_node("craft_guide:lcd_pc", { 38 | description = "Craft PC", 39 | drawtype = "nodebox", 40 | tiles = { 41 | "craft_guide_pc_grey.png", 42 | "craft_guide_pc_grey.png", 43 | "craft_guide_pc_grey.png", 44 | "craft_guide_pc_grey.png", 45 | "craft_guide_pc_black.png", 46 | "craft_guide_pc_screen.png", 47 | }, 48 | paramtype = 'light', 49 | paramtype2 = "facedir", 50 | sunlight_propagates = true, 51 | walkable = false, 52 | selection_box = {type="regular"}, 53 | groups = {choppy=2,dig_immediate=2}, 54 | -- thanks cactuz_pl for the nodebox code! =) 55 | node_box = { 56 | type = "fixed", 57 | fixed = { 58 | {-1.0000000e-1,-0.45259861,2.5136044e-2, 0.10000000,-2.5986075e-3,-2.4863956e-2}, 59 | {-0.40006064,-0.25615262,-0.13023723, -0.37006064,0.26767738,-0.16023723}, 60 | {0.37054221,-0.25615274,-0.13023723, 0.40054221,0.26767750,-0.16023723}, 61 | {-0.40000000,-0.30600000,-0.13023723, 0.40000000,-0.25600000,-0.16023723}, 62 | {-0.40000000,0.26433021,-0.12945597, 0.40000000,0.29433021,-0.15945597}, 63 | {-0.35000000,-0.25514168,-2.9045502e-2, 0.35000000,0.24485832,-7.9045502e-2}, 64 | {-0.40000000,-0.30617002,-8.0237234e-2, 0.40000000,0.29382998,-0.13023723}, 65 | {-0.25000000,-0.50000000,0.25000000, 0.25000000,-0.45000000,-0.25000000} 66 | }, 67 | }, 68 | --sounds = default.node_sound_defaults(), 69 | on_construct = craft_guide.on_construct, 70 | on_receive_fields = craft_guide.on_receive_fields, 71 | allow_metadata_inventory_move = craft_guide.allow_metadata_inventory_move, 72 | allow_metadata_inventory_put = craft_guide.allow_metadata_inventory_put, 73 | allow_metadata_inventory_take = craft_guide.allow_metadata_inventory_take, 74 | }) 75 | 76 | -- craft sign 77 | minetest.register_node("craft_guide:sign_wall_locked", { 78 | description = "Craft Sign (locked)", 79 | drawtype = "signlike", 80 | tiles = {"craft_guide_sign.png"}, 81 | inventory_image = "craft_guide_sign.png", 82 | paramtype = 'light', 83 | paramtype2 = "wallmounted", 84 | sunlight_propagates = true, 85 | walkable = false, 86 | groups = {choppy=2,dig_immediate=2,book=1}, 87 | --sounds = default.node_sound_defaults(), 88 | selection_box = { 89 | type = "wallmounted", 90 | }, 91 | on_construct = craft_guide.on_construct, 92 | on_receive_fields = craft_guide.on_receive_fields, 93 | allow_metadata_inventory_move = craft_guide.allow_metadata_inventory_move, 94 | allow_metadata_inventory_put = craft_guide.allow_metadata_inventory_put, 95 | allow_metadata_inventory_take = craft_guide.allow_metadata_inventory_take, 96 | }) 97 | 98 | -- craft pc 99 | minetest.register_node("craft_guide:lcd_pc_locked", { 100 | description = "Craft PC (locked)", 101 | drawtype = "nodebox", 102 | tiles = { 103 | "craft_guide_pc_grey.png", 104 | "craft_guide_pc_grey.png", 105 | "craft_guide_pc_grey.png", 106 | "craft_guide_pc_grey.png", 107 | "craft_guide_pc_black.png", 108 | "craft_guide_pc_screen.png", 109 | }, 110 | paramtype = 'light', 111 | paramtype2 = "facedir", 112 | sunlight_propagates = true, 113 | walkable = false, 114 | selection_box = {type="regular"}, 115 | groups = {choppy=2,dig_immediate=2}, 116 | -- thanks cactuz_pl for the nodebox code! =) 117 | node_box = { 118 | type = "fixed", 119 | fixed = { 120 | {-1.0000000e-1,-0.45259861,2.5136044e-2, 0.10000000,-2.5986075e-3,-2.4863956e-2}, 121 | {-0.40006064,-0.25615262,-0.13023723, -0.37006064,0.26767738,-0.16023723}, 122 | {0.37054221,-0.25615274,-0.13023723, 0.40054221,0.26767750,-0.16023723}, 123 | {-0.40000000,-0.30600000,-0.13023723, 0.40000000,-0.25600000,-0.16023723}, 124 | {-0.40000000,0.26433021,-0.12945597, 0.40000000,0.29433021,-0.15945597}, 125 | {-0.35000000,-0.25514168,-2.9045502e-2, 0.35000000,0.24485832,-7.9045502e-2}, 126 | {-0.40000000,-0.30617002,-8.0237234e-2, 0.40000000,0.29382998,-0.13023723}, 127 | {-0.25000000,-0.50000000,0.25000000, 0.25000000,-0.45000000,-0.25000000} 128 | }, 129 | }, 130 | --sounds = default.node_sound_defaults(), 131 | on_construct = craft_guide.on_construct, 132 | on_receive_fields = craft_guide.on_receive_fields, 133 | allow_metadata_inventory_move = craft_guide.allow_metadata_inventory_move, 134 | allow_metadata_inventory_put = craft_guide.allow_metadata_inventory_put, 135 | allow_metadata_inventory_take = craft_guide.allow_metadata_inventory_take, 136 | }) 137 | -------------------------------------------------------------------------------- /craft_guide/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornernote/minetest-craft_guide/20520b5030f31a648b321f7a983b844efc3d52a9/craft_guide/screenshot.png -------------------------------------------------------------------------------- /craft_guide/textures/craft_guide_pc_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornernote/minetest-craft_guide/20520b5030f31a648b321f7a983b844efc3d52a9/craft_guide/textures/craft_guide_pc_black.png -------------------------------------------------------------------------------- /craft_guide/textures/craft_guide_pc_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornernote/minetest-craft_guide/20520b5030f31a648b321f7a983b844efc3d52a9/craft_guide/textures/craft_guide_pc_grey.png -------------------------------------------------------------------------------- /craft_guide/textures/craft_guide_pc_screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornernote/minetest-craft_guide/20520b5030f31a648b321f7a983b844efc3d52a9/craft_guide/textures/craft_guide_pc_screen.png -------------------------------------------------------------------------------- /craft_guide/textures/craft_guide_sign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornernote/minetest-craft_guide/20520b5030f31a648b321f7a983b844efc3d52a9/craft_guide/textures/craft_guide_sign.png -------------------------------------------------------------------------------- /modpack.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornernote/minetest-craft_guide/20520b5030f31a648b321f7a983b844efc3d52a9/modpack.txt --------------------------------------------------------------------------------