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