minetest.register_craftitem

From Minetest Developer Wiki
Jump to: navigation, search

Contents

Syntax

minetest.register_craftitem("name", {item_definition})

Description

Registers a craftitem.

item_definition is a table with the following fields:

  • description = "string" — inventory tooltip
  • groups = table — the groups of the craftitem
  • inventory_image = "imagestring" — inventory texture of the item
  • wield_image = "imagestring"texture shown when wielded
  • wield_scale = pos — scale of wield_image
  • stack_max = int — maximum amount of items per stack, default is 99
  • liquids_pointable = bool — wether the player can point at liquids while wielding the item or not, default it false
  • metadata

Callbacks

These callbacks are defined in item_definition:

called on rightclick
should return the leftover itemstack (if nil, no item is removed)
default: minetest.item_place()
note.png
Note: this is not called when pointing at nothing


called when dropping the item (with "Q")
should return the leftover itemstack (if nil, no item is removed)
default: minetest.item_drop()
called on leftclick
should return the leftover itemstack (if nil, no item is removed)
default: nil
note.png
Note: if this function is not nil the item can not dig any nodes


Example

minetest.register_craftitem("test:test", {
	description = "Testcraftitem",
	inventory_image = "test_test.png",
 
	on_drop = function(itemstack, dropper, pos)
		-- Prints a random number and removes one item from the stack
		minetest.chat_send_all(math.random())
		itemstack:take_item()
		return itemstack
	end,
})
Retrieved from "http://dev.minetest.net/index.php?title=minetest.register_craftitem&oldid=3430"
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox