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_craft({
53 recipe
= "magicbeans_w:stem",
57 minetest
.register_node("magicbeans_w:cloud", {
58 description
= S("Thin Cloud"),
61 tiles
= {"default_cloud.png"},
64 sunlight_propagates
= true,
65 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",
86 local magicbeans_w_list
= {
87 { S("Magic jumping bean"), S("Magic super jump"), "jumping", nil, 5, nil, {"jump"},
88 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."),
89 doc
.sub
.items
.temp
.eat
, },
90 { S("Magic flying bean"), S("Magic flying"), "flying", 2, nil, 0.02, {"speed", "gravity"},
91 S("Eating a running bean will greatly increase your walking speed for 30 seconds. It also cancels out any previous walking speed effects."),
92 doc
.sub
.items
.temp
.eat
, },
93 { S("Magic running bean"), S("Magic super speed"), "running", 3, nil, nil, {"speed"},
94 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."),
95 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."), },
96 { S("Magic beanstalk bean"), nil, "beanstalk", nil, nil, nil, nil,
97 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."),
98 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."),
102 for i
in ipairs(magicbeans_w_list
) do
104 local beandesc
= magicbeans_w_list
[i
][1]
105 local effdesc
= magicbeans_w_list
[i
][2]
106 local bean
= magicbeans_w_list
[i
][3]
107 local beanspeed
= magicbeans_w_list
[i
][4]
108 local beanjump
= magicbeans_w_list
[i
][5]
109 local beangrav
= magicbeans_w_list
[i
][6]
110 local beangroups
= magicbeans_w_list
[i
][7]
111 local longdesc
= magicbeans_w_list
[i
][8]
112 local usagehelp
= magicbeans_w_list
[i
][9]
114 --Register effect types
115 if(beangroups
~= nil) then
116 playereffects
.register_effect_type("bean_"..bean
, effdesc
, "magicbeans_w_"..bean
.."16.png", beangroups
,
118 player
:set_physics_override({speed
=beanspeed
, jump
=beanjump
, gravity
=beangrav
})
121 local player
= minetest
.get_player_by_name(effect
.playername
)
122 local speed
, jump
, grav
123 if beanspeed
~= nil then speed
= 1 end
124 if beanjump
~= nil then jump
= 1 end
125 if beangrav
~= nil then grav
= 1 end
126 player
:set_physics_override({speed
=speed
, jump
=jump
, gravity
=grav
})
131 minetest
.register_craftitem("magicbeans_w:"..bean
, {
132 description
= beandesc
,
133 x_doc_items_longdesc
= longdesc
,
134 x_doc_items_usagehelp
= usagehelp
,
135 inventory_image
= "magicbeans_w_"..bean
..".png",
136 on_place
= function(itemstack
, placer
, pointed_thing
)
137 if pointed_thing
.type == "node" then
138 if bean
~= "beanstalk" then
139 minetest
.add_item(pointed_thing
.above
, {name
="magicbeans_w:"..bean
})
142 local stalk
= pointed_thing
.above
143 local floor = pointed_thing
.under
144 if minetest
.get_item_group(minetest
.get_node(floor).name
, "soil") == 0 then
147 stalk
.x
= stalk
.x
- 2
148 stalk
.z
= stalk
.z
- 2
149 local height
= 127 - stalk
.y
150 local c
= {1, 1, 1, 1, 2, 1, 1, 1, 1}
151 local d
= {1, 2, 3, 6}
152 local e
= {9, 8, 7, 4}
156 local why1
, ex1
, zed1
, node
158 local can_replace
= function(pos
)
159 local node
= minetest
.get_node(pos
).name
160 if minetest
.registered_nodes
[node
] then
161 return minetest
.registered_nodes
[node
].buildable_to
166 for why
= 0,height
do
168 if blank
> 4 then blank
= 1 end
177 node
= "magicbeans_w:leaves"
178 if i
== d
[blank
] or i
== e
[blank
] then node
= "magicbeans_w:blank" end
180 node
= "magicbeans_w:stem"
184 local pos
= {x
=ex1
, y
=why1
, z
=zed1
}
185 if can_replace(pos
) then
186 minetest
.set_node(pos
,{name
=node
})
187 elseif node
== "magicbeans_w:stem" then
188 -- Stop growing if stem hits an obstacle
194 -- Build cloud platform
199 local pos
= {x
=ex1
, y
=why1
, z
=zed1
}
200 if can_replace(pos
) then
201 minetest
.set_node(pos
,{name
="magicbeans_w:cloud"})
206 itemstack
:take_item()
210 on_use
= function(itemstack
, user
, pointed_thing
)
211 if bean
== "beanstalk" then
212 -- Beanstalk bean can't be eaten
215 playereffects
.apply_effect_type("bean_"..bean
, 30, user
)
216 itemstack
:take_item()
224 minetest
.register_abm(
225 {nodenames
= {"default:dirt_with_grass"},
228 action
= function(pos
)
230 math
.randomseed(os
.time())
231 local j
= math
.random(4)
232 local bean
= magicbeans_w_list
[j
][3]
233 minetest
.add_item(pos
, {name
="magicbeans_w:"..bean
})
237 -- Remove beanstalk blanks
238 minetest
.register_abm(
239 {nodenames
= {"magicbeans_w:blank"},
242 action
= function(pos
)
244 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
-1 },
245 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
+1 },
246 { x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
},
247 { x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
},
248 { x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
},
249 { x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
},
251 local attached
= false
252 for i
=1,#neighbors
do
253 local node
= minetest
.get_node_or_nil(neighbors
[i
])
255 if node
.name
== "magicbeans_w:leaves" or node
.name
== "magicbeans_w:stem" then
261 if(attached
== false) then
262 minetest
.remove_node(pos
)