[Mod] Farming Redo [1.48] [farming]

SFENCE
Member
Posts: 280
Joined: Sun Sep 29, 2019 07:13
GitHub: SFENCE
In-game: SFENCE

Re: [Mod] Farming Redo [1.46] [farming]

by SFENCE » Post

When I am using farming redo with working_villages, it sometimes fails in farming.refill_plant function because of player:get_inventory method return nil.

It looks like I cannot prevent it from happening because it is probably connected to the villager entity unloading and refill_plant calling via minetest.after.

So, can you please add some code like

Code: Select all

if not inv then
  return
end
after line local inv = player:get_inventory() in farming.refill_plant function?
cdb_3P0AYqjEIn68

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Update:

by TenPlus1 » Post

- Some recipes tweaked for use with wooden_bucket mod
- Inventory nil check added to refill_plant (thanks SFENCE)

User avatar
RighteousJammies
New member
Posts: 3
Joined: Mon Jun 06, 2022 16:04

Re: [Mod] Farming Redo [1.46] [farming]

by RighteousJammies » Post

Hey there 10plus1, i'm relatively new to minetest, and only recently have gotten a forum account, mainly to ask this question

im trying to make a fork of this mod, and currently, this will not run in a test world, as it says between the 2nd to last and the 3rd to last lines that there is something there that should not be, any help would be awesome!

minetest.register_abm({
nodenames = {"farming:infinisoil"},
interval = 10.0, -- Run every 10 seconds,
pos = (pos.x, y = pos.y + 1, z = pos.z)
if pos{"default:air"} then
minetest.swap_node{x = pos.x, y = pos.y + 1, z = pos.z, meta}
})
end

the meta reference is initialized in another area if that helps, specifically the error comes after the "}" after meta
My Jammies are Righteous, my rhymes not so much, anyways my brain is mush.

Josselin2
Member
Posts: 102
Joined: Thu May 28, 2020 15:32
GitHub: axcore
In-game: Josselin
Location: Tunnelers' Abyss

Re: [Mod] Farming Redo [1.46] [farming]

by Josselin2 » Post

See this example code from rubenwardy's mod tutorial.

Code: Select all

minetest.register_abm({
	nodenames = {"default:dirt_with_grass"},
	neighbors = {"default:water_source", "default:water_flowing"},
	interval = 10.0, -- Run every 10 seconds
	chance = 50, -- Select every 1 in 50 nodes
	action = function(pos, node, active_object_count, active_object_count_wider)
		minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "aliens:grass"})
	end
})
The ABM is created by a function.

Code: Select all

minetest.register_abm()
The function receives a table as an argument.

Code: Select all

minetest.register_abm({
	key = value,
	key = value,
	key = value,
})
That's not what you have, you have two key-value pairs and then a blob of code.

One of the values should be a function, which starts with function and ends with end.

Code: Select all

minetest.register_abm({
	key = value,
	key = value,
	action = function(pos)
		SOME CODE GOES HERE
	end,
})
pos is another table, which you are trying to declare using brackets, instead of curly braces. Edit: Also both of us forgot to include the x = part.

Code: Select all

pos = {x = pos.x, y = pos.y + 1, z = pos.z}
I'm not sure what this is supposed to do. Are you trying to find out what is at position pos?

Code: Select all

if pos{"default:air"} then
If so, you should replace it with minetest.get_node(). Also, I think it is just air, not default:air.

Code: Select all

local node = minetest.get_node(pos)
if node.name = "air" then
	SOME CODE GOES HERE
end
The minetest.swap_node() line is also wrong, but without more code I can't see what you're trying to do.

User avatar
RighteousJammies
New member
Posts: 3
Joined: Mon Jun 06, 2022 16:04

Re: [Mod] Farming Redo [1.46] [farming]

by RighteousJammies » Post

okay, so heres what i have now, the infiniy is supposed to grab the block above the current block, and then get its data on right click, then if the block above is air, replace it with the stored metadata (infinimeta) block

