Move craftitem_place_item as minetest.craftitem_place_item in builtin.lua

This commit is contained in:
Perttu Ahola 2011-11-30 23:52:02 +02:00
parent 1b61ca412b
commit 918c507a66
3 changed files with 49 additions and 43 deletions

@ -1,3 +1,10 @@
--
-- This file contains built-in stuff in Minetest implemented in Lua.
--
-- It is always loaded and executed after registration of the C API,
-- before loading and running any mods.
--
function basic_dump2(o)
if type(o) == "number" then
return tostring(o)
@ -296,6 +303,30 @@ function test_stackstring()
end
test_stackstring()
--
-- craftitem helpers
--
minetest.craftitem_place_item = function(item, placer, pos)
--print("craftitem_place_item")
--print("item: " .. dump(item))
--print("placer: " .. dump(placer))
--print("pos: " .. dump(pos))
minetest.env:add_item(pos, 'CraftItem "' .. item .. '" 1')
return true
end
minetest.craftitem_eat = function(hp_change)
return function(item, user, pointed_thing) -- closure
--print("craftitem_eat(" .. hp_change .. ")")
--print("item: " .. dump(item))
--print("user: " .. dump(user))
--print("pointed_thing: " .. dump(pointed_thing))
user:set_hp(user:get_hp() + hp_change)
return true
end
end
--
-- Callback registration
--

@ -1,8 +1,3 @@
local craftitem_place_item = function(item, player, pos)
minetest.env:add_item(pos, 'CraftItem "' .. item .. '" 1')
return true
end
minetest.register_craft({
output = 'CraftItem "bucket" 1',
recipe = {
@ -15,7 +10,7 @@ minetest.register_craftitem("bucket", {
image = "bucket.png",
stack_max = 1,
liquids_pointable = true,
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
on_use = function(item, player, pointed_thing)
if pointed_thing.type == "node" then
n = minetest.env:get_node(pointed_thing.under)
@ -37,7 +32,7 @@ minetest.register_craftitem("bucket_water", {
image = "bucket_water.png",
stack_max = 1,
liquids_pointable = true,
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
on_use = function(item, player, pointed_thing)
if pointed_thing.type == "node" then
n = minetest.env:get_node(pointed_thing.under)
@ -59,7 +54,7 @@ minetest.register_craftitem("bucket_lava", {
image = "bucket_lava.png",
stack_max = 1,
liquids_pointable = true,
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
on_use = function(item, player, pointed_thing)
if pointed_thing.type == "node" then
n = minetest.env:get_node(pointed_thing.under)

@ -1132,68 +1132,48 @@ minetest.register_node("apple", {
-- Crafting items
--
local craftitem_place_item = function(item, placer, pos)
--print("craftitem_place_item")
--print("item: " .. dump(item))
--print("placer: " .. dump(placer))
--print("pos: " .. dump(pos))
minetest.env:add_item(pos, 'CraftItem "' .. item .. '" 1')
return true
end
local craftitem_eat = function(hp_change)
return function(item, user, pointed_thing) -- closure
--print("craftitem_eat(" .. hp_change .. ")")
--print("item: " .. dump(item))
--print("user: " .. dump(user))
--print("pointed_thing: " .. dump(pointed_thing))
user:set_hp(user:get_hp() + hp_change)
return true
end
end
minetest.register_craftitem("Stick", {
image = "stick.png",
--furnace_burntime = ...,
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("paper", {
image = "paper.png",
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("book", {
image = "book.png",
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("lump_of_coal", {
image = "lump_of_coal.png",
furnace_burntime = 40;
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("lump_of_iron", {
image = "lump_of_iron.png",
cookresult_item = 'CraftItem "steel_ingot" 1',
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("lump_of_clay", {
image = "lump_of_clay.png",
cookresult_item = 'CraftItem "clay_brick" 1',
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("steel_ingot", {
image = "steel_ingot.png",
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("clay_brick", {
image = "clay_brick.png",
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("rat", {
@ -1208,13 +1188,13 @@ minetest.register_craftitem("rat", {
minetest.register_craftitem("cooked_rat", {
image = "cooked_rat.png",
cookresult_item = 'CraftItem "scorched_stuff" 1',
on_place_on_ground = craftitem_place_item,
on_use = craftitem_eat(6),
on_place_on_ground = minetest.craftitem_place_item,
on_use = minetest.craftitem_eat(6),
})
minetest.register_craftitem("scorched_stuff", {
image = "scorched_stuff.png",
on_place_on_ground = craftitem_place_item,
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem("firefly", {
@ -1227,14 +1207,14 @@ minetest.register_craftitem("firefly", {
minetest.register_craftitem("apple", {
image = "apple.png",
on_place_on_ground = craftitem_place_item,
on_use = craftitem_eat(4),
on_place_on_ground = minetest.craftitem_place_item,
on_use = minetest.craftitem_eat(4),
})
minetest.register_craftitem("apple_iron", {
image = "apple_iron.png",
on_place_on_ground = craftitem_place_item,
on_use = craftitem_eat(8),
on_place_on_ground = minetest.craftitem_place_item,
on_use = minetest.craftitem_eat(8),
})
print(dump(minetest.registered_craftitems))