minetest.item_drop

From Minetest Developer Wiki
Jump to: navigation, search

Syntax

minetest.item_drop(itemstack, dropper, pos)
  • itemstack — The ItemStack that contains the items being dropped.
  • dropper — The Player object for the player dropping the items.
  • pos — The position of the player dropping the node item. Note that this is not the place where the item is dropped in-world; the function calculates the actual drop location based on the given position (which it assumes is the player's position) and the direction the player's camera is pointing.

Description

Programmatically drops an item or stack of items in-world, mimicking the same effect as when the player drops items from inventory using the drop button (they Q key by default). Some points to note:

  • The item(s) being dropped do not actually need to be in the inventory of the Player passed to the function. In fact they don't need to exist anywhere. If you call this function and want to remove the items being placed from an inventory, you have to also do the programmatic removal from inventory (see InvRef, Player, and minetest.get_inventory).
  • The function calculates a position and velocity for the dropped item based on the position given and the direction the given player's camera is currently pointing (the current implementation picks a point 1m in front of the camera and a velocity of 2m/s away from the camera plus 1m/s straight down).
  • All dropped items in-world are embodied by a special LuaEntitySAO of type "__builtin:item" with the immortal flag set so they will not be damaged by weapons.
  • This function is the default implementation for a node's on_drop callback method (see minetest.register_node).

If you want the simpler behavior of just placing the item(s) in-world at a fixed position and zero velocity, use minetest.add_item(pos, itemstack) instead. This function uses that one under the covers anyway.


This article is missing examples, feel free to add them.


Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox