Updated readme
[minetest_magicbeans_w.git] / init.lua
blobe8b86008c60466b5ccb437cd4349619b0ea6a215
1 --Register beanstalk nodes
2 minetest.register_node("magicbeans:leaves", {
3 tiles = {"magicbeans_leaves.png"},
4 drawtype = "plantlike",
5 walkable = false,
6 climbable = true,
7 paramtype = "light",
8 groups = {dig_immediate = 3},
9 })
11 minetest.register_node("magicbeans:blank", {
12 tiles = {"magicbeans_blank.png"},
13 drawtype = "plantlike",
14 walkable = false,
15 climbable = true,
16 paramtype = "light",
17 groups = {dig_immediate = 3},
20 minetest.register_node("magicbeans:stem", {
21 tiles = {"magicbeans_stem.png"},
22 paramtype = "light",
23 groups = {dig_immediate = 3},
26 minetest.register_node("magicbeans:cloud", {
27 tiles = {"default_cloud.png"},
28 walkable = false,
29 climbable = true,
30 paramtype = "light",
31 sunlight_propagates = true,
32 groups = {dig_immediate = 3},
35 magicbeans_list = {
36 { "Magic Jumping Beans", "jumping", 1, 5, 1},
37 { "Magic Flying Beans", "flying", 2, 1, 0.02},
38 { "Magic Running Beans", "running", 3, 1, 1},
39 { "Magic Beanstalk Beans", "beanstalk", 1, 1, 1},
42 for i in ipairs(magicbeans_list) do
44 local beandesc = magicbeans_list[i][1]
45 local bean = magicbeans_list[i][2]
46 local beanspeed = magicbeans_list[i][3]
47 local beanjump = magicbeans_list[i][4]
48 local beangrav = magicbeans_list[i][5]
50 --Register beans
51 minetest.register_craftitem("magicbeans:"..bean, {
52 description = beandesc,
53 inventory_image = "magicbeans_"..bean..".png",
54 on_place = function(itemstack, placer, pointed_thing)
55 if pointed_thing.above then
56 if bean ~= "beanstalk" then
57 minetest.env:add_item(pointed_thing.above, {name="magicbeans:"..bean})
58 else
59 -- Grow Beanstalk
60 minetest.chat_send_player(placer:get_player_name(),"It's gonna grow - wait for it!")
61 math.randomseed(os.time())
62 local stalk = pointed_thing.above
63 stalk.x = stalk.x - 2
64 stalk.z = stalk.z - 2
65 local height = 127 - stalk.y
66 local c = {1, 1, 1, 1, 2, 1, 1, 1, 1}
67 local d = {1, 2, 3, 6}
68 local e = {9, 8, 7, 4}
69 local ex = 0
70 local zed = 1
71 local blank = 0
72 for why = 0,height do
73 blank = blank + 1
74 if blank > 4 then blank = 1 end
75 why1 = stalk.y + why
76 for i = 1,9 do
77 ex = ex + 1
78 if ex > 3 then
79 zed = zed + 1
80 ex = 1
81 end
82 if c[i] == 1 then
83 node = "magicbeans:leaves"
84 if i == d[blank] or i == e[blank] then node = "magicbeans:blank" end
85 else
86 node = "magicbeans:stem"
87 end
88 ex1 = stalk.x + ex
89 zed1 = stalk.z + zed
90 minetest.set_node({x=ex1, y=why1, z=zed1},{name=node})
91 end
92 zed = 0
93 end
94 -- Build cloud platform
95 for ex = -10,20 do
96 for zed = -10,20 do
97 ex1 = stalk.x + ex
98 zed1 = stalk.z + zed
99 minetest.set_node({x=ex1, y=why1, z=zed1},{name="magicbeans:cloud"})
100 end
101 end
103 itemstack:take_item()
105 return itemstack
106 end,
107 on_use = function(itemstack, user, pointed_thing)
108 if bean == "beanstalk" then
109 minetest.chat_send_player(user:get_player_name(),"You can't eat magic beanstalk beans - you have to plant them.")
110 return
112 user:set_physics_override(beanspeed, beanjump, beangrav)
113 minetest.chat_send_player(user:get_player_name(),"Whoa, that was a strong magic "..bean.." bean!")
114 local normjump = function()
115 user:set_physics_override(1, 1, 1)
116 minetest.chat_send_player(user:get_player_name(),"Looks like you're back to normal now - no more crazy "..bean.."!")
117 end
118 minetest.after(30, normjump)
119 itemstack:take_item()
120 return itemstack
121 end,
126 -- Bean Spawning
127 minetest.register_abm(
128 {nodenames = {"default:dirt_with_grass"},
129 interval = 600,
130 chance = 3000,
131 action = function(pos)
132 pos.y = pos.y + 1
133 math.randomseed(os.time())
134 local j = math.random(4)
135 local bean = magicbeans_list[j][2]
136 minetest.env:add_item(pos, {name="magicbeans:"..bean})
137 end,