Add German translation
[minetest_magicbeans_w.git] / init.lua
blob3a669f9389a98cb4cffde3b392489ea3d290e848
1 -- get intllib optionally
2 local S
3 if (minetest.get_modpath("intllib")) then
4 S = intllib.Getter()
5 else
6 S = function ( s ) return s end
7 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,
18 walkable = false,
19 climbable = true,
20 paramtype = "light",
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,
28 drawtype = "airlike",
29 inventory_image = "unknown_node.png",
30 wield_image = "unknown_node.png",
31 walkable = false,
32 climbable = true,
33 paramtype = "light",
34 buildable_to = true,
35 pointable = false,
36 diggable = false,
37 drop = "",
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({
53 type="fuel",
54 recipe = "magicbeans_w:stem",
55 burntime = 21,
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."),
61 drawtype = "liquid",
62 paramtype = "light",
63 tiles = {"default_cloud.png"},
64 walkable = false,
65 climbable = true,
66 sunlight_propagates = true,
67 post_effect_color = "#FFFFFFA0",
68 alpha = 192,
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 } },
72 drop = "",
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",
80 trigger = {
81 type = "dig",
82 node = "magicbeans_w:cloud",
83 target = 1,
86 end
88 local eat
89 if minetest.get_modpath("doc_items") then
90 eat = doc.sub.items.temp.eat
91 end
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."),
96 eat, },
97 { S("Magic flying bean"), S("Magic flying"), "flying", 2, nil, 0.02, {"speed", "gravity"},
98 S("Eating a running bean will greatly increase your walking speed for 30 seconds. It also cancels out any previous walking speed effects."),
99 eat, },
100 { S("Magic running bean"), S("Magic super speed"), "running", 3, nil, nil, {"speed"},
101 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."),
102 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."), },
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,
124 function(player)
125 player:set_physics_override({speed=beanspeed, jump=beanjump, gravity=beangrav})
126 end,
127 function(effect)
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})
138 local on_use = nil
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()
143 return itemstack
146 --Register beans
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})
156 else
157 -- Grow Beanstalk
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
161 return itemstack
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}
169 local ex = 0
170 local zed = 1
171 local blank = 0
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
179 return false
182 for why = 0,height do
183 blank = blank + 1
184 if blank > 4 then blank = 1 end
185 why1 = stalk.y + why
186 for i = 1,9 do
187 ex = ex + 1
188 if ex > 3 then
189 zed = zed + 1
190 ex = 1
192 if c[i] == 1 then
193 node = "magicbeans_w:leaves"
194 if i == d[blank] or i == e[blank] then node = "magicbeans_w:blank" end
195 else
196 node = "magicbeans_w:stem"
198 ex1 = stalk.x + ex
199 zed1 = stalk.z + zed
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
205 return itemstack
208 zed = 0
210 -- Build cloud platform
211 for ex = -10,20 do
212 for zed = -10,20 do
213 ex1 = stalk.x + ex
214 zed1 = stalk.z + zed
215 local pos = {x=ex1, y=why1, z=zed1}
216 if can_replace(pos) then
217 minetest.set_node(pos,{name="magicbeans_w:cloud"})
219 end
220 end
222 itemstack:take_item()
224 return itemstack
225 end,
226 on_use = on_use,
231 -- Bean Spawning
232 minetest.register_abm(
233 {nodenames = {"default:dirt_with_grass"},
234 interval = 600,
235 chance = 3000,
236 action = function(pos)
237 pos.y = pos.y + 1
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})
242 end,
245 -- Remove beanstalk blanks
246 minetest.register_abm(
247 {nodenames = {"magicbeans_w:blank"},
248 interval = 5,
249 chance = 1,
250 action = function(pos)
251 local neighbors = {
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])
262 if(node ~= nil) then
263 if node.name == "magicbeans_w:leaves" or node.name == "magicbeans_w:stem" then
264 attached = true
265 break
269 if(attached == false) then
270 minetest.remove_node(pos)