5 -- An example furnace-thing implemented in Lua
7 minetest.register_node("luafurnace", {
8 tile_images = {"lava.png", "furnace_side.png", "furnace_side.png",
9 "furnace_side.png", "furnace_side.png", "furnace_front.png"},
10 --inventory_image = "furnace_front.png",
11 inventory_image = inventorycube("furnace_front.png"),
12 paramtype = "facedir_simple",
13 metadata_name = "generic",
14 material = digprop_stonelike(3.0),
17 minetest.register_on_placenode(function(pos, newnode, placer)
18 if newnode.name == "luafurnace" then
20 local meta = minetest.env:get_meta(pos)
21 print("inventory_set_list");
22 meta:inventory_set_list("fuel", {""})
23 print("inventory_set_list");
24 meta:inventory_set_list("src", {""})
25 print("inventory_set_list");
26 meta:inventory_set_list("dst", {"","","",""})
27 print("set_inventory_draw_spec");
28 meta:set_inventory_draw_spec(
30 .."list[current_name;fuel;2,3;1,1;]"
31 .."list[current_name;src;2,1;1,1;]"
32 .."list[current_name;dst;5,1;2,2;]"
33 .."list[current_player;main;0,5;8,4;]"
36 local total_cooked = 0;
38 meta:set_string("total_cooked", total_cooked)
39 print("set_infotext");
40 meta:set_infotext("Lua Furnace: total cooked: "..total_cooked)
44 minetest.register_abm({
45 nodenames = {"luafurnace"},
48 action = function(pos, node, active_object_count, active_object_count_wider)
49 local meta = minetest.env:get_meta(pos)
50 local fuellist = meta:inventory_get_list("fuel")
51 local srclist = meta:inventory_get_list("src")
52 local dstlist = meta:inventory_get_list("dst")
53 if fuellist == nil or srclist == nil or dstlist == nil then
56 _, srcitem = stackstring_take_item(srclist[1])
57 _, fuelitem = stackstring_take_item(fuellist[1])
58 if not srcitem or not fuelitem then return end
59 if fuelitem.type == "NodeItem" then
60 local prop = minetest.registered_nodes[fuelitem.name]
61 if prop == nil then return end
62 if prop.furnace_burntime < 0 then return end
66 local resultstack = nil
67 if srcitem.type == "NodeItem" then
68 local prop = minetest.registered_nodes[srcitem.name]
69 if prop == nil then return end
70 if prop.cookresult_item == "" then return end
71 resultstack = prop.cookresult_item
76 if resultstack == nil then
80 dstlist[1], success = stackstring_put_stackstring(dstlist[1], resultstack)
85 fuellist[1], _ = stackstring_take_item(fuellist[1])
86 srclist[1], _ = stackstring_take_item(srclist[1])
88 meta:inventory_set_list("fuel", fuellist)
89 meta:inventory_set_list("src", srclist)
90 meta:inventory_set_list("dst", dstlist)
92 local total_cooked = meta:get_string("total_cooked")
93 total_cooked = tonumber(total_cooked) + 1
94 meta:set_string("total_cooked", total_cooked)
95 meta:set_infotext("Lua Furnace: total cooked: "..total_cooked)
99 minetest.register_craft({
100 output = 'NodeItem "luafurnace" 1',
102 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
103 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
104 {'NodeItem "cobble"', 'NodeItem "cobble"', 'NodeItem "cobble"'},
113 minetest.register_tool("horribletool", {
128 minetest.register_craft({
129 output = 'NodeItem "somenode" 4',
131 {'CraftItem "Stick" 1'},
135 minetest.register_node("somenode", {
136 tile_images = {"lava.png", "mese.png", "stone.png", "grass.png", "cobble.png", "tree_top.png"},
137 inventory_image = "treeprop.png",
139 diggability = "normal",
146 metadata_name = "chest",
150 -- TNT (not functional)
153 minetest.register_craft({
154 output = 'NodeItem "TNT" 4',
156 {'NodeItem "wood" 1'},
157 {'CraftItem "lump_of_coal" 1'},
158 {'NodeItem "wood" 1'}
162 minetest.register_node("TNT", {
163 tile_images = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png", "tnt_side.png", "tnt_side.png", "tnt_side.png"},
164 inventory_image = "tnt_side.png",
165 dug_item = '', -- Get nothing
173 physical = true, -- Collides with things
175 collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
177 textures = {"tnt_top.png","tnt_bottom.png","tnt_side.png","tnt_side.png","tnt_side.png","tnt_side.png"},
178 -- Initial value for our timer
180 -- Number of punches required to defuse
186 -- Called when a TNT object is created
187 function TNT:on_activate(staticdata)
188 print("TNT:on_activate()")
189 self.object:setvelocity({x=0, y=4, z=0})
190 self.object:setacceleration({x=0, y=-10, z=0})
191 self.object:settexturemod("^[brighten")
194 -- Called periodically
195 function TNT:on_step(dtime)
196 --print("TNT:on_step()")
197 self.timer = self.timer + dtime
198 self.blinktimer = self.blinktimer + dtime
199 if self.blinktimer > 0.5 then
200 self.blinktimer = self.blinktimer - 0.5
201 if self.blinkstatus then
202 self.object:settexturemod("")
204 self.object:settexturemod("^[brighten")
206 self.blinkstatus = not self.blinkstatus
210 -- Called when object is punched
211 function TNT:on_punch(hitter)
212 print("TNT:on_punch()")
213 self.health = self.health - 1
214 if self.health <= 0 then
216 hitter:add_to_inventory("NodeItem TNT 1")
217 hitter:set_hp(hitter:get_hp() - 1)
221 -- Called when object is right-clicked
222 function TNT:on_rightclick(clicker)
223 --pos = self.object:getpos()
224 --pos = {x=pos.x, y=pos.y+0.1, z=pos.z}
225 --self.object:moveto(pos, false)
228 print("TNT dump: "..dump(TNT))
230 print("Registering TNT");
231 minetest.register_entity("TNT", TNT)
234 -- A test entity for testing animated and yaw-modulated sprites
237 minetest.register_entity("testentity", {
239 physical = true, -- Collides with things
241 collisionbox = {-0.7,-1.35,-0.7, 0.7,1.0,0.7},
242 --collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
244 visual_size = {x=2, y=3},
245 textures = {"dungeon_master.png^[makealpha:128,0,0^[makealpha:128,128,0"},
246 spritediv = {x=6, y=5},
247 initial_sprite_basepos = {x=0, y=0},
249 on_activate = function(self, staticdata)
250 print("testentity.on_activate")
251 self.object:setsprite({x=0,y=0}, 1, 0, true)
252 --self.object:setsprite({x=0,y=0}, 4, 0.3, true)
255 self.object:setacceleration({x=0, y=-10, z=0})
256 -- Jump a bit upwards
257 self.object:setvelocity({x=0, y=10, z=0})
260 on_punch = function(self, hitter)
262 hitter:add_to_inventory('CraftItem testobject1 1')
270 minetest.register_on_respawnplayer(function(player)
271 print("on_respawnplayer")
272 -- player:setpos({x=0, y=30, z=0})
276 minetest.register_on_generated(function(minp, maxp)
277 --print("on_generated: minp="..dump(minp).." maxp="..dump(maxp))
278 --cp = {x=(minp.x+maxp.x)/2, y=(minp.y+maxp.y)/2, z=(minp.z+maxp.z)/2}
279 --minetest.env:add_node(cp, {name="sand"})
282 -- Example setting get
283 print("setting max_users = " .. dump(minetest.setting_get("max_users")))
284 print("setting asdf = " .. dump(minetest.setting_get("asdf")))
286 minetest.register_on_chat_message(function(name, message)
287 --[[print("on_chat_message: name="..dump(name).." message="..dump(message))
288 local cmd = "/testcommand"
289 if message:sub(0, #cmd) == cmd then
290 print(cmd.." invoked")
294 if message:sub(0, #cmd) == cmd then
295 print("script-overridden help command")
296 minetest.chat_send_all("script-overridden help command")
301 -- Grow papyrus on TNT every 10 seconds
302 --[[minetest.register_abm({
306 action = function(pos, node, active_object_count, active_object_count_wider)
307 print("TNT ABM action")
309 minetest.env:add_node(pos, {name="papyrus"})
313 -- Replace texts of alls signs with "foo" every 10 seconds
314 --[[minetest.register_abm({
315 nodenames = {"sign_wall"},
318 action = function(pos, node, active_object_count, active_object_count_wider)
319 print("ABM: Sign text changed")
320 local meta = minetest.env:get_meta(pos)
325 --[[local ncpos = nil
328 {2, 1, 0, 3}, {3, 0, 1, 2}, {4, -1, 0, 1}, {5, -1, 0, 1}, {6, 0, -1, 0},
329 {7, 0, -1, 0}, {8, 1, 0, 3}, {9, 1, 0, 3}, {10, 1, 0, 3}, {11, 0, 1, 2},
330 {12, 0, 1, 2}, {13, 0, 1, 2}, {14, -1, 0, 1}, {15, -1, 0, 1}, {16, -1, 0, 1},
331 {17, -1, 0, 1}, {18, 0, -1, 0}, {19, 0, -1, 0}, {20, 0, -1, 0}, {21, 0, -1, 0},
332 {22, 1, 0, 3}, {23, 1, 0, 3}, {24, 1, 0, 3}, {25, 1, 0, 3}, {10, 0, 1, 2}
337 minetest.register_abm({
338 nodenames = {"dirt_with_grass"},
341 action = function(pos, node, active_object_count, active_object_count_wider)
346 if pos.x % 16 ~= 8 or pos.z % 16 ~= 8 then
351 n = minetest.env:get_node(pos)
353 if n.name ~= "air" then
360 minetest.env:add_node(ncpos, {name="nyancat"})
364 minetest.register_abm({
365 nodenames = {"nyancat"},
368 action = function(pos, node, active_object_count, active_object_count_wider)
372 if pos.x == ncpos.x and pos.y == ncpos.y and pos.z == ncpos.z then
374 if clock - nctime < 0.1 then
383 p1 = {x = p0.x + s0[2], y = p0.y, z = p0.z + s0[3]}
384 p2 = {x = p1.x + s1[2], y = p1.y, z = p1.z + s1[3]}
385 table.insert(ncold, 1, p0)
386 while #ncold >= 10 do
387 minetest.env:add_node(ncold[#ncold], {name="air"})
388 table.remove(ncold, #ncold)
390 minetest.env:add_node(p0, {name="nyancat_rainbow"})
391 minetest.env:add_node(p1, {name="nyancat", param1=s0[4]})
392 minetest.env:add_node(p2, {name="air"})