How to create a custom chest?

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

How to create a custom chest?

by Jeija » Tue Feb 07, 2012 16:13

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!
Last edited by Jeija on Tue Feb 07, 2012 16:14, edited 1 time in total.
Redstone for minetest: Mesecons (mesecons.net)
 

matusz
New member
 
Posts: 5
Joined: Mon Feb 06, 2012 21:42

by matusz » Tue Feb 07, 2012 20:06

it seems API has changed or something, you could probably use something like this

meta:get_inventory():set_list(
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Tue Feb 07, 2012 20:17

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!
Last edited by Jeija on Tue Feb 07, 2012 20:18, edited 1 time in total.
Redstone for minetest: Mesecons (mesecons.net)
 

User avatar
dannydark
Member
 
Posts: 428
Joined: Fri Aug 12, 2011 21:28

by dannydark » Tue Feb 07, 2012 20:42

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",
Last edited by dannydark on Tue Feb 07, 2012 21:20, edited 1 time in total.
 

matusz
New member
 
Posts: 5
Joined: Mon Feb 06, 2012 21:42

by matusz » Tue Feb 07, 2012 22:11

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
Last edited by matusz on Tue Feb 07, 2012 22:56, edited 1 time in total.
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Wed Feb 08, 2012 17:03

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.
Last edited by Jeija on Wed Feb 08, 2012 17:25, edited 1 time in total.
Redstone for minetest: Mesecons (mesecons.net)
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Wed Feb 08, 2012 19:51

abms should only work when the area which the chest is in is loaded as a chunk.
Last edited by Jordach on Wed Feb 08, 2012 19:53, edited 1 time in total.

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Wed Feb 08, 2012 20:58

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.
Redstone for minetest: Mesecons (mesecons.net)
 

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

by Temperest » Wed Feb 08, 2012 21:41

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.
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21

by bgsmithjr » Fri Apr 06, 2012 15:51

I hope you guys are you using minetest.env:get_inventory(location)
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 12 guests

cron