1 -- get intllib optionally
3 if (minetest
.get_modpath("intllib")) then
6 S
= function ( s
) return s
end
8 math
.randomseed(os
.time())
10 --Register beanstalk nodes
11 minetest
.register_node("magicbeans_w:leaves", {
12 description
= S("Magic beanstalk leaves"),
13 _doc_items_longdesc
= S("Leaves from a giant magic beanstalk, a plant which grows high into the sky. It is grown from a magic beanstalk bean. Can you climb to the top?"),
14 tiles
= {"magicbeans_w_leaves.png"},
15 inventory_image
= "magicbeans_w_leaves.png",
16 drawtype
= "plantlike",
17 is_ground_content
= false,
21 groups
= {leaves
= 1, snappy
= 3, flammable
= 2},
22 sounds
= default
.node_sound_leaves_defaults()
25 minetest
.register_node("magicbeans_w:blank", {
26 description
= S("Magic beanstalk climbable blank"),
27 _doc_items_create_entry
= false,
29 inventory_image
= "unknown_node.png",
30 wield_image
= "unknown_node.png",
38 groups
= {not_in_creative_inventory
= 1},
41 minetest
.register_node("magicbeans_w:stem", {
42 description
= S("Magic beanstalk stem"),
43 is_ground_content
= false,
44 _doc_items_longdesc
= S("A stem from a giant magic beanstalk, a plant which grows high into the sky. It is grown from a magic beanstalk bean."),
45 tiles
= {"magicbeans_w_stem_topbottom.png", "magicbeans_w_stem_topbottom.png", "magicbeans_w_stem.png"},
46 paramtype2
= "facedir",
47 groups
= {oddly_breakable_by_hand
= 1, choppy
= 3, flammable
= 2},
48 sounds
= default
.node_sound_wood_defaults(),
49 on_place
= minetest
.rotate_node
,
52 minetest
.register_craft({
54 recipe
= "magicbeans_w:stem",
58 minetest
.register_node("magicbeans_w:cloud", {
59 description
= S("Thin Cloud"),
60 _doc_items_longdesc
= S("Thin clouds are rather unstable, are destroyed by a single punch and can't be collected. You can walk, climb and build on them, but be careful not to accidentaly fall through, especially when you drop on these."),
62 tiles
= {"default_cloud.png"},
65 sunlight_propagates
= true,
66 post_effect_color
= "#FFFFFFA0",
67 groups
= {dig_immediate
= 3, not_in_creative_inventory
= 1},
68 sounds
= { dig
= { name
= "", gain
= 0 }, footstep
= { name
= "", gain
= 0 },
69 dug
= { name
= "", gain
= 0 }, player
= { name
= "", gain
= 0 } },
73 if(minetest
.get_modpath("awards") ~= nil) then
74 awards
.register_achievement("magicbeans_w_beanstalk", {
75 title
= S("Sam and the Beanstalk"),
76 description
= S("Climb up a magic beanstalk and touch the clouds."),
77 icon
= "magicbeans_w_stem.png",
80 node
= "magicbeans_w:cloud",
87 if minetest
.get_modpath("doc_items") then
88 eat
= doc
.sub
.items
.temp
.eat
91 local magicbeans_w_list
= {
92 { S("Magic jumping bean"), S("Magic super jump"), "jumping", nil, 5, nil, {"jump"},
93 S("Eating this bean will make your jumps much, much higher for 30 seconds. In fact, you can jump so high that you may hurt yourself when you fall down again. Use with caution. It also cancels any previous jumping effects."),
95 { S("Magic flying bean"), S("Magic flying"), "flying", 2, nil, 0.02, {"speed", "gravity"},
96 S("Eating a flying bean will allow you to fly for 30 seconds, after which your flight will abruptly end. Use with caution. It also cancels out any gravity and walking speed effects you have."),
97 S("Hold it in your hand, then leftclick to eat the bean. To initiate the flight, just jump. You will very slowly rise high in the skies and eventually sink again. Plan your flights carefully as falling down in mid-flight can be very harmful."), },
98 { S("Magic running bean"), S("Magic super speed"), "running", 3, nil, nil, {"speed"},
99 S("Eating a running bean will greatly increase your walking speed for 30 seconds. It also cancels out any previous walking speed effects."),
101 { S("Magic beanstalk bean"), nil, "beanstalk", nil, nil, nil, nil,
102 S("This magic bean will grow into a giant beanstalk when planted. The beanstalk can grow up to a height of about 100 blocks, easily reaching into the clouds."),
103 S("Rightclick with it on dirt with grass (or any other block which allows saplings to grow) to plant it, then wait for a short while for the giant beanstalk to appear."),
107 local pp_mod
= minetest
.get_modpath("playerphysics")
109 for i
in ipairs(magicbeans_w_list
) do
111 local beandesc
= magicbeans_w_list
[i
][1]
112 local effdesc
= magicbeans_w_list
[i
][2]
113 local bean
= magicbeans_w_list
[i
][3]
114 local beanspeed
= magicbeans_w_list
[i
][4]
115 local beanjump
= magicbeans_w_list
[i
][5]
116 local beangrav
= magicbeans_w_list
[i
][6]
117 local beangroups
= magicbeans_w_list
[i
][7]
118 local longdesc
= magicbeans_w_list
[i
][8]
119 local usagehelp
= magicbeans_w_list
[i
][9]
121 --Register effect types
122 if(beangroups
~= nil) then
123 playereffects
.register_effect_type("bean_"..bean
, effdesc
, "magicbeans_w_"..bean
.."16.png", beangroups
,
126 if beanspeed
~= nil then
127 playerphysics
.add_physics_factor(player
, "speed", "magicbeans_w:speed", beanspeed
)
129 if beanjump
~= nil then
130 playerphysics
.add_physics_factor(player
, "jump", "magicbeans_w:jump", beanjump
)
132 if beangrav
~= nil then
133 playerphysics
.add_physics_factor(player
, "gravity", "magicbeans_w:gravity", beangrav
)
136 player
:set_physics_override({speed
=beanspeed
, jump
=beanjump
, gravity
=beangrav
})
140 local player
= minetest
.get_player_by_name(effect
.playername
)
142 playerphysics
.remove_physics_factor(player
, "speed", "magicbeans_w:speed")
143 playerphysics
.remove_physics_factor(player
, "jump", "magicbeans_w:jump")
144 playerphysics
.remove_physics_factor(player
, "gravity", "magicbeans_w:gravity")
146 local speed
, jump
, grav
147 if beanspeed
~= nil then speed
= 1 end
148 if beanjump
~= nil then jump
= 1 end
149 if beangrav
~= nil then grav
= 1 end
150 player
:set_physics_override({speed
=speed
, jump
=jump
, gravity
=grav
})
157 if bean
~= "beanstalk" then
158 on_use
= function(itemstack
, user
, pointed_thing
)
159 playereffects
.apply_effect_type("bean_"..bean
, 30, user
)
160 itemstack
:take_item()
165 minetest
.register_craftitem("magicbeans_w:"..bean
, {
166 description
= beandesc
,
167 _doc_items_longdesc
= longdesc
,
168 _doc_items_usagehelp
= usagehelp
,
169 inventory_image
= "magicbeans_w_"..bean
..".png",
170 on_place
= function(itemstack
, placer
, pointed_thing
)
171 if pointed_thing
.type == "node" then
172 if bean
~= "beanstalk" then
173 minetest
.add_item(pointed_thing
.above
, {name
="magicbeans_w:"..bean
})
176 local stalk
= pointed_thing
.above
177 local floor = pointed_thing
.under
178 if minetest
.get_item_group(minetest
.get_node(floor).name
, "soil") == 0 then
181 stalk
.x
= stalk
.x
- 2
182 stalk
.z
= stalk
.z
- 2
183 local height
= 127 - stalk
.y
184 local c
= {1, 1, 1, 1, 2, 1, 1, 1, 1}
185 local d
= {1, 2, 3, 6}
186 local e
= {9, 8, 7, 4}
190 local why1
, ex1
, zed1
, node
192 local can_replace
= function(pos
)
193 local node
= minetest
.get_node(pos
).name
194 if minetest
.registered_nodes
[node
] then
195 return minetest
.registered_nodes
[node
].buildable_to
200 for why
= 0,height
do
202 if blank
> 4 then blank
= 1 end
211 node
= "magicbeans_w:leaves"
212 if i
== d
[blank
] or i
== e
[blank
] then node
= "magicbeans_w:blank" end
214 node
= "magicbeans_w:stem"
218 local pos
= {x
=ex1
, y
=why1
, z
=zed1
}
219 if can_replace(pos
) then
220 minetest
.set_node(pos
,{name
=node
})
221 elseif node
== "magicbeans_w:stem" then
222 -- Stop growing if stem hits an obstacle
228 -- Build cloud platform
233 local pos
= {x
=ex1
, y
=why1
, z
=zed1
}
234 if can_replace(pos
) then
235 minetest
.set_node(pos
,{name
="magicbeans_w:cloud"})
240 itemstack
:take_item()
250 minetest
.register_abm(
251 {nodenames
= {"default:dirt_with_grass"},
254 action
= function(pos
)
256 math
.randomseed(os
.time())
257 local j
= math
.random(4)
258 local bean
= magicbeans_w_list
[j
][3]
259 minetest
.add_item(pos
, {name
="magicbeans_w:"..bean
})
263 -- Remove beanstalk blanks
264 minetest
.register_abm(
265 {nodenames
= {"magicbeans_w:blank"},
268 action
= function(pos
)
270 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
-1 },
271 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
+1 },
272 { x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
},
273 { x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
},
274 { x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
},
275 { x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
},
277 local attached
= false
278 for i
=1,#neighbors
do
279 local node
= minetest
.get_node_or_nil(neighbors
[i
])
281 if node
.name
== "magicbeans_w:leaves" or node
.name
== "magicbeans_w:stem" then
287 if(attached
== false) then
288 minetest
.remove_node(pos
)