Is this a bug or an "undocumented feature"?

Post Reply
isaiah658
Member
Posts: 40
Joined: Sun Jan 24, 2016 14:58

Is this a bug or an "undocumented feature"?

by isaiah658 » Post

Using add_item with on_rightclick seems to have different behavior than if add_item is used with lets say on_punch. With on_rightclick the player will not receive the item if the slot the item is meant to go into (the first open slot) is the wielded/active slot. So if the first slot in the hotbar is empty and the player has the first slot as their active slot an item will not be added with add_item if used in on_rightclick. It will be added though if it is used with on_punch. Here are two examples:

This will properly if the wielded spot is where the item is meant to go:

Code: Select all

on_punch = function(pos, node, player, pointed_thing)
	local inv = player:get_inventory()
	local left = inv:add_item("main", "default:dirt")
end,
This will not work if the wielded spot is where the item is meant to go:

Code: Select all

on_rightclick = function(pos, node, player, itemstack, pointed_thing)
	local inv = player:get_inventory()
	local left = inv:add_item("main", "default:dirt")
end,
Surprisingly add_item in on_rightclick is still returning true as if it did add the item. Is this an annoying feature that is meant to be this way or a bug? It would seem like a bug to me because it is inconsistent.

Zedicius
New member
Posts: 6
Joined: Thu Jul 28, 2016 06:12
GitHub: Zedicius
IRC: Zedicius
In-game: Zedicius

Re: Is this a bug or an "undocumented feature"?

by Zedicius » Post

I can confirm this issue.

Code: Select all

minetest.register_node("testmod:bush", {
	description = "Bush",
	tiles = {"bush.png"},
	walkable = true,
	groups = {snappy = 3, flammable = 2},
	sounds = default.node_sound_leaves_defaults(),
  on_rightclick = function(pos, node, clicker, itemstack, object)
    clicker:get_inventory():add_item("main", "testmod:crystal")
    minetest.remove_node(pos)
    minetest.place_node(pos, {name = "testmod:bush_depleted"})
  end
})
Is there a workaround for this at the moment?

isaiah658
Member
Posts: 40
Joined: Sun Jan 24, 2016 14:58

Re: Is this a bug or an "undocumented feature"?

by isaiah658 » Post

Edit: Better workaround thanks to Void7. If you use:

Code: Select all

minetest.after(0, function() inv:add_item("main", itemdrop) end)
then the item will be added as you would expect. It has to do with how the game is checking things with on_rightclick. So not technically a bug.

The only workaround I know of is to use minetest.add_item(droppos, itemdrop) and drop the item on the ground nearby. That's what I'm doing with the berry bushes of mine. You could also use on_punch (essentially left clicking) which would work with adding the item to the inventory properly. Since I'm not alone wondering about this I'm going to post on the irc and hope I can get a solid response. If anyone has any input please share it.

Zedicius
New member
Posts: 6
Joined: Thu Jul 28, 2016 06:12
GitHub: Zedicius
IRC: Zedicius
In-game: Zedicius

Re: Is this a bug or an "undocumented feature"?

by Zedicius » Post

Ah! I did not know about the .after method. I should really go over the entire list this weekend.

Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest