1 -- default (Minetest 0.4 mod)
4 -- Quick documentation about the API
5 -- =================================
7 -- Helper functions defined by builtin.lua:
8 -- dump2(obj, name="_", dumped={})
9 -- dump(obj, dumped={})
15 -- $path_userdata/usermods/
18 -- On a run-in-place version (eg. the distributed windows version):
19 -- minetest-0.4.x/data/mods/
20 -- minetest-0.4.x/usermods/
21 -- minetest-0.4.x/world/worldmods/
23 -- On an installed version on linux:
24 -- /usr/share/minetest/mods/
25 -- ~/.minetest/usermods
26 -- ~/.minetest/world/worldmods
28 -- Naming convention for registered textual names
29 -- ----------------------------------------------
30 -- "modname:<whatever>" (<whatever> can have characters a-zA-Z0-9_)
32 -- This is to prevent conflicting names from corrupting maps and is
33 -- enforced by the mod loader.
35 -- Example: mod "experimental", ideal item/node/entity name "tnt":
36 -- -> the name should be "experimental:tnt".
38 -- Enforcement can be overridden by prefixing the name with ":". This can
39 -- be used for overriding the registrations of some other mod.
41 -- Example: Any mod can redefine experimental:tnt by using the name
42 -- ":experimental:tnt" when registering it.
43 -- (also that mods is required to have "experimental" as a dependency)
45 -- The legacy mod uses ":" for maintaining backwards compatibility.
49 -- Mods should generally prefix their textures with modname_, eg. given
50 -- the mod name "foomod", a texture could be called "default_foomod_superfurnace.png"
52 -- This is not crucial and a conflicting name will not corrupt maps.
54 -- Representations of simple things
55 -- --------------------------------
57 -- MapNode representation:
58 -- {name="name", param1=num, param2=num}
60 -- param1 and param2 are 8 bit and 4 bit integers, respectively. They
61 -- are reserved for certain automated functions. If you don't use these
62 -- functions, you can use them to store arbitrary values.
64 -- param1 is reserved for the engine when:
65 -- paramtype != "none"
66 -- param2 is reserved for the engine when any of these are used:
67 -- liquidtype == "flowing"
68 -- drawtype == "flowingliquid"
69 -- drawtype == "torchlike"
70 -- drawtype == "signlike"
72 -- Position representation:
73 -- {x=num, y=num, z=num}
75 -- stackstring/itemstring: A stack of items in serialized format.
76 -- eg. 'node "default:dirt" 5'
77 -- eg. 'tool "default:pick_wood" 21323'
78 -- eg. 'craft "default:apple" 2'
80 -- item: A stack of items in Lua table format.
81 -- eg. {name="default:dirt", count=1, wear=0, metadata=""}
82 -- ^ a single dirt node
83 -- eg. {name="default:pick_wood", count=1, wear=21323, metadata=""}
84 -- ^ a wooden pick about 1/3 weared out
85 -- eg. {name="default:apple", count=1, wear=0, metadata=""}
88 -- Any time an item must be passed to a function, it can be an
89 -- ItemStack (see below), an itemstring or a table in the above format.
92 -- minetest.register_entity(name, prototype table)
93 -- minetest.register_abm(abm definition)
94 -- minetest.register_node(name, node definition)
95 -- minetest.register_tool(name, item definition)
96 -- minetest.register_craftitem(name, item definition)
97 -- minetest.register_alias(name, convert_to)
98 -- minetest.register_craft(recipe)
99 -- minetest.register_globalstep(func(dtime))
100 -- minetest.register_on_placenode(func(pos, newnode, placer))
101 -- minetest.register_on_dignode(func(pos, oldnode, digger))
102 -- minetest.register_on_punchnode(func(pos, node, puncher))
103 -- minetest.register_on_generated(func(minp, maxp))
104 -- minetest.register_on_newplayer(func(ObjectRef))
105 -- minetest.register_on_dieplayer(func(ObjectRef))
106 -- minetest.register_on_respawnplayer(func(ObjectRef))
107 -- ^ return true in func to disable regular player placement
108 -- ^ currently called _before_ repositioning of player occurs
109 -- minetest.register_on_chat_message(func(name, message))
110 -- minetest.add_to_creative_inventory(itemstring)
111 -- minetest.setting_get(name) -> string or nil
112 -- minetest.setting_getbool(name) -> boolean value or nil
113 -- minetest.chat_send_all(text)
114 -- minetest.chat_send_player(name, text)
115 -- minetest.get_player_privs(name) -> set of privs
116 -- minetest.get_inventory(location) -> InvRef
117 -- ^ location = eg. {type="player", name="celeron55"}
118 -- {type="node", pos={x=, y=, z=}}
119 -- minetest.get_current_modname() -> string
120 -- minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
121 -- ^ Useful for loading additional .lua modules or static data from mod
122 -- minetest.get_worldpath(modname) -> eg. "/home/user/.minetest/world"
123 -- ^ Useful for storing custom data
125 -- minetest.debug(line)
127 -- minetest.log(line)
128 -- minetest.log(loglevel, line)
129 -- ^ loglevel one of "error", "action", "info", "verbose"
131 -- minetest.digprop_constanttime(time)
132 -- minetest.digprop_stonelike(toughness)
133 -- minetest.digprop_dirtlike(toughness)
134 -- minetest.digprop_gravellike(toughness)
135 -- minetest.digprop_woodlike(toughness)
136 -- minetest.digprop_leaveslike(toughness)
137 -- minetest.digprop_glasslike(toughness)
140 -- minetest.env - environment reference
143 -- minetest.registered_items
144 -- ^ List of registered items, indexed by name
145 -- minetest.registered_nodes
146 -- ^ List of registered node definitions, indexed by name
147 -- minetest.registered_craftitems
148 -- ^ List of registered craft item definitions, indexed by name
149 -- minetest.registered_tools
150 -- ^ List of registered tool definitions, indexed by name
151 -- minetest.registered_entities
152 -- ^ List of registered entity prototypes, indexed by name
153 -- minetest.object_refs
154 -- ^ List of object references, indexed by active object id
155 -- minetest.luaentities
156 -- ^ List of lua entities, indexed by active object id
158 -- EnvRef is basically ServerEnvironment and ServerMap combined.
160 -- - add_node(pos, node)
161 -- - remove_node(pos)
163 -- ^ Returns {name="ignore", ...} for unloaded area
164 -- - get_node_or_nil(pos)
165 -- ^ Returns nil for unloaded area
166 -- - get_node_light(pos, timeofday) -> 0...15 or nil
167 -- ^ timeofday: nil = current time, 0 = night, 0.5 = day
168 -- - add_entity(pos, name): Returns ObjectRef or nil if failed
169 -- - add_item(pos, itemstring)
171 -- - add_firefly(pos)
172 -- - get_meta(pos) -- Get a NodeMetaRef at that position
173 -- - get_player_by_name(name) -- Get an ObjectRef to a player
174 -- - get_objects_inside_radius(pos, radius)
175 -- - set_timeofday(val): val: 0...1; 0 = midnight, 0.5 = midday
178 -- NodeMetaRef (this stuff is subject to change in a future version)
180 -- - allows_text_input()
181 -- - set_text(text) -- eg. set the text of a sign
184 -- - set_owner(string)
185 -- Generic node metadata specific:
186 -- - set_infotext(infotext)
187 -- - get_inventory() -> InvRef
188 -- - set_inventory_draw_spec(string)
189 -- - set_allow_text_input(bool)
190 -- - set_allow_removal(bool)
191 -- - set_enforce_owner(bool)
192 -- - is_inventory_modified()
193 -- - reset_inventory_modified()
194 -- - is_text_modified()
195 -- - reset_text_modified()
196 -- - set_string(name, value)
197 -- - get_string(name)
199 -- ObjectRef is basically ServerActiveObject.
200 -- ObjectRef methods:
201 -- - remove(): remove object (after returning from Lua)
202 -- - getpos() -> {x=num, y=num, z=num}
203 -- - setpos(pos); pos={x=num, y=num, z=num}
204 -- - moveto(pos, continuous=false): interpolated move
205 -- - punch(puncher, time_from_last_punch, tool_capabilities, direction)
206 -- ^ puncher = an another ObjectRef,
207 -- ^ time_from_last_punch = time since last punch action of the puncher
208 -- - right_click(clicker); clicker = an another ObjectRef
209 -- - get_hp(): returns number of hitpoints (2 * number of hearts)
210 -- - set_hp(hp): set number of hitpoints (2 * number of hearts)
211 -- - get_inventory() -> InvRef
212 -- - get_wield_list(): returns the name of the inventory list the wielded item is in
213 -- - get_wield_index(): returns the index of the wielded item
214 -- - get_wielded_item() -> ItemStack
215 -- - set_wielded_item(item): replaces the wielded item, returns true if successful
216 -- LuaEntitySAO-only: (no-op for other objects)
217 -- - setvelocity({x=num, y=num, z=num})
218 -- - getvelocity() -> {x=num, y=num, z=num}
219 -- - setacceleration({x=num, y=num, z=num})
220 -- - getacceleration() -> {x=num, y=num, z=num}
222 -- - getyaw() -> radians
223 -- - settexturemod(mod)
224 -- - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
225 -- - select_horiz_by_yawpitch=false)
226 -- - ^ Select sprite from spritesheet with optional animation and DM-style
227 -- - texture selection based on yaw relative to camera
228 -- - set_armor_groups({group1=rating, group2=rating, ...})
229 -- - get_entity_name() (DEPRECATED: Will be removed in a future version)
231 -- Player-only: (no-op for other objects)
232 -- - get_player_name(): will return nil if is not a player
233 -- - get_look_dir(): get camera direction as a unit vector
234 -- - get_look_pitch(): pitch in radians
235 -- - get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
238 -- - get_size(listname): get size of a list
239 -- - set_size(listname, size): set size of a list
240 -- - get_stack(listname, i): get a copy of stack index i in list
241 -- - set_stack(listname, i, stack): copy stack to index i in list
242 -- - get_list(listname): return full list
243 -- - set_list(listname, list): set full list (size will not change)
244 -- - add_item(listname, stack): add item somewhere in list, returns leftover ItemStack
245 -- - room_for_item(listname, stack): returns true if the stack of items
246 -- can be fully added to the list
247 -- - contains_item(listname, stack): returns true if the stack of items
248 -- can be fully taken from the list
249 -- remove_item(listname, stack): take as many items as specified from the list,
250 -- returns the items that were actually removed (as an ItemStack)
252 -- ItemStack methods:
253 -- - is_empty(): return true if stack is empty
254 -- - get_name(): returns item name (e.g. "default:stone")
255 -- - get_count(): returns number of items on the stack
256 -- - get_wear(): returns tool wear (0-65535), 0 for non-tools
257 -- - get_metadata(): returns metadata (a string attached to an item stack)
258 -- - clear(): removes all items from the stack, making it empty
259 -- - replace(item): replace the contents of this stack (item can also
260 -- be an itemstring or table)
261 -- - to_string(): returns the stack in itemstring form
262 -- - to_table(): returns the stack in Lua table form
263 -- - get_stack_max(): returns the maximum size of the stack (depends on the item)
264 -- - get_free_space(): returns get_stack_max() - get_count()
265 -- - is_known(): returns true if the item name refers to a defined item type
266 -- - get_definition(): returns the item definition table
267 -- - get_tool_capabilities(): returns the digging properties of the item,
268 -- ^ or those of the hand if none are defined for this item type
269 -- - add_wear(amount): increases wear by amount if the item is a tool
270 -- - add_item(item): put some item or stack onto this stack,
271 -- ^ returns leftover ItemStack
272 -- - item_fits(item): returns true if item or stack can be fully added to this one
273 -- - take_item(n): take (and remove) up to n items from this stack
274 -- ^ returns taken ItemStack
275 -- ^ if n is omitted, n=1 is used
276 -- - peek_item(n): copy (don't remove) up to n items from this stack
277 -- ^ returns copied ItemStack
278 -- ^ if n is omitted, n=1 is used
280 -- Registered entities:
281 -- - Functions receive a "luaentity" as self:
282 -- - It has the member .name, which is the registered name ("mod:thing")
283 -- - It has the member .object, which is an ObjectRef pointing to the object
284 -- - The original prototype stuff is visible directly via a metatable
286 -- - on_activate(self, staticdata)
287 -- - on_step(self, dtime)
288 -- - on_punch(self, hitter)
289 -- - on_rightclick(self, clicker)
290 -- - get_staticdata(self)
291 -- ^ return string that will be passed to on_activate when the object
292 -- is created next time
294 -- Entity prototype table:
297 -- collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
298 -- visual = "cube"/"sprite",
299 -- visual_size = {x=1, y=1},
300 -- textures = {texture,texture,texture,texture,texture,texture},
301 -- spritediv = {x=1, y=1},
302 -- initial_sprite_basepos = {x=0, y=0},
303 -- on_activate = function(self, staticdata),
304 -- on_step = function(self, dtime),
305 -- on_punch = function(self, hitter),
306 -- on_rightclick = function(self, clicker),
307 -- get_staticdata = function(self),
308 -- # Also you can define arbitrary member variables here
309 -- myvariable = whatever,
312 -- Item definition options (register_node, register_craftitem, register_tool)
314 -- description = "Steel Axe",
315 -- groups = {}, -- key=name, value=rating; rating=1..3.
316 -- if rating not applicable, use 1.
317 -- eg. {wool=1, fluffy=3}
318 -- {soil=2, outerspace=1, crumbly=1}
319 -- {hard=3, brittle=3, spikes=2
320 -- {hard=1, metal=1, spikes=1}
321 -- inventory_image = "default_tool_steelaxe.png",
323 -- wield_scale = {x=1,y=1,z=1},
325 -- liquids_pointable = false,
326 -- tool_capabilities = {
327 -- full_punch_interval = 1.0,
330 -- dt_crackiness = -0.2,
331 -- dt_crumbliness = 1,
332 -- dt_cuttability = -0.5,
333 -- basedurability = 330,
335 -- dd_crackiness = 0,
336 -- dd_crumbliness = 0,
337 -- dd_cuttability = 0,
339 -- on_drop = func(item, dropper, pos),
340 -- on_place = func(item, placer, pointed_thing),
341 -- on_use = func(item, user, pointed_thing),
344 -- Node definition options (register_node):
346 -- <all fields allowed in item definitions>,
347 -- drawtype = "normal",
348 -- visual_scale = 1.0,
349 -- tile_images = {"default_unknown_block.png"},
350 -- special_materials = {
351 -- {image="", backface_culling=true},
352 -- {image="", backface_culling=true},
355 -- post_effect_color = {a=0, r=0, g=0, b=0},
356 -- paramtype = "none",
357 -- paramtype2 = "none",
358 -- is_ground_content = false,
359 -- sunlight_propagates = false,
363 -- climbable = false,
364 -- buildable_to = false,
366 -- -- alternatively drop = { max_items = ..., items = { ... } }
367 -- metadata_name = "",
368 -- liquidtype = "none",
369 -- liquid_alternative_flowing = "",
370 -- liquid_alternative_source = "",
371 -- liquid_viscosity = 0,
373 -- damage_per_second = 0,
374 -- selection_box = {type="regular"},
375 -- legacy_facedir_simple = false, -- Support maps made in and before January 2012
376 -- legacy_wallmounted = false, -- Support maps made in and before January 2012
381 -- output = 'default:pick_stone',
383 -- {'default:cobble', 'default:cobble', 'default:cobble'},
384 -- {'', 'default:stick', ''},
385 -- {'', 'default:stick', ''},
387 -- replacements = <optional list of item pairs,
388 -- replace one input item with another item on crafting>
391 -- Recipe (shapeless):
393 -- type = "shapeless",
394 -- output = 'mushrooms:mushroom_stew',
397 -- "mushrooms:mushroom_brown",
398 -- "mushrooms:mushroom_red",
400 -- replacements = <optional list of item pairs,
401 -- replace one input item with another item on crafting>
404 -- Recipe (tool repair):
406 -- type = "toolrepair",
407 -- additional_wear = -0.02,
413 -- output = "default:glass",
414 -- recipe = "default:sand",
418 -- Recipe (furnace fuel):
421 -- recipe = "default:leaves",
425 -- ABM (ActiveBlockModifier) definition:
427 -- nodenames = {"default:lava_source"},
428 -- neighbors = {"default:water_source", "default:water_flowing"}, -- (any of these)
429 -- ^ If left out or empty, any neighbor will do
430 -- ^ This might get removed in the future
431 -- interval = 1.0, -- (operation interval)
432 -- chance = 1, -- (chance of trigger is 1.0/this)
433 -- action = func(pos, node, active_object_count, active_object_count_wider),
441 -- Definitions made by this mod that other mods can use too
448 minetest.register_tool("default:pick_wood", {
449 description = "Wooden Pickaxe",
450 inventory_image = "default_tool_woodpick.png",
451 tool_capabilities = {
454 cracky={times={[2]=1.50, [3]=0.80}, maxwear=0.1, maxlevel=1}
458 minetest.register_tool("default:pick_stone", {
459 description = "Stone Pickaxe",
460 inventory_image = "default_tool_stonepick.png",
461 tool_capabilities = {
464 cracky={times={[1]=1.50, [2]=0.80, [3]=0.60}, maxwear=0.05, maxlevel=1}
468 minetest.register_tool("default:pick_steel", {
469 description = "Steel Pickaxe",
470 inventory_image = "default_tool_steelpick.png",
471 tool_capabilities = {
474 cracky={times={[1]=1.00, [2]=0.60, [3]=0.40}, maxwear=0.1, maxlevel=2}
478 minetest.register_tool("default:pick_mese", {
479 description = "Mese Pickaxe",
480 inventory_image = "default_tool_mesepick.png",
481 tool_capabilities = {
484 cracky={times={[1]=0.2, [2]=0.2, [3]=0.2}, maxwear=0.05, maxlevel=3},
485 crumbly={times={[1]=0.2, [2]=0.2, [3]=0.2}, maxwear=0.05, maxlevel=3},
486 snappy={times={[1]=0.2, [2]=0.2, [3]=0.2}, maxwear=0.05, maxlevel=3}
490 minetest.register_tool("default:shovel_wood", {
491 description = "Wooden Shovel",
492 inventory_image = "default_tool_woodshovel.png",
493 tool_capabilities = {
496 crumbly={times={[1]=1.50, [2]=0.80, [3]=0.50}, maxwear=0.1, maxlevel=1}
500 minetest.register_tool("default:shovel_stone", {
501 description = "Stone Shovel",
502 inventory_image = "default_tool_stoneshovel.png",
503 tool_capabilities = {
506 crumbly={times={[1]=0.80, [2]=0.50, [3]=0.30}, maxwear=0.05, maxlevel=1}
510 minetest.register_tool("default:shovel_steel", {
511 description = "Steel Shovel",
512 inventory_image = "default_tool_steelshovel.png",
513 tool_capabilities = {
516 crumbly={times={[1]=0.50, [2]=0.35, [3]=0.30}, maxwear=0.1, maxlevel=2}
520 minetest.register_tool("default:axe_wood", {
521 description = "Wooden Axe",
522 inventory_image = "default_tool_woodaxe.png",
523 tool_capabilities = {
526 choppy={times={[2]=1.50, [3]=0.80}, maxwear=0.1, maxlevel=1},
527 fleshy={times={[2]=1.50, [3]=0.80}, maxwear=0.1, maxlevel=1}
531 minetest.register_tool("default:axe_stone", {
532 description = "Stone Axe",
533 inventory_image = "default_tool_stoneaxe.png",
534 tool_capabilities = {
537 choppy={times={[1]=1.50, [2]=1.00, [3]=0.60}, maxwear=0.05, maxlevel=1},
538 fleshy={times={[2]=1.30, [3]=0.70}, maxwear=0.05, maxlevel=1}
542 minetest.register_tool("default:axe_steel", {
543 description = "Steel Axe",
544 inventory_image = "default_tool_steelaxe.png",
545 tool_capabilities = {
548 choppy={times={[1]=1.00, [2]=0.80, [3]=0.50}, maxwear=0.1, maxlevel=2},
549 fleshy={times={[2]=1.10, [3]=0.60}, maxwear=0.03, maxlevel=1}
553 minetest.register_tool("default:sword_wood", {
554 description = "Wooden Sword",
555 inventory_image = "default_tool_woodsword.png",
556 tool_capabilities = {
557 full_punch_interval = 2.0,
560 fleshy={times={[2]=1.10, [3]=0.60}, maxwear=0.1, maxlevel=1},
561 snappy={times={[2]=1.00, [3]=0.50}, maxwear=0.1, maxlevel=1},
562 choppy={times={[3]=1.00}, maxwear=0.05, maxlevel=0}
566 minetest.register_tool("default:sword_stone", {
567 description = "Stone Sword",
568 inventory_image = "default_tool_stonesword.png",
569 tool_capabilities = {
570 full_punch_interval = 2.0,
573 fleshy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1},
574 snappy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1},
575 choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0}
579 minetest.register_tool("default:sword_steel", {
580 description = "Steel Sword",
581 inventory_image = "default_tool_steelsword.png",
582 tool_capabilities = {
583 full_punch_interval = 2.0,
586 fleshy={times={[1]=1.00, [2]=0.40, [3]=0.20}, maxwear=0.1, maxlevel=2},
587 snappy={times={[2]=0.70, [3]=0.30}, maxwear=0.03, maxlevel=1},
588 choppy={times={[3]=0.70}, maxwear=0.03, maxlevel=0}
594 -- Crafting definition
597 minetest.register_craft({
598 output = 'default:wood 4',
604 minetest.register_craft({
605 output = 'default:stick 4',
611 minetest.register_craft({
612 output = 'default:fence_wood 2',
614 {'default:stick', 'default:stick', 'default:stick'},
615 {'default:stick', 'default:stick', 'default:stick'},
619 minetest.register_craft({
620 output = 'default:sign_wall',
622 {'default:wood', 'default:wood', 'default:wood'},
623 {'default:wood', 'default:wood', 'default:wood'},
624 {'', 'default:stick', ''},
628 minetest.register_craft({
629 output = 'default:torch 4',
631 {'default:coal_lump'},
636 minetest.register_craft({
637 output = 'default:pick_wood',
639 {'default:wood', 'default:wood', 'default:wood'},
640 {'', 'default:stick', ''},
641 {'', 'default:stick', ''},
645 minetest.register_craft({
646 output = 'default:pick_stone',
648 {'default:cobble', 'default:cobble', 'default:cobble'},
649 {'', 'default:stick', ''},
650 {'', 'default:stick', ''},
654 minetest.register_craft({
655 output = 'default:pick_steel',
657 {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
658 {'', 'default:stick', ''},
659 {'', 'default:stick', ''},
663 minetest.register_craft({
664 output = 'default:pick_mese',
666 {'default:mese', 'default:mese', 'default:mese'},
667 {'', 'default:stick', ''},
668 {'', 'default:stick', ''},
672 minetest.register_craft({
673 output = 'default:shovel_wood',
681 minetest.register_craft({
682 output = 'default:shovel_stone',
690 minetest.register_craft({
691 output = 'default:shovel_steel',
693 {'default:steel_ingot'},
699 minetest.register_craft({
700 output = 'default:axe_wood',
702 {'default:wood', 'default:wood'},
703 {'default:wood', 'default:stick'},
704 {'', 'default:stick'},
708 minetest.register_craft({
709 output = 'default:axe_stone',
711 {'default:cobble', 'default:cobble'},
712 {'default:cobble', 'default:stick'},
713 {'', 'default:stick'},
717 minetest.register_craft({
718 output = 'default:axe_steel',
720 {'default:steel_ingot', 'default:steel_ingot'},
721 {'default:steel_ingot', 'default:stick'},
722 {'', 'default:stick'},
726 minetest.register_craft({
727 output = 'default:sword_wood',
735 minetest.register_craft({
736 output = 'default:sword_stone',
744 minetest.register_craft({
745 output = 'default:sword_steel',
747 {'default:steel_ingot'},
748 {'default:steel_ingot'},
753 minetest.register_craft({
754 output = 'default:rail 15',
756 {'default:steel_ingot', '', 'default:steel_ingot'},
757 {'default:steel_ingot', 'default:stick', 'default:steel_ingot'},
758 {'default:steel_ingot', '', 'default:steel_ingot'},
762 minetest.register_craft({
763 output = 'default:chest',
765 {'default:wood', 'default:wood', 'default:wood'},
766 {'default:wood', '', 'default:wood'},
767 {'default:wood', 'default:wood', 'default:wood'},
771 minetest.register_craft({
772 output = 'default:chest_locked',
774 {'default:wood', 'default:wood', 'default:wood'},
775 {'default:wood', 'default:steel_ingot', 'default:wood'},
776 {'default:wood', 'default:wood', 'default:wood'},
780 minetest.register_craft({
781 output = 'default:furnace',
783 {'default:cobble', 'default:cobble', 'default:cobble'},
784 {'default:cobble', '', 'default:cobble'},
785 {'default:cobble', 'default:cobble', 'default:cobble'},
789 minetest.register_craft({
790 output = 'default:steelblock',
792 {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
793 {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
794 {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
798 minetest.register_craft({
799 output = 'default:sandstone',
801 {'default:sand', 'default:sand'},
802 {'default:sand', 'default:sand'},
806 minetest.register_craft({
807 output = 'default:clay',
809 {'default:clay_lump', 'default:clay_lump'},
810 {'default:clay_lump', 'default:clay_lump'},
814 minetest.register_craft({
815 output = 'default:brick',
817 {'default:clay_brick', 'default:clay_brick'},
818 {'default:clay_brick', 'default:clay_brick'},
822 minetest.register_craft({
823 output = 'default:paper',
825 {'default:papyrus', 'default:papyrus', 'default:papyrus'},
829 minetest.register_craft({
830 output = 'default:book',
838 minetest.register_craft({
839 output = 'default:bookshelf',
841 {'default:wood', 'default:wood', 'default:wood'},
842 {'default:book', 'default:book', 'default:book'},
843 {'default:wood', 'default:wood', 'default:wood'},
847 minetest.register_craft({
848 output = 'default:ladder',
850 {'default:stick', '', 'default:stick'},
851 {'default:stick', 'default:stick', 'default:stick'},
852 {'default:stick', '', 'default:stick'},
857 -- Crafting (tool repair)
859 minetest.register_craft({
861 additional_wear = -0.02,
868 minetest.register_craft({
870 output = "default:glass",
871 recipe = "default:sand",
874 minetest.register_craft({
876 output = "default:coal_lump",
877 recipe = "default:tree",
880 minetest.register_craft({
882 output = "default:coal_lump",
883 recipe = "default:jungletree",
886 minetest.register_craft({
888 output = "default:stone",
889 recipe = "default:cobble",
892 minetest.register_craft({
894 output = "default:steel_ingot",
895 recipe = "default:iron_lump",
898 minetest.register_craft({
900 output = "default:clay_brick",
901 recipe = "default:clay_lump",
908 minetest.register_craft({
910 recipe = "default:tree",
914 minetest.register_craft({
916 recipe = "default:jungletree",
920 minetest.register_craft({
922 recipe = "default:junglegrass",
926 minetest.register_craft({
928 recipe = "default:leaves",
932 minetest.register_craft({
934 recipe = "default:cactus",
938 minetest.register_craft({
940 recipe = "default:papyrus",
944 minetest.register_craft({
946 recipe = "default:bookshelf",
950 minetest.register_craft({
952 recipe = "default:fence_wood",
956 minetest.register_craft({
958 recipe = "default:ladder",
962 minetest.register_craft({
964 recipe = "default:wood",
968 minetest.register_craft({
970 recipe = "default:mese",
974 minetest.register_craft({
976 recipe = "default:lava_source",
980 minetest.register_craft({
982 recipe = "default:torch",
986 minetest.register_craft({
988 recipe = "default:sign_wall",
992 minetest.register_craft({
994 recipe = "default:chest",
998 minetest.register_craft({
1000 recipe = "default:chest_locked",
1004 minetest.register_craft({
1006 recipe = "default:nyancat",
1010 minetest.register_craft({
1012 recipe = "default:nyancat_rainbow",
1016 minetest.register_craft({
1018 recipe = "default:sapling",
1022 minetest.register_craft({
1024 recipe = "default:apple",
1028 minetest.register_craft({
1030 recipe = "default:coal_lump",
1038 minetest.register_node("default:stone", {
1039 description = "Stone",
1040 tile_images = {"default_stone.png"},
1041 is_ground_content = true,
1042 groups = {cracky=3},
1043 drop = 'default:cobble',
1044 legacy_mineral = true,
1047 minetest.register_node("default:stone_with_coal", {
1048 description = "Stone with coal",
1049 tile_images = {"default_stone.png^default_mineral_coal.png"},
1050 is_ground_content = true,
1051 groups = {cracky=3},
1052 drop = 'default:coal_lump',
1055 minetest.register_node("default:stone_with_iron", {
1056 description = "Stone with iron",
1057 tile_images = {"default_stone.png^default_mineral_iron.png"},
1058 is_ground_content = true,
1059 groups = {cracky=3},
1060 drop = 'default:iron_lump',
1063 minetest.register_node("default:dirt_with_grass", {
1064 description = "Dirt with grass",
1065 tile_images = {"default_grass.png", "default_dirt.png", "default_dirt.png^default_grass_side.png"},
1066 is_ground_content = true,
1067 groups = {crumbly=3},
1068 drop = 'default:dirt',
1071 minetest.register_node("default:dirt_with_grass_footsteps", {
1072 description = "Dirt with grass and footsteps",
1073 tile_images = {"default_grass_footsteps.png", "default_dirt.png", "default_dirt.png^default_grass_side.png"},
1074 is_ground_content = true,
1075 groups = {crumbly=3},
1076 drop = 'default:dirt',
1079 minetest.register_node("default:dirt", {
1080 description = "Dirt",
1081 tile_images = {"default_dirt.png"},
1082 is_ground_content = true,
1083 groups = {crumbly=3},
1086 minetest.register_node("default:sand", {
1087 description = "Sand",
1088 tile_images = {"default_sand.png"},
1089 is_ground_content = true,
1090 groups = {crumbly=3},
1093 minetest.register_node("default:gravel", {
1094 description = "Gravel",
1095 tile_images = {"default_gravel.png"},
1096 is_ground_content = true,
1097 groups = {crumbly=2},
1100 minetest.register_node("default:sandstone", {
1101 description = "Sandstone",
1102 tile_images = {"default_sandstone.png"},
1103 is_ground_content = true,
1104 groups = {crumbly=2,cracky=2},
1105 drop = 'default:sand',
1108 minetest.register_node("default:clay", {
1109 description = "Clay",
1110 tile_images = {"default_clay.png"},
1111 is_ground_content = true,
1112 groups = {crumbly=3},
1113 drop = 'default:clay_lump 4',
1116 minetest.register_node("default:brick", {
1117 description = "Brick",
1118 tile_images = {"default_brick.png"},
1119 is_ground_content = true,
1120 groups = {cracky=3},
1121 drop = 'default:clay_brick 4',
1124 minetest.register_node("default:tree", {
1125 description = "Tree",
1126 tile_images = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"},
1127 is_ground_content = true,
1128 groups = {snappy=2,choppy=2},
1131 minetest.register_node("default:jungletree", {
1132 description = "Jungle Tree",
1133 tile_images = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"},
1134 is_ground_content = true,
1135 groups = {snappy=2,choppy=2},
1138 minetest.register_node("default:junglegrass", {
1139 description = "Jungle Grass",
1140 drawtype = "plantlike",
1142 tile_images = {"default_junglegrass.png"},
1143 inventory_image = "default_junglegrass.png",
1144 wield_image = "default_junglegrass.png",
1145 paramtype = "light",
1147 groups = {snappy=3},
1150 minetest.register_node("default:leaves", {
1151 description = "Leaves",
1152 drawtype = "allfaces_optional",
1154 tile_images = {"default_leaves.png"},
1155 paramtype = "light",
1156 groups = {snappy=3},
1161 -- player will get sapling with 1/20 chance
1162 items = {'default:sapling'},
1166 -- player will get leaves only if he get no saplings,
1167 -- this is because max_items is 1
1168 items = {'default:leaves'},
1174 minetest.register_node("default:cactus", {
1175 description = "Cactus",
1176 tile_images = {"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"},
1177 is_ground_content = true,
1178 groups = {snappy=2,choppy=3},
1181 minetest.register_node("default:papyrus", {
1182 description = "Papyrus",
1183 drawtype = "plantlike",
1184 tile_images = {"default_papyrus.png"},
1185 inventory_image = "default_papyrus.png",
1186 wield_image = "default_papyrus.png",
1187 paramtype = "light",
1188 is_ground_content = true,
1190 groups = {snappy=3},
1193 minetest.register_node("default:bookshelf", {
1194 description = "Bookshelf",
1195 tile_images = {"default_wood.png", "default_wood.png", "default_bookshelf.png"},
1196 is_ground_content = true,
1197 groups = {snappy=2,choppy=3},
1200 minetest.register_node("default:glass", {
1201 description = "Glass",
1202 drawtype = "glasslike",
1203 tile_images = {"default_glass.png"},
1204 inventory_image = minetest.inventorycube("default_glass.png"),
1205 paramtype = "light",
1206 sunlight_propagates = true,
1207 is_ground_content = true,
1208 groups = {snappy=2,cracky=3},
1211 minetest.register_node("default:fence_wood", {
1212 description = "Wooden Fence",
1213 drawtype = "fencelike",
1214 tile_images = {"default_wood.png"},
1215 inventory_image = "default_fence.png",
1216 wield_image = "default_fence.png",
1217 paramtype = "light",
1218 is_ground_content = true,
1221 fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
1223 groups = {snappy=2,choppy=2},
1226 minetest.register_node("default:rail", {
1227 description = "Rail",
1228 drawtype = "raillike",
1229 tile_images = {"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"},
1230 inventory_image = "default_rail.png",
1231 wield_image = "default_rail.png",
1232 paramtype = "light",
1233 is_ground_content = true,
1239 groups = {bendy=2,snappy=1},
1242 minetest.register_node("default:ladder", {
1243 description = "Ladder",
1244 drawtype = "signlike",
1245 tile_images = {"default_ladder.png"},
1246 inventory_image = "default_ladder.png",
1247 wield_image = "default_ladder.png",
1248 paramtype = "light",
1249 paramtype2 = "wallmounted",
1250 is_ground_content = true,
1254 type = "wallmounted",
1255 --wall_top = = <default>
1256 --wall_bottom = = <default>
1257 --wall_side = = <default>
1259 groups = {snappy=2,choppy=2},
1260 legacy_wallmounted = true,
1263 minetest.register_node("default:wood", {
1264 description = "Wood",
1265 tile_images = {"default_wood.png"},
1266 is_ground_content = true,
1267 groups = {snappy=2,choppy=2},
1270 minetest.register_node("default:mese", {
1271 description = "Mese",
1272 tile_images = {"default_mese.png"},
1273 is_ground_content = true,
1274 groups = {cracky=1},
1277 minetest.register_node("default:cloud", {
1278 description = "Cloud",
1279 tile_images = {"default_cloud.png"},
1280 is_ground_content = true,
1283 minetest.register_node("default:water_flowing", {
1284 description = "Water (flowing)",
1285 inventory_image = minetest.inventorycube("default_water.png"),
1286 drawtype = "flowingliquid",
1287 tile_images = {"default_water.png"},
1288 alpha = WATER_ALPHA,
1289 paramtype = "light",
1293 buildable_to = true,
1294 liquidtype = "flowing",
1295 liquid_alternative_flowing = "default:water_flowing",
1296 liquid_alternative_source = "default:water_source",
1297 liquid_viscosity = WATER_VISC,
1298 post_effect_color = {a=64, r=100, g=100, b=200},
1299 special_materials = {
1300 {image="default_water.png", backface_culling=false},
1301 {image="default_water.png", backface_culling=true},
1303 groups = {water=3, liquid=3},
1306 minetest.register_node("default:water_source", {
1307 description = "Water",
1308 inventory_image = minetest.inventorycube("default_water.png"),
1309 drawtype = "liquid",
1310 tile_images = {"default_water.png"},
1311 alpha = WATER_ALPHA,
1312 paramtype = "light",
1316 buildable_to = true,
1317 liquidtype = "source",
1318 liquid_alternative_flowing = "default:water_flowing",
1319 liquid_alternative_source = "default:water_source",
1320 liquid_viscosity = WATER_VISC,
1321 post_effect_color = {a=64, r=100, g=100, b=200},
1322 special_materials = {
1323 -- New-style water source material (mostly unused)
1324 {image="default_water.png", backface_culling=false},
1326 groups = {water=3, liquid=3},
1329 minetest.register_node("default:lava_flowing", {
1330 description = "Lava (flowing)",
1331 inventory_image = minetest.inventorycube("default_lava.png"),
1332 drawtype = "flowingliquid",
1333 tile_images = {"default_lava.png"},
1334 paramtype = "light",
1335 light_source = LIGHT_MAX - 1,
1339 buildable_to = true,
1340 liquidtype = "flowing",
1341 liquid_alternative_flowing = "default:lava_flowing",
1342 liquid_alternative_source = "default:lava_source",
1343 liquid_viscosity = LAVA_VISC,
1344 damage_per_second = 4*2,
1345 post_effect_color = {a=192, r=255, g=64, b=0},
1346 special_materials = {
1347 {image="default_lava.png", backface_culling=false},
1348 {image="default_lava.png", backface_culling=true},
1350 groups = {lava=3, liquid=2, hot=3},
1353 minetest.register_node("default:lava_source", {
1354 description = "Lava",
1355 inventory_image = minetest.inventorycube("default_lava.png"),
1356 drawtype = "liquid",
1357 tile_images = {"default_lava.png"},
1358 paramtype = "light",
1359 light_source = LIGHT_MAX - 1,
1363 buildable_to = true,
1364 liquidtype = "source",
1365 liquid_alternative_flowing = "default:lava_flowing",
1366 liquid_alternative_source = "default:lava_source",
1367 liquid_viscosity = LAVA_VISC,
1368 damage_per_second = 4*2,
1369 post_effect_color = {a=192, r=255, g=64, b=0},
1370 special_materials = {
1371 -- New-style lava source material (mostly unused)
1372 {image="default_lava.png", backface_culling=false},
1374 groups = {lava=3, liquid=2, hot=3},
1377 minetest.register_node("default:torch", {
1378 description = "Torch",
1379 drawtype = "torchlike",
1380 tile_images = {"default_torch_on_floor.png", "default_torch_on_ceiling.png", "default_torch.png"},
1381 inventory_image = "default_torch_on_floor.png",
1382 wield_image = "default_torch_on_floor.png",
1383 paramtype = "light",
1384 paramtype2 = "wallmounted",
1385 sunlight_propagates = true,
1387 light_source = LIGHT_MAX-1,
1389 type = "wallmounted",
1390 wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
1391 wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
1392 wall_side = {-0.5, -0.3, -0.1, -0.5+0.3, 0.3, 0.1},
1394 groups = {dig_immediate=1},
1395 legacy_wallmounted = true,
1398 minetest.register_node("default:sign_wall", {
1399 description = "Sign",
1400 drawtype = "signlike",
1401 tile_images = {"default_sign_wall.png"},
1402 inventory_image = "default_sign_wall.png",
1403 wield_image = "default_sign_wall.png",
1404 paramtype = "light",
1405 paramtype2 = "wallmounted",
1406 sunlight_propagates = true,
1408 metadata_name = "sign",
1410 type = "wallmounted",
1411 --wall_top = <default>
1412 --wall_bottom = <default>
1413 --wall_side = <default>
1415 groups = {dig_immediate=2},
1416 legacy_wallmounted = true,
1419 minetest.register_node("default:chest", {
1420 description = "Chest",
1421 tile_images = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
1422 "default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
1423 paramtype2 = "facedir",
1424 metadata_name = "chest",
1425 groups = {snappy=2,choppy=2},
1426 legacy_facedir_simple = true,
1429 minetest.register_node("default:chest_locked", {
1430 description = "Locked Chest",
1431 tile_images = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
1432 "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"},
1433 paramtype2 = "facedir",
1434 metadata_name = "locked_chest",
1435 groups = {snappy=2,choppy=2},
1436 legacy_facedir_simple = true,
1439 minetest.register_node("default:furnace", {
1440 description = "Furnace",
1441 tile_images = {"default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png",
1442 "default_furnace_side.png", "default_furnace_side.png", "default_furnace_front.png"},
1443 paramtype2 = "facedir",
1444 metadata_name = "furnace",
1445 groups = {cracky=2},
1446 legacy_facedir_simple = true,
1449 minetest.register_node("default:cobble", {
1450 description = "Cobble",
1451 tile_images = {"default_cobble.png"},
1452 is_ground_content = true,
1453 groups = {cracky=3},
1456 minetest.register_node("default:mossycobble", {
1457 description = "Mossy Cobble",
1458 tile_images = {"default_mossycobble.png"},
1459 is_ground_content = true,
1460 groups = {cracky=3},
1463 minetest.register_node("default:steelblock", {
1464 description = "Steel Block",
1465 tile_images = {"default_steel_block.png"},
1466 is_ground_content = true,
1467 groups = {snappy=1,bendy=2},
1470 minetest.register_node("default:nyancat", {
1471 description = "Nyancat",
1472 tile_images = {"default_nc_side.png", "default_nc_side.png", "default_nc_side.png",
1473 "default_nc_side.png", "default_nc_back.png", "default_nc_front.png"},
1474 inventory_image = "default_nc_front.png",
1475 paramtype2 = "facedir",
1476 groups = {cracky=2},
1477 legacy_facedir_simple = true,
1480 minetest.register_node("default:nyancat_rainbow", {
1481 description = "Nyancat Rainbow",
1482 tile_images = {"default_nc_rb.png"},
1483 inventory_image = "default_nc_rb.png",
1484 groups = {cracky=2},
1487 minetest.register_node("default:sapling", {
1488 description = "Sapling",
1489 drawtype = "plantlike",
1491 tile_images = {"default_sapling.png"},
1492 inventory_image = "default_sapling.png",
1493 wield_image = "default_sapling.png",
1494 paramtype = "light",
1496 groups = {dig_immediate=1},
1499 minetest.register_node("default:apple", {
1500 description = "Apple",
1501 drawtype = "plantlike",
1503 tile_images = {"default_apple.png"},
1504 inventory_image = "default_apple.png",
1505 paramtype = "light",
1506 sunlight_propagates = true,
1508 groups = {dig_immediate=1},
1509 on_use = minetest.item_eat(4),
1516 minetest.register_craftitem("default:stick", {
1517 description = "Stick",
1518 inventory_image = "default_stick.png",
1521 minetest.register_craftitem("default:paper", {
1522 description = "Paper",
1523 inventory_image = "default_paper.png",
1526 minetest.register_craftitem("default:book", {
1527 description = "Book",
1528 inventory_image = "default_book.png",
1531 minetest.register_craftitem("default:coal_lump", {
1532 description = "Lump of coal",
1533 inventory_image = "default_coal_lump.png",
1536 minetest.register_craftitem("default:iron_lump", {
1537 description = "Lump of iron",
1538 inventory_image = "default_iron_lump.png",
1541 minetest.register_craftitem("default:clay_lump", {
1542 description = "Lump of clay",
1543 inventory_image = "default_clay_lump.png",
1546 minetest.register_craftitem("default:steel_ingot", {
1547 description = "Steel ingot",
1548 inventory_image = "default_steel_ingot.png",
1551 minetest.register_craftitem("default:clay_brick", {
1552 description = "Clay brick",
1553 inventory_image = "default_steel_ingot.png",
1554 inventory_image = "default_clay_brick.png",
1557 minetest.register_craftitem("default:scorched_stuff", {
1558 description = "Scorched stuff",
1559 inventory_image = "default_scorched_stuff.png",
1563 -- Creative inventory
1566 minetest.add_to_creative_inventory('default:pick_mese')
1567 minetest.add_to_creative_inventory('default:pick_steel')
1568 minetest.add_to_creative_inventory('default:axe_steel')
1569 minetest.add_to_creative_inventory('default:shovel_steel')
1571 minetest.add_to_creative_inventory('default:torch')
1572 minetest.add_to_creative_inventory('default:cobble')
1573 minetest.add_to_creative_inventory('default:dirt')
1574 minetest.add_to_creative_inventory('default:stone')
1575 minetest.add_to_creative_inventory('default:sand')
1576 minetest.add_to_creative_inventory('default:sandstone')
1577 minetest.add_to_creative_inventory('default:clay')
1578 minetest.add_to_creative_inventory('default:brick')
1579 minetest.add_to_creative_inventory('default:tree')
1580 minetest.add_to_creative_inventory('default:wood')
1581 minetest.add_to_creative_inventory('default:leaves')
1582 minetest.add_to_creative_inventory('default:cactus')
1583 minetest.add_to_creative_inventory('default:papyrus')
1584 minetest.add_to_creative_inventory('default:bookshelf')
1585 minetest.add_to_creative_inventory('default:glass')
1586 minetest.add_to_creative_inventory('default:fence_wood')
1587 minetest.add_to_creative_inventory('default:rail')
1588 minetest.add_to_creative_inventory('default:mese')
1589 minetest.add_to_creative_inventory('default:chest')
1590 minetest.add_to_creative_inventory('default:furnace')
1591 minetest.add_to_creative_inventory('default:sign_wall')
1592 minetest.add_to_creative_inventory('default:water_source')
1593 minetest.add_to_creative_inventory('default:lava_source')
1594 minetest.add_to_creative_inventory('default:ladder')
1597 -- Some common functions
1600 default.falling_node_names = {}
1602 function nodeupdate_single(p)
1603 n = minetest.env:get_node(p)
1604 if default.falling_node_names[n.name] ~= nil then
1605 p_bottom = {x=p.x, y=p.y-1, z=p.z}
1606 n_bottom = minetest.env:get_node(p_bottom)
1607 if n_bottom.name == "air" then
1608 minetest.env:remove_node(p)
1609 minetest.env:add_entity(p, "default:falling_"..n.name)
1615 function nodeupdate(p)
1619 p2 = {x=p.x+x, y=p.y+y, z=p.z+z}
1620 nodeupdate_single(p2)
1630 function default.register_falling_node(nodename, texture)
1631 default.falling_node_names[nodename] = true
1632 -- Override naming conventions for stuff like :default:falling_default:sand
1633 minetest.register_entity(":default:falling_"..nodename, {
1634 -- Static definition
1636 collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
1638 textures = {texture,texture,texture,texture,texture,texture},
1641 on_step = function(self, dtime)
1643 self.object:setacceleration({x=0, y=-10, z=0})
1644 -- Turn to actual sand when collides to ground or just move
1645 local pos = self.object:getpos()
1646 local bcp = {x=pos.x, y=pos.y-0.7, z=pos.z} -- Position of bottom center point
1647 local bcn = minetest.env:get_node(bcp)
1648 if bcn.name ~= "air" then
1649 -- Turn to a sand node
1650 local np = {x=bcp.x, y=bcp.y+1, z=bcp.z}
1651 minetest.env:add_node(np, {name=nodename})
1652 self.object:remove()
1660 default.register_falling_node("default:sand", "default_sand.png")
1661 default.register_falling_node("default:gravel", "default_gravel.png")
1667 -- Global environment step function
1668 function on_step(dtime)
1671 minetest.register_globalstep(on_step)
1673 function on_placenode(p, node)
1674 --print("on_placenode")
1677 minetest.register_on_placenode(on_placenode)
1679 function on_dignode(p, node)
1680 --print("on_dignode")
1683 minetest.register_on_dignode(on_dignode)
1685 function on_punchnode(p, node)
1687 minetest.register_on_punchnode(on_punchnode)
1689 local function handle_give_command(cmd, giver, receiver, stackstring)
1690 if not minetest.get_player_privs(giver)["give"] then
1691 minetest.chat_send_player(giver, "error: you don't have permission to give")
1694 minetest.debug("DEBUG: "..cmd..' invoked, stackstring="'..stackstring..'"')
1695 minetest.log(cmd..' invoked, stackstring="'..stackstring..'"')
1696 local itemstack = ItemStack(stackstring)
1697 if itemstack:is_empty() then
1698 minetest.chat_send_player(giver, 'error: cannot give an empty item')
1700 elseif not itemstack:is_known() then
1701 minetest.chat_send_player(giver, 'error: cannot give an unknown item')
1704 local receiverref = minetest.env:get_player_by_name(receiver)
1705 if receiverref == nil then
1706 minetest.chat_send_player(giver, receiver..' is not a known player')
1709 local leftover = receiverref:get_inventory():add_item("main", itemstack)
1710 if leftover:is_empty() then
1712 elseif leftover:get_count() == itemstack:get_count() then
1713 partiality = "could not be "
1715 partiality = "partially "
1717 -- The actual item stack string may be different from what the "giver"
1718 -- entered (e.g. big numbers are always interpreted as 2^16-1).
1719 stackstring = itemstack:to_string()
1720 if giver == receiver then
1721 minetest.chat_send_player(giver, '"'..stackstring
1722 ..'" '..partiality..'added to inventory.');
1724 minetest.chat_send_player(giver, '"'..stackstring
1725 ..'" '..partiality..'added to '..receiver..'\'s inventory.');
1726 minetest.chat_send_player(receiver, '"'..stackstring
1727 ..'" '..partiality..'added to inventory.');
1731 minetest.register_on_chat_message(function(name, message)
1732 --print("default on_chat_message: name="..dump(name).." message="..dump(message))
1733 local cmd = "/giveme"
1734 if message:sub(0, #cmd) == cmd then
1735 local stackstring = string.match(message, cmd.." (.*)")
1736 if stackstring == nil then
1737 minetest.chat_send_player(name, 'usage: '..cmd..' stackstring')
1738 return true -- Handled chat message
1740 handle_give_command(cmd, name, name, stackstring)
1744 if message:sub(0, #cmd) == cmd then
1745 local receiver, stackstring = string.match(message, cmd.." ([%a%d_-]+) (.*)")
1746 if receiver == nil or stackstring == nil then
1747 minetest.chat_send_player(name, 'usage: '..cmd..' name stackstring')
1748 return true -- Handled chat message
1750 handle_give_command(cmd, name, receiver, stackstring)
1753 local cmd = "/spawnentity"
1754 if message:sub(0, #cmd) == cmd then
1755 if not minetest.get_player_privs(name)["give"] then
1756 minetest.chat_send_player(name, "you don't have permission to spawn (give)")
1757 return true -- Handled chat message
1759 if not minetest.get_player_privs(name)["interact"] then
1760 minetest.chat_send_player(name, "you don't have permission to interact")
1761 return true -- Handled chat message
1763 local entityname = string.match(message, cmd.." (.*)")
1764 if entityname == nil then
1765 minetest.chat_send_player(name, 'usage: '..cmd..' entityname')
1766 return true -- Handled chat message
1768 print(cmd..' invoked, entityname="'..entityname..'"')
1769 local player = minetest.env:get_player_by_name(name)
1770 if player == nil then
1771 print("Unable to spawn entity, player is nil")
1772 return true -- Handled chat message
1774 local p = player:getpos()
1776 minetest.env:add_entity(p, entityname)
1777 minetest.chat_send_player(name, '"'..entityname
1779 return true -- Handled chat message
1781 local cmd = "/pulverize"
1782 if message:sub(0, #cmd) == cmd then
1783 local player = minetest.env:get_player_by_name(name)
1784 if player == nil then
1785 print("Unable to pulverize, player is nil")
1786 return true -- Handled chat message
1788 if player:get_wielded_item():is_empty() then
1789 minetest.chat_send_player(name, 'Unable to pulverize, no item in hand.')
1791 player:set_wielded_item(nil)
1792 minetest.chat_send_player(name, 'An item was pulverized.')
1799 -- Done, print some random stuff
1802 --print("minetest.registered_entities:")
1803 --dump2(minetest.registered_entities)