]> git.lizzy.rs Git - Crafter.git/blob - mods/farming/init.lua
Rebalance EVERYTHING
[Crafter.git] / mods / farming / init.lua
1 --Quick definition of hoes
2 local material = {"wood","stone","iron","gold","diamond"}
3
4 local function till_soil(pos)
5         local is_dirt = minetest.get_node_group(minetest.get_node(pos).name, "farm_tillable") > 0
6         local is_farmland = minetest.get_node_group(minetest.get_node(pos).name, "farmland") > 0
7         if is_dirt and not is_farmland then
8                 minetest.sound_play("dirt",{pos=pos})
9                 minetest.set_node(pos,{name="farming:farmland_dry"})
10                 return(true)
11         end
12 end
13
14 for level,material in pairs(material) do
15         local wear = 100*(6-level)
16         local groupcaps2
17         if material == "wood" then
18                 groupcaps2={
19                         dirt =  {times={[1]=0.4,[2]=1.5,[3]=3,[4]=6,[5]=12},    uses=59, maxlevel=1},
20                         snow =  {times={[1]=0.4,[2]=1.5,[3]=3,[4]=6,[5]=12},    uses=59, maxlevel=1},
21                         grass = {times={[1]=0.45,[2]=1.5,[3]=3,[4]=6,[5]=12},   uses=59, maxlevel=1},
22                         sand =  {times={[1]=0.4,[2]=1.5,[3]=3,[4]=6,[5]=12},    uses=59, maxlevel=1},
23                 }
24                 damage = 2.5
25         elseif material == "stone" then
26                 groupcaps2={
27                         dirt =  {times={[1]=0.2,[2]=0.2,[3]=1.5,[4]=3,[5]=6},   uses=131, maxlevel=1},
28                         snow =  {times={[1]=0.2,[2]=0.2,[3]=1.5,[4]=3,[5]=6},   uses=131, maxlevel=1},
29                         grass = {times={[1]=0.25,[2]=0.25,[3]=1.5,[4]=3,[5]=6}, uses=131, maxlevel=1},
30                         sand =  {times={[1]=0.2,[2]=0.2,[3]=1.5,[4]=3,[5]=6},   uses=131, maxlevel=1},
31                 }
32                 damage = 3.5
33         elseif material == "iron" then
34                 groupcaps2={
35                         dirt =  {times={[1]=0.15,[2]=0.15,[3]=0.15,[4]=1.5,[5]=3}, uses=250, maxlevel=1},
36                         snow =  {times={[1]=0.15,[2]=0.15,[3]=0.15,[4]=1.5,[5]=3}, uses=250, maxlevel=1},
37                         grass = {times={[1]=0.15,[2]=0.15,[3]=0.15,[4]=1.5,[5]=3}, uses=250, maxlevel=1},
38                         sand =  {times={[1]=0.15,[2]=0.15,[3]=0.15,[4]=1.5,[5]=3}, uses=250, maxlevel=1},
39                 }
40                 damage = 4.5
41         elseif material == "gold" then
42                 groupcaps2={
43                         dirt =  {times={[1]=0.1,[2]=0.1,[3]=0.1,[4]=0.1,[5]=1.5}, uses=32, maxlevel=1},
44                         snow =  {times={[1]=0.1,[2]=0.1,[3]=0.1,[4]=0.1,[5]=1.5}, uses=32, maxlevel=1},
45                         grass = {times={[1]=0.1,[2]=0.1,[3]=0.1,[4]=0.1,[5]=1.5}, uses=32, maxlevel=1},
46                         sand =  {times={[1]=0.1,[2]=0.1,[3]=0.1,[4]=0.1,[5]=1.5}, uses=32, maxlevel=1},
47                 }
48                 damage = 2.5
49         elseif material == "diamond" then
50                 groupcaps2={
51                         dirt =  {times={[1]= 0.1,[2]=0.1,[3]=0.1,[4]=0.1,[5]=1.5},     uses=1561, maxlevel=1},
52                         snow =  {times={[1]= 0.1,[2]=0.1,[3]=0.1,[4]=0.1,[5]=1.5},     uses=1561, maxlevel=1},
53                         grass = {times={[1]= 0.15,[2]=0.15,[3]=0.15,[4]=0.15,[5]=1.5}, uses=1561, maxlevel=1},
54                         sand =  {times={[1]= 0.1,[2]=0.1,[3]=0.1,[4]=0.1,[5]=1.5},     uses=1561, maxlevel=1},
55                 }
56                 damage = 5.5
57         end
58         minetest.register_tool("farming:"..material.."hoe", {
59                 description = material:gsub("^%l", string.upper).." Hoe",
60                 inventory_image = material.."hoe.png",
61                 tool_capabilities = {
62                                 --full_punch_interval = 1.2,
63                                 --max_drop_level=0,
64                                 groupcaps=groupcaps2,
65                                 damage_groups = {damage=damage},
66                         },
67                 sound = {breaks = {name="tool_break",gain=0.4}}, -- change this
68                 groups = {flammable = 2, tool=1 },
69                 
70                 on_place = function(itemstack, placer, pointed_thing)
71                         local noddef = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
72                         local sneak = placer:get_player_control().sneak
73                         
74                         if not sneak and noddef.on_rightclick then
75                                 minetest.item_place(itemstack, placer, pointed_thing)
76                                 return
77                         end
78                 
79                         local tilled = till_soil(pointed_thing.under)
80                         if tilled == true then 
81                                 if minetest.registered_nodes[minetest.get_node(vector.new(pointed_thing.under.x,pointed_thing.under.y+1,pointed_thing.under.z)).name].buildable_to then
82                                         minetest.dig_node(vector.new(pointed_thing.under.x,pointed_thing.under.y+1,pointed_thing.under.z))
83                                 end
84                                 itemstack:add_wear(wear)
85                         end
86                         
87                         local damage = itemstack:get_wear()
88                         print(damage)
89                         if damage <= 0 and tilled == true  then
90                                 minetest.sound_play("tool_break",{object=placer})
91                         end
92                         return(itemstack)
93                 end,
94         })
95         minetest.register_craft({
96                 output = "farming:"..material.."hoe",
97                 recipe = {
98                         {"","main:"..material, "main:"..material},
99                         {"","main:stick", ""},
100                         {"", "main:stick", ""}
101                 }
102         })
103         minetest.register_craft({
104                 output = "farming:"..material.."hoe",
105                 recipe = {
106                         {"main:"..material,"main:"..material, ""},
107                         {"","main:stick", ""},
108                         {"", "main:stick", ""}
109                 }
110         })
111 end
112
113 local farmland = {"wet","dry"}
114
115 for level,dryness in pairs(farmland) do
116         local coloring = 160/level
117
118         minetest.register_node("farming:farmland_"..dryness,{
119                 description = "Farmland",
120                 paramtype = "light",
121                 drawtype = "nodebox",
122                 sounds = main.dirtSound(),
123                 --paramtype2 = "wallmounted",
124                 node_box = {
125                         type = "fixed",
126                         --{xmin, ymin, zmin, xmax, ymax, zmax}
127
128                         fixed = {-0.5, -0.5, -0.5, 0.5, 6/16, 0.5},
129                 },
130                 wetness = math.abs(level-2),
131                 collision_box = {
132                         type = "fixed",
133                         --{xmin, ymin, zmin, xmax, ymax, zmax}
134
135                         fixed = {-0.5, -0.5, -0.5, 0.5, 6/16, 0.5},
136                 },
137                 tiles = {"dirt.png^farmland.png^[colorize:black:"..coloring,"dirt.png^[colorize:black:"..coloring,"dirt.png^[colorize:black:"..coloring,"dirt.png^[colorize:black:"..coloring,"dirt.png^[colorize:black:"..coloring,"dirt.png^[colorize:black:"..coloring},
138                 groups = {dirt = 1, soft = 1, shovel = 1, hand = 1, soil=1,farmland=1},
139                 drop="main:dirt",
140         })
141 end
142
143
144 --drying and wetting abm for farmland
145 minetest.register_abm({
146         label = "Farmland Wet",
147         nodenames = {"farming:farmland_dry"},
148         neighbors = {"air","group:crop"},
149         interval = 3,
150         chance = 150,
151         action = function(pos)
152                 local found = minetest.find_node_near(pos, 3, {"main:water","main:waterflow"})
153                 if found then
154                         minetest.set_node(pos,{name="farming:farmland_wet"})
155                 else
156                         minetest.set_node(pos,{name="main:dirt"})
157                 end
158         end,
159 })
160 minetest.register_abm({
161         label = "Farmland dry",
162         nodenames = {"farming:farmland_wet"},
163         neighbors = {"air"},
164         interval = 5,
165         chance = 500,
166         action = function(pos)
167                 local found = minetest.find_node_near(pos, 3, {"main:water","main:waterflow"})
168                 if not found then
169                         minetest.set_node(pos,{name="farming:farmland_dry"})
170                 end
171         end,
172 })
173
174
175 minetest.register_node("farming:grass", {
176     description = "Tall Grass",
177     drawtype = "plantlike",
178         waving = 1,
179         walkable = false,
180         climbable = false,
181         paramtype = "light",
182         is_ground_content = false,      
183     tiles = {"tallgrass.png"},
184     paramtype2 = "degrotate",
185     buildable_to = true,
186     groups = {leaves = 1, plant = 1, axe = 1, hand = 0,dig_immediate=1,attached_node=1},
187     sounds = main.grassSound(),
188     selection_box = {
189                 type = "fixed",
190                 fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, 4 / 16, 4 / 16}
191         },
192         drop =  {
193                 max_items = 1,
194                 items= {
195                  {
196                         -- Only drop if using a tool whose name is identical to one
197                         -- of these.
198                         rarity = 10,
199                         items = {"farming:seeds"},
200                         -- Whether all items in the dropped item list inherit the
201                         -- hardware coloring palette color from the dug node.
202                         -- Default is 'false'.
203                         --inherit_color = true,
204                 },
205                 },
206         },
207 })
208
209
210 --wheat definitions
211 local wheat_max = 7
212 minetest.register_abm({
213         label = "crops grow",
214         nodenames = {"group:crops"},
215         neighbors = {"group:farmland"},
216         interval = 3,
217         chance = 150,
218         action = function(pos)
219                 
220                 local node_under = minetest.get_node(vector.new(pos.x,pos.y-1,pos.z)).name
221                 local wetness = minetest.registered_nodes[node_under].wetness
222                 
223                 if wetness == 0 or not wetness then
224                         return
225                 end
226                 
227                 local node = minetest.get_node(pos).name
228                 local stage = minetest.registered_nodes[node].grow_stage
229                 if stage < wheat_max then
230                         minetest.set_node(pos,{name="farming:wheat_"..stage+1})
231                 end
232         end,
233 })
234 for i = 0,wheat_max do
235         local drop = ""
236         if i == wheat_max then 
237                 drop = {
238                         max_items = 2,
239                         items= {
240                          {
241                                 -- Only drop if using a tool whose name is identical to one
242                                 -- of these.
243                                 --rarity = 10,
244                                 items = {"farming:wheat"},
245                                 -- Whether all items in the dropped item list inherit the
246                                 -- hardware coloring palette color from the dug node.
247                                 -- Default is 'false'.
248                                 --inherit_color = true,
249                         },
250                         {
251                                 -- Only drop if using a tool whose name is identical to one
252                                 -- of these.
253                                 rarity = 3,
254                                 items = {"farming:seeds"},
255                                 -- Whether all items in the dropped item list inherit the
256                                 -- hardware coloring palette color from the dug node.
257                                 -- Default is 'false'.
258                                 --inherit_color = true,
259                         },
260                         },
261                         }
262                 
263              
264         end
265         
266         minetest.register_node("farming:wheat_"..i, {
267             description = "Wheat Stage "..i,
268             drawtype = "plantlike",
269                 waving = 1,
270                 walkable = false,
271                 climbable = false,
272                 paramtype = "light",
273                 is_ground_content = false,      
274             tiles = {"wheat_stage_"..i..".png"},
275             paramtype2 = "degrotate",
276             buildable_to = true,
277             grow_stage = i,
278             groups = {leaves = 1, plant = 1, axe = 1, hand = 0,dig_immediate=1,attached_node=1,crops=1},
279             sounds = main.grassSound(),
280             selection_box = {
281                         type = "fixed",
282                         fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, 4 / 16, 4 / 16}
283                 },
284                 drop = drop,
285         })
286 end
287
288
289 minetest.register_craftitem("farming:seeds", {
290         description = "Seeds",
291         inventory_image = "seeds.png",
292         on_place = function(itemstack, placer, pointed_thing)
293                 if pointed_thing.type ~= "node" then
294                         return itemstack
295                 end
296                 local pb = pointed_thing.above
297                 if minetest.get_node_group(minetest.get_node(vector.new(pb.x,pb.y-1,pb.z)).name, "farmland") == 0 or minetest.get_node(pointed_thing.above).name ~= "air"  then
298                         return itemstack
299                 end
300
301                 local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
302
303                 local fakestack = itemstack
304                 local retval = false
305
306                 retval = fakestack:set_name("farming:wheat_0")
307
308                 if not retval then
309                         return itemstack
310                 end
311                 itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
312                 itemstack:set_name("farming:seeds")
313
314                 if retval then
315                         minetest.sound_play("leaves", {pos=pointed_thing.above, gain = 1.0})
316                 end
317
318                 return itemstack
319         end
320 })
321
322
323 minetest.register_decoration({
324         deco_type = "simple",
325         place_on = "main:grass",
326         sidelen = 16,
327         fill_ratio = 0.5,
328         --biomes = {"grassland"},
329         decoration = "farming:grass",
330         height = 1,
331 })
332
333
334 minetest.register_craftitem("farming:wheat", {
335         description = "Wheat",
336         inventory_image = "wheat_harvested.png",
337 })
338
339
340 minetest.register_craftitem("farming:bread", {
341         description = "Bread",
342         inventory_image = "bread.png",
343         health = 3,
344 })
345
346 minetest.register_craftitem("farming:toast", {
347         description = "Toast",
348         inventory_image = "bread.png^[colorize:black:100",
349         health = 5,
350 })
351
352 minetest.register_craft({
353         output = "farming:bread",
354         recipe = {
355                 {"farming:wheat", "farming:wheat", "farming:wheat"}
356         }
357 })
358
359
360 minetest.register_craft({
361         type = "cooking",
362         output = "farming:toast",
363         recipe = "farming:bread",
364         cooktime = 3,
365 })