Page 1 of 1

How do I make a node change when right-clicked with a bucket?

PostPosted: Thu May 23, 2013 20:11
by scifiboi
I've been trying to get a "cauldron" to change into a "cauldron_filled" by right-clicking it with a "bucket:bucket_water" in hand. I have tried several times and failed at each attempt. How would I go about this? Thanks in advanced.

PostPosted: Thu May 23, 2013 20:42
by kaeza
Use on_rightclick callback on the cauldron, and check the itemstack name.
EDIT: 1000th post!!!

PostPosted: Thu May 23, 2013 21:35
by PilzAdam
kaeza wrote:EDIT: 1000th post!!!

Nice.

PostPosted: Thu May 23, 2013 21:51
by Jordach
PilzAdam wrote:
kaeza wrote:EDIT: 1000th post!!!

Nice.
Anyways, yeah, kaeza is right. Also: I'm 3.042x better.

PostPosted: Thu May 23, 2013 22:20
by Evergreen
kaeza wrote:Use on_rightclick callback on the cauldron, and check the itemstack name.
EDIT: 1000th post!!!

Exactly how do you check the itemstack name?

PostPosted: Fri May 24, 2013 01:24
by kaeza
Evergreen wrote:Exactly how do you check the itemstack name?

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
on_rightclick = function(pos, node, clicker, itemstack)
  if itemstack:get_name() == "bucket:bucket_water" then
    -- Switch nodes here
  end
end

PostPosted: Fri May 24, 2013 13:30
by Evergreen
kaeza wrote:
Evergreen wrote:Exactly how do you check the itemstack name?

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
on_rightclick = function(pos, node, clicker, itemstack)
  if itemstack:get_name() == "bucket:bucket_water" then
    -- Switch nodes here
  end
end

Ah, thanks a lot. I wish someone would update the dev wiki so people(like me) wouldn't be asking questions like this.

PostPosted: Fri May 24, 2013 14:04
by Evergreen
I am getting very close to getting this to work. Here is the code:
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("thaumtest:cauldron_empty",{
    drawtype="nodebox",
    description= "Cauldron",
    paramtype = "light",
    tiles = {"default_wood.png"},
    groups = {choppy=2},
    node_box = {
        type = "fixed",
        fixed = {
            {-0.500000,-0.375000,-0.500000,-0.375000,0.500000,0.500000},
            {0.375000,-0.375000,-0.500000,0.500000,0.500000,0.500000},
            {-0.500000,-0.375000,-0.500000,0.500000,0.500000,-0.375000},
            {-0.500000,-0.375000,0.375000,0.500000,0.500000,0.500000},
            {-0.500000,-0.500000,-0.500000,-0.375000,0.500000,-0.375000},
            {0.375000,-0.500000,-0.500000,0.500000,0.500000,-0.375000},
            {0.375000,-0.500000,0.375000,0.500000,0.500000,0.500000},
            {-0.500000,-0.500000,0.375000,-0.375000,0.500000,0.500000},
            {-0.500000,-0.375000,-0.500000,0.500000,-0.312500,0.500000},
        }
    }
    on_rightclick = function(pos, node, clicker, itemstack)
            if itemstack:get_name() == "bucket:bucket_water" then
               minetest.node_dig(pos, node, digger)
               minetest.env:remove_node(pos)
            end
    end,
   
    after_destruct = function(pos, oldnode)
        oldnode.name = "thaumtest:cauldron_full"
        minetest.env:set_node(pos, oldnode)
    end
})

Could you tell me what is wrong with it? I would appreciate it.

PostPosted: Fri May 24, 2013 20:06
by kaeza
why don't you call set_node(...) directly in on_rightclick?

PostPosted: Fri May 24, 2013 20:11
by Evergreen
kaeza wrote:why don't you call set_node(...) directly in on_rightclick?

Okay, thanks.

