]> git.lizzy.rs Git - Crafter.git/blob - mods/main/nodes.lua
Add in /home and /sethome
[Crafter.git] / mods / main / nodes.lua
1 local minetest,pairs = minetest,pairs
2 --ore def with required tool
3 local tool = {"main:woodpick","main:coalpick","main:stonepick","main:ironpick","main:lapispick","main:goldpick","main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"}
4 local ores = {
5 ["coal"]={"main:woodpick","main:coalpick","main:stonepick","main:ironpick","main:lapispick","main:goldpick","main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"},
6 ["iron"]={"main:coalpick","main:stonepick","main:ironpick","main:lapispick","main:goldpick","main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"},
7 ["lapis"]={"main:ironpick","main:lapispick","main:goldpick","main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"},
8 ["gold"]={"main:ironpick","main:lapispick","main:goldpick","main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"},
9 ["diamond"]={"main:ironpick","main:lapispick","main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"},
10 ["emerald"]={"main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"},
11 ["sapphire"]={"main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"},
12 ["ruby"]={"main:diamondpick","main:emeraldpick","main:sapphirepick","main:rubypick"},
13 }
14
15 local drops ={
16         ["coal"]={"main:coal"},
17         ["iron"]={"main:ironore"},
18         ["lapis"]={"main:lapis"},
19         ["gold"]={"main:goldore"},
20         ["diamond"]={"main:diamond"},
21         ["emerald"]={"main:emerald"},
22         ["sapphire"]={"main:sapphire"},
23         ["ruby"]={"main:ruby"},
24 }
25
26 local levels = {
27         ["coal"]=1,
28         ["iron"]=2,
29         ["lapis"]=3,
30         ["gold"]=3,
31         ["diamond"]=4,
32         ["emerald"]=5,
33         ["sapphire"]=6,
34         ["ruby"]=7,
35 }
36
37
38 local level = 0
39 local experience
40 for ore,tool_required in pairs(ores) do
41         level = levels[ore]
42
43         if ore == "iron" or ore == "gold" then 
44                 experience = 0
45         else
46                 experience = level
47         end
48         
49         minetest.register_node("main:"..ore.."block", {
50                 description = ore:gsub("^%l", string.upper).." Block",
51                 tiles = {ore.."block.png"},
52                 groups = {stone = level, pathable = 1},
53                 sounds = main.stoneSound(),
54                 --light_source = 14,--debugging ore spawn
55                 drop = {
56                         max_items = 1,
57                         items= {
58                                 {
59                                         rarity = 0,
60                                         tools = tool_required,
61                                         items = {"main:"..ore.."ore"},
62                                 },
63                                 },
64                         },
65                 })
66
67         minetest.register_node("main:"..ore.."ore", {
68                 description = ore:gsub("^%l", string.upper).." Ore",
69                 tiles = {"stone.png^"..ore.."ore.png"},
70                 groups = {stone = level, pathable = 1,experience=experience},
71                 sounds = main.stoneSound(),
72                 --light_source = 14,--debugging ore spawn
73                 drop = {
74                         max_items = 1,
75                         items= {
76                                 {
77                                         rarity = 0,
78                                         tools = tool_required,
79                                         items = drops[ore],
80                                 },
81                                 },
82                         },
83                 })
84 end
85
86 minetest.register_node("main:stone", {
87     description = "Stone",
88     tiles = {"stone.png"},
89     groups = {stone = 1, hand = 1,pathable = 1},
90     sounds = main.stoneSound(),
91     drop = {
92                 max_items = 1,
93                 items= {
94                         {
95                                 rarity = 0,
96                                 tools = tool,
97                                 items = {"main:cobble"},
98                         },
99                         },
100                 },
101         })
102
103 minetest.register_node("main:cobble", {
104     description = "Cobblestone",
105     tiles = {"cobble.png"},
106     groups = {stone = 1, pathable = 1},
107     sounds = main.stoneSound(),
108     drop = {
109                 max_items = 1,
110                 items= {
111                         {
112                                 rarity = 0,
113                                 tools = tool,
114                                 items = {"main:cobble"},
115                         },
116                         },
117                 },
118 })
119
120 minetest.register_node("main:mossy_cobble", {
121     description = "Mossy Cobblestone",
122     tiles = {"mossy_cobble.png"},
123     groups = {stone = 1, pathable = 1},
124     sounds = main.stoneSound(),
125     drop = {
126                 max_items = 1,
127                 items= {
128                         {
129                                 rarity = 0,
130                                 tools = tool,
131                                 items = {"main:mossy_cobble"},
132                         },
133                         },
134                 },
135 })
136
137 minetest.register_node("main:glass", {
138     description = "Glass",
139     tiles = {"glass.png"},
140     drawtype = "glasslike",
141         paramtype = "light",
142         sunlight_propagates = true,
143         is_ground_content = false,
144     groups = {glass = 1, pathable = 1},
145     sounds = main.stoneSound({
146                 footstep = {name = "glass_footstep", gain = 0.4},
147         dug =  {name = "break_glass", gain = 0.4},
148         }),
149     drop = "",
150 })
151         
152 minetest.register_node("main:ice", {
153     description = "Ice",
154     tiles = {"ice.png"},
155     drawtype = "glasslike",
156         paramtype = "light",
157         sunlight_propagates = true,
158         sunlight_propagates = true,
159         is_ground_content = false,
160     groups = {glass = 1, pathable = 1,slippery=3},
161     sounds = main.stoneSound({
162                 footstep = {name = "glass_footstep", gain = 0.4},
163         dug =  {name = "break_glass", gain = 0.4},
164         }),
165         use_texture_alpha = false,
166         alpha = 100,
167     drop = "",
168     after_destruct = function(pos, oldnode)
169        minetest.set_node(pos, {name="main:water"})                            
170     end                
171 })
172 minetest.register_node("main:ice_mapgen", {
173     description = "Ice",
174     tiles = {"ice.png"},
175     drawtype = "normal",
176         sunlight_propagates = true,
177         sunlight_propagates = true,
178         is_ground_content = false,
179     groups = {glass = 1, pathable = 1,slippery=3},
180     sounds = main.stoneSound({
181                 footstep = {name = "glass_footstep", gain = 0.4},
182         dug =  {name = "break_glass", gain = 0.4},
183         }),
184         use_texture_alpha = false,
185     drop = "",           
186 })
187
188 minetest.register_node("main:dirt", {
189     description = "Dirt",
190     tiles = {"dirt.png"},
191     groups = {dirt = 1, soil=1,pathable = 1, farm_tillable=1},
192     sounds = main.dirtSound(),
193     paramtype = "light",
194 })
195
196 minetest.register_node("main:grass", {
197     description = "Grass",
198     tiles = {"grass.png"},
199     groups = {grass = 1, soil=1,pathable = 1, farm_tillable=1},
200     sounds = main.dirtSound(),
201     drop="main:dirt",
202 })
203
204 minetest.register_node("main:sand", {
205     description = "Sand",
206     tiles = {"sand.png"},
207     groups = {sand = 1, falling_node = 1,pathable = 1,soil=1},
208     sounds = main.sandSound(),
209 })
210
211 minetest.register_node("main:gravel", {
212     description = "Gravel",
213     tiles = {"gravel.png"},
214     groups = {sand = 1, falling_node = 1,pathable = 1},
215     sounds = main.dirtSound(),
216     drop = {
217                 max_items = 1,
218                 items= {
219                  {
220                         -- Only drop if using a tool whose name is identical to one
221                         -- of these.
222                         rarity = 10,
223                         items = {"main:flint"},
224                         -- Whether all items in the dropped item list inherit the
225                         -- hardware coloring palette color from the dug node.
226                         -- Default is 'false'.
227                         --inherit_color = true,
228                 },
229                 {
230                         -- Only drop if using a tool whose name is identical to one
231                         -- of these.
232                         --tools = {"main:shears"},
233                         rarity = 0,
234                         items = {"main:gravel"},
235                         -- Whether all items in the dropped item list inherit the
236                         -- hardware coloring palette color from the dug node.
237                         -- Default is 'false'.
238                         --inherit_color = true,
239                 },
240         }},
241 })
242
243 minetest.register_node("main:tree", {
244     description = "Tree",
245     tiles = {"treeCore.png","treeCore.png","treeOut.png","treeOut.png","treeOut.png","treeOut.png"},
246     groups = {wood = 1, tree = 1, pathable = 1, flammable=1},
247     sounds = main.woodSound(),
248     --set metadata so treecapitator doesn't destroy houses
249     on_place = function(itemstack, placer, pointed_thing)
250                 if not pointed_thing.type == "node" then
251                         return
252                 end
253                 
254                 local sneak = placer:get_player_control().sneak
255                 local noddef = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
256                 if not sneak and noddef.on_rightclick then
257                         minetest.item_place(itemstack, placer, pointed_thing)
258                         return
259                 end
260                 
261                 local pos = pointed_thing.above
262                 minetest.item_place_node(itemstack, placer, pointed_thing)
263                 local meta = minetest.get_meta(pos)
264                 meta:set_string("placed", "true")       
265                 return(itemstack)
266         end,
267         --treecapitator - move treecapitator into own file using override
268         on_dig = function(pos, node, digger)
269                 --bvav_create_vessel(pos,minetest.facedir_to_dir(minetest.dir_to_facedir(minetest.yaw_to_dir(digger:get_look_horizontal()+(math.pi/2)))))
270                 --check if wielding axe?
271                 --turn treecapitator into an enchantment?
272                 local meta = minetest.get_meta(pos)
273                 --local tool_meta = digger:get_wielded_item():get_meta()
274                 --if tool_meta:get_int("treecapitator") > 0 then
275                 if not meta:contains("placed") and string.match(digger:get_wielded_item():get_name(), "axe") then
276                         local tool_capabilities = digger:get_wielded_item():get_tool_capabilities()
277                         
278                         local wear = minetest.get_dig_params({wood=1}, tool_capabilities).wear
279
280                         local wield_stack = digger:get_wielded_item()
281
282                         --remove tree
283                         for y = -6,6 do
284                                 local name = minetest.get_node(vector.new(pos.x,pos.y+y,pos.z)).name
285
286                                 if name == "main:tree" or name == "redstone:node_activated_tree" then
287                                         wield_stack:add_wear(wear)
288                                         minetest.node_dig(vector.new(pos.x,pos.y+y,pos.z), node, digger)
289                                         minetest.add_particlespawner({
290                                                 amount = 30,
291                                                 time = 0.0001,
292                                                 minpos = {x=pos.x-0.5, y=pos.y-0.5+y, z=pos.z-0.5},
293                                                 maxpos = {x=pos.x+0.5, y=pos.y+0.5+y, z=pos.z+0.5},
294                                                 minvel = vector.new(-1,0,-1),
295                                                 maxvel = vector.new(1,0,1),
296                                                 minacc = {x=0, y=-9.81, z=0},
297                                                 maxacc = {x=0, y=-9.81, z=0},
298                                                 minexptime = 0.5,
299                                                 maxexptime = 1.5,
300                                                 minsize = 0,
301                                                 maxsize = 0,
302                                                 collisiondetection = true,
303                                                 vertical = false,
304                                                 node = {name= name},
305                                         })
306                                         
307                                         local name2 = minetest.get_node(vector.new(pos.x,pos.y+y-1,pos.z)).name
308                                         if name2 == "main:dirt" or name2 == "main:grass" then
309                                                 minetest.add_node(vector.new(pos.x,pos.y+y,pos.z),{name="main:sapling"})
310                                         end
311                                 end
312                         end
313                         digger:set_wielded_item(wield_stack)
314                 else
315                         minetest.node_dig(pos, node, digger)
316                 end
317                 
318         end
319 })
320
321 minetest.register_node("main:wood", {
322     description = "Wood",
323     tiles = {"wood.png"},
324     groups = {wood = 1, pathable = 1,flammable=1},
325     sounds = main.woodSound(),
326 })
327
328 minetest.register_node("main:leaves", {
329     description = "Leaves",
330     drawtype = "allfaces_optional",
331         waving = 1,
332         walkable = false,
333         climbable = true,
334         paramtype = "light",
335         is_ground_content = false,      
336     tiles = {"leaves.png"},
337     groups = {leaves = 1, leafdecay = 1,flammable=1},
338     sounds = main.grassSound(),
339     drop = {
340                 max_items = 1,
341                 items= {
342                 {
343                         tools = {"main:shears"},
344                         items = {"main:dropped_leaves"},
345                 },
346                 {
347                         rarity = 6,
348                         items = {"main:apple"},
349                 },
350                 {
351                         rarity = 10,
352                         items = {"main:sapling"},
353                 },
354                 },
355     },
356 })
357
358
359 minetest.register_node("main:dropped_leaves", {
360     description = "Leaves",
361     drawtype = "allfaces_optional",
362         waving = 0,
363         walkable = false,
364         climbable = false,
365         paramtype = "light",
366         is_ground_content = false,      
367     tiles = {"leaves.png"},
368     groups = {leaves = 1, flammable=1},
369     sounds = main.grassSound(),
370     drop = {
371                 max_items = 1,
372                 items= {
373                 {
374                         tools = {"main:shears"},
375                         items = {"main:dropped_leaves"},
376                 },
377     },
378     },
379 })
380
381
382
383
384
385
386 minetest.register_node("main:water", {
387         description = "Water Source",
388         drawtype = "liquid",
389         waving = 3,
390         tiles = {
391                 {
392                         name = "water_source.png",
393                         backface_culling = false,
394                         animation = {
395                                 type = "vertical_frames",
396                                 aspect_w = 16,
397                                 aspect_h = 16,
398                                 length = 1,
399                         },
400                 },
401                 {
402                         name = "water_source.png",
403                         backface_culling = true,
404                         animation = {
405                                 type = "vertical_frames",
406                                 aspect_w = 16,
407                                 aspect_h = 16,
408                                 length = 1,
409                         },
410                 },
411         },
412         alpha = 191,
413         paramtype = "light",
414         walkable = false,
415         pointable = false,
416         diggable = false,
417         buildable_to = true,
418         is_ground_content = false,
419         drop = "",
420         liquidtype = "source",
421         liquid_alternative_flowing = "main:waterflow",
422         liquid_alternative_source = "main:water",
423         liquid_viscosity = 1,
424         post_effect_color = {a = 103, r = 30, g = 60, b = 90},
425         groups = {water = 1, liquid = 1, cools_lava = 1, bucket = 1, source = 1,pathable = 1,drowning=1,disable_fall_damage=1,extinguish=1},
426         --sounds = default.node_sound_water_defaults(),
427         
428         --water explodes in the nether
429         on_construct = function(pos)
430                 local under = minetest.get_node(vector.new(pos.x,pos.y-1,pos.z)).name
431                 if under == "nether:glowstone" then
432                         minetest.remove_node(pos)
433                         create_aether_portal(pos)
434                 elseif pos.y <= -10033 then
435                         minetest.remove_node(pos)
436                         tnt(pos,10)
437                 end
438         end,
439 })
440
441 minetest.register_node("main:waterflow", {
442         description = "Water Flow",
443         drawtype = "flowingliquid",
444         waving = 3,
445         tiles = {"water_static.png"},
446         special_tiles = {
447                 {
448                         name = "water_flow.png",
449                         backface_culling = false,
450                         animation = {
451                                 type = "vertical_frames",
452                                 aspect_w = 16,
453                                 aspect_h = 16,
454                                 length = 0.5,
455                         },
456                 },
457                 {
458                         name = "water_flow.png",
459                         backface_culling = true,
460                         animation = {
461                                 type = "vertical_frames",
462                                 aspect_w = 16,
463                                 aspect_h = 16,
464                                 length = 0.5,
465                         },
466                 },
467         },
468         selection_box = {
469             type = "fixed",
470             fixed = {
471                 {0, 0, 0, 0, 0, 0},
472             },
473         },
474         alpha = 191,
475         paramtype = "light",
476         paramtype2 = "flowingliquid",
477         walkable = false,
478         pointable = false,
479         diggable = false,
480         buildable_to = true,
481         is_ground_content = false,
482         drop = "",
483         liquidtype = "flowing",
484         liquid_alternative_flowing = "main:waterflow",
485         liquid_alternative_source = "main:water",
486         liquid_viscosity = 1,
487         post_effect_color = {a = 103, r = 30, g = 60, b = 90},
488         groups = {water = 1, liquid = 1, notInCreative = 1, cools_lava = 1,pathable = 1,drowning=1,disable_fall_damage=1,extinguish=1},
489         --sounds = default.node_sound_water_defaults(),
490 })
491
492 minetest.register_node("main:lava", {
493         description = "Lava",
494         drawtype = "liquid",
495         tiles = {
496                 {
497                         name = "lava_source.png",
498                         backface_culling = false,
499                         animation = {
500                                 type = "vertical_frames",
501                                 aspect_w = 16,
502                                 aspect_h = 16,
503                                 length = 2.0,
504                         },
505                 },
506                 {
507                         name = "lava_source.png",
508                         backface_culling = true,
509                         animation = {
510                                 type = "vertical_frames",
511                                 aspect_w = 16,
512                                 aspect_h = 16,
513                                 length = 2.0,
514                         },
515                 },
516         },
517         paramtype = "light",
518         light_source = 13,
519         walkable = false,
520         pointable = false,
521         diggable = false,
522         buildable_to = true,
523         is_ground_content = false,
524         drop = "",
525         drowning = 1,
526         liquidtype = "source",
527         liquid_alternative_flowing = "main:lavaflow",
528         liquid_alternative_source = "main:lava",
529         liquid_viscosity = 7,
530         liquid_renewable = false,
531         post_effect_color = {a = 191, r = 255, g = 64, b = 0},
532         groups = {lava = 3, liquid = 2, igniter = 1, fire=1,hurt_inside=1},
533 })
534
535 minetest.register_node("main:lavaflow", {
536         description = "Flowing Lava",
537         drawtype = "flowingliquid",
538         tiles = {"lava_flow.png"},
539         special_tiles = {
540                 {
541                         name = "lava_flow.png",
542                         backface_culling = false,
543                         animation = {
544                                 type = "vertical_frames",
545                                 aspect_w = 16,
546                                 aspect_h = 16,
547                                 length = 3.3,
548                         },
549                 },
550                 {
551                         name = "lava_flow.png",
552                         backface_culling = true,
553                         animation = {
554                                 type = "vertical_frames",
555                                 aspect_w = 16,
556                                 aspect_h = 16,
557                                 length = 3.3,
558                         },
559                 },
560         },
561         selection_box = {
562             type = "fixed",
563             fixed = {
564                 {0, 0, 0, 0, 0, 0},
565             },
566         },
567         paramtype = "light",
568         paramtype2 = "flowingliquid",
569         light_source = 13,
570         walkable = false,
571         pointable = false,
572         diggable = false,
573         buildable_to = true,
574         is_ground_content = false,
575         drop = "",
576         drowning = 1,
577         liquidtype = "flowing",
578         liquid_alternative_flowing = "main:lavaflow",
579         liquid_alternative_source = "main:lava",
580         liquid_viscosity = 7,
581         liquid_renewable = false,
582         liquid_range = 3,
583         post_effect_color = {a = 191, r = 255, g = 64, b = 0},
584         groups = {lava = 3, liquid = 2, igniter = 1, fire=1,hurt_inside=1},
585 })
586
587 minetest.register_node("main:ladder", {
588         description = "Ladder",
589         drawtype = "signlike",
590         tiles = {"ladder.png"},
591         inventory_image = "ladder.png",
592         wield_image = "ladder.png",
593         paramtype = "light",
594         paramtype2 = "wallmounted",
595         sunlight_propagates = true,
596         walkable = false,
597         climbable = true,
598         is_ground_content = false,
599         node_placement_prediction = "",
600         selection_box = {
601                 type = "wallmounted",
602                 --wall_top = = <default>
603                 --wall_bottom = = <default>
604                 --wall_side = = <default>
605         },
606         groups = {wood = 1, flammable = 1, attached_node=1},
607         sounds = main.woodSound(),
608         on_place = function(itemstack, placer, pointed_thing)
609                 --copy from torch
610                 if pointed_thing.type ~= "node" then
611                         return itemstack
612                 end
613                 
614                 local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
615
616                 local fakestack = itemstack
617                 local retval = false
618                 if wdir > 1 then
619                         retval = fakestack:set_name("main:ladder")
620                 else
621                         return itemstack
622                 end
623                 
624                 if not retval then
625                         return itemstack
626                 end
627                 
628                 itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
629                 
630                 if retval then
631                         minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
632                 end
633                 
634                 print(itemstack, retval)
635                 itemstack:set_name("main:ladder")
636
637                 return itemstack
638         end,
639 })