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 and climb on them with ease, but be careful not to accidentaly fall off."),
63 tiles
= {"default_cloud.png"},
66 sunlight_propagates
= true,
67 post_effect_color
= "#FFFFFFA0",
69 groups
= {dig_immediate
= 3, not_in_creative_inventory
= 1},
70 sounds
= { dig
= { name
= "", gain
= 0 }, footstep
= { name
= "", gain
= 0 },
71 dug
= { name
= "", gain
= 0 }, player
= { name
= "", gain
= 0 } },
75 if(minetest
.get_modpath("awards") ~= nil) then
76 awards
.register_achievement("magicbeans_w_beanstalk", {
77 title
= S("Sam and the Beanstalk"),
78 description
= S("Climb up a magic beanstalk and touch the clouds."),
79 icon
= "magicbeans_w_stem.png",
82 node
= "magicbeans_w:cloud",
89 if minetest
.get_modpath("doc_items") then
90 eat
= doc
.sub
.items
.temp
.eat
93 local magicbeans_w_list
= {
94 { S("Magic jumping bean"), S("Magic super jump"), "jumping", nil, 5, nil, {"jump"},
95 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."),
97 { S("Magic flying bean"), S("Magic flying"), "flying", 2, nil, 0.02, {"speed", "gravity"},
98 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."),
99 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."), },
100 { S("Magic running bean"), S("Magic super speed"), "running", 3, nil, nil, {"speed"},
101 S("Eating a running bean will greatly increase your walking speed for 30 seconds. It also cancels out any previous walking speed effects."),
103 { S("Magic beanstalk bean"), nil, "beanstalk", nil, nil, nil, nil,
104 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."),
105 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."),
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
,
125 player
:set_physics_override({speed
=beanspeed
, jump
=beanjump
, gravity
=beangrav
})
128 local player
= minetest
.get_player_by_name(effect
.playername
)
129 local speed
, jump
, grav
130 if beanspeed
~= nil then speed
= 1 end
131 if beanjump
~= nil then jump
= 1 end
132 if beangrav
~= nil then grav
= 1 end
133 player
:set_physics_override({speed
=speed
, jump
=jump
, gravity
=grav
})
139 if bean
~= "beanstalk" then
140 on_use
= function(itemstack
, user
, pointed_thing
)
141 playereffects
.apply_effect_type("bean_"..bean
, 30, user
)
142 itemstack
:take_item()
147 minetest
.register_craftitem("magicbeans_w:"..bean
, {
148 description
= beandesc
,
149 _doc_items_longdesc
= longdesc
,
150 _doc_items_usagehelp
= usagehelp
,
151 inventory_image
= "magicbeans_w_"..bean
..".png",
152 on_place
= function(itemstack
, placer
, pointed_thing
)
153 if pointed_thing
.type == "node" then
154 if bean
~= "beanstalk" then
155 minetest
.add_item(pointed_thing
.above
, {name
="magicbeans_w:"..bean
})
158 local stalk
= pointed_thing
.above
159 local floor = pointed_thing
.under
160 if minetest
.get_item_group(minetest
.get_node(floor).name
, "soil") == 0 then
163 stalk
.x
= stalk
.x
- 2
164 stalk
.z
= stalk
.z
- 2
165 local height
= 127 - stalk
.y
166 local c
= {1, 1, 1, 1, 2, 1, 1, 1, 1}
167 local d
= {1, 2, 3, 6}
168 local e
= {9, 8, 7, 4}
172 local why1
, ex1
, zed1
, node
174 local can_replace
= function(pos
)
175 local node
= minetest
.get_node(pos
).name
176 if minetest
.registered_nodes
[node
] then
177 return minetest
.registered_nodes
[node
].buildable_to
182 for why
= 0,height
do
184 if blank
> 4 then blank
= 1 end
193 node
= "magicbeans_w:leaves"
194 if i
== d
[blank
] or i
== e
[blank
] then node
= "magicbeans_w:blank" end
196 node
= "magicbeans_w:stem"
200 local pos
= {x
=ex1
, y
=why1
, z
=zed1
}
201 if can_replace(pos
) then
202 minetest
.set_node(pos
,{name
=node
})
203 elseif node
== "magicbeans_w:stem" then
204 -- Stop growing if stem hits an obstacle
210 -- Build cloud platform
215 local pos
= {x
=ex1
, y
=why1
, z
=zed1
}
216 if can_replace(pos
) then
217 minetest
.set_node(pos
,{name
="magicbeans_w:cloud"})
222 itemstack
:take_item()
232 minetest
.register_abm(
233 {nodenames
= {"default:dirt_with_grass"},
236 action
= function(pos
)
238 math
.randomseed(os
.time())
239 local j
= math
.random(4)
240 local bean
= magicbeans_w_list
[j
][3]
241 minetest
.add_item(pos
, {name
="magicbeans_w:"..bean
})
245 -- Remove beanstalk blanks
246 minetest
.register_abm(
247 {nodenames
= {"magicbeans_w:blank"},
250 action
= function(pos
)
252 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
-1 },
253 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
+1 },
254 { x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
},
255 { x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
},
256 { x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
},
257 { x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
},
259 local attached
= false
260 for i
=1,#neighbors
do
261 local node
= minetest
.get_node_or_nil(neighbors
[i
])
263 if node
.name
== "magicbeans_w:leaves" or node
.name
== "magicbeans_w:stem" then
269 if(attached
== false) then
270 minetest
.remove_node(pos
)