Post your modding questions here

Locked
prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

Calling "take_item()" will change the local ItemStack you have in your function there, but the API actually passes ItemStacks around by value (copies) rather than by reference. So you have to tell the API to do something with the modified ItemStack. For example, you could pass it back to ObjectRef:set_wielded_item(...).

User avatar
10twenty4
Member
Posts: 40
Joined: Tue Mar 12, 2013 20:54

by 10twenty4 » Post

I'm trying to create a menu when you right click a node. I believe I'm doing this correctly (adding a formspec to the metadata), but nothing happens. I've tried copying the line from the furnace code and other examples, but that doesn't work either. I'm assuming I'm missing something, but I don't know what.

Code: Select all

on_construct= function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("formspec",
                "size[8,9]"..
        "list[current_name;fuel;2,3;1,1;]"..
        "list[current_player;main;0,5;8,4]"
        )
        meta:set_string("infotext", "Campfire")
        local inv = meta:get_inventory()
        inv:set_size("fuel",1)

    end,

User avatar
Evergreen
Member
Posts: 2135
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen
Location: A forest in the midwest
Contact:

by Evergreen » Post

10twenty4 wrote:I'm trying to create a menu when you right click a node. I believe I'm doing this correctly (adding a formspec to the metadata), but nothing happens. I've tried copying the line from the furnace code and other examples, but that doesn't work either. I'm assuming I'm missing something, but I don't know what.

Code: Select all

on_construct= function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("formspec",
                "size[8,9]"..
        "list[current_name;fuel;2,3;1,1;]"..
        "list[current_player;main;0,5;8,4]"
        )
        meta:set_string("infotext", "Campfire")
        local inv = meta:get_inventory()
        inv:set_size("fuel",1)

    end,
Exactly what I was going to ask.
Back from the dead!

User avatar
10twenty4
Member
Posts: 40
Joined: Tue Mar 12, 2013 20:54

by 10twenty4 » Post

This time, I'm trying to have a craftitem decrement by one when used on a node.

Code: Select all

on_use = function(itemstack, user, pointed_thing)
            if pointed_thing.type == "node" then
                itemstack: take_item()
                user:set_wielded_item(itemstack)
            end
        end
    })
I've done a bit of testing, and it appears that while user's wielded item is decremented, user is a different object from the player, so the player's inventory is unaffected. Can you recommend a way around that?

edit: nvrmind, I just released I can use return itemstack
Last edited by 10twenty4 on Tue Mar 19, 2013 02:24, edited 1 time in total.

prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

If the formspec is badly formed, nothing happens. Silent failure. And unfortunately the documentation for formspecs is a little inconsistent and wrong. I believe you'll need a semicolon at the name of the player's list, just like the node inventory's list.

User avatar
pandaro
Member
Posts: 327
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

by pandaro » Post

There is already a way to check for a collision between two objects?
sorry for bad english
Linux debian 7 wheezy 64
kde

Sokomine
Member
Posts: 4276
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

by Sokomine » Post

Ask sapier. AFAIK he was working on something like that or at least knows where to look. Perhaps a patch is even linked in the mobf-thread. The mobf mobs do at least detect collusion with ground/nodes even without that patch.
A list of my mods can be found here.

User avatar
pandaro
Member
Posts: 327
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

by pandaro » Post

thanks for now!
sorry for bad english
Linux debian 7 wheezy 64
kde

User avatar
Likwid H-Craft
Member
Posts: 1113
Joined: Sun Jan 06, 2013 14:20
Location: Lost in Crypt

by Likwid H-Craft » Post

I am try make a info box show a node/item/block in a menu so how do I make it work plus I like it have text here code.


