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