PostPosted: Fri May 24, 2013 20:22
by Evergreen
I still get an error though. Here is the code:
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("thaumtest:cauldron_empty",{
    drawtype="nodebox",
    description= "Cauldron",
    paramtype = "light",
    tiles = {"default_wood.png"},
    groups = {choppy=2},
    node_box = {
        type = "fixed",
        fixed = {
            {-0.500000,-0.375000,-0.500000,-0.375000,0.500000,0.500000},
            {0.375000,-0.375000,-0.500000,0.500000,0.500000,0.500000},
            {-0.500000,-0.375000,-0.500000,0.500000,0.500000,-0.375000},
            {-0.500000,-0.375000,0.375000,0.500000,0.500000,0.500000},
            {-0.500000,-0.500000,-0.500000,-0.375000,0.500000,-0.375000},
            {0.375000,-0.500000,-0.500000,0.500000,0.500000,-0.375000},
            {0.375000,-0.500000,0.375000,0.500000,0.500000,0.500000},
            {-0.500000,-0.500000,0.375000,-0.375000,0.500000,0.500000},
            {-0.500000,-0.375000,-0.500000,0.500000,-0.312500,0.500000},
        }
    }
    on_rightclick = function(pos, node, clicker, itemstack)
            if itemstack:get_name() == "bucket:bucket_water" then
                  minetest.env:set_node(pos, "thaumtest:cauldron_full")
            end
    end
    }
})

PostPosted: Wed May 29, 2013 21:49
by doyousketch2
I think in your last line you have one too many closing brackets.

Take out the squiggly }
Just leave the )

I also think you need commas after the closing brackets that you do have.

There's 3 of these }

That should look like this instead:

},

not tested, but this looks more correct to me:

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("thaumtest:cauldron_empty",{
    drawtype="nodebox",
    description= "Cauldron",
    paramtype = "light",
    tiles = {"default_wood.png"},
    groups = {choppy=2},
    node_box = {
        type = "fixed",
        fixed = {
            {-0.500000,-0.375000,-0.500000,-0.375000,0.500000,0.500000},
            {0.375000,-0.375000,-0.500000,0.500000,0.500000,0.500000},
            {-0.500000,-0.375000,-0.500000,0.500000,0.500000,-0.375000},
            {-0.500000,-0.375000,0.375000,0.500000,0.500000,0.500000},
            {-0.500000,-0.500000,-0.500000,-0.375000,0.500000,-0.375000},
            {0.375000,-0.500000,-0.500000,0.500000,0.500000,-0.375000},
            {0.375000,-0.500000,0.375000,0.500000,0.500000,0.500000},
            {-0.500000,-0.500000,0.375000,-0.375000,0.500000,0.500000},
            {-0.500000,-0.375000,-0.500000,0.500000,-0.312500,0.500000},
        },
    },
    on_rightclick = function(pos, node, clicker, itemstack)
            if itemstack:get_name() == "bucket:bucket_water" then
                  minetest.env:set_node(pos, "thaumtest:cauldron_full")
            end
    end
    },
)

PostPosted: Wed May 29, 2013 22:02
by Evergreen
doyousketch2 wrote:I think in your last line you have one too many closing brackets.

Take out the squiggly }
Just leave the )

I also think you need commas after the closing brackets that you do have.

There's 3 of these }

That should look like this instead:

},

not tested, but this looks more correct to me:

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("thaumtest:cauldron_empty",{
    drawtype="nodebox",
    description= "Cauldron",
    paramtype = "light",
    tiles = {"default_wood.png"},
    groups = {choppy=2},
    node_box = {
        type = "fixed",
        fixed = {
            {-0.500000,-0.375000,-0.500000,-0.375000,0.500000,0.500000},
            {0.375000,-0.375000,-0.500000,0.500000,0.500000,0.500000},
            {-0.500000,-0.375000,-0.500000,0.500000,0.500000,-0.375000},
            {-0.500000,-0.375000,0.375000,0.500000,0.500000,0.500000},
            {-0.500000,-0.500000,-0.500000,-0.375000,0.500000,-0.375000},
            {0.375000,-0.500000,-0.500000,0.500000,0.500000,-0.375000},
            {0.375000,-0.500000,0.375000,0.500000,0.500000,0.500000},
            {-0.500000,-0.500000,0.375000,-0.375000,0.500000,0.500000},
            {-0.500000,-0.375000,-0.500000,0.500000,-0.312500,0.500000},
        },
    },
    on_rightclick = function(pos, node, clicker, itemstack)
            if itemstack:get_name() == "bucket:bucket_water" then
                  minetest.env:set_node(pos, "thaumtest:cauldron_full")
            end
    end
    },
)

No, it is working, but I had a problem that I posted in the modding questions topic.