Page 1 of 1

How to create a custom chest?

PostPosted: Tue Feb 07, 2012 16:13
by Jeija
I am writing an extension for the oil mod that adds a mesecon power generator. It should look like a 1x1 chest you can put the fuel in. This is what the code looks like:

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("oil:generator", {
    tile_images = {"default_lava.png"},
    paramtype = "facedir_simple",
    metadata_name = "generic",
    material = minetest.digprop_stonelike(3.0),
})


minetest.register_on_placenode(function(pos, newnode, placer)
    if newnode.name == "oil:generator" then
    local meta = minetest.env:get_meta(pos)
    meta:inventory_set_list("0", {""}) -- THIS LINE SEEMS TO CAUSE THE ERROR
    meta:set_inventory_draw_spec(
        "invsize[8,9;]list[current_name;0;4,4;1,1;]"
        .."list[current_player;main;0,5;8,4;]"
    )
   
    end
end)

If you want to see the whole code, just paste the thing above below the oil mod code

For some reason, i always get this error:
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
20:18:28: ERROR[ServerThread]: ERROR: An unhandled exception occurred: LuaError: error: /home/florian/.minetest/usermods/oil/init.lua:536: attempt to call method 'inventory_set_list' (a nil value)


Any idea why? Any suggestions on how to fix the bug? Morechests mod works fine and I can't really see a big difference from my mod to the morechests thing...
Please help!

PostPosted: Tue Feb 07, 2012 20:06
by matusz
it seems API has changed or something, you could probably use something like this

meta:get_inventory():set_list(

PostPosted: Tue Feb 07, 2012 20:17
by Jeija
Still not working...
The morechests mod uses same code; And the morechest mod works, WHY NOT THIS?
I changed the line to:
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
        meta:get_inventory():set_size("0", 1)

which is actually used in the morechest mod --> Same error.
Do you have any other ideas? Anyway, thx for the answer :D!

PostPosted: Tue Feb 07, 2012 20:42
by dannydark
shouldn't the if statement be like:

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
if newnode.name == "generator" then


Not tested as not on my system at the moment so I might be completely wrong >_<

EDIT: Actually...wtf am I talking about haha ignore me ¬_¬ If your still having problems with this when I get home I'll try and have a look at it for you.

EDIT2: Also the paramtype in your register_node is wrong it should now be:

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
paramtype2 = "facedir",

PostPosted: Tue Feb 07, 2012 22:11
by matusz
I don't know, I took your code, changed inventory_ to get_inventory(): and the names to relevant to my problem and it worked

see https://github.com/mormon/klchest - seek klchest:key_duplicator

PostPosted: Wed Feb 08, 2012 17:03
by Jeija
I found the problem! It's really weird!!!

Bug report
If there are 2
minetest.register_on_placenode
functions in the same mod, the line
meta:get_inventory():set_list("whatever", {""})
causes an error:
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
attempt to index a nil value


Does any C++ dev have an idea why? Is this a real bug or what else is wrong?

EDIT: The bug also seems to be caused by placenode functions in the dependencies.

--> Workaround:
Create an own mod for the placenode function with only dependency default.

PostPosted: Wed Feb 08, 2012 19:51
by Jordach
abms should only work when the area which the chest is in is loaded as a chunk.

PostPosted: Wed Feb 08, 2012 20:58
by Jeija
are you referring to another topic?
The information you gave is right,
but this placenode thing has nothing to do with the abm problem ^^.

Of course the energy generator only works if there are players nearby.
This is a general mesecons problem.

PostPosted: Wed Feb 08, 2012 21:41
by Temperest
I'm having the same issue with a work-in-progress node detector for mesecons - can't confirm the need for two register_on_placenode() condition though.

PostPosted: Fri Apr 06, 2012 15:51
by bgsmithjr
I hope you guys are you using minetest.env:get_inventory(location)