[lua]
minetest.register_node("ibox:info_box", {
description = "Info Box",
tiles = {"ibox_info_box.png"},
is_ground_content = true,
groups = {cracky=3,fleshy=2},
drop = 'default:bookshelf 7', 'default:mese_crystal_fragment 2',
on_construct = function(pos)
--local n = minetest.env:get_node(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", "field[text;;${text}]")
meta:set_string("infotext", "\"\"")
end,
on_receive_fields = function(pos, formname, fields, sender)
--print("Sign at "..minetest.pos_to_string(pos).." got "..dump(fields))
local meta = minetest.env:get_meta(pos)
fields.text = fields.text or ""
print((sender:get_player_name() or "").. wrote \""..fields.text..
"\" to sign at "..minetest.pos_to_string(pos))
meta:set_string("text", fields.text)
meta:set_string("infotext", '"'..fields.text..'"')
end,
})
[/lua]

I edit made the color text so make it just like, as if it the real deal :) and you don't know how long it took me, to edit the text have the right color...

Oh and, How I make the block drop 2 thing not one.
Last edited by Likwid H-Craft on Wed Mar 27, 2013 15:57, edited 1 time in total.
My Domain's/others:
http://likwidtest.hj.cx/ (Not Done)

bentleysb
Member
Posts: 18
Joined: Sat Feb 09, 2013 02:18

by bentleysb » Post

I am trying to make it so when a block is placed then 2 other blocks are placed to the right and left of that block (resulting in a 3 x 1 panel) here is what I have so far:

Code: Select all

local on_place_trans = function(pos, node, placer)
        if node.name == 'mod:panel_center'then
        fdir = minetest.dir_to_facedir(placer:get_look_dir())
        minetest.env:add_node({x=pos.x+1, y=pos.y, z=pos.z}, { name = "mod:panel_right", paramtype2='none', param2=fdir})
        nodeupdate(pos)
        minetest.env:add_node({x=pos.x-1, y=pos.y, z=pos.z}, { name = "mode:panel_left", paramtype2='none', param2=fdir})
        nodeupdate(pos)
        end
        end

minetest.register_on_placenode(on_place_trans)
what happens currently is that the 2 nodes place to the x+1 and x-1. What i want to do, but don't know how, is to code it so that if placer:dir = front then it will use the x+1 and x-1, if the placer:dir = right then it will use the z-1 and z+1. If someone could tell me how to code something like that, that would be great.

prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

bentleysb wrote:I am trying to make it so when a block is placed then 2 other blocks are placed to the right and left of that block....
Just test whether the absolute value of the look direction's x or z coordinate is smaller, and modify that direction. Something like:

Code: Select all

local lookDir = placer:get_look_dir()
local pos1, pos2
if math.abs(lookDir.x) < math.abs(lookDir.z) then
   pos1 = { x = pos.x-1, y = pos.y, z = pos.z }
   pos2 = { x = pos.x+1, y = pos.y, z = pos.z }
else
   pos1 = { x = pos.x, y = pos.y, z = pos.z-1 }
   pos2 = { x = pos.x, y = pos.y, z = pos.z+1 }
end
Last edited by prestidigitator on Fri Mar 29, 2013 05:01, edited 1 time in total.

User avatar
Casimir
Member
Posts: 1206
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

by Casimir » Post

I tried to make a register_on_item_eat function, but failed. Nothing happens.

in item.lua

Code: Select all

function minetest.register_on_item_eat(hp_change, replace_with_item)
    print("[register_on_item_eat] 2")
    return function(itemstack, user, pointed_thing)  -- closure
        if itemstack:take_item() ~= nil then
            user:set_hp(user:get_hp() + hp_change)
            itemstack:add_item(replace_with_item) -- note: replace_with_item is optional
        end
        return itemstack
    end
end

function minetest.item_eat(hp_change, replace_with_item)
    print("[register_on_item_eat] 1")
    -- Run script hook
    local _, callback
    for _, callback in ipairs(minetest.registered_on_item_eat) do
        -- Copy hp_change and replace_with_item because callback can modify them
        local hp_change_copy = {x=pos.x, y=pos.y, z=pos.z}
        local replace_copy = hp_change
        callback(hp_change_copy, return_copy)
    end
