Remove cloud from creative inv.
[minetest_magicbeans_w.git] / init.lua
blob90c97f27b504547e0c7ed0b3e77fd9e77603bdbf
1 -- get intllib optionally
2 local S
3 if (minetest.get_modpath("intllib")) then
4 dofile(minetest.get_modpath("intllib").."/intllib.lua")
5 S = intllib.Getter(minetest.get_current_modname())
6 else
7 S = function ( s ) return s end
8 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,
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 x_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 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({
52 type="fuel"
53 recipe = "magicbeans_w:stem",
54 burntime = 21,
57 minetest.register_node("magicbeans_w:cloud", {
58 description = S("Thin Cloud"),
59 drawtype = "liquid",
60 paramtype = "light",
61 tiles = {"default_cloud.png"},
62 walkable = false,
63 climbable = true,
64 sunlight_propagates = true,
65 post_effect_color = "#FFFFFFA0",
66 alpha = 192,
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 } },
70 drop = "",
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",
78 trigger = {
79 type = "dig",
80 node = "magicbeans_w:cloud",
81 target = 1,
84 end
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,
117 function(player)
118 player:set_physics_override({speed=beanspeed, jump=beanjump, gravity=beangrav})
119 end,
120 function(effect)
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})
130 --Register beans
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})
140 else
141 -- Grow Beanstalk
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
145 return itemstack
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}
153 local ex = 0
154 local zed = 1
155 local blank = 0
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
163 return false
166 for why = 0,height do
167 blank = blank + 1
168 if blank > 4 then blank = 1 end
169 why1 = stalk.y + why
170 for i = 1,9 do
171 ex = ex + 1
172 if ex > 3 then
173 zed = zed + 1
174 ex = 1
176 if c[i] == 1 then
177 node = "magicbeans_w:leaves"
178 if i == d[blank] or i == e[blank] then node = "magicbeans_w:blank" end
179 else
180 node = "magicbeans_w:stem"
182 ex1 = stalk.x + ex
183 zed1 = stalk.z + zed
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
189 return itemstack
192 zed = 0
194 -- Build cloud platform
195 for ex = -10,20 do
196 for zed = -10,20 do
197 ex1 = stalk.x + ex
198 zed1 = stalk.z + zed
199 local pos = {x=ex1, y=why1, z=zed1}
200 if can_replace(pos) then
201 minetest.set_node(pos,{name="magicbeans_w:cloud"})
203 end
204 end
206 itemstack:take_item()
208 return itemstack
209 end,
210 on_use = function(itemstack, user, pointed_thing)
211 if bean == "beanstalk" then
212 -- Beanstalk bean can't be eaten
213 return
215 playereffects.apply_effect_type("bean_"..bean, 30, user)
216 itemstack:take_item()
217 return itemstack
218 end,
223 -- Bean Spawning
224 minetest.register_abm(
225 {nodenames = {"default:dirt_with_grass"},
226 interval = 600,
227 chance = 3000,
228 action = function(pos)
229 pos.y = pos.y + 1
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})
234 end,
237 -- Remove beanstalk blanks
238 minetest.register_abm(
239 {nodenames = {"magicbeans_w:blank"},
240 interval = 5,
241 chance = 1,
242 action = function(pos)
243 local neighbors = {
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])
254 if(node ~= nil) then
255 if node.name == "magicbeans_w:leaves" or node.name == "magicbeans_w:stem" then
256 attached = true
257 break
261 if(attached == false) then
262 minetest.remove_node(pos)