Merge pull request #3 from Athemis/master
[MineClone.git] / mods / farming / melon.lua
blob065849249f3881304dddd537e089a6ddf17c7c3a
1 minetest.register_node("farming:melon", {
2 description = "Melon",
3 paramtype2 = "facedir",
4 stack_max = 64,
5 tiles = {"farming_melon_top.png", "farming_melon_top.png", "farming_melon_side.png", "farming_melon_side.png", "farming_melon_side.png", "farming_melon_side.png"},
6 groups = {choppy=2, oddly_breakable_by_hand=2},
7 drop = {
8 max_items = 1,
9 items = {
10 { items = {'farming:melon_item 3'} },
11 { items = {'farming:melon_item 4'}, rarity = 2 },
12 { items = {'farming:melon_item 5'}, rarity = 5 },
13 { items = {'farming:melon_item 6'}, rarity = 10 },
14 { items = {'farming:melon_item 7'}, rarity = 14 }
17 after_dig_node = function(pos, oldnode, oldmetadata, user)
18 local have_change = 0
19 for x=-1,1 do
20 local p = {x=pos.x+x, y=pos.y, z=pos.z}
21 local n = minetest.env:get_node(p)
22 if string.find(n.name, "melontige_linked_") and have_change == 0 then
23 have_change = 1
24 minetest.env:add_node(p, {name="farming:melontige_unconnect"})
25 end
26 end
27 if have_change == 0 then
28 for z=-1,1 do
29 p = {x=pos.x, y=pos.y, z=pos.z+z}
30 local n = minetest.env:get_node(p)
31 if string.find(n.name, "melontige_linked_") and have_change == 0 then
32 have_change = 1
33 minetest.env:add_node(p, {name="farming:melontige_unconnect"})
34 end
35 end
36 end
37 end
40 minetest.register_node("farming:melontige_1", {
41 paramtype = "light",
42 walkable = false,
43 drawtype = "plantlike",
44 sunlight_propagates = true,
45 drop = "",
46 tiles = {"farming_tige_1.png"},
47 selection_box = {
48 type = "fixed",
49 fixed = {
50 {-0.5, -0.5, -0.5, 0.5, -0.5+6/16, 0.5}
53 groups = {snappy=3, flammable=2, not_in_creative_inventory=1 ,dig_by_water=1},
54 sounds = default.node_sound_leaves_defaults(),
57 minetest.register_node("farming:melontige_2", {
58 paramtype = "light",
59 walkable = false,
60 drawtype = "plantlike",
61 sunlight_propagates = true,
62 drop = "",
63 tiles = {"farming_tige_2.png"},
64 selection_box = {
65 type = "fixed",
66 fixed = {
67 {-0.5, -0.5, -0.5, 0.5, -0.5+9/16, 0.5}
70 groups = {snappy=3, flammable=2, not_in_creative_inventory=1 ,dig_by_water=1},
71 sounds = default.node_sound_leaves_defaults(),
74 minetest.register_node("farming:melontige_unconnect", {
75 paramtype = "light",
76 walkable = false,
77 sunlight_propagates = true,
78 drop = "",
79 drawtype = "plantlike",
80 tiles = {"farming_tige_end.png"},
81 groups = {snappy=3, flammable=2, not_in_creative_inventory=1 ,dig_by_water=1},
82 sounds = default.node_sound_leaves_defaults(),
85 minetest.register_node("farming:melontige_linked_r", {
86 paramtype = "light",
87 sunlight_propagates = true,
88 walkable = false,
89 drop = "",
90 drawtype = "nodebox",
91 paramtype = "light",
92 paramtype2 = "wallmounted",
93 legacy_wallmounted = true,
94 node_box = {
95 type = "fixed",
96 fixed = {
97 {-0.5, -0.5, 0, 0.5, 0.5, 0}, -- NodeBox1
100 selection_box = {
101 type = "fixed",
102 fixed = {-0.2, -0.5, -0.2, 0.2, 0.2, 0.2}
104 tiles = {
105 "farming_tige_connnect.png", --top
106 "farming_tige_connnect.png", -- bottom
107 "farming_tige_connnect.png", -- right
108 "farming_tige_connnect.png", -- left
109 "farming_tige_connnect.png", -- back
110 "farming_tige_connnect.png^[transformFX90" --front
112 groups = {snappy=3, flammable=2, not_in_creative_inventory=1 ,dig_by_water=1},
113 sounds = default.node_sound_leaves_defaults(),
116 minetest.register_node("farming:melontige_linked_l", {
117 paramtype = "light",
118 walkable = false,
119 sunlight_propagates = true,
120 drop = "",
121 drawtype = "nodebox",
122 paramtype = "light",
123 paramtype2 = "wallmounted",
124 legacy_wallmounted = true,
125 node_box = {
126 type = "fixed",
127 fixed = {
128 {-0.5, -0.5, 0, 0.5, 0.5, 0}, -- NodeBox1
131 selection_box = {
132 type = "fixed",
133 fixed = {-0.2, -0.5, -0.2, 0.2, 0.2, 0.2}
135 tiles = {
136 "farming_tige_connnect.png", --top
137 "farming_tige_connnect.png", -- bottom
138 "farming_tige_connnect.png", -- right
139 "farming_tige_connnect.png", -- left
140 "farming_tige_connnect.png^[transformFX90", -- back
141 "farming_tige_connnect.png" --front
143 groups = {snappy=3, flammable=2, not_in_creative_inventory=1 ,dig_by_water=1},
144 sounds = default.node_sound_leaves_defaults(),
147 minetest.register_node("farming:melontige_linked_t", {
148 paramtype = "light",
149 walkable = false,
150 sunlight_propagates = true,
151 drop = "",
152 drawtype = "nodebox",
153 paramtype = "light",
154 paramtype2 = "wallmounted",
155 legacy_wallmounted = true,
156 node_box = {
157 type = "fixed",
158 fixed = {
159 {0, -0.5, -0.5, 0, 0.5, 0.5}, -- NodeBox1
162 selection_box = {
163 type = "fixed",
164 fixed = {-0.2, -0.5, -0.2, 0.2, 0.2, 0.2}
166 tiles = {
167 "farming_tige_connnect.png", --top
168 "farming_tige_connnect.png", -- bottom
169 "farming_tige_connnect.png^[transformFX90", -- right
170 "farming_tige_connnect.png", -- left
171 "farming_tige_connnect.png", -- back
172 "farming_tige_connnect.png" --front
174 groups = {snappy=3, flammable=2, not_in_creative_inventory=1 ,dig_by_water=1},
175 sounds = default.node_sound_leaves_defaults(),
178 minetest.register_node("farming:melontige_linked_b", {
179 paramtype = "light",
180 walkable = false,
181 sunlight_propagates = true,
182 drop = "",
183 drawtype = "nodebox",
184 paramtype = "light",
185 paramtype2 = "wallmounted",
186 legacy_wallmounted = true,
187 node_box = {
188 type = "fixed",
189 fixed = {
190 {0, -0.5, -0.5, 0, 0.5, 0.5}, -- NodeBox1
193 selection_box = {
194 type = "fixed",
195 fixed = {-0.2, -0.5, -0.2, 0.2, 0.2, 0.2}
197 tiles = {
198 "farming_tige_connnect.png", --top
199 "farming_tige_connnect.png", -- bottom
200 "farming_tige_connnect.png", -- right
201 "farming_tige_connnect.png^[transformFX90", -- left
202 "farming_tige_connnect.png", -- back
203 "farming_tige_connnect.png" --front
205 groups = {snappy=3, flammable=2, not_in_creative_inventory=1 ,dig_by_water=1},
206 sounds = default.node_sound_leaves_defaults(),
209 minetest.register_craftitem("farming:melon_seed", {
210 description = "Melon seed",
211 stack_max = 64,
212 inventory_image = "farming_melon_seed.png",
213 on_place = function(itemstack, placer, pointed_thing)
214 return farming:place_seed(itemstack, placer, pointed_thing, "farming:melontige_1")
215 end,
218 minetest.register_craftitem("farming:melon_item", {
219 description = "Melon",
220 stack_max = 64,
221 inventory_image = "farming_melon.png",
222 on_use = minetest.item_eat(2),
225 minetest.register_craftitem("farming:melon_item_speckled", {
226 description = "Melon Speckled",
227 stack_max = 64,
228 inventory_image = "farming_melon_speckled.png",
231 minetest.register_abm({
232 nodenames = {"farming:melontige_unconnect"},
233 neighbors = {"air"},
234 interval = 25,
235 chance = 15,
236 action = function(pos)
237 local have_change = 0
238 local newpos = {x=pos.x, y=pos.y, z=pos.z}
239 local light = minetest.get_node_light(pos)
240 if light or light > 10 then
241 for x=-1,1 do
242 local p = {x=pos.x+x, y=pos.y-1, z=pos.z}
243 newpos = {x=pos.x+x, y=pos.y, z=pos.z}
244 local n = minetest.env:get_node(p)
245 local nod = minetest.env:get_node(newpos)
246 if n.name=="default:dirt_with_grass" and nod.name=="air" and have_change == 0
247 or n.name=="default:dirt" and nod.name=="air" and have_change == 0
248 or string.find(n.name, "farming:soil") and nod.name=="air" and have_change == 0 then
249 have_change = 1
250 minetest.env:add_node(newpos, {name="farming:melon"})
251 if x == 1 then
252 minetest.env:add_node(pos, {name="farming:melontige_linked_r" })
253 else
254 minetest.env:add_node(pos, {name="farming:melontige_linked_l"})
258 if have_change == 0 then
259 for z=-1,1 do
260 p = {x=pos.x, y=pos.y-1, z=pos.z+z}
261 newpos = {x=pos.x, y=pos.y, z=pos.z+z}
262 n = minetest.env:get_node(p)
263 local nod2 = minetest.env:get_node(newpos)
264 if n.name=="default:dirt_with_grass" and nod2.name=="air" and have_change == 0
265 or n.name=="default:dirt" and nod2.name=="air" and have_change == 0
266 or string.find(n.name, "farming:soil") and nod2.name=="air" and have_change == 0 then
267 have_change = 1
268 minetest.env:add_node(newpos, {name="farming:melon"})
269 if z == 1 then
270 minetest.env:add_node(pos, {name="farming:melontige_linked_t" })
271 else
272 minetest.env:add_node(pos, {name="farming:melontige_linked_b" })
278 end,
281 farming:add_plant("farming:melontige_unconnect", {"farming:melontige_1", "farming:melontige_2"}, 50, 20)
283 minetest.register_craft({
284 type = "shapeless",
285 output = "farming:melon_seed",
286 recipe = {"farming:melon_item"}
289 minetest.register_craft({
290 output = 'farming:melon',
291 recipe = {
292 {'farming:melon_item', 'farming:melon_item', 'farming:melon_item'},
293 {'farming:melon_item', 'farming:melon_item', 'farming:melon_item'},
294 {'farming:melon_item', 'farming:melon_item', 'farming:melon_item'},