aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/builtin.lua31
-rw-r--r--data/mods/bucket/init.lua11
-rw-r--r--data/mods/default/init.lua50
3 files changed, 49 insertions, 43 deletions
diff --git a/data/builtin.lua b/data/builtin.lua
index dc41caf69..c3e426db5 100644
--- a/data/builtin.lua
+++ b/data/builtin.lua
@@ -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)
@@ -297,6 +304,30 @@ 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
--
diff --git a/data/mods/bucket/init.lua b/data/mods/bucket/init.lua
index aaed49ab1..013ff2408 100644
--- a/data/mods/bucket/init.lua
+++ b/data/mods/bucket/init.lua
@@ -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)
diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua
index f04f381c4..858e002c7 100644
--- a/data/mods/default/init.lua
+++ b/data/mods/default/init.lua
@@ -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))