fix incorrect drop behavior when stipping bogus color

in the case of full inv.

Should be the same as normal Minetest behavior now:

In survival mode, the node is deleted, then:

* If there is room in your inv, you get whatever the node
  would normally give you.

* If there's no room, the node drops to the ground as an item
  entity.

In creative mode, the node is deleted, then:

* If you don't already have one of the item, you get one.

* If you already have one, or if there's no room in your
  inventory, "you'll get nothing and LIKE it!" :-)

Also: made sure to check for creative priv as well as proper
creative mode.
This commit is contained in:
Vanessa Dannenberg 2019-09-15 23:36:49 -04:00
parent 0082b1513a
commit 9271f07f12

View File

@ -197,9 +197,13 @@ minetest.register_on_placenode(
-- The complementary function: strip-off the color if the node being dug is still white/neutral -- The complementary function: strip-off the color if the node being dug is still white/neutral
local function move_item(item, pos, inv) local function move_item(item, pos, inv, digger)
if not creative_mode or not inv:contains_item("main", item, true) then local creative = creative_mode or minetest.check_player_privs(digger, "creative")
if inv:room_for_item("main", item)
and (not creative or not inv:contains_item("main", item, true)) then
inv:add_item("main", item) inv:add_item("main", item)
elseif not creative then
minetest.item_drop(item, digger, pos)
end end
minetest.remove_node(pos) minetest.remove_node(pos)
end end
@ -227,7 +231,7 @@ function unifieddyes.on_dig(pos, node, digger)
local inv = digger:get_inventory() local inv = digger:get_inventory()
if del_color then if del_color then
if inv:room_for_item("main", node.name) then move_item(node.name, pos, inv) end move_item(node.name, pos, inv, digger)
else else
return minetest.node_dig(pos, node, digger) return minetest.node_dig(pos, node, digger)
end end