1 -- get intllib optionally
3 if (minetest
.get_modpath("intllib")) then
4 dofile(minetest
.get_modpath("intllib").."/intllib.lua")
5 S
= intllib
.Getter(minetest
.get_current_modname())
7 S
= function ( s
) return s
end
9 math
.randomseed(os
.time())
11 --Register beanstalk nodes
12 minetest
.register_node("magicbeans_w:leaves", {
13 description
= S("Magic beanstalk leaves"),
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 x_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 tiles
= {"magicbeans_w_stem_topbottom.png", "magicbeans_w_stem_topbottom.png", "magicbeans_w_stem.png"},
45 paramtype2
= "facedir",
46 groups
= {oddly_breakable_by_hand
= 1, choppy
= 3, flammable
= 2},
47 sounds
= default
.node_sound_wood_defaults(),
48 on_place
= minetest
.rotate_node
,
51 minetest
.register_node("magicbeans_w:cloud", {
52 description
= S("Thin Cloud"),
55 tiles
= {"default_cloud.png"},
58 sunlight_propagates
= true,
59 post_effect_color
= "#FFFFFFA0",
61 groups
= {dig_immediate
= 3},
62 sounds
= { dig
= { name
= "", gain
= 0 }, footstep
= { name
= "", gain
= 0 },
63 dug
= { name
= "", gain
= 0 }, player
= { name
= "", gain
= 0 } },
67 if(minetest
.get_modpath("awards") ~= nil) then
68 awards
.register_achievement("magicbeans_w_beanstalk", {
69 title
= S("Sam and the Beanstalk"),
70 description
= S("Climb up a magic beanstalk and touch the clouds."),
71 icon
= "magicbeans_w_stem.png",
74 node
= "magicbeans_w:cloud",
80 local magicbeans_w_list
= {
81 { S("Magic jumping bean"), S("Magic super jump"), "jumping", nil, 5, nil, {"jump"},
82 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."),
83 doc
.sub
.items
.temp
.eat
, },
84 { S("Magic flying bean"), S("Magic flying"), "flying", 2, nil, 0.02, {"speed", "gravity"},
85 S("Eating a running bean will greatly increase your walking speed for 30 seconds. It also cancels out any previous walking speed effects."),
86 doc
.sub
.items
.temp
.eat
, },
87 { S("Magic running bean"), S("Magic super speed"), "running", 3, nil, nil, {"speed"},
88 S("Eating a flying bean will allow you to fly for 30 seconds, after which your flight will apruptly end. Use with caution. It also cancels out any gravity and walking speed effects you have."),
89 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."), },
90 { S("Magic beanstalk bean"), nil, "beanstalk", nil, nil, nil, nil,
91 S("This magic bean will grow into a giant beanstalk when planted. The beanstalk can grop up to a height of about 100 blocks, easily reaching into the clouds."),
92 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."),
96 for i
in ipairs(magicbeans_w_list
) do
98 local beandesc
= magicbeans_w_list
[i
][1]
99 local effdesc
= magicbeans_w_list
[i
][2]
100 local bean
= magicbeans_w_list
[i
][3]
101 local beanspeed
= magicbeans_w_list
[i
][4]
102 local beanjump
= magicbeans_w_list
[i
][5]
103 local beangrav
= magicbeans_w_list
[i
][6]
104 local beangroups
= magicbeans_w_list
[i
][7]
105 local longdesc
= magicbeans_w_list
[i
][8]
106 local usagehelp
= magicbeans_w_list
[i
][9]
108 --Register effect types
109 if(beangroups
~= nil) then
110 playereffects
.register_effect_type("bean_"..bean
, effdesc
, "magicbeans_w_"..bean
.."16.png", beangroups
,
112 player
:set_physics_override({speed
=beanspeed
, jump
=beanjump
, gravity
=beangrav
})
115 local player
= minetest
.get_player_by_name(effect
.playername
)
116 local speed
, jump
, grav
117 if beanspeed
~= nil then speed
= 1 end
118 if beanjump
~= nil then jump
= 1 end
119 if beangrav
~= nil then grav
= 1 end
120 player
:set_physics_override({speed
=speed
, jump
=jump
, gravity
=grav
})
125 minetest
.register_craftitem("magicbeans_w:"..bean
, {
126 description
= beandesc
,
127 x_doc_items_longdesc
= longdesc
,
128 x_doc_items_usagehelp
= usagehelp
,
129 inventory_image
= "magicbeans_w_"..bean
..".png",
130 on_place
= function(itemstack
, placer
, pointed_thing
)
131 if pointed_thing
.type == "node" then
132 if bean
~= "beanstalk" then
133 minetest
.add_item(pointed_thing
.above
, {name
="magicbeans_w:"..bean
})
136 local stalk
= pointed_thing
.above
137 local floor = pointed_thing
.under
138 if minetest
.get_item_group(minetest
.get_node(floor).name
, "soil") == 0 then
141 stalk
.x
= stalk
.x
- 2
142 stalk
.z
= stalk
.z
- 2
143 local height
= 127 - stalk
.y
144 local c
= {1, 1, 1, 1, 2, 1, 1, 1, 1}
145 local d
= {1, 2, 3, 6}
146 local e
= {9, 8, 7, 4}
150 local why1
, ex1
, zed1
, node
151 for why
= 0,height
do
153 if blank
> 4 then blank
= 1 end
162 node
= "magicbeans_w:leaves"
163 if i
== d
[blank
] or i
== e
[blank
] then node
= "magicbeans_w:blank" end
165 node
= "magicbeans_w:stem"
169 minetest
.set_node({x
=ex1
, y
=why1
, z
=zed1
},{name
=node
})
173 -- Build cloud platform
178 minetest
.set_node({x
=ex1
, y
=why1
, z
=zed1
},{name
="magicbeans_w:cloud"})
182 itemstack
:take_item()
186 on_use
= function(itemstack
, user
, pointed_thing
)
187 if bean
== "beanstalk" then
188 -- Beanstalk bean can't be eaten
191 playereffects
.apply_effect_type("bean_"..bean
, 30, user
)
192 itemstack
:take_item()
200 minetest
.register_abm(
201 {nodenames
= {"default:dirt_with_grass"},
204 action
= function(pos
)
206 math
.randomseed(os
.time())
207 local j
= math
.random(4)
208 local bean
= magicbeans_w_list
[j
][3]
209 minetest
.add_item(pos
, {name
="magicbeans_w:"..bean
})
213 -- Remove beanstalk blanks
214 minetest
.register_abm(
215 {nodenames
= {"magicbeans_w:blank"},
218 action
= function(pos
)
220 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
-1 },
221 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
+1 },
222 { x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
},
223 { x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
},
224 { x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
},
225 { x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
},
227 local attached
= false
228 for i
=1,#neighbors
do
229 local node
= minetest
.get_node_or_nil(neighbors
[i
])
231 if node
.name
== "magicbeans_w:leaves" or node
.name
== "magicbeans_w:stem" then
237 if(attached
== false) then
238 minetest
.remove_node(pos
)