minetest.register_abm({
nodenames = {"farming:infinisoil"},
infiniy = {x = pos.x, y = pos.y + 1, z = pos.z},
infinimeta = set_string("infinisoilplant", minetest.get_meta {infiniy}),
on_rightclick = get_meta{x = pos.x, y = pos.y + 1, z = pos.z},
interval = 10.0, -- Run every 10 seconds,
action = function(infiniy)
local node = minetest.get_node(infiniy)
if node.name == "air" then
minetest.swap_node{x = pos.x, y = pos.y + 1, z = pos.z, infinimeta}
end
end
})
My Jammies are Righteous, my rhymes not so much, anyways my brain is mush.

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Farming Redo [1.46] [farming]

by TenPlus1 » Post

@RighteousJammies - May I ask what it is you are trying to do with the 'meta' block that warrants a fork of the farming mod and not a separate mod of it's own that works alongside farming ?

Josselin2
Member
Posts: 102
Joined: Thu May 28, 2020 15:32
GitHub: axcore
In-game: Josselin
Location: Tunnelers' Abyss

Re: [Mod] Farming Redo [1.46] [farming]

by Josselin2 » Post

Again: minetest.register_abm() is a function that receives a table as an argument. The table consists of key-value pairs.

Code: Select all

minetest.register_abm({
	key = value,
	key = value,
	key = value,
})
The Minetest API https://github.com/minetest/minetest/bl ... ua_api.txt lists the key-value pairs that can be used. Everything else should be inside the function.

Code: Select all

minetest.register_abm({
    -- key-value pairs
    nodenames = {"farming:infinisoil"},
    interval = 10.0, -- Run every 10 seconds,

    -- all of the code should be inside the function
    action = function(infiniy)
        infiniy = {x = pos.x, y = pos.y + 1, z = pos.z}
        infinimeta = set_string("infinisoilplant", minetest.get_meta {infiniy})
        local node = minetest.get_node(infiniy)
        if node.name == "air" then
            minetest.swap_node{x = pos.x, y = pos.y + 1, z = pos.z, infinimeta}
        end
    end
})
Now let's turn our attention to brackets. Functions use round brackets (...). Tables use curly braces {...}. They are not interchangeable, you must use the right kind of bracket.

Code: Select all

minetest.get_meta {infiniy}
This is wrong, because minetest.get_meta() is a function, so it uses round brackets.

Code: Select all

minetest.swap_node{x = pos.x, y = pos.y + 1, z = pos.z, infinimeta}
This is wrong, because minetest.swap_node() is a function, so it uses round brackets.

Code: Select all

infiniy = {x = pos.x, y = pos.y + 1, z = pos.z}
This is right, because pos is a table containing the keys x, y and z, so it uses curly braces.

After making those changes, we get this:

Code: Select all

minetest.register_abm({
    nodenames = {"farming:infinisoil"},
    interval = 10.0, -- Run every 10 seconds,

    action = function(infiniy)
        infiniy = {x = pos.x, y = pos.y + 1, z = pos.z}
        infinimeta = set_string("infinisoilplant", minetest.get_meta(infiniy))
        local node = minetest.get_node(infiniy)
        if node.name == "air" then
            minetest.swap_node(x = pos.x, y = pos.y + 1, z = pos.z, infinimeta)
        end
    end
})
The code still does not work, because your minetest functions are in the wrong format. For example, from the API we can see that minetest.swap_node() expects two arguments, not four.

Code: Select all

minetest.swap_node(pos, node)
The first argument is a table, so you need to express your values as a table. Both of these lines would be correct Lua:

Code: Select all

minetest.swap_node({x = pos.x, y = pos.y + 1, z = pos.z}, node)
minetest.swap_node(infiniy, node)
Next, this is wrong. There is no function called set_string() (unless you created one yourself).

Code: Select all

infinimeta = set_string("infinisoilplant", minetest.get_meta(infiniy))
The MetaDataRef does have a function with that name, it's normally expressed something like this.

Code: Select all

local meta = minetest.get_meta(pos)
meta:set_string("key", "value")
While we're on the subject, any variables that are not global variables should be declared explicitly as local variables. That includes both infiniy and infinimeta.

Code: Select all

local infiniy = {x = pos.x, y = pos.y + 1, z = pos.z}
local infinimeta = minetest.get_meta(pos)
I have a short-ish tutorial which explains many of these concepts: https://github.com/axcore/minetest_modding_tutorial

