Fix vines destruction not destoying hanging vines
[MineClone/MineClone2/killajk2201.git] / mods / ITEMS / mcl_core / nodes_climb.lua
blob6e865f0d203047d6dff33619233b0c96f12f3547
1 -- Climbable nodes
3 minetest.register_node("mcl_core:ladder", {
4 description = "Ladder",
5 _doc_items_longdesc = "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.",
6 drawtype = "signlike",
7 is_ground_content = false,
8 tiles = {"default_ladder.png"},
9 inventory_image = "default_ladder.png",
10 wield_image = "default_ladder.png",
11 paramtype = "light",
12 sunlight_propagates = true,
13 paramtype2 = "wallmounted",
14 walkable = true,
15 climbable = true,
16 node_box = {
17 type = "wallmounted",
18 wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 },
20 selection_box = {
21 type = "wallmounted",
22 wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 },
24 stack_max = 64,
25 groups = {handy=1,axey=1, attached_node=1, deco_block=1, dig_by_piston=1},
26 sounds = mcl_sounds.node_sound_wood_defaults(),
27 node_placement_prediction = "",
28 -- Restrict placement of ladders
29 on_place = function(itemstack, placer, pointed_thing)
30 if pointed_thing.type ~= "node" then
31 -- no interaction possible with entities
32 return itemstack
33 end
35 local under = pointed_thing.under
36 local node = minetest.get_node(under)
37 local def = minetest.registered_nodes[node.name]
38 if not def then
39 return itemstack
40 end
41 local groups = def.groups
43 -- Don't allow to place the ladder at particular nodes
44 if (groups and (groups.glass or groups.leaves or groups.slab)) or
45 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
46 return itemstack
47 end
49 -- Check special rightclick action of pointed node
50 if def and def.on_rightclick then
51 if not placer:get_player_control().sneak then
52 return def.on_rightclick(under, node, placer, itemstack,
53 pointed_thing) or itemstack, false
54 end
55 end
56 local above = pointed_thing.above
58 -- Ladders may not be placed on ceiling or floor
59 if under.y ~= above.y then
60 return itemstack
61 end
62 local idef = itemstack:get_definition()
63 local success = minetest.item_place_node(itemstack, placer, pointed_thing)
65 if success then
66 if idef.sounds and idef.sounds.place then
67 minetest.sound_play(idef.sounds.place, {pos=above, gain=1})
68 end
69 end
70 return itemstack
71 end,
73 _mcl_blast_resistance = 2,
74 _mcl_hardness = 0.4,
78 minetest.register_node("mcl_core:vine", {
79 description = "Vines",
80 _doc_items_longdesc = "Vines are climbable blocks which can be placed on the sides solid full-cube blocks. Vines very slowly grow upwards and downwards.",
81 drawtype = "signlike",
82 tiles = {"mcl_core_vine.png"},
83 inventory_image = "mcl_core_vine.png",
84 wield_image = "mcl_core_vine.png",
85 paramtype = "light",
86 sunlight_propagates = true,
87 paramtype2 = "wallmounted",
88 walkable = false,
89 climbable = true,
90 buildable_to = true,
91 selection_box = {
92 type = "wallmounted",
94 stack_max = 64,
95 groups = {handy=1,axey=1,shearsy=1,swordy=1, flammable=2,deco_block=1,destroy_by_lava_flow=1,dig_by_piston=1},
96 sounds = mcl_sounds.node_sound_leaves_defaults(),
97 drop = "",
98 _mcl_shears_drop = true,
99 node_placement_prediction = "",
100 -- Restrict placement of vines
101 on_place = function(itemstack, placer, pointed_thing)
102 if pointed_thing.type ~= "node" then
103 -- no interaction possible with entities
104 return itemstack
107 local under = pointed_thing.under
108 local node = minetest.get_node(under)
109 local def = minetest.registered_nodes[node.name]
110 if not def then return itemstack end
111 local groups = def.groups
113 -- Check special rightclick action of pointed node
114 if def and def.on_rightclick then
115 if not placer:get_player_control().sneak then
116 return def.on_rightclick(under, node, placer, itemstack,
117 pointed_thing) or itemstack, false
121 -- Only place on full cubes
122 if not mcl_core.supports_vines(node.name) then
123 return itemstack
126 local above = pointed_thing.above
128 -- Vines may not be placed on top or below another block
129 if under.y ~= above.y then
130 return itemstack
132 local idef = itemstack:get_definition()
133 local itemstack, success = minetest.item_place_node(itemstack, placer, pointed_thing)
135 if success then
136 if idef.sounds and idef.sounds.place then
137 minetest.sound_play(idef.sounds.place, {pos=above, gain=1})
140 return itemstack
141 end,
143 -- If destroyed, also a “dependant” vine below it.
144 -- A vine is dependant if it hangs from this node and has no supporting block.
145 after_destruct = function(pos, oldnode)
146 local below = {x=pos.x, y=pos.y-1, z=pos.z}
147 local belownode = minetest.get_node(below)
148 if belownode.name == oldnode.name and (not mcl_core.check_vines_supported(below, belownode)) then
149 minetest.remove_node(below)
151 end,
154 _mcl_blast_resistance = 1,
155 _mcl_hardness = 0.2,