1 -- get intllib optionally
2 if (minetest
.get_modpath("intllib")) then
3 dofile(minetest
.get_modpath("intllib").."/intllib.lua")
4 S
= intllib
.Getter(minetest
.get_current_modname())
6 S
= function ( s
) return s
end
9 --Register beanstalk nodes
10 minetest
.register_node("magicbeans_w:leaves", {
11 description
= S("magic beanstalk leaves"),
12 tiles
= {"magicbeans_w_leaves.png"},
13 inventory_image
= "magicbeans_w_leaves.png",
14 drawtype
= "plantlike",
18 groups
= {leaves
= 1, snappy
= 3, flammable
= 2},
21 minetest
.register_node("magicbeans_w:blank", {
22 description
= S("magic beanstalk climbable blank"),
31 groups
= {not_in_creative_inventory
= 1},
34 minetest
.register_node("magicbeans_w:stem", {
35 description
= S("magic beanstalk stem"),
36 tiles
= {"magicbeans_w_stem.png"},
38 groups
= {oddly_breakable_by_hand
= 1, choppy
= 3, flammable
= 2},
41 minetest
.register_node("magicbeans_w:cloud", {
42 description
= S("cloud"),
43 tiles
= {"default_cloud.png"},
47 sunlight_propagates
= true,
48 groups
= {dig_immediate
= 3},
52 { S("magic jumping bean"), S("Magic super jump"), "jumping", nil, 5, nil, {"jump"}},
53 { S("magic flying bean"), S("Magic flying"), "flying", 2, nil, 0.02, {"speed", "gravity"}},
54 { S("magic running bean"), S("Magic super speed"), "running", 3, nil, nil, {"speed"}},
55 { S("magic beanstalk bean"), nil, "beanstalk", nil, nil, nil, nil},
58 for i
in ipairs(magicbeans_w_list
) do
60 local beandesc
= magicbeans_w_list
[i
][1]
61 local effdesc
= magicbeans_w_list
[i
][2]
62 local bean
= magicbeans_w_list
[i
][3]
63 local beanspeed
= magicbeans_w_list
[i
][4]
64 local beanjump
= magicbeans_w_list
[i
][5]
65 local beangrav
= magicbeans_w_list
[i
][6]
66 local beangroups
= magicbeans_w_list
[i
][7]
68 --Register effect types
69 if(beangroups
~= nil) then
70 playereffects
.register_effect_type("bean_"..bean
, effdesc
, beangroups
,
72 player
:set_physics_override({speed
=beanspeed
, jump
=beanjump
, gravity
=beangrav
})
75 local player
= minetest
.get_player_by_name(effect
.playername
)
76 local speed
, jump
, grav
77 if beanspeed
~= nil then speed
= 1 end
78 if beanjump
~= nil then jump
= 1 end
79 if beangrav
~= nil then grav
= 1 end
80 player
:set_physics_override({speed
=speed
, jump
=jump
, gravity
=grav
})
85 minetest
.register_craftitem("magicbeans_w:"..bean
, {
86 description
= beandesc
,
87 inventory_image
= "magicbeans_w_"..bean
..".png",
88 on_place
= function(itemstack
, placer
, pointed_thing
)
89 if pointed_thing
.above
then
90 if bean
~= "beanstalk" then
91 minetest
.env
:add_item(pointed_thing
.above
, {name
="magicbeans_w:"..bean
})
94 minetest
.chat_send_player(placer
:get_player_name(),S("It's gonna grow - wait for it!"))
95 math
.randomseed(os
.time())
96 local stalk
= pointed_thing
.above
99 local height
= 127 - stalk
.y
100 local c
= {1, 1, 1, 1, 2, 1, 1, 1, 1}
101 local d
= {1, 2, 3, 6}
102 local e
= {9, 8, 7, 4}
106 for why
= 0,height
do
108 if blank
> 4 then blank
= 1 end
117 node
= "magicbeans_w:leaves"
118 if i
== d
[blank
] or i
== e
[blank
] then node
= "magicbeans_w:blank" end
120 node
= "magicbeans_w:stem"
124 minetest
.set_node({x
=ex1
, y
=why1
, z
=zed1
},{name
=node
})
128 -- Build cloud platform
133 minetest
.set_node({x
=ex1
, y
=why1
, z
=zed1
},{name
="magicbeans_w:cloud"})
137 itemstack
:take_item()
141 on_use
= function(itemstack
, user
, pointed_thing
)
142 if bean
== "beanstalk" then
143 minetest
.chat_send_player(user
:get_player_name(),S("You can't eat magic beanstalk beans - you have to plant them."))
146 playereffects
.apply_effect_type("bean_"..bean
, 30, user
)
147 itemstack
:take_item()
155 minetest
.register_abm(
156 {nodenames
= {"default:dirt_with_grass"},
159 action
= function(pos
)
161 math
.randomseed(os
.time())
162 local j
= math
.random(4)
163 local bean
= magicbeans_w_list
[j
][3]
164 minetest
.env
:add_item(pos
, {name
="magicbeans_w:"..bean
})
168 -- Remove beanstalk blanks
169 minetest
.register_abm(
170 {nodenames
= {"magicbeans_w:blank"},
173 action
= function(pos
)
175 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
-1 },
176 { x
=pos
.x
, y
=pos
.y
, z
=pos
.z
+1 },
177 { x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
},
178 { x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
},
179 { x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
},
180 { x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
},
182 local attached
= false
183 for i
=1,#neighbors
do
184 local node
= minetest
.get_node_or_nil(neighbors
[i
])
186 if node
.name
== "magicbeans_w:leaves" or node
.name
== "magicbean_w:stem" then
192 if(attached
== false) then
193 minetest
.remove_node(pos
)