Josselin2
Member
Posts: 102
Joined: Thu May 28, 2020 15:32
GitHub: axcore
In-game: Josselin
Location: Tunnelers' Abyss

Re: [Mod] Farming Redo [1.46] [farming]

by Josselin2 » Post

Duplicate post
Last edited by Josselin2 on Tue Jun 07, 2022 06:58, edited 1 time in total.

Josselin2
Member
Posts: 102
Joined: Thu May 28, 2020 15:32
GitHub: axcore
In-game: Josselin
Location: Tunnelers' Abyss

Re: [Mod] Farming Redo [1.46] [farming]

by Josselin2 » Post

okay, so heres what i have now, the infiniy is supposed to grab the block above the current block, and then get its data on right click, then if the block above is air, replace it with the stored metadata (infinimeta) block
I am not quite sure why you would want to use an ABM for this. ABMs and LBMs run continuously on the background; why would you use an ABM for something that only happens when a block is right-clicked?

(Someone can correct me if I'm on the wrong track with that.)
Last edited by Josselin2 on Tue Jun 07, 2022 06:59, edited 1 time in total.

Josselin2
Member
Posts: 102
Joined: Thu May 28, 2020 15:32
GitHub: axcore
In-game: Josselin
Location: Tunnelers' Abyss

Re: [Mod] Farming Redo [1.46] [farming]

by Josselin2 » Post

Duplicate post
Last edited by Josselin2 on Tue Jun 07, 2022 07:00, edited 1 time in total.

Josselin2
Member
Posts: 102
Joined: Thu May 28, 2020 15:32
GitHub: axcore
In-game: Josselin
Location: Tunnelers' Abyss

Re: [Mod] Farming Redo [1.46] [farming]

by Josselin2 » Post

Duplicate post

User avatar
RighteousJammies
New member
Posts: 3
Joined: Mon Jun 06, 2022 16:04

Re: [Mod] Farming Redo [1.46] [farming]

by RighteousJammies » Post

In response to 10plus1 im essentailly just adding a soil block to the mod, the purpose of the block would be for things like public farms, or owners or admins to use to automatically replant the crop that was used (rightclicked) on the block, this is my first ever project in lua, so i'm sorry if i wind up asking a lot of questions here. I currently have it so it grabs the meta data of the crop that was right clicked and id like to think that its being stored, unsure because i havent been able to test it. but it is supposed to grab the meta data, and i use swap node to replace the air above it if there is one (checks every 10 seconds) and replaces it with the correct plant.
My Jammies are Righteous, my rhymes not so much, anyways my brain is mush.

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Farming Redo [1.46] [farming]

by TenPlus1 » Post

So let me see if I have this right, a soil block that when right-clicked with a crop, will plant the crop while the abm stores the crop name in metadata so that when it's harvested, it automatically replants it ?

If that is the case then I wrote this a while ago to add a special admin soil that keeps itself replanted, it has to be dug and replaced for new crops though as it's a simple solution for public farms :)

The following code can be stored in a new mod (e.g. "admin_soil") with farming as a dependency for textures and node registration.

Code: Select all

minetest.register_node(":farming:admin_soil", {
	description = "Admin Soil",
	tiles = {
		"default_dirt.png^farming_soil_wet.png",
		"default_dirt.png^farming_soil_wet_side.png"
	},
	drop = "default:dirt", -- drops normal soil so players cannot steal admin soil
	groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 3, field = 1},
	sounds = default.node_sound_dirt_defaults(),

	on_timer = function(pos, elapsed)

		-- get meta string inside soil and node above with definition
		local meta = minetest.get_meta(pos)
		local crop = meta:get_string("crop") or ""
		local pos2 = {x = pos.x, y = pos.y + 1, z = pos.z}
		local node = minetest.get_node(pos2)
		local def = minetest.registered_nodes[node.name]
		local is_crop = def and def.groups and def.groups.growing

		-- if 'crop' meta is empty and crop planted above, set default crop
		if crop == "" and is_crop then
			meta:set_string("crop", node.name) ; print("==set")
		end

		-- if no crop planted and default 'crop' set then replant
		if node.name == "air" and crop ~= "" then
			minetest.set_node(pos2, {name = crop}) ; print("==planted")
		end

		return true -- restart timer
	end,

	on_construct = function(pos)
		local timer = minetest.get_node_timer(pos)
		timer:start(10) -- every 10 seconds
	end
})

User avatar
amelaye
Member
Posts: 32
Joined: Sun Jun 14, 2020 10:47
GitHub: amelaye
Contact:

Re: [Mod] Farming Redo [1.46] [farming]

by amelaye » Post

Hi,
How do you make hemp fibre ? There is no recipe !
Thanks
My server : 188.165.239.63:30000 - My website : http://minetest.amelieonline.net

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Farming Redo [1.46] [farming]

by TenPlus1 » Post

Hemp Fibre is made with a water bucket surrounded by hemp leaf. If the recipe does not appear then it means an item is missing so you may be using farming redo alongside a different [game] than the default minetest_game.

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: [Mod] Farming Redo [1.46] [farming]

by Icalasari » Post

Is there a trick to grapes? I am regrowing them on the wild stalk, but they just won't grow on the trellis...

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Farming Redo [1.46] [farming]

by TenPlus1 » Post

Once you craft a trellis and place upon hoe'd soil that is near a water source and right-clicking with grapes (hitbox is at bottom) it should grow fine, 8-steps later you should see full purple grapes on the trellis ready for harvesting.

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: [Mod] Farming Redo [1.46] [farming]

by Icalasari » Post

Issue is I do see full purple grapes as soon as I plant them, and they seem to delete the trellis

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Farming Redo [1.46] [farming]

by TenPlus1 » Post

@Icalasari - are you trying to plant a grape bush ? This is what is found that you dig first to get some wild grapes to plant on the trellis. Also what version of Minetest are you using ?

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: [Mod] Farming Redo [1.46] [farming]

by Icalasari » Post

Most recent version. And I right click the trellis with grapes in hand and it just... Never grows or changes, staying in a fully formed grape state that is effectively decoration

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Farming Redo [1.46] [farming]

by TenPlus1 » Post

@Icalasari - Tested and is working ok, tilled soil near water, placed trellis, right-clicked trellis with grapes near bottom, started growing, after some time it grew step by step into fully fruited grape vine, harvested by digging and got trellis back and grapes.

What other mods are you using ?

Icalasari
Member
Posts: 166
Joined: Tue Sep 23, 2014 05:29
IRC: Icalasari
In-game: Icalasari

Re: [Mod] Farming Redo [1.46] [farming]

by Icalasari » Post

@TenPlus1 It's a long list (trying out a bunch of mods to figure out what to use for a server), so I'll post a pic

Image

EDIT: ...Please don't tell me this whole time I was using the wrong mod

User avatar
stylite
New member
Posts: 7
Joined: Mon Aug 01, 2022 11:07

Re: [Mod] Farming Redo [1.46] [farming]

by stylite » Post

When starting a MT-server, i get the following error
2022-08-10 20:06:28: WARNING[Main]: Will not load: /usr/share/minetest/games/minetest_game/mods/farming
2022-08-10 20:06:28: WARNING[Main]: Overridden by: /home/beheerder/.minetest/mods/farming
In /usr/share/ it is the original (?) mod, in /.minetest/mods Farming Redo.

Should i ignore this message, merge the folders or remove the folder in /usr?

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: [Mod] Farming Redo [1.46] [farming]

by Blockhead » Post

stylite wrote:
Wed Aug 10, 2022 20:24
Should i ignore this message, merge the folders or remove the folder in /usr?
Ignore it, it's working as intended. This mod will override the farming mod that's included with Minetest Game. Don't worry though, it's a superset of the base game's farming mod.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

NomadKing3
New member
Posts: 3
Joined: Sat Aug 13, 2022 19:46

Re: [Mod] Farming Redo [1.46] [farming]

by NomadKing3 » Post

I'm having trouble with forageables spawning. I can get any of the grass based seeds just fine, but anything that is supposed to be foraged for doesn't spawn at all. I have tried uninstalling and reinstalling the mod and tried to replace it the Farming mod from Mesecraft, but neither have worked.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 22 guests