diff --git a/bananas.lua b/bananas.lua index c5184a2..e7f9194 100644 --- a/bananas.lua +++ b/bananas.lua @@ -1,29 +1,41 @@ --- main `S` code in init.lua +-- Hauptcode für 'S' in init.lua local S -S = farming.S +-- Überprüfe, ob die Variablen 'farming' und 'farming.S' existieren +if farming and farming.S then + -- Wenn sie existieren, weise 'farming.S' der Variable 'S' zu + S = farming.S +else + -- Wenn nicht, erstelle eine Dummy-Funktion für 'S' + S = function (s) return s end + -- Gib eine Warnmeldung aus + print("Warnung: farming.S ist nil, es wird stattdessen eine Dummy-Funktion verwendet.") +end + +-- Registriere den Banana Tree Sapling (Banana-Baum Setzling) minetest.register_node("farming_plus:banana_sapling", { - description = S("Banana Tree Sapling"), + description = S("Banana Tree Sapling"), -- Beschreibung des Setzlings drawtype = "plantlike", - tiles = {"farming_banana_sapling.png"}, - inventory_image = "farming_banana_sapling.png", - wield_image = "farming_banana_sapling.png", + tiles = {"farming_banana_sapling.png"}, -- Textur für den Setzling + inventory_image = "farming_banana_sapling.png", -- Bild für den Setzling im Inventar + wield_image = "farming_banana_sapling.png", -- Bild für den Setzling beim Halten paramtype = "light", walkable = false, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} }, - groups = {dig_immediate=3,flammable=2}, - sounds = default.node_sound_defaults(), + groups = {dig_immediate=3, flammable=2}, -- Gruppen, zu denen der Setzling gehört + sounds = default.node_sound_defaults(), -- Klangeffekte für den Setzling }) +-- Registriere die Banana Leaves (Banana-Blätter) minetest.register_node("farming_plus:banana_leaves", { drawtype = "allfaces_optional", - tiles = {"farming_banana_leaves.png"}, + tiles = {"farming_banana_leaves.png"}, -- Textur für die Banana-Blätter paramtype = "light", - groups = {snappy=3, leafdecay=3, flammable=2, not_in_creative_inventory=1}, - drop = { + groups = {snappy=3, leafdecay=3, flammable=2, not_in_creative_inventory=1}, -- Gruppen für die Banana-Blätter + drop = { max_items = 1, items = { { @@ -32,9 +44,10 @@ minetest.register_node("farming_plus:banana_leaves", { }, } }, - sounds = default.node_sound_leaves_defaults(), + sounds = default.node_sound_leaves_defaults(), -- Klangeffekte für die Banana-Blätter }) +-- Registriere einen ABM (Automatic Block Modifier) für das Wachstum der Banana-Bäume minetest.register_abm({ nodenames = {"farming_plus:banana_sapling"}, interval = 60, @@ -44,6 +57,7 @@ minetest.register_abm({ end }) +-- Registriere eine Funktion, die auf der Generierung der Welt basiert und zufällig Banana-Bäume erzeugt minetest.register_on_generated(function(minp, maxp, blockseed) if math.random(1, 100) > 5 then return @@ -55,17 +69,19 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end end) +-- Registriere die Banana (Banane) als Node minetest.register_node("farming_plus:banana", { - description = S("Banana"), - tiles = {"farming_banana.png"}, - inventory_image = "farming_banana.png", - wield_image = "farming_banana.png", + description = S("Banana"), -- Beschreibung der Banane + tiles = {"farming_banana.png"}, -- Textur für die Banane + inventory_image = "farming_banana.png", -- Bild für die Banane im Inventar + wield_image = "farming_banana.png", -- Bild für die Banane beim Halten drawtype = "torchlike", paramtype = "light", sunlight_propagates = true, walkable = false, - groups = {fleshy=3,dig_immediate=3,flammable=2,leafdecay=3,leafdecay_drop=1}, - sounds = default.node_sound_defaults(), - + groups = {fleshy=3, dig_immediate=3, flammable=2, leafdecay=3, leafdecay_drop=1}, -- Gruppen für die Banane + sounds = default.node_sound_defaults(), -- Klangeffekte für die Banane + + -- Funktion für den Verzehr der Banane on_use = minetest.item_eat(6), }) diff --git a/carrots.lua b/carrots.lua index 7f55644..b8dbecf 100644 --- a/carrots.lua +++ b/carrots.lua @@ -1,21 +1,33 @@ --- main `S` code in init.lua +-- Hauptcode für 'S' in init.lua local S -S = farming.S +-- Überprüfe, ob die Variablen 'farming' und 'farming.S' existieren +if farming and farming.S then + -- Wenn sie existieren, weise 'farming.S' der Variable 'S' zu + S = farming.S +else + -- Wenn nicht, erstelle eine Dummy-Funktion für 'S' + S = function (s) return s end + -- Gib eine Warnmeldung aus + print("Warnung: farming.S ist nil, es wird stattdessen eine Dummy-Funktion verwendet.") +end + +-- Registriere das Saatgut für Karotten minetest.register_craftitem("farming_plus:carrot_seed", { - description = S("Carrot Seeds"), - inventory_image = "farming_carrot_seed.png", + description = S("Carrot Seeds"), -- Beschreibung des Saatguts + inventory_image = "farming_carrot_seed.png", -- Bild für das Saatgut im Inventar on_place = function(itemstack, placer, pointed_thing) return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:carrot_1") end }) +-- Registriere die erste Phase der Karottenpflanze minetest.register_node("farming_plus:carrot_1", { paramtype = "light", walkable = false, drawtype = "plantlike", drop = "", - tiles = {"farming_carrot_1.png"}, + tiles = {"farming_carrot_1.png"}, -- Textur für die erste Phase selection_box = { type = "fixed", fixed = { @@ -23,15 +35,16 @@ minetest.register_node("farming_plus:carrot_1", { }, }, groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + sounds = default.node_sound_leaves_defaults(), -- Klangeffekte für die Pflanze }) +-- Registriere die zweite Phase der Karottenpflanze minetest.register_node("farming_plus:carrot_2", { paramtype = "light", walkable = false, drawtype = "plantlike", drop = "", - tiles = {"farming_carrot_2.png"}, + tiles = {"farming_carrot_2.png"}, -- Textur für die zweite Phase selection_box = { type = "fixed", fixed = { @@ -39,15 +52,16 @@ minetest.register_node("farming_plus:carrot_2", { }, }, groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + sounds = default.node_sound_leaves_defaults(), -- Klangeffekte für die Pflanze }) +-- Registriere die dritte Phase der Karottenpflanze minetest.register_node("farming_plus:carrot_3", { paramtype = "light", walkable = false, drawtype = "plantlike", drop = "", - tiles = {"farming_carrot_3.png"}, + tiles = {"farming_carrot_3.png"}, -- Textur für die dritte Phase selection_box = { type = "fixed", fixed = { @@ -55,14 +69,15 @@ minetest.register_node("farming_plus:carrot_3", { }, }, groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + sounds = default.node_sound_leaves_defaults(), -- Klangeffekte für die Pflanze }) +-- Registriere die reife Karottenpflanze minetest.register_node("farming_plus:carrot", { paramtype = "light", walkable = false, drawtype = "plantlike", - tiles = {"farming_carrot_4.png"}, + tiles = {"farming_carrot_4.png"}, -- Textur für reife Karotten drop = { max_items = 6, items = { @@ -75,13 +90,15 @@ minetest.register_node("farming_plus:carrot", { } }, groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + sounds = default.node_sound_leaves_defaults(), -- Klangeffekte für die Pflanze }) +-- Registriere die Karotten als Handwerksgegenstand minetest.register_craftitem("farming_plus:carrot_item", { - description = S("Carrot"), - inventory_image = "farming_carrot.png", - on_use = minetest.item_eat(3), + description = S("Carrot"), -- Beschreibung der Karotte + inventory_image = "farming_carrot.png", -- Bild für die Karotte im Inventar + on_use = minetest.item_eat(3), -- Essen der Karotte gibt 3 Lebenspunkte zurück }) +-- Füge die Karottenpflanze zur Liste der anbaubaren Pflanzen hinzu farming.add_plant("farming_plus:carrot", {"farming_plus:carrot_1", "farming_plus:carrot_2", "farming_plus:carrot_3"}, 50, 20) diff --git a/cocoa.lua b/cocoa.lua index 42a7705..5f30421 100644 --- a/cocoa.lua +++ b/cocoa.lua @@ -1,26 +1,38 @@ --- main `S` code in init.lua +-- Hauptcode für 'S' in init.lua local S -S = farming.S +-- Überprüfe, ob die Variablen 'farming' und 'farming.S' existieren +if farming and farming.S then + -- Wenn sie existieren, weise 'farming.S' der Variable 'S' zu + S = farming.S +else + -- Wenn nicht, erstelle eine Dummy-Funktion für 'S' + S = function (s) return s end + -- Gib eine Warnmeldung aus + print("Warnung: farming.S ist nil, es wird stattdessen eine Dummy-Funktion verwendet.") +end + +-- Registriere den Baumsetzling für den Kakaobaum minetest.register_node("farming_plus:cocoa_sapling", { - description = S("Cocoa Tree Sapling"), + description = S("Cocoa Tree Sapling"), -- Beschreibung des Setzlings drawtype = "plantlike", - tiles = {"farming_cocoa_sapling.png"}, - inventory_image = "farming_cocoa_sapling.png", - wield_image = "farming_cocoa_sapling.png", + tiles = {"farming_cocoa_sapling.png"}, -- Textur des Setzlings + inventory_image = "farming_cocoa_sapling.png", -- Bild für den Setzling im Inventar + wield_image = "farming_cocoa_sapling.png", -- Bild für den Setzling beim Halten paramtype = "light", walkable = false, selection_box = { type = "fixed", - fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} + fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} -- Auswahlbox für den Setzling }, - groups = {dig_immediate=3,flammable=2}, - sounds = default.node_sound_defaults(), + groups = {dig_immediate=3, flammable=2}, -- Gruppeneinstellungen für den Setzling + sounds = default.node_sound_defaults(), -- Klangeffekte für den Setzling }) +-- Registriere die Kakaoblätter minetest.register_node("farming_plus:cocoa_leaves", { drawtype = "allfaces_optional", - tiles = {"farming_banana_leaves.png"}, + tiles = {"farming_banana_leaves.png"}, -- Textur der Blätter paramtype = "light", groups = {snappy=3, leafdecay=3, flammable=2, not_in_creative_inventory=1}, drop = { @@ -32,9 +44,10 @@ minetest.register_node("farming_plus:cocoa_leaves", { }, } }, - sounds = default.node_sound_leaves_defaults(), + sounds = default.node_sound_leaves_defaults(), -- Klangeffekte für die Blätter }) +-- Registriere das Wachstum des Kakaobaums minetest.register_abm({ nodenames = {"farming_plus:cocoa_sapling"}, interval = 60, @@ -44,6 +57,7 @@ minetest.register_abm({ end }) +-- Registriere das Erscheinen von Kakaobäumen in der Welt minetest.register_on_generated(function(minp, maxp, blockseed) if math.random(1, 100) > 5 then return @@ -55,27 +69,30 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end end) +-- Registriere den Kakaobaum selbst minetest.register_node("farming_plus:cocoa", { - description = S("Cocoa"), - tiles = {"farming_cocoa.png"}, + description = S("Cocoa"), -- Beschreibung des Baums + tiles = {"farming_cocoa.png"}, -- Textur des Baums visual_scale = 0.5, - inventory_image = "farming_cocoa.png", - wield_image = "farming_cocoa.png", + inventory_image = "farming_cocoa.png", -- Bild für den Baum im Inventar + wield_image = "farming_cocoa.png", -- Bild für den Baum beim Halten drawtype = "torchlike", paramtype = "light", sunlight_propagates = true, walkable = false, - groups = {fleshy=3,dig_immediate=3,flammable=2,leafdecay=3,leafdecay_drop=1}, - sounds = default.node_sound_defaults(), + groups = {fleshy=3, dig_immediate=3, flammable=2, leafdecay=3, leafdecay_drop=1}, -- Gruppeneinstellungen für den Baum + sounds = default.node_sound_defaults(), -- Klangeffekte für den Baum }) +-- Registriere die Kakaobohne als Handwerksgegenstand minetest.register_craftitem("farming_plus:cocoa_bean", { - description = "Cocoa Bean", - inventory_image = "farming_cocoa_bean.png", + description = "Cocoa Bean", -- Beschreibung der Bohne + inventory_image = "farming_cocoa_bean.png", -- Bild für die Bohne im Inventar }) +-- Registriere das Handwerksrezept für Kakaobohnen minetest.register_craft({ - output = "farming_plus:cocoa_bean 10", + output = "farming_plus:cocoa_bean 10", -- Ausgabe und Menge der Bohnen type = "shapeless", - recipe = {"farming_plus:cocoa"}, + recipe = {"farming_plus:cocoa"}, -- Rezept: Ein Kakaobaum wird zu Bohnen verarbeitet }) diff --git a/init.lua b/init.lua index 4f949e7..e055882 100644 --- a/init.lua +++ b/init.lua @@ -8,6 +8,7 @@ else farming.S = function ( s ) return s end end +--adds a function for adding a plant to the game function farming.add_plant(full_grown, names, interval, chance) minetest.register_abm({ nodenames = names, @@ -51,6 +52,7 @@ function farming.add_plant(full_grown, names, interval, chance) }) end +--adds a function for generating a Tree function farming.generate_tree(pos, trunk, leaves, underground, replacements) pos.y = pos.y-1 local nodename = minetest.get_node(pos).name @@ -145,6 +147,7 @@ function farming.generate_tree(pos, trunk, leaves, underground, replacements) end end +--Tabelle named `farming.seeds`, to save all seed types and there data. farming.seeds = { ["farming:pumpkin_seed"]=60, ["farming_plus:strawberry_seed"]=30, @@ -210,6 +213,8 @@ minetest.register_on_generated(function(minp, maxp, seed) end end) +--adds the function to set seeds on a node + function farming.place_seed(itemstack, placer, pointed_thing, plantname) -- Call on_rightclick if the pointed node defines it @@ -280,6 +285,7 @@ for lvl = 1, 6, 1 do }) end +-- registering of the aliases. minetest.register_alias("farming:cotton", "farming:cotton_3") minetest.register_alias("farming:wheat_harvested", "farming:wheat") diff --git a/oranges.lua b/oranges.lua index 685ebb3..4c21f3f 100644 --- a/oranges.lua +++ b/oranges.lua @@ -1,31 +1,46 @@ --- main `S` code in init.lua +-- Hauptcode für 'S' in init.lua local S -S = farming.S +-- Überprüfe, ob die Variablen 'farming' und 'farming.S' existieren +if farming and farming.S then + -- Wenn sie existieren, weise 'farming.S' der Variable 'S' zu + S = farming.S +else + -- Wenn nicht, erstelle eine Dummy-Funktion für 'S' + S = function (s) return s end + -- Gib eine Warnmeldung aus + print("Warnung: farming.S ist nil, es wird stattdessen eine Dummy-Funktion verwendet.") +end + +-- Registriere einen Handwerksgegenstand für Orangensamen minetest.register_craftitem("farming_plus:orange_seed", { - description = S("Orange Seeds"), - inventory_image = "farming_orange_seed.png", + description = S("Orange Seeds"), -- Beschreibung des Gegenstands + inventory_image = "farming_orange_seed.png", -- Bild für den Gegenstand im Inventar on_place = function(itemstack, placer, pointed_thing) return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:orange_1") + -- Die Funktion 'farming.place_seed' wird aufgerufen, um die Samen zu pflanzen. + -- Sie gibt ein aktualisiertes 'itemstack' zurück. end }) +-- Registriere die erste Entwicklungsstufe des Orangenbaums minetest.register_node("farming_plus:orange_1", { paramtype = "light", walkable = false, drawtype = "plantlike", drop = "", - tiles = {"farming_orange_1.png"}, + tiles = {"farming_orange_1.png"}, -- Textur für die Pflanze selection_box = { type = "fixed", fixed = { - {-0.5, -0.5, -0.5, 0.5, -0.5+3/16, 0.5} + {-0.5, -0.5, -0.5, 0.5, -0.5+3/16, 0.5} -- Auswahlbox für die Pflanze }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1, plant=1}, -- Gruppeneinstellungen für die Pflanze + sounds = default.node_sound_leaves_defaults(), -- Klangeffekte für die Pflanze }) +-- Registriere die zweite Entwicklungsstufe des Orangenbaums (ähnlich wie oben) minetest.register_node("farming_plus:orange_2", { paramtype = "light", walkable = false, @@ -38,10 +53,11 @@ minetest.register_node("farming_plus:orange_2", { {-0.5, -0.5, -0.5, 0.5, -0.5+8/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, + groups = {snappy=3, flammable=2, not_in_creative_inventory=1, plant=1}, sounds = default.node_sound_leaves_defaults(), }) +-- Registriere die dritte Entwicklungsstufe des Orangenbaums (ähnlich wie oben) minetest.register_node("farming_plus:orange_3", { paramtype = "light", walkable = false, @@ -54,10 +70,11 @@ minetest.register_node("farming_plus:orange_3", { {-0.5, -0.5, -0.5, 0.5, -0.5+14/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, + groups = {snappy=3, flammable=2, not_in_creative_inventory=1, plant=1}, sounds = default.node_sound_leaves_defaults(), }) +-- Registriere den ausgewachsenen Orangenbaum (ähnlich wie oben) minetest.register_node("farming_plus:orange", { paramtype = "light", walkable = false, @@ -74,14 +91,16 @@ minetest.register_node("farming_plus:orange", { { items = {'farming_plus:orange_item'}, rarity = 5 } } }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, + groups = {snappy=3, flammable=2, not_in_creative_inventory=1, plant=1}, sounds = default.node_sound_leaves_defaults(), }) +-- Registriere den Orangen-Gegenstand minetest.register_craftitem("farming_plus:orange_item", { - description = S("Orange"), - inventory_image = "farming_orange.png", - on_use = minetest.item_eat(4), + description = S("Orange"), -- Beschreibung des Gegenstands + inventory_image = "farming_orange.png", -- Bild für den Gegenstand im Inventar + on_use = minetest.item_eat(4), -- Funktion für den Verzehr des Gegenstands }) +-- Füge den Orangenbaum zur Farming-Mod hinzu farming.add_plant("farming_plus:orange", {"farming_plus:orange_1", "farming_plus:orange_2", "farming_plus:orange_3"}, 50, 20) diff --git a/potatoes.lua b/potatoes.lua index 794c021..686a23e 100644 --- a/potatoes.lua +++ b/potatoes.lua @@ -1,31 +1,46 @@ -- main `S` code in init.lua local S -S = farming.S +-- Check if the 'farming' and 'farming.S' variables exist +if farming and farming.S then + -- If they exist, assign 'farming.S' to 'S' + S = farming.S +else + -- If not, create a dummy function for 'S' + S = function (s) return s end + -- Print a warning message + print("Warning: farming.S is nil, using a dummy function instead.") +end + +-- Registrierung eines Handwerksgegenstands für Kartoffelsamen minetest.register_craftitem("farming_plus:potato_seed", { - description = ("Potato Seeds"), - inventory_image = "farming_potato_seed.png", + description = ("Potato Seeds"), -- Beschreibung des Gegenstands + inventory_image = "farming_potato_seed.png", -- Bild für den Gegenstand im Inventar on_place = function(itemstack, placer, pointed_thing) return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:potato_1") + -- Die Funktion 'farming.place_seed' wird aufgerufen, um die Samen zu pflanzen. + -- Sie gibt ein aktualisiertes 'itemstack' zurück. end }) +-- Registrierung der ersten Entwicklungsstufe der Kartoffelpflanze minetest.register_node("farming_plus:potato_1", { paramtype = "light", walkable = false, drawtype = "plantlike", drop = "", - tiles = {"farming_potato_1.png"}, + tiles = {"farming_potato_1.png"}, -- Textur für die Pflanze selection_box = { type = "fixed", fixed = { - {-0.5, -0.5, -0.5, 0.5, -0.5+6/16, 0.5} + {-0.5, -0.5, -0.5, 0.5, -0.5+6/16, 0.5} -- Auswahlbox für die Pflanze }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1, plant=1}, -- Gruppeneinstellungen für die Pflanze + sounds = default.node_sound_leaves_defaults(), -- Klangeffekte für die Pflanze }) +-- Registrierung der zweiten Entwicklungsstufe der Kartoffelpflanze (ähnlich wie oben) minetest.register_node("farming_plus:potato_2", { paramtype = "light", walkable = false, @@ -38,10 +53,11 @@ minetest.register_node("farming_plus:potato_2", { {-0.5, -0.5, -0.5, 0.5, -0.5+9/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, + groups = {snappy=3, flammable=2, not_in_creative_inventory=1, plant=1}, sounds = default.node_sound_leaves_defaults(), }) +-- Registrierung der ausgewachsenen Kartoffelpflanze (ähnlich wie oben) minetest.register_node("farming_plus:potato", { paramtype = "light", walkable = false, @@ -58,20 +74,22 @@ minetest.register_node("farming_plus:potato", { { items = {'farming_plus:potato_item'}, rarity = 5 } } }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, + groups = {snappy=3, flammable=2, not_in_creative_inventory=1, plant=1}, sounds = default.node_sound_leaves_defaults(), }) +-- Registrierung des Kartoffel-Gegenstands minetest.register_craftitem("farming_plus:potato_item", { - description = S("Potato"), - inventory_image = "farming_potato.png", + description = S("Potato"), -- Beschreibung des Gegenstands + inventory_image = "farming_potato.png", -- Bild für den Gegenstand im Inventar }) +-- Hinzufügen der Kartoffelpflanze zum Farming-Mod farming.add_plant("farming_plus:potato", {"farming_plus:potato_1", "farming_plus:potato_2"}, 50, 20) +-- Alias-Registrierungen für verschiedene Namen der Kartoffelpflanze minetest.register_alias("farming_plus:potatoe_item", "farming_plus:potato_item") minetest.register_alias("farming_plus:potatoe_seed", "farming_plus:potato_seed") minetest.register_alias("farming_plus:potatoe", "farming_plus:potato") minetest.register_alias("farming_plus:potatoe_1", "farming_plus:potato_1") minetest.register_alias("farming_plus:potatoe_2", "farming_plus:potato_2") - diff --git a/pumpkin.lua b/pumpkin.lua index 4a68b99..d1d2b9f 100644 --- a/pumpkin.lua +++ b/pumpkin.lua @@ -1,279 +1,307 @@ -- main `S` code in init.lua local S -S = farming.S +-- Check if the 'farming' and 'farming.S' variables exist +if farming and farming.S then + -- If they exist, assign 'farming.S' to 'S' + S = farming.S +else + -- If not, create a dummy function for 'S' + S = function (s) return s end + -- Print a warning message + print("Warning: farming.S is nil, using a dummy function instead.") +end +-- Register a craftitem for pumpkin seeds minetest.register_craftitem(":farming:pumpkin_seed", { - description = S("Pumpkin Seed"), - inventory_image = "farming_pumpkin_seed.png", - on_place = function(itemstack, placer, pointed_thing) - return farming.place_seed(itemstack, placer, pointed_thing, "farming:pumpkin_1") - end + description = S("Pumpkin Seed"), -- Localized description using 'S' + inventory_image = "farming_pumpkin_seed.png", + on_place = function(itemstack, placer, pointed_thing) + -- Call the 'farming.place_seed' function + return farming.place_seed(itemstack, placer, pointed_thing, "farming:pumpkin_1") + end }) +-- Register the first stage of the pumpkin plant minetest.register_node(":farming:pumpkin_1", { - paramtype = "light", - sunlight_propagates = true, - drawtype = "nodebox", - drop = "", - tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png"}, - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} - }, - }, - groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2, not_in_creative_inventory=1, plant=1}, - sounds = default.node_sound_wood_defaults(), + paramtype = "light", + sunlight_propagates = true, + drawtype = "nodebox", + drop = "", + tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png"}, + node_box = { + type = "fixed", + fixed = { + {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} + }, + }, + groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2, not_in_creative_inventory=1, plant=1}, + sounds = default.node_sound_wood_defaults(), }) +-- Register the second stage of the pumpkin plant minetest.register_node(":farming:pumpkin_2", { - paramtype = "light", - sunlight_propagates = true, - drawtype = "nodebox", - drop = "", - tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png"}, - node_box = { - type = "fixed", - fixed = { - {-0.35, -0.5, -0.35, 0.35, 0.2, 0.35} - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.35, -0.5, -0.35, 0.35, 0.2, 0.35} - }, - }, - groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2, not_in_creative_inventory=1, plant=1}, - sounds = default.node_sound_wood_defaults(), + paramtype = "light", + sunlight_propagates = true, + drawtype = "nodebox", + drop = "", + tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png"}, + node_box = { + type = "fixed", + fixed = { + {-0.35, -0.5, -0.35, 0.35, 0.2, 0.35} + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.35, -0.5, -0.35, 0.35, 0.2, 0.35} + }, + }, + groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2, not_in_creative_inventory=1, plant=1}, + sounds = default.node_sound_wood_defaults(), }) +-- Register the fully grown pumpkin plant minetest.register_node(":farming:pumpkin", { - description = S("Pumpkin"), - paramtype2 = "facedir", - tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png"}, - groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2, plant=1}, - sounds = default.node_sound_wood_defaults(), - - on_punch = function(pos, node, puncher) - local tool = puncher:get_wielded_item():get_name() - if tool and string.match(tool, "sword") then - node.name = "farming:pumpkin_face" - minetest.set_node(pos, node) - puncher:get_inventory():add_item("main", ItemStack("farming:pumpkin_seed")) - if math.random(1, 5) == 1 then - puncher:get_inventory():add_item("main", ItemStack("farming:pumpkin_seed")) - end - end - end + description = S("Pumpkin"), -- Localized description using 'S' + paramtype2 = "facedir", + tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png"}, + groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2, plant=1}, + sounds = default.node_sound_wood_defaults(), + + on_punch = function(pos, node, puncher) + local tool = puncher:get_wielded_item():get_name() + if tool and string.match(tool, "sword") then + node.name = "farming:pumpkin_face" + minetest.set_node(pos, node) + puncher:get_inventory():add_item("main", ItemStack("farming:pumpkin_seed")) + if math.random(1, 5) == 1 then + puncher:get_inventory():add_item("main", ItemStack("farming:pumpkin_seed")) + end + end + end }) +-- Add the pumpkin plant to farming mod farming.add_plant("farming:pumpkin", {"farming:pumpkin_1", "farming:pumpkin_2"}, 80, 20) +-- Register a node for a carved pumpkin face minetest.register_node(":farming:pumpkin_face", { - description = S("Pumpkin Face"), - paramtype2 = "facedir", - tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_face.png"}, - groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2, plant=1}, - sounds = default.node_sound_wood_defaults(), + description = S("Pumpkin Face"), -- Localized description using 'S' + paramtype2 = "facedir", + tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_face.png"}, + groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2, plant=1}, + sounds = default.node_sound_wood_defaults(), }) +-- Register a node for a carved pumpkin face with light minetest.register_node(":farming:pumpkin_face_light", { - description = S("Pumpkin Face With Light"), - paramtype2 = "facedir", - light_source = LIGHT_MAX-2, - tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_face_light.png"}, - groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2}, - sounds = default.node_sound_wood_defaults(), + description = S("Pumpkin Face With Light"), -- Localized description using 'S' + paramtype2 = "facedir", + light_source = LIGHT_MAX-2, + tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_face_light.png"}, + groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2}, + sounds = default.node_sound_wood_defaults(), }) +-- Register a craft recipe to combine a carved pumpkin face with a torch minetest.register_craft({ - type = "shapeless", - output = "farming:pumpkin_face_light", - recipe = {"farming:pumpkin_face", "default:torch"} + type = "shapeless", + output = "farming:pumpkin_face_light", + recipe = {"farming:pumpkin_face", "default:torch"} }) --- ========= BIG PUMPKIN ========= +-- Register a node for a big pumpkin minetest.register_node(":farming:big_pumpkin", { - description = S("Big Pumpkin"), - paramtype2 = "facedir", - tiles = {"farming_pumpkin_big_side.png"}, - selection_box = { - type = "fixed", - fixed = { - {-1, -0.5, -1, 1, 1.5, 1} - } - }, - groups = {choppy=1, oddly_breakable_by_hand=1, flammable=2}, - sounds = default.node_sound_wood_defaults(), - - after_place_node = function(pos, placer) - for dx=-1,1 do - for dy=0,1 do - for dz=-1,1 do - pos.x = pos.x+dx - pos.y = pos.y+dy - pos.z = pos.z+dz - if dx ~= 0 or dy ~= 0 or dz ~= 0 then - if minetest.get_node(pos).name ~= "air" then - pos.x = pos.x-dx - pos.y = pos.y-dy - pos.z = pos.z-dz - minetest.remove_node(pos) - minetest.after(0.1, function(placer) - local inv = placer:get_inventory() - local index = placer:get_wield_index() - inv:set_stack("main", index, ItemStack("farming:big_pumpkin")) - end, placer) - return - end - end - pos.x = pos.x-dx - pos.y = pos.y-dy - pos.z = pos.z-dz - end - end - end - for dy=0,1 do - pos.y = pos.y+dy - pos.z = pos.z+1 - minetest.set_node(pos, {name="farming:big_pumpkin_side", param2=2}) - pos.x = pos.x-1 - minetest.set_node(pos, {name="farming:big_pumpkin_corner", param2=2}) - pos.x = pos.x+1 - pos.z = pos.z-2 - minetest.set_node(pos, {name="farming:big_pumpkin_side", param2=4}) - pos.x = pos.x+1 - minetest.set_node(pos, {name="farming:big_pumpkin_corner", param2=4}) - pos.z = pos.z+1 - minetest.set_node(pos, {name="farming:big_pumpkin_side", param2=3}) - pos.z = pos.z+1 - minetest.set_node(pos, {name="farming:big_pumpkin_corner", param2=3}) - pos.z = pos.z-1 - pos.x = pos.x-2 - minetest.set_node(pos, {name="farming:big_pumpkin_side", param2=1}) - pos.z = pos.z-1 - minetest.set_node(pos, {name="farming:big_pumpkin_corner", param2=1}) - pos.z = pos.z+1 - pos.x = pos.x+1 - pos.y = pos.y-dy - end - pos.y = pos.y+1 - minetest.set_node(pos, {name="farming:big_pumpkin_top"}) - end, - - after_destruct = function(pos, oldnode) - for dx=-1,1 do - for dy=0,1 do - for dz=-1,1 do - pos.x = pos.x+dx - pos.y = pos.y+dy - pos.z = pos.z+dz - local name = minetest.get_node(pos).name - if string.find(name, "farming:big_pumpkin") then - minetest.remove_node(pos) - end - pos.x = pos.x-dx - pos.y = pos.y-dy - pos.z = pos.z-dz - end - end - end - end + description = S("Big Pumpkin"), -- Localized description using 'S' + paramtype2 = "facedir", + tiles = {"farming_pumpkin_big_side.png"}, + selection_box = { + type = "fixed", + fixed = { + {-1, -0.5, -1, 1, 1.5, 1} + } + }, + groups = {choppy=1, oddly_breakable_by_hand=1, flammable=2}, + sounds = default.node_sound_wood_defaults(), + + -- Function to run after placing a big pumpkin + after_place_node = function(pos, placer) + -- Iterate through surrounding blocks + for dx=-1,1 do + for dy=0,1 do + for dz=-1,1 do + pos.x = pos.x+dx + pos.y = pos.y+dy + pos.z = pos.z+dz + if dx ~= 0 or dy ~= 0 or dz ~= 0 then + if minetest.get_node(pos).name ~= "air" then + pos.x = pos.x-dx + pos.y = pos.y-dy + pos.z = pos.z-dz + -- Remove the big pumpkin if there's an obstruction + minetest.remove_node(pos) + minetest.after(0.1, function(placer) + local inv = placer:get_inventory() + local index = placer:get_wield_index() + inv:set_stack("main", index, ItemStack("farming:big_pumpkin")) + end, placer) + return + end + end + pos.x = pos.x-dx + pos.y = pos.y-dy + pos.z = pos.z-dz + end + end + end + -- Create the structure of the big pumpkin + for dy=0,1 do + pos.y = pos.y+dy + pos.z = pos.z+1 + minetest.set_node(pos, {name="farming:big_pumpkin_side", param2=2}) + pos.x = pos.x-1 + minetest.set_node(pos, {name="farming:big_pumpkin_corner", param2=2}) + pos.x = pos.x+1 + pos.z = pos.z-2 + minetest.set_node(pos, {name="farming:big_pumpkin_side", param2=4}) + pos.x = pos.x+1 + minetest.set_node(pos, {name="farming:big_pumpkin_corner", param2=4}) + pos.z = pos.z+1 + minetest.set_node(pos, {name="farming:big_pumpkin_side", param2=3}) + pos.z = pos.z+1 + minetest.set_node(pos, {name="farming:big_pumpkin_corner", param2=3}) + pos.z = pos.z-1 + pos.x = pos.x-2 + minetest.set_node(pos, {name="farming:big_pumpkin_side", param2=1}) + pos.z = pos.z-1 + minetest.set_node(pos, {name="farming:big_pumpkin_corner", param2=1}) + pos.z = pos.z+1 + pos.x = pos.x+1 + pos.y = pos.y-dy + end + pos.y = pos.y+1 + minetest.set_node(pos, {name="farming:big_pumpkin_top"}) + end, + + -- Function to run after destructing a big pumpkin + after_destruct = function(pos, oldnode) + -- Iterate through surrounding blocks + for dx=-1,1 do + for dy=0,1 do + for dz=-1,1 do + pos.x = pos.x+dx + pos.y = pos.y+dy + pos.z = pos.z+dz + local name = minetest.get_node(pos).name + -- Remove any big pumpkin-related nodes + if string.find(name, "farming:big_pumpkin") then + minetest.remove_node(pos) + end + pos.x = pos.x-dx + pos.y = pos.y-dy + pos.z = pos.z-dz + end + end + end + end }) +-- Register nodes for the sides and corners of a big pumpkin minetest.register_node(":farming:big_pumpkin_side", { - paramtype = "light", - sunlight_propagates = true, - paramtype2 = "facedir", - tiles = {"farming_pumpkin_big_top_side.png", "farming_pumpkin_big_side.png"}, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, 0, 0.5, 0.5, 0.5} - } - }, - selection_box = { - type = "fixed", - fixed = { - {0, 0, 0, 0, 0, 0} - } - }, - groups = {not_in_creative_inventory=1}, + paramtype = "light", + sunlight_propagates = true, + paramtype2 = "facedir", + tiles = {"farming_pumpkin_big_top_side.png", "farming_pumpkin_big_side.png"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, 0, 0.5, 0.5, 0.5} + } + }, + selection_box = { + type = "fixed", + fixed = { + {0, 0, 0, 0, 0, 0} + } + }, + groups = {not_in_creative_inventory=1}, }) + minetest.register_node(":farming:big_pumpkin_corner", { - paramtype = "light", - sunlight_propagates = true, - paramtype2 = "facedir", - tiles = {"farming_pumpkin_big_top_corner.png", "farming_pumpkin_big_side.png"}, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, 0, 0, 0.5, 0.5} - } - }, - selection_box = { - type = "fixed", - fixed = { - {0, 0, 0, 0, 0, 0} - } - }, - groups = {not_in_creative_inventory=1}, + paramtype = "light", + sunlight_propagates = true, + paramtype2 = "facedir", + tiles = {"farming_pumpkin_big_top_corner.png", "farming_pumpkin_big_side.png"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, 0, 0, 0.5, 0.5} + } + }, + selection_box = { + type = "fixed", + fixed = { + {0, 0, 0, 0, 0, 0} + } + }, + groups = {not_in_creative_inventory=1}, }) minetest.register_node(":farming:big_pumpkin_top", { - paramtype = "light", - sunlight_propagates = true, - tiles = {"farming_pumpkin_big_top.png"}, - selection_box = { - type = "fixed", - fixed = { - {0, 0, 0, 0, 0, 0} - } - }, - groups = {not_in_creative_inventory=1}, + paramtype = "light", + sunlight_propagates = true, + tiles = {"farming_pumpkin_big_top.png"}, + selection_box = { + type = "fixed", + fixed = { + {0, 0, 0, 0, 0, 0} + } + }, + groups = {not_in_creative_inventory=1}, }) +-- Register a craft recipe to obtain a big pumpkin from a bucket of water and a pumpkin minetest.register_craft({ - type = "shapeless", - output = "farming:big_pumpkin", - recipe = {"bucket:bucket_water", "farming:pumpkin"}, - replacements = { - {"bucket:bucket_water", "bucket:bucket_empty"} - } + type = "shapeless", + output = "farming:big_pumpkin", + recipe = {"bucket:bucket_water", "farming:pumpkin"}, + replacements = { + {"bucket:bucket_water", "bucket:bucket_empty"} + } }) --- ========= SCARECROW ========= +-- Register a scarecrow node local box1 = { - {-1, -8, -1, 1, 8, 1}, + {-1, -8, -1, 1, 8, 1}, } local box2 = { - {-1, -8, -1, 1, 8, 1}, - {-12, -8, -1, 12, -7, 1}, - {-5, -2, -5, 5, 8, 5} + {-1, -8, -1, 1, 8, 1}, + {-12, -8, -1, 12, -7, 1}, + {-5, -2, -5, 5, 8, 5} } for j,list in ipairs(box1) do - for i,int in ipairs(list) do - list[i] = int/16 - end - box1[j] = list + for i,int in ipairs(list) do + list[i] = int/16 + end + box1[j] = list end for j,list in ipairs(box2) do - for i,int in ipairs(list) do - list[i] = int/16 - end - box2[j] = list + for i,int in ipairs(list) do + list[i] = int/16 + end + box2[j] = list end minetest.register_node(":farming:scarecrow", { @@ -294,7 +322,7 @@ minetest.register_node(":farming:scarecrow", { } }, groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2}, - + after_place_node = function(pos, placer) local node = minetest.get_node(pos) local param2 = node.param2 @@ -314,7 +342,7 @@ minetest.register_node(":farming:scarecrow", { node.name = "farming:scarecrow_bottom" minetest.set_node(pos, node) end, - + after_destruct = function(pos, oldnode) pos.y = pos.y-1 if minetest.get_node(pos).name == "farming:scarecrow_bottom" then @@ -370,7 +398,7 @@ minetest.register_node(":farming:scarecrow_light", { } }, groups = {choppy=2, oddly_breakable_by_hand=2, flammable=2}, - + after_place_node = function(pos, placer) local node = minetest.get_node(pos) local param2 = node.param2 @@ -390,7 +418,7 @@ minetest.register_node(":farming:scarecrow_light", { node.name = "farming:scarecrow_bottom" minetest.set_node(pos, node) end, - + after_destruct = function(pos, oldnode) pos.y = pos.y-1 if minetest.get_node(pos).name == "farming:scarecrow_bottom" then diff --git a/rhubarb.lua b/rhubarb.lua index 43c5baa..e7801e8 100644 --- a/rhubarb.lua +++ b/rhubarb.lua @@ -1,54 +1,62 @@ -- main `S` code in init.lua -local S -S = farming.S +local S -- Declare a local variable named `S` +if farming.S then -- Check if `farming.S` is not nil + S = farming.S -- Assign the value of `farming.S` to the local variable `S` +else + print("Error: farming.S is nil") -- Print an error message if `farming.S` is nil +end +-- Register a craftitem for rhubarb seeds minetest.register_craftitem("farming_plus:rhubarb_seed", { - description = S("Rhubarb Seeds"), - inventory_image = "farming_rhubarb_seed.png", - on_place = function(itemstack, placer, pointed_thing) - return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:rhubarb_1") + description = S("Rhubarb Seeds"), -- Description for the item + inventory_image = "farming_rhubarb_seed.png", -- Image for the item in inventory + on_place = function(itemstack, placer, pointed_thing) -- Function to execute when item is placed + return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:rhubarb_1") -- Place the seed and return the modified itemstack end }) +-- Register a node for the first stage of rhubarb growth minetest.register_node("farming_plus:rhubarb_1", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - drop = "", - tiles = {"farming_rhubarb_1.png"}, - selection_box = { + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + drop = "", -- No items are dropped when node is dug + tiles = {"farming_rhubarb_1.png"}, -- Texture for the node + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+5/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a node for the second stage of rhubarb growth minetest.register_node("farming_plus:rhubarb_2", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - drop = "", - tiles = {"farming_rhubarb_2.png"}, - selection_box = { + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + drop = "", -- No items are dropped when node is dug + tiles = {"farming_rhubarb_2.png"}, -- Texture for the node + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+11/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a node for the final stage of rhubarb growth minetest.register_node("farming_plus:rhubarb", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - tiles = {"farming_rhubarb_3.png"}, - drop = { - max_items = 6, + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + tiles = {"farming_rhubarb_3.png"}, -- Texture for the node + drop = { -- Items to drop when node is dug + max_items = 6, -- Maximum number of items to drop items = { { items = {'farming_plus:rhubarb_seed'} }, { items = {'farming_plus:rhubarb_seed'}, rarity = 2}, @@ -58,13 +66,15 @@ minetest.register_node("farming_plus:rhubarb", { { items = {'farming_plus:rhubarb_item'}, rarity = 5 } } }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a craftitem for the rhubarb item minetest.register_craftitem("farming_plus:rhubarb_item", { - description = S("Rhubarb"), - inventory_image = "farming_rhubarb.png", + description = S("Rhubarb"), -- Description for the item + inventory_image = "farming_rhubarb.png", -- Image for the item in inventory }) +-- Add the rhubarb plant to the farming module, defining its growth stages and chances of growth farming.add_plant("farming_plus:rhubarb", {"farming_plus:rhubarb_1", "farming_plus:rhubarb_2"}, 50, 20) diff --git a/strawberries.lua b/strawberries.lua index 3c5ef7b..6ce8f8f 100644 --- a/strawberries.lua +++ b/strawberries.lua @@ -1,70 +1,79 @@ -- main `S` code in init.lua -local S -S = farming.S +local S -- Declare a local variable named `S` +if farming.S then -- Check if `farming.S` is not nil + S = farming.S -- Assign the value of `farming.S` to the local variable `S` +else + print("Error: farming.S is nil") -- Print an error message if `farming.S` is nil +end +-- Register a craftitem for strawberry seeds minetest.register_craftitem("farming_plus:strawberry_seed", { - description = S("Strawberry Seeds"), - inventory_image = "farming_strawberry_seed.png", - on_place = function(itemstack, placer, pointed_thing) - return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:strawberry_1") + description = S("Strawberry Seeds"), -- Description for the item + inventory_image = "farming_strawberry_seed.png", -- Image for the item in inventory + on_place = function(itemstack, placer, pointed_thing) -- Function to execute when item is placed + return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:strawberry_1") -- Place the seed and return the modified itemstack end }) +-- Register a node for the first stage of strawberry growth minetest.register_node("farming_plus:strawberry_1", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - drop = "", - tiles = {"farming_strawberry_1.png"}, - selection_box = { + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + drop = "", -- No items are dropped when node is dug + tiles = {"farming_strawberry_1.png"}, -- Texture for the node + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+9/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a node for the second stage of strawberry growth minetest.register_node("farming_plus:strawberry_2", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - drop = "", - tiles = {"farming_strawberry_2.png"}, - selection_box = { + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + drop = "", -- No items are dropped when node is dug + tiles = {"farming_strawberry_2.png"}, -- Texture for the node + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+12/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a node for the third stage of strawberry growth minetest.register_node("farming_plus:strawberry_3", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - drop = "", - tiles = {"farming_strawberry_3.png"}, - selection_box = { + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + drop = "", -- No items are dropped when node is dug + tiles = {"farming_strawberry_3.png"}, -- Texture for the node + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+14/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a node for the final stage of strawberry growth minetest.register_node("farming_plus:strawberry", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - tiles = {"farming_strawberry_4.png"}, - drop = { - max_items = 6, + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + tiles = {"farming_strawberry_4.png"}, -- Texture for the node + drop = { -- Items to drop when node is dug + max_items = 6, -- Maximum number of items to drop items = { { items = {'farming_plus:strawberry_seed'} }, { items = {'farming_plus:strawberry_seed'}, rarity = 2}, @@ -74,14 +83,16 @@ minetest.register_node("farming_plus:strawberry", { { items = {'farming_plus:strawberry_item'}, rarity = 5 } } }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a craftitem for the strawberry item minetest.register_craftitem("farming_plus:strawberry_item", { - description = S("Strawberry"), - inventory_image = "farming_strawberry.png", - on_use = minetest.item_eat(2), + description = S("Strawberry"), -- Description for the item + inventory_image = "farming_strawberry.png", -- Image for the item in inventory + on_use = minetest.item_eat(2), -- Function to execute when item is used }) +-- Add the strawberry plant to the farming module, defining its growth stages and chances of growth farming.add_plant("farming_plus:strawberry", {"farming_plus:strawberry_1", "farming_plus:strawberry_2", "farming_plus:strawberry_3"}, 50, 20) diff --git a/tomatoes.lua b/tomatoes.lua index 5926dcf..523e6b9 100644 --- a/tomatoes.lua +++ b/tomatoes.lua @@ -1,70 +1,79 @@ -- main `S` code in init.lua -local S -S = farming.S +local S -- Declare a local variable named `S` +if farming.S then -- Check if `farming.S` is not nil + S = farming.S -- Assign the value of `farming.S` to the local variable `S` +else + print("Error: farming.S is nil") -- Print an error message if `farming.S` is nil +end +-- Register a craftitem for tomato seeds minetest.register_craftitem("farming_plus:tomato_seed", { - description = S("Tomato Seeds"), - inventory_image = "farming_tomato_seed.png", - on_place = function(itemstack, placer, pointed_thing) - return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:tomato_1") + description = S("Tomato Seeds"), -- Description for the item + inventory_image = "farming_tomato_seed.png", -- Image for the item in inventory + on_place = function(itemstack, placer, pointed_thing) -- Function to execute when item is placed + return farming.place_seed(itemstack, placer, pointed_thing, "farming_plus:tomato_1") -- Place the seed and return the modified itemstack end }) +-- Register a node for the first stage of tomato growth minetest.register_node("farming_plus:tomato_1", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - drop = "", - tiles = {"farming_tomato_1.png"}, - selection_box = { + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + drop = "", -- No items are dropped when node is dug + tiles = {"farming_tomato_1.png"}, -- Texture for the node + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+5/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a node for the second stage of tomato growth minetest.register_node("farming_plus:tomato_2", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - drop = "", - tiles = {"farming_tomato_2.png"}, - selection_box = { + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + drop = "", -- No items are dropped when node is dug + tiles = {"farming_tomato_2.png"}, -- Texture for the node + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+8/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a node for the third stage of tomato growth minetest.register_node("farming_plus:tomato_3", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - drop = "", - tiles = {"farming_tomato_3.png"}, - selection_box = { + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + drop = "", -- No items are dropped when node is dug + tiles = {"farming_tomato_3.png"}, -- Texture for the node + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+13/16, 0.5} }, }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a node for the final stage of tomato growth minetest.register_node("farming_plus:tomato", { - paramtype = "light", - walkable = false, - drawtype = "plantlike", - tiles = {"farming_tomato_4.png"}, - drop = { - max_items = 6, + paramtype = "light", -- Parameter type for light + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + tiles = {"farming_tomato_4.png"}, -- Texture for the node + drop = { -- Items to drop when node is dug + max_items = 6, -- Maximum number of items to drop items = { { items = {'farming_plus:tomato_seed'} }, { items = {'farming_plus:tomato_seed'}, rarity = 2}, @@ -74,14 +83,16 @@ minetest.register_node("farming_plus:tomato", { { items = {'farming_plus:tomato_item'}, rarity = 5 } } }, - groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, - sounds = default.node_sound_leaves_defaults(), + groups = {snappy=3, flammable=2, not_in_creative_inventory=1,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register a craftitem for the tomato item minetest.register_craftitem("farming_plus:tomato_item", { - description = S("Tomato"), - inventory_image = "farming_tomato.png", - on_use = minetest.item_eat(4), + description = S("Tomato"), -- Description for the item + inventory_image = "farming_tomato.png", -- Image for the item in inventory + on_use = minetest.item_eat(4), -- Function to execute when item is used }) +-- Add the tomato plant to the farming module, defining its growth stages and chances of growth farming.add_plant("farming_plus:tomato", {"farming_plus:tomato_1", "farming_plus:tomato_2", "farming_plus:tomato_3"}, 50, 20) diff --git a/weed.lua b/weed.lua index b117870..950f746 100644 --- a/weed.lua +++ b/weed.lua @@ -1,44 +1,51 @@ -- main `S` code in init.lua -local S -S = farming.S +local S -- Declare a local variable named `S` +if farming.S then -- Check if `farming.S` is not nil + S = farming.S -- Assign the value of `farming.S` to the local variable `S` +else + print("Error: farming.S is nil") -- Print an error message if `farming.S` is nil +end +-- Register a node for weed minetest.register_node(":farming:weed", { - description = S("Weed"), - paramtype = "light", - sunlight_propagates = true, - walkable = false, - drawtype = "plantlike", - tiles = {"farming_weed.png"}, - inventory_image = "farming_weed.png", - selection_box = { + description = S("Weed"), -- Description for the node + paramtype = "light", -- Parameter type for light + sunlight_propagates = true, -- Allow sunlight to propagate through the node + walkable = false, -- Node is not walkable + drawtype = "plantlike", -- Draw type is plant-like + tiles = {"farming_weed.png"}, -- Texture for the node + inventory_image = "farming_weed.png", -- Image for the node in inventory + selection_box = { -- Selection box dimensions type = "fixed", fixed = { {-0.5, -0.5, -0.5, 0.5, -0.5+4/16, 0.5} }, }, - groups = {snappy=3, flammable=2,plant=1}, - sounds = default.node_sound_leaves_defaults() + groups = {snappy=3, flammable=2,plant=1}, -- Node groups and their properties + sounds = default.node_sound_leaves_defaults(), -- Sound settings for the node }) +-- Register an Active Block Modifier (ABM) to handle soil wetness and weed growth minetest.register_abm({ - nodenames = {"farming:soil_wet", "farming:soil"}, - interval = 50, - chance = 10, - action = function(pos, node) + nodenames = {"farming:soil_wet", "farming:soil"}, -- Nodes to which the ABM applies + interval = 50, -- Interval (in seconds) at which the ABM is executed + chance = 10, -- Chance of the ABM being executed at each interval + action = function(pos, node) -- Function to execute when the ABM is triggered if minetest.find_node_near(pos, 4, {"farming:scarecrow", "farming:scarecrow_light"}) ~= nil then - return + return -- Exit if a scarecrow is found nearby end - pos.y = pos.y+1 - if minetest.get_node(pos).name == "air" then - node.name = "farming:weed" - minetest.set_node(pos, node) + pos.y = pos.y+1 -- Adjust the y-coordinate of the position + if minetest.get_node(pos).name == "air" then -- Check if the node at the new position is air + node.name = "farming:weed" -- Set the name of the node to "farming:weed" + minetest.set_node(pos, node) -- Set the node at the new position to "farming:weed" end end }) -- ========= FUEL ========= +-- Register a crafting recipe for using weed as fuel minetest.register_craft({ - type = "fuel", - recipe = "farming:weed", - burntime = 1 + type = "fuel", -- Type of craft is fuel + recipe = "farming:weed", -- Recipe is weed + burntime = 1 -- Burn time is 1 })