end
in misc_register.lua

Code: Select all

minetest.registered_on_item_eat, minetest.register_on_item_eat = make_registration()

User avatar
jojoa1997
Member
Posts: 2890
Joined: Thu Dec 13, 2012 05:11
Location: Earth

by jojoa1997 » Post

I think you either have to change player.lua or some code that is in C++
Coding;
1X coding
3X debugging
12X tweaking to be just right

prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

Casimir wrote:I tried to make a register_on_item_eat function, but failed. Nothing happens.
Here is why. minetest.item_eat(...) is called by mods when they are registering items. This is before the game is really started, and players do not have the chance yet to interact. At that time your list of callbacks is probably going to be empty or uninteresting (depending on what mods have been loaded in what order), so calling them probably isn't going to do much. Also, the way the mods use minetest.item_eat(...), they expect it to return a function to assign to the item's on_use() callback. Your minetest.item_eat(...) returns nothing (nil). So when the player takes an item and left-clicks with it to use it, the game will see the item's on_use as nil, meaning there is no callback.

Your other function...I think maybe you meant to call minetest.register_on_item_eat(...) rather than define it? Not sure.

(And no, this doesn't need to be done in C++. It is very possible to do it in Lua.)
Last edited by prestidigitator on Fri Mar 29, 2013 16:55, edited 1 time in total.

User avatar
Likwid H-Craft
Member
Posts: 1113
Joined: Sun Jan 06, 2013 14:20
Location: Lost in Crypt

by Likwid H-Craft » Post

Is there a way make a node, to be set on fire forever like MC Nether block?
My Domain's/others:
http://likwidtest.hj.cx/ (Not Done)

Zsoltisawesome
Member
Posts: 180
Joined: Sun Dec 18, 2011 18:07
GitHub: YellowberryHN
IRC: YellowberryHN
In-game: YellowberryHN
Location: Utah, USA
Contact:

by Zsoltisawesome » Post

Is there way to make a node edible?
Check Out Moontest! http://hnss.gq/moontest
Buddies: Likwid H-Craft, 0gb.us, Death, Starfellow, asie, and many more!

User avatar
Likwid H-Craft
Member
Posts: 1113
Joined: Sun Jan 06, 2013 14:20
Location: Lost in Crypt

by Likwid H-Craft » Post

Zsoltisawesome wrote:Is there way to make a node edible?
Yes
My Domain's/others:
http://likwidtest.hj.cx/ (Not Done)

Zsoltisawesome
Member
Posts: 180
Joined: Sun Dec 18, 2011 18:07
GitHub: YellowberryHN
IRC: YellowberryHN
In-game: YellowberryHN
Location: Utah, USA
Contact:

by Zsoltisawesome » Post

Likwid H-Craft wrote:
Zsoltisawesome wrote:Is there way to make a node edible?
Yes
How? I Really Need To KNOW!
Check Out Moontest! http://hnss.gq/moontest
Buddies: Likwid H-Craft, 0gb.us, Death, Starfellow, asie, and many more!

User avatar
Likwid H-Craft
Member
Posts: 1113
Joined: Sun Jan 06, 2013 14:20
Location: Lost in Crypt

by Likwid H-Craft » Post

Add this:
on_use = minetest.item_eat(#),
#: Any number.
My Domain's/others:
http://likwidtest.hj.cx/ (Not Done)

ch98
Member
Posts: 463
Joined: Wed Jan 02, 2013 06:14

by ch98 » Post

Copy of my forcefield mod help topic:


I am going to make a forcefield mod where undigable block (forcefield block) is placed around about 6 blocks from forcefield generator block when it has coal in it and takes a coal away every 10 times forcefield block is hit, every 10 seconds, or if any block is missing, and destroys all forcefield block when there is no more coal. I am stuck on part detecting if coal is in the forcefield generator and there will be way more help needed afterwards.

init.lua:

Code: Select all

minetest.register_node("forcefield:forcefield", {
    tiles = {"forcefield_forcefield.png"},
    drawtype = glasslike,
    sunlight_propagates = true,
    walkable = true,
    diggable = false,
    on_punch = function(pos, node, puncher)
        pos = position
        a = "a" + "1"
    end,
})




default.forcefield_formspec =
    "size[8,9]"..
    "list[current_name;coal;1,1;6,3;]"..
    "list[current_player;main;0,5;8,4;]"



minetest.register_node("forcefield:fmaker", {
    description = "Forcefield Generator",
    tiles = {"forcefield_sides.png","forcefield_sides.png","forcefield_front.png","forcefield_sides.png","forcefield_sides.png","forcefield_sides.png"},
    groups = {snappy=2, choppy=2},
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("formspec", default.forcefield_formspec)
        meta:set_string("infotext", "forcefield generator")
        local inv = meta:get_inventory()
        inv:set_size("coal", 18)
    end,
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("coal", 18) then
            return false
        end
        return true
    end,
 
})



minetest.register_abm({
    nodenames = {"forcefield:fmaker"},
    interval = 1.0,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local meta = minetest.env:get_meta(pos)
        local inv = meta:get_inventory()
        local fuel = inv:get_list("coal")
            if fuel == "default:coal_lump" then
            srcstack = inv:get_stack("coal", 1)
                    srcstack:take_item("default:coal_lump")
                    inv:set_stack("coal", 1, srcstack)
                else
                    print("there was no coal")
        end
    end,
})


minetest.register_craft({
    output = 'forcefield:fmaker',
    recipe = {
        {'default:mese', 'default:mese', 'default:mese'},
        {'default:mese', 'default:furnace', 'default:mese'},
        {'default:mese', 'default:mese', 'default:mese'},
    }
})

I have stopped playing minetest, and may not come back to it again. I would like to thank everyone that made the amazing time I had playing it. This account is not in use anymore, and the email has been linked to a unused account. If any administrator reading this has time, feel free to delete my account. Thank you very much for the great experience.

prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

ch98 wrote:Copy of my forcefield mod help topic:
...
I am stuck on part detecting if coal is in the forcefield generator....
Non-copy of answer: http://forum.minetest.net/viewtopic.php ... 855#p81855

;-)

User avatar
pandaro
Member
Posts: 327
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

by pandaro » Post

how to handle collisions between objects?
sorry for bad english
Linux debian 7 wheezy 64
kde

1244
Member
Posts: 45
Joined: Fri Jul 13, 2012 16:40
Location: Poland

by 1244 » Post

Why this function isn't working?

Code: Select all

function register_element (name1,image,description1)
minetest.register_alias("chemistry:..name1..","..name1..")

minetest.register_craftitem("chemistry:..name1..", {    
description = "..description1..",
inventory_image = "..image.."
})
end
My mods:
Barrels, Chemistry

deivan
Member
Posts: 452
Joined: Fri Feb 15, 2013 10:16
Location: Brazil. :D

by deivan » Post

I think ".." don't be a valid part of a name.

User avatar
kaeza
Moderator
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza
Location: Montevideo, Uruguay
Contact:

by kaeza » Post

1244 wrote:Why this function isn't working?

Code: Select all

function register_element (name1,image,description1)
minetest.register_alias("chemistry:..name1..","..name1..")

minetest.register_craftitem("chemistry:..name1..", {    
description = "..description1..",
inventory_image = "..image.."
})
end
Maybe this is what you meant:

Code: Select all

function register_element (name1,image,description1)
minetest.register_alias(name1,"chemistry:"..name1)

minetest.register_craftitem("chemistry:"..name1, {    
description = description1,
inventory_image = image
})
end
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal

Locked

Who is online

Users browsing this forum: No registered users and 6 guests