Replace archaic minetest.env
[minetest_magicbeans_w.git] / init.lua
blob08e704b67be86d4f04c29e6e5f6595fff9e3ebbb
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
10 --Register beanstalk nodes
11 minetest.register_node("magicbeans_w:leaves", {
12 description = S("Magic beanstalk leaves"),
13 tiles = {"magicbeans_w_leaves.png"},
14 inventory_image = "magicbeans_w_leaves.png",
15 drawtype = "plantlike",
16 is_ground_content = false,
17 walkable = false,
18 climbable = true,
19 paramtype = "light",
20 groups = {leaves = 1, snappy = 3, flammable = 2},
21 sounds = default.node_sound_leaves_defaults()
24 minetest.register_node("magicbeans_w:blank", {
25 description = S("Magic beanstalk climbable blank"),
26 x_doc_items_create_entry = false,
27 drawtype = "airlike",
28 inventory_image = "unknown_node.png",
29 wield_image = "unknown_node.png",
30 walkable = false,
31 climbable = true,
32 paramtype = "light",
33 buildable_to = true,
34 pointable = false,
35 diggable = false,
36 drop = "",
37 groups = {not_in_creative_inventory = 1},
40 minetest.register_node("magicbeans_w:stem", {
41 description = S("Magic beanstalk stem"),
42 is_ground_content = false,
43 tiles = {"magicbeans_w_stem_topbottom.png", "magicbeans_w_stem_topbottom.png", "magicbeans_w_stem.png"},
44 paramtype2 = "facedir",
45 groups = {oddly_breakable_by_hand = 1, choppy = 3, flammable = 2},
46 sounds = default.node_sound_wood_defaults(),
47 on_place = minetest.rotate_node,
50 minetest.register_node("magicbeans_w:cloud", {
51 description = S("Cloud"),
52 tiles = {"default_cloud.png"},
53 walkable = false,
54 climbable = true,
55 paramtype = "light",
56 sunlight_propagates = true,
57 groups = {dig_immediate = 3},
58 sounds = { dig = { name = "", gain = 0 }, footstep = { name = "", gain = 0 },
59 dug = { name = "", gain = 0 }, player = { name = "", gain = 0 } }
62 if(minetest.get_modpath("awards") ~= nil) then
63 awards.register_achievement("magicbeans_w_beanstalk", {
64 title = S("Sam and the Beanstalk"),
65 description = S("Plant a magic beanstalk bean."),
66 icon = "magicbeans_w_stem.png",
68 end
70 local magicbeans_w_list = {
71 { S("Magic jumping bean"), S("Magic super jump"), "jumping", nil, 5, nil, {"jump"},
72 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."),
73 doc.sub.items.temp.eat, },
74 { S("Magic flying bean"), S("Magic flying"), "flying", 2, nil, 0.02, {"speed", "gravity"},
75 S("Eating a running bean will greatly increase your walking speed for 30 seconds. It also cancels out any previous walking speed effects."),
76 doc.sub.items.temp.eat, },
77 { S("Magic running bean"), S("Magic super speed"), "running", 3, nil, nil, {"speed"},
78 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."),
79 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."), },
80 { S("Magic beanstalk bean"), nil, "beanstalk", nil, nil, nil, nil,
81 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."),
82 S("Rightclick with it on the floor to plant it, then wait for a short while for the giant beanstalk to appear."),
86 for i in ipairs(magicbeans_w_list) do
88 local beandesc = magicbeans_w_list[i][1]
89 local effdesc = magicbeans_w_list[i][2]
90 local bean = magicbeans_w_list[i][3]
91 local beanspeed = magicbeans_w_list[i][4]
92 local beanjump = magicbeans_w_list[i][5]
93 local beangrav = magicbeans_w_list[i][6]
94 local beangroups = magicbeans_w_list[i][7]
95 local longdesc = magicbeans_w_list[i][8]
96 local usagehelp = magicbeans_w_list[i][9]
98 --Register effect types
99 if(beangroups ~= nil) then
100 playereffects.register_effect_type("bean_"..bean, effdesc, "magicbeans_w_"..bean.."16.png", beangroups,
101 function(player)
102 player:set_physics_override({speed=beanspeed, jump=beanjump, gravity=beangrav})
103 end,
104 function(effect)
105 local player = minetest.get_player_by_name(effect.playername)
106 local speed, jump, grav
107 if beanspeed ~= nil then speed = 1 end
108 if beanjump ~= nil then jump = 1 end
109 if beangrav ~= nil then grav = 1 end
110 player:set_physics_override({speed=speed, jump=jump, gravity=grav})
114 --Register beans
115 minetest.register_craftitem("magicbeans_w:"..bean, {
116 description = beandesc,
117 x_doc_items_longdesc = longdesc,
118 x_doc_items_usagehelp = usagehelp,
119 inventory_image = "magicbeans_w_"..bean..".png",
120 on_place = function(itemstack, placer, pointed_thing)
121 if pointed_thing.above then
122 if bean ~= "beanstalk" then
123 minetest.add_item(pointed_thing.above, {name="magicbeans_w:"..bean})
124 else
125 -- Grow Beanstalk
126 if(minetest.get_modpath("awards") ~= nil) then
127 awards.unlock(placer:get_player_name(), "magicbeans_w_beanstalk")
129 math.randomseed(os.time())
130 local stalk = pointed_thing.above
131 stalk.x = stalk.x - 2
132 stalk.z = stalk.z - 2
133 local height = 127 - stalk.y
134 local c = {1, 1, 1, 1, 2, 1, 1, 1, 1}
135 local d = {1, 2, 3, 6}
136 local e = {9, 8, 7, 4}
137 local ex = 0
138 local zed = 1
139 local blank = 0
140 local why1, ex1, zed1, node
141 for why = 0,height do
142 blank = blank + 1
143 if blank > 4 then blank = 1 end
144 why1 = stalk.y + why
145 for i = 1,9 do
146 ex = ex + 1
147 if ex > 3 then
148 zed = zed + 1
149 ex = 1
151 if c[i] == 1 then
152 node = "magicbeans_w:leaves"
153 if i == d[blank] or i == e[blank] then node = "magicbeans_w:blank" end
154 else
155 node = "magicbeans_w:stem"
157 ex1 = stalk.x + ex
158 zed1 = stalk.z + zed
159 minetest.set_node({x=ex1, y=why1, z=zed1},{name=node})
161 zed = 0
163 -- Build cloud platform
164 for ex = -10,20 do
165 for zed = -10,20 do
166 ex1 = stalk.x + ex
167 zed1 = stalk.z + zed
168 minetest.set_node({x=ex1, y=why1, z=zed1},{name="magicbeans_w:cloud"})
169 end
170 end
172 itemstack:take_item()
174 return itemstack
175 end,
176 on_use = function(itemstack, user, pointed_thing)
177 if bean == "beanstalk" then
178 -- Beanstalk bean can't be eaten
179 return
181 playereffects.apply_effect_type("bean_"..bean, 30, user)
182 itemstack:take_item()
183 return itemstack
184 end,
189 -- Bean Spawning
190 minetest.register_abm(
191 {nodenames = {"default:dirt_with_grass"},
192 interval = 600,
193 chance = 3000,
194 action = function(pos)
195 pos.y = pos.y + 1
196 math.randomseed(os.time())
197 local j = math.random(4)
198 local bean = magicbeans_w_list[j][3]
199 minetest.add_item(pos, {name="magicbeans_w:"..bean})
200 end,
203 -- Remove beanstalk blanks
204 minetest.register_abm(
205 {nodenames = {"magicbeans_w:blank"},
206 interval = 5,
207 chance = 1,
208 action = function(pos)
209 local neighbors = {
210 { x=pos.x, y=pos.y, z=pos.z-1 },
211 { x=pos.x, y=pos.y, z=pos.z+1 },
212 { x=pos.x, y=pos.y-1, z=pos.z },
213 { x=pos.x, y=pos.y+1, z=pos.z },
214 { x=pos.x-1, y=pos.y, z=pos.z },
215 { x=pos.x+1, y=pos.y, z=pos.z },
217 local attached = false
218 for i=1,#neighbors do
219 local node = minetest.get_node_or_nil(neighbors[i])
220 if(node ~= nil) then
221 if node.name == "magicbeans_w:leaves" or node.name == "magicbeans_w:stem" then
222 attached = true
223 break
227 if(attached == false) then
228 minetest.remove_node(pos)