Image in formspec

User avatar
kotolegokot
Member
 
Posts: 131
Joined: Mon Jul 02, 2012 17:03

Image in formspec

by kotolegokot » Mon Oct 15, 2012 16:30

Image
Image
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_node("anvil:self", {
    description = "Anvil",
    tiles = {"anvil_top.png","anvil_top.png","anvil_side.png"},
    drawtype = "nodebox",
    paramtype = "light",
    paramtype2 = "facedir",
    node_box = {
        type = "fixed",
        fixed = {
            {-0.5,-0.5,-0.3,0.5,-0.4,0.3},
            {-0.35,-0.4,-0.25,0.35,-0.3,0.25},
            {-0.3,-0.3,-0.15,0.3,-0.1,0.15},
            {-0.35,-0.1,-0.2,0.35,0.1,0.2},
        },
    },
    selection_box = {
        type = "fixed",
        fixed = {
            {-0.5,-0.5,-0.3,0.5,-0.4,0.3},
            {-0.35,-0.4,-0.25,0.35,-0.3,0.25},
            {-0.3,-0.3,-0.15,0.3,-0.1,0.15},
            {-0.35,-0.1,-0.2,0.35,0.1,0.2},
        },
    },
    groups = {oddly_breakable_by_hand=2, cracky=3, dig_immediate=1},
    sounds = default.node_sound_stone_defaults(),
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("hammer") then
            return false
        elseif not inv:is_empty("ingot") then
            return false
        elseif not inv:is_empty("res") then
            return false
        elseif not inv:is_empty("recipe") then
            return false
        end
        return true
    end,
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("formspec", "invsize[8,10;]"..
                "image[1,3.5;1,1;anvil_test.png]"..
                "list[current_name;hammer;1,3.5;1,1;]"..
                "list[current_name;ingot;1,1.5;1,1;]"..
                "list[current_name;recipe;6,1.5;1,1;]"..
                "list[current_name;res;3,1.5;1,1;]"..
                "label[1,1;Ingot:]"..
                "label[6,1;Recipe:]"..
                "label[3,1;Output:]"..
                "label[1,3;Hammer:]"..
                "button[4,2.5;2,3;forge;Forge]"..
                "list[current_player;main;0,6;8,4;]")
        meta:set_string("infotext", "Anvil")
        local inv = meta:get_inventory()
        inv:set_size("hammer", 1)
        inv:set_size("ingot", 1)
        inv:set_size("recipe", 1)
        inv:set_size("res", 1)
    end,
    on_receive_fields = function(pos, formname, fields, sender)
        local meta = minetest.env:get_meta(pos)
        local inv = meta:get_inventory()
       
        if fields["forge"] then
            if inv:is_empty("hammer") or inv:is_empty("ingot") then
                return
            end
           
            local ingotstack = inv:get_stack("ingot", 1)
            local recipestack = inv:get_stack("recipe", 1)
            local hammerstack = inv:get_stack("hammer", 1)
            local resstack = inv:get_stack("res", 1)
           
            if table_containts(HAMMERS_LIST, hammerstack:get_name()) then
                local s = ingotstack:get_name()
                if not inv:is_empty("recipe") then
                    if recipestack:get_name()=="metals:recipe_axe" then
                        inv:add_item("res","metals:tool_axe_"..string.sub(s,8,string.len(s)-6).."_head")
                        ingotstack:take_item()
                        inv:set_stack("ingot",1,ingotstack)
                        hammerstack:add_wear(65535/30)
                        inv:set_stack("hammer",1,hammerstack)
                    elseif recipestack:get_name()=="metals:recipe_hammer" then
                        inv:add_item("res","metals:tool_hammer_"..string.sub(s,8,string.len(s)-6).."_head")
                        ingotstack:take_item()
                        inv:set_stack("ingot",1,ingotstack)
                        hammerstack:add_wear(65535/30)
                        inv:set_stack("hammer",1,hammerstack)
                    elseif recipestack:get_name()=="metals:recipe_pick" then
                        inv:add_item("res","metals:tool_pick_"..string.sub(s,8,string.len(s)-6).."_head")
                        ingotstack:take_item()
                        inv:set_stack("ingot",1,ingotstack)
                        hammerstack:add_wear(65535/30)
                        inv:set_stack("hammer",1,hammerstack)
                    elseif recipestack:get_name()=="metals:recipe_shovel" then
                        inv:add_item("res","metals:tool_shovel_"..string.sub(s,8,string.len(s)-6).."_head")
                        ingotstack:take_item()
                        inv:set_stack("ingot",1,ingotstack)
                        hammerstack:add_wear(65535/30)
                        inv:set_stack("hammer",1,hammerstack)
                    elseif recipestack:get_name()=="metals:recipe_spear" then
                        inv:add_item("res","metals:tool_spear_"..string.sub(s,8,string.len(s)-6).."_head")
                        ingotstack:take_item()
                        inv:set_stack("ingot",1,ingotstack)
                        hammerstack:add_wear(65535/30)
                        inv:set_stack("hammer",1,hammerstack)
                    elseif recipestack:get_name()=="metals:recipe_sword" then
                        inv:add_item("res","metals:tool_sword_"..string.sub(s,8,string.len(s)-6).."_head")
                        ingotstack:take_item()
                        inv:set_stack("ingot",1,ingotstack)
                        hammerstack:add_wear(65535/30)
                        inv:set_stack("hammer",1,hammerstack)
                    elseif recipestack:get_name()=="metals:recipe_bucket" then
                        inv:add_item("res","metals:bucket_empty_"..string.sub(s,8,string.len(s)-6))
                        ingotstack:take_item()
                        inv:set_stack("ingot",1,ingotstack)
                        hammerstack:add_wear(65535/30)
                        inv:set_stack("hammer",1,hammerstack)
                    end
                end
                if ingotstack:get_name()=="metals:pig_iron_ingot" then
                    inv:add_item("res","metals:wrought_iron_ingot")
                    ingotstack:take_item()
                    inv:set_stack("ingot",1,ingotstack)
                    hammerstack:add_wear(65535/30)
                    inv:set_stack("hammer",1,hammerstack)
                elseif string.sub(ingotstack:get_name(), 1, 7)=="metals:" and string.sub(ingotstack:get_name(),-9,-1)=="_unshaped" then
                    inv:add_item("res", "metals:"..string.sub(ingotstack:get_name(),8,-10).."_ingot")
                    ingotstack:take_item()
                    inv:set_stack("ingot",1,ingotstack)
                    hammerstack:add_wear(65535/30)
                    inv:set_stack("hammer",1,hammerstack)
                end
            end
        end
    end,
})

Image of hammer must be on background. Help me, please.
Last edited by kotolegokot on Mon Oct 15, 2012 16:32, edited 1 time in total.
I'm creator of these mods: Locked sign, Locked furnace, Money. And I'm a developer of The RealTest Game.
 

User avatar
kotolegokot
Member
 
Posts: 131
Joined: Mon Jul 02, 2012 17:03

by kotolegokot » Mon Oct 22, 2012 17:01

up
I'm creator of these mods: Locked sign, Locked furnace, Money. And I'm a developer of The RealTest Game.
 

User avatar
kotolegokot
Member
 
Posts: 131
Joined: Mon Jul 02, 2012 17:03

by kotolegokot » Mon Nov 05, 2012 11:26

I'm creator of these mods: Locked sign, Locked furnace, Money. And I'm a developer of The RealTest Game.
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 8 guests

cron