[solved] Use a node to show formspec of a chest?

Post Reply
User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

[solved] Use a node to show formspec of a chest?

by Linuxdirk » Post

I have a mod that implements a node that has to be placed above a chest in order to do what it is supposed to do. This works as expected, so no big deal here.

As a convenience function I want to allow players to access the chest below said node. Ideally by simply using (right-clicking) my node so my node acts a a “proxy” and simply shows the chest’s formspec to the player so the player can interact with it as if they would directly access the chest.

Is there a simple way to do so or do I need to re-create the chest formspec and manually load the chest’s inventory?
Last edited by Linuxdirk on Wed Apr 22, 2020 15:07, edited 1 time in total.

User avatar
v-rob
Developer
Posts: 971
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Use a node to show formspec of a chest (given by positio

by v-rob » Post

You might be able to call the node's on_rightclick function manually, something like (untested):

Code: Select all

-- `clicker`, `itemstack`, and `pointed_thing` come from your `on_rightclick` function
-- `pointed_thing` might need to be modified somehow, but I doubt chests require it.
minetest.registered_nodes["default:chest"].on_rightclick(chest_pos, minetest.get_node(chest_pos), clicker, itemstack, pointed_thing)
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Use a node to show formspec of a chest (given by positio

by Linuxdirk » Post

v-rob wrote:You might be able to call the node's on_rightclick function manually, something like (untested):
Haha, nice. I was so into this formspec thing that I totally missed the obvious here. This – of course – works very well. Thanks for the hint :)

Code: Select all

on_rightclick = function(pos, node, clicker)
    local chest_def = minetest.registered_nodes['default:chest']
    local actual_pos = { x = pos.x, y = pos.y-1, z = pos.z }
    if minetest.get_node(actual_pos).name == 'default:chest' then
        chest_def.on_rightclick(actual_pos, node, clicker)
    end
end
Only pos, node and clicker are needed. And not even node – according to the chest’s definition it is only used to change the lid state but since the lid is obstructed by my node, the node parameter is not used.

And since it actually calls the chest’s on_rightclick function it automatically has all the error handling, inventory management, and access management without re-coding it.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests