Merge branch 'mcl_explosions'
[MineClone/MineClone2.git] / mods / ITEMS / mcl_core / nodes_climb.lua
blobd9ecd76d3f4f0ecd1a18ad316dc0c42032986daa
1 -- Climbable nodes
2 local S = minetest.get_translator("mcl_core")
4 local rotate_climbable = function(pos, node, user, mode)
5 if mode == screwdriver.ROTATE_FACE then
6 local r = screwdriver.rotate.wallmounted(pos, node, mode)
7 node.param2 = r
8 minetest.swap_node(pos, node)
9 return true
10 end
11 return false
12 end
14 minetest.register_node("mcl_core:ladder", {
15 description = S("Ladder"),
16 _doc_items_longdesc = S("A piece of ladder which allows you to climb vertically. Ladders can only be placed on the side of solid blocks and not on glass, leaves, ice, slabs, glowstone, nor sea lanterns."),
17 drawtype = "signlike",
18 is_ground_content = false,
19 tiles = {"default_ladder.png"},
20 inventory_image = "default_ladder.png",
21 wield_image = "default_ladder.png",
22 paramtype = "light",
23 sunlight_propagates = true,
24 paramtype2 = "wallmounted",
25 walkable = true,
26 climbable = true,
27 node_box = {
28 type = "wallmounted",
29 wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 },
31 selection_box = {
32 type = "wallmounted",
33 wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 },
35 stack_max = 64,
36 groups = {handy=1,axey=1, attached_node=1, deco_block=1, dig_by_piston=1},
37 sounds = mcl_sounds.node_sound_wood_defaults(),
38 node_placement_prediction = "",
39 -- Restrict placement of ladders
40 on_place = function(itemstack, placer, pointed_thing)
41 if pointed_thing.type ~= "node" then
42 -- no interaction possible with entities
43 return itemstack
44 end
46 local under = pointed_thing.under
47 local node = minetest.get_node(under)
48 local def = minetest.registered_nodes[node.name]
49 if not def then
50 return itemstack
51 end
52 local groups = def.groups
54 -- Don't allow to place the ladder at particular nodes
55 if (groups and (groups.glass or groups.leaves or groups.slab)) or
56 node.name == "mcl_core:ladder" or node.name == "mcl_core:ice" or node.name == "mcl_nether:glowstone" or node.name == "mcl_ocean:sea_lantern" then
57 return itemstack
58 end
60 -- Check special rightclick action of pointed node
61 if def and def.on_rightclick then
62 if not placer:get_player_control().sneak then
63 return def.on_rightclick(under, node, placer, itemstack,
64 pointed_thing) or itemstack, false
65 end
66 end
67 local above = pointed_thing.above
69 -- Ladders may not be placed on ceiling or floor
70 if under.y ~= above.y then
71 return itemstack
72 end
73 local idef = itemstack:get_definition()
74 local success = minetest.item_place_node(itemstack, placer, pointed_thing)
76 if success then
77 if idef.sounds and idef.sounds.place then
78 minetest.sound_play(idef.sounds.place, {pos=above, gain=1}, true)
79 end
80 end
81 return itemstack
82 end,
84 _mcl_blast_resistance = 0.4,
85 _mcl_hardness = 0.4,
86 on_rotate = rotate_climbable,
90 minetest.register_node("mcl_core:vine", {
91 description = S("Vines"),
92 _doc_items_longdesc = S("Vines are climbable blocks which can be placed on the sides of solid full-cube blocks. Vines slowly grow and spread."),
93 drawtype = "signlike",
94 tiles = {"mcl_core_vine.png"},
95 inventory_image = "mcl_core_vine.png",
96 wield_image = "mcl_core_vine.png",
97 paramtype = "light",
98 sunlight_propagates = true,
99 paramtype2 = "wallmounted",
100 walkable = false,
101 climbable = true,
102 buildable_to = true,
103 selection_box = {
104 type = "wallmounted",
106 stack_max = 64,
107 groups = {handy=1,axey=1,shearsy=1,swordy=1, flammable=2,deco_block=1,destroy_by_lava_flow=1,dig_by_piston=1, fire_encouragement=15, fire_flammability=100},
108 sounds = mcl_sounds.node_sound_leaves_defaults(),
109 drop = "",
110 _mcl_shears_drop = true,
111 node_placement_prediction = "",
112 -- Restrict placement of vines
113 on_place = function(itemstack, placer, pointed_thing)
114 if pointed_thing.type ~= "node" then
115 -- no interaction possible with entities
116 return itemstack
119 local under = pointed_thing.under
120 local node = minetest.get_node(under)
121 local def = minetest.registered_nodes[node.name]
122 if not def then return itemstack end
123 local groups = def.groups
125 -- Check special rightclick action of pointed node
126 if def and def.on_rightclick then
127 if not placer:get_player_control().sneak then
128 return def.on_rightclick(under, node, placer, itemstack,
129 pointed_thing) or itemstack, false
133 -- Only place on full cubes
134 if not mcl_core.supports_vines(node.name) then
135 return itemstack
138 local above = pointed_thing.above
140 -- Vines may not be placed on top or below another block
141 if under.y ~= above.y then
142 return itemstack
144 local idef = itemstack:get_definition()
145 local itemstack, success = minetest.item_place_node(itemstack, placer, pointed_thing)
147 if success then
148 if idef.sounds and idef.sounds.place then
149 minetest.sound_play(idef.sounds.place, {pos=above, gain=1}, true)
152 return itemstack
153 end,
155 -- If dug, also dig a “dependant” vine below it.
156 -- A vine is dependant if it hangs from this node and has no supporting block.
157 on_dig = function(pos, node, digger)
158 local below = {x=pos.x, y=pos.y-1, z=pos.z}
159 local belownode = minetest.get_node(below)
160 minetest.node_dig(pos, node, digger)
161 if belownode.name == node.name and (not mcl_core.check_vines_supported(below, belownode)) then
162 minetest.registered_nodes[node.name].on_dig(below, node, digger)
164 end,
167 _mcl_blast_resistance = 0.2,
168 _mcl_hardness = 0.2,
169 on_rotate = false,