[SOLVED] Self contained growing plant + Relative Directional Node Placement

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

[SOLVED] Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

I know about the farming mod, trying to see if I can make this work without said mod nor abms

Essentially, stumped at making it perform a minetest.set_node after a timer under certain light conditions

Code: Select all

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_plant_sapling_cherry.png"
		},
	inventory_image = "mindeca_item_berries_spirit.png",
	wield_image = "mindeca_item_berries_spirit.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	on_construct = function(pos)
		minetest.get_node_timer(pos):start(math.random(1, 1))

	after_place_node = function(pos, placer, itemstack)
			if minetest.get_node_light(pos) > 10 then
				if minetest.get_node_timer(pos) == 1 then
					minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower"})
				else
				end
			end
		end
	end,
})
This is the current iteration of... Six or seven. I'm just not sure why it isn't setting the node over it

-

The other question is in regards to making melons. Basically I want it to place the melon node after a time opposite face_dir, and not sure how to make it refer to a relative direction rather than absolute north/east/south/west. I recall reading about angles, but couldn't translate it to set_node

Edit: On the melons, something clicked. Going to try what came to mind once back at the computer and if that works, pray for a click in how to do growing
Last edited by Icalasari on Thu Aug 25, 2022 21:38, edited 3 times in total.

loosewheel
Member
Posts: 155
Joined: Mon Dec 28, 2020 01:19
GitHub: loosewheel
In-game: loosewheel

Re: Self contained growing plant + Relative Directional Node Placement

by loosewheel » Post

The on_timer callback gets called when the timer elapses. The on_timer doesn't get called if the node is in an unloaded block. So if you have several stages of growth you may need a more sophisticated method to set the appropriate stage if the block has been idle for a long time.

The after_place_node callback is called just after the node is placed, with the extra info of player (maybe) and itemstack to further set up the node.

minetest.get_node_timer(pos) == 1

minetest.get_node_timer returns a NodeTimerRef. Its never going to return 1.

If you want the rotation to be opposite to the default action, for horizontal rotation, you could use something like this:

Code: Select all

local param2

if player and player:is_player () then
   param2 = (minetest.dir_to_facedir (player:get_look_dir (), false) + 2) % 4
end
Then use param2 with your placement method.

*Edit: removed inner local keyword from code.
Last edited by loosewheel on Sat Aug 13, 2022 19:06, edited 1 time in total.

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

Gah, so guessing I won't be able to do a self contained growing node then without ABMs? That sucks =/

As for the rotation, it's more... If I place the node facing north, then the new node would grow on its south. If it's facing east, new node west. South? North. And west, east. Can't find the thread that explained angles in the way I potentially needed either, so issues there too now. It feels like it would be something to check if there is air at facedir + 180 degrees and soil under it, and if so, grow the melon after the timer is up

EDIT: The weird thing with the flower is that bushes can regrow berries over time and are essentially doing something similar, and I even used some bush code from my raspberry bush...

Ok no this should be possible, time to figure out where I'm going wrong here

(Still not sure with the melon stuff)

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

Ok yeah totally lost now. The flower should work. This was my first attempt

Code: Select all

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_plant_sapling_cherry.png"
		},
	inventory_image = "mindeca_item_berries_spirit.png",
	wield_image = "mindeca_item_berries_spirit.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	on_timer = function(pos, elapsed)
		if minetest.get_node_light(pos) < 3 then
			minetest.get_node_timer(pos):start(1)
		else
			minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower"})
		end
	end,
})
Thing is, this works with the bush

Code: Select all

minetest.register_node("mindeca:bush_rasp_leaves", {
	description = "Raspberry Bush Leaves\n\nLeaves that once bore raspberries.\n\nMindeca",
	drawtype = "allfaces_optional",
	tiles = {"mindeca_bush_rasp_leaves.png"},
	special_tiles = {"mindeca_bush_rasp_leaves_s.png"},
	paramtype = "light",
	light_source = 4,
	groups = {snappy = 3, flammable = 2, leaves = 1, spirit = 1},
	drop = {
		max_items = 1,
		items = {
			{items = {"mindeca:bush_rasp_seed"}, rarity = 5},
			{items = {"mindeca:bush_rasp_leaves"}}
		}
	},
	sounds = default.node_sound_leaves_defaults(),

	on_timer = function(pos, elapsed)
		if minetest.get_node_light(pos) < 3 then
			minetest.get_node_timer(pos):start(200)
		else
			minetest.set_node(pos, {name = "mindeca:bush_rasp_berries"})
		end
	end,
})
So yeah, definitely incredibly confused. There shouldn't be any difference =/

EDIT: ...Wait, placed leaves don't grow the berries. So the heck is off with this... How to make this work when you DO place it...

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Self contained growing plant + Relative Directional Node Placement

by Skamiz Kazzarch » Post

In the last two code samples I notice that there doesn't seem to be any code to start up the node timer for the first time. Only to re-start it when there is insufficient light.

Astrobe
Member
Posts: 571
Joined: Sun Apr 01, 2018 10:46

Re: Self contained growing plant + Relative Directional Node Placement

by Astrobe » Post

Icalasari wrote:
Sat Aug 13, 2022 06:32
Gah, so guessing I won't be able to do a self contained growing node then without ABMs? That sucks =/
FYI ABMs have the same limitation as timers - they are not active if there's no player around - and similar possible walkarounds (elapsed time info for timers, catch-up property for ABMs).

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

Skamiz Kazzarch wrote:
Sat Aug 13, 2022 07:21
In the last two code samples I notice that there doesn't seem to be any code to start up the node timer for the first time. Only to re-start it when there is insufficient light.
...I feel like a complete moron now. I think I know what to do now
Astrobe wrote:
Sat Aug 13, 2022 07:22
FYI ABMs have the same limitation as timers - they are not active if there's no player around - and similar possible walkarounds (elapsed time info for timers, catch-up property for ABMs).
Oh, wait, may have misunderstood things - I don't mind them not doing things if no players are around. If it's good enough for tree and bush saplings, then it should be fine for farming stuff. Although glad to know about elapsed time info in case it ends up a problem



EDIT: Nope, that didn't work either. Hmm... Think I might not know how to get this to trigger right. Looking through things

EDIT 2: ...Wait then how does it work for... ...It's because the leaf nodes are placed in the world by schematics/decorations/etc. But I don't want to make a whole separate node that increases any crops like this to another node... Hmm

EDIT 3: Still not working, but I think I'm getting somewhere

Code: Select all

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_flower_sunflower.png"
		},
	inventory_image = "mindeca_item_pl_food_sunflower.png",
	wield_image = "mindeca_item_pl_food_sunflower.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	on_timer = function(pos, elapsed)
		if not minedeca.can_grow_full(pos) then
			minetest.get_node_timer(pos):start(math.random(1, 1))
			return
		end
		minetest.remove_node(pos)
		minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower"})
	end,
})
EDIT 4: Trying to find any mod that swaps nodes. This really is looking like it's not possible with a placed node, yet it feels like it *should* be possible...

Plus side, found something involving pos.x[face] (glanced at it while looking for anything that proves what I want to do is possible), so the melon stuff is seeming like it is getting more possible...

EDIT 5: ...Well, I... Am not sure how this is happening

ERROR:

Code: Select all

AsyncErr: Lua: Runtime error from mod 'mindeca' in callback item_OnPlace(): ...bin\..\mods\mindeca\Mindeca Main/treegrowth/2fullsun.lua:5: attempt to perform arithmetic on field 'y' (a nil value)
stack traceback:
	...bin\..\mods\mindeca\Mindeca Main/treegrowth/2fullsun.lua:5: in function 'can_grow_fullsun'
	...t-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/nodes.lua:22: in function <...t-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/nodes.lua:21>
Nodes:

Code: Select all

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_flower_sunflower.png"
		},
	inventory_image = "mindeca_item_pl_food_sunflower.png",
	wield_image = "mindeca_item_pl_food_sunflower.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	on_place = function(pos, elapsed)
		if not mindeca.can_grow_fullsun(pos) then
			minetest.get_node_timer(pos):start(math.random(1, 1))
			return
		end
		minetest.remove_node(pos)
		minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower"})
	end,
})
2fullsun:

Code: Select all

-----
--'can grow full' function

function mindeca.can_grow_fullsun(pos)
	local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
	if not node_under then
		return false
	end
	if minetest.get_item_group(node_under.name, "soil") == 0 then
		return false
	end
	local light_level = minetest.get_node_light(pos)
	if not light_level or light_level < 12 then
		return false
	end
	return true
end
Everything else that uses mindeca.can_grow_fullsun(pos) has no issue - I even checked with a sapling and that grew just fine

So no idea how y is being nil

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

FINALLY got it figured out! Needed on_construct!

Now I have a self contained growing node! Woo!

Code: Select all

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_flower_sunflower.png"
		},
	inventory_image = "mindeca_item_pl_food_sunflower.png",
	wield_image = "mindeca_item_pl_food_sunflower.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	on_construct = function(pos)
		if not mindeca.can_grow_fullsun(pos) then
			minetest.get_node_timer(pos):start(math.random(1, 1))
			return
		end
		minetest.remove_node(pos)
		minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower"})
	end,
})
Now that just leaves figuring out how to deal with melons

Going to make a rough image for it

Yellow = Player
Blue = Vine
Red Line = Direction vine is facing
Green = Melon/Gourd

Image

This is basically what I'm trying to do with the melons and gourds - Based on the direction the player places it, it will grow the melon or gourd in the opposite direction

EDIT: ...It's just skipping the timer for the flower. But at least there's progress?

EDIT 2: Still no clue why it won't read the timer. Tried a bunch of things and it's still just instant growth. Been up all night so going to rest for now and hope something comes to me after some rest


EDIT 3:

Melons - Finally found the rotation part I lost vector.rotate(vector.new(0, 0, 1), r), but realized that it still doesn't help as pos is still x, y, z. Wonder if there is a way to have the "pos" be x,y,z = forward? Maybe looking at a mob mod might help me there?

Flower Growth - I'm going to, when I can sit back down, try seeing if node_dig_prediction has a set version and if that's why the bush goes on a timer and the sunflower doesn't

EDIT - node_placement_prediction is the dig version. And looking at the API, my hunch is 100% right - Dig replaces the node with the chosen one, and that's the ONLY thing missing from the sunflower code. I'm betting that the timer only works right when the environment places the node

If this works, then that just leaves the melon code to figure out

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

You know what? With how things have been going, it figures that it just breaks in old ways

EDIT: I am at the point I am messing up even basic forum formatting code dear god

Node Code:

Code: Select all

-----
--Soil
-----



-----
--Sand
-----



-----
--Stone
-----



-----
--Ores
-----

minetest.register_node("mindeca:ore_copper", {
	description = ("Copper Ore" .. "\n" .. "Ore with copper embedded. The copper practically glistens." .. "\n" .. "\n" .. "Mindeca"),
	tiles = {"default_stone.png^mindeca_ore_copper.png"},
	groups = {cracky = 2},
	drop = "mindeca:item_copper",
	sounds = default.node_sound_stone_defaults()
})

minetest.register_node("mindeca:ore_tin", {
	description = "Tin Ore\n\nOre with tin embedded. The tin is soft and pliable.\n\nMindeca",
	tiles = {"default_stone.png^mindeca_ore_tin.png"},
	groups = {cracky = 2},
	drop = "mindeca:item_tin",
	sounds = default.node_sound_stone_defaults()
})

minetest.register_node("mindeca:ore_ruby", {
	description = ("Ruby Ore" .. "\n" .. "Ore with rubies embedded. One is of high quality." .. "\n" .. "\n" .. "Mindeca"),
	tiles = {"default_stone.png^mindeca_ore_ruby.png"},
	groups = {cracky = 2},
	drop = "mindeca:item_ruby",
	sounds = default.node_sound_stone_defaults()
})



-----
--Plants
-----



-----
--Grass



-----
--Bushes/Berries


--Spring


--Summer




---
--Melons/Gourds

minetest.register_node("mindeca:plant_mel_watermelon", {
	description = "Watermelon\n\nBig ol' watery melon.\n\nMindeca",
	tiles = {"mindeca_bush_rasp_leaves_s.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {snappy = 3, flammable = 1},
	sounds = default.node_sound_leaves_defaults(),
	on_place = minetest.rotate_node
})

minetest.register_node("mindeca:plant_flower_magnolia", {
	description = "Magnolia Flower\n\nMindeca",
	drawtype = "plantlike",
	waving = 1,
	tiles = {"mindeca_item_flower_magnolia.png"},
	inventory_image = "mindeca_item_flower_magnolia.png",
	wield_image = "mindeca_item_flower_magnolia.png",
	paramtype = "light",
	paramtype2 = "meshoptions",
	place_param2 = 10,
	sunlight_propagates = true,
	walkable = false,
	buildable_to = true,
	groups = {snappy = 3, flora = 1, attached_node = 1, grass = 1, flammable = 1, spirit = 1},
	sounds = default.node_sound_leaves_defaults(),
	selection_box = {
		type = "fixed",
		fixed = {-8/16, -0.5, -8/16, 8/16, 5/16, 8/16},
	},
})


---
--Flowers


--Summer

minetest.register_node("mindeca:plant_flower_magnolia", {
	description = "Magnolia Flower\n\nMindeca",
	drawtype = "plantlike",
	waving = 1,
	tiles = {"mindeca_item_flower_magnolia.png"},
	inventory_image = "mindeca_item_flower_magnolia.png",
	wield_image = "mindeca_item_flower_magnolia.png",
	paramtype = "light",
	paramtype2 = "meshoptions",
	place_param2 = 10,
	sunlight_propagates = true,
	walkable = false,
	buildable_to = true,
	groups = {snappy = 3, flora = 1, attached_node = 1, grass = 1, flammable = 1, spirit = 1},
	sounds = default.node_sound_leaves_defaults(),
	selection_box = {
		type = "fixed",
		fixed = {-8/16, -0.5, -8/16, 8/16, 5/16, 8/16},
	},
})

minetest.register_node("mindeca:plant_flower_dogwood", {
	description = "Dogwood Flower\n\nMindeca",
	drawtype = "plantlike",
	tiles = {"mindeca_item_flower_dogwood.png"},
	inventory_image = "mindeca_item_flower_dogwood.png",
	paramtype = "light",
	paramtype2 = "facedir",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {snappy = 3, flora = 1, grass = 1, flammable = 1, spirit = 1},
	sounds = default.node_sound_leaves_defaults(),

	after_place_node = function(pos, placer, itemstack)
		minetest.set_node(pos, {name = "mindeca:plant_flower_dogwood"})
	end,

	on_place = minetest.rotate_node
})

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_flower_sunflower1.png"
		},
	inventory_image = "mindeca_item_pl_food_sunflower.png",
	wield_image = "mindeca_item_pl_food_sunflower.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	node_placement_prediction = "mindeca:food_pl_sunflower",
	on_place = function(pos, oldnode, oldmetadata, digger)
		if not mindeca.can_grow_fullsun(pos) then
			minetest.get_node_timer(pos):start(math.random(200, 200))
			return
		end
		minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower1"})
		minetest.get_node_timer(pos):start(math.random(300, 1500))
	end
})

minetest.register_node("mindeca:plant_flower_sunflower1", {
	description = "Sunflower (Young)\n\nDoing some decorating?\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_flower_sunflower2.png"
		},
	inventory_image = "mindeca_item_flower_sunflower2.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	drop = "mindeca:food_pl_sunflower",
	sounds = default.node_sound_leaves_defaults(),

	on_timer = function(pos, elapsed)
		if minetest.get_node_light(pos) < 3 then
			minetest.get_node_timer(pos):start(200)
		else
			minetest.set_node(pos, {name = "mindeca:bush_rasp_berries"})
		end
	end,
})

minetest.register_node("mindeca:plant_flower_sunflower2", {
	description = "Sunflower\n\nA beautiful flower that tracks the sun. Except here.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {"mindeca_item_flower_sunflower.png"},
	inventory_image = "mindeca_item_flower_sunflower.png",
	paramtype = "light",
	paramtype2 = "facedir",
	visual_scale = 1.9,
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-4/16, -8/16, -4/16, 4/16, 24/16, 4/16}
	},
	groups = {snappy = 3, flora = 1, grass = 1, flammable = 1},
	drop = {
		max_items = 1,
		items = {
			{ items = {"mindeca:item_deco_sunflower"}, rarity = 25 },
			{ items = {"mindeca:food_pl_sunflower1 5"}, rarity = 5 },
			{ items = {"mindeca:food_pl_sunflower1 3"}, rarity = 2 },
			{ items = {"mindeca:food_pl_sunflower1 2"} },
		}
	},
	sounds = default.node_sound_leaves_defaults(),

	after_place_node = function(pos, placer, itemstack)
		minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower2"})
	end,

	on_place = minetest.rotate_node
})



---
--Vines

minetest.register_node("mindeca:plant_glitter_vine", {
	description = ("Glitter Vine" .. "\n" .. "A golden vine that glitters in the dark. It is thought to contain spiritual energy." .. "\n" .. "\n" .. "Mindeca"),
	drawtype = "nodebox",
	tiles = {"mindeca_plant_glitter_vine.png"},
	inventory_image = "mindeca_plant_glitter_vine.png",
	wield_image = "mindeca_plant_glitter_vine.png",
	use_texture_alpha = "clip",
	paramtype = "light",
	paramtype2 = "wallmounted",
	node_box = {
		type = "wallmounted",
		wall_top    = {-0.5, 0.45, -0.5, 0.5, 0.5, 0.5,},
		wall_bottom = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5,},
		wall_side   = {-0.5, -0.5, -0.5, -0.45, 0.5, 0.5,},
	},
	sunlight_propogates = true,
	walkable = false,
	climbable = true,
	buildable_to = true,
	is_ground_content = false,
	waving = 1,
	groups = {snappy = 3, fleshy = 3, dig_immediate = 3, flammable = 2, attached_node = 1, leafdecay = 3, leafdecay_drop = 1},
	drop = "mindeca:plant_glitter_vine",
	sounds = default.node_sound_leaves_defaults(),
	light_source = 14,
})

-----
--Wood
-----

-----
--Natural



-----
--Liquids
-----



-----
--Insects
-----

minetest.register_node("mindeca:cicada", {
	description = "Cicada\n\nA very, VERY noisy insect.\n\nMindeca",
	tiles = {"mindeca_insect_cicada.png"},
	drawtype = "mesh",
	collision_box = {
		type = "fixed",
		fixed =	{-5/16, -8/16, 4/16, 5/16, 8/16, 8/16},
	},
	selection_box = {
		type = "fixed",
		fixed =	{-5/16, -8/16, 4/16, 5/16, 8/16, 8/16},
	},
	mesh = "mindeca_cicada.obj",
	use_texture_alpha = "clip",
	paramtype = "light",
	paramtype2 = "facedir",
	groups = {oddly_breakable_by_hand = 1, flammable = 1, insect = 1},
	after_place_node = function(pos)
		local timer = minetest.get_node_timer(pos) 
		timer:start(6,10)
		return true
	end,
	on_timer = function(pos)
		local timer = minetest.get_node_timer(pos) 
		minetest.sound_play('mindeca_cicada', {
			pos = pos,
			gain = 0.525,
			max_hear_distance = 32
		})
		timer:start(6,10)
	end
})



-----
--Traps
-----

minetest.register_node("mindeca:trap_oak_leaves", {
	description = "Leaf Pile\n\nA pile of autumn leaves. Careful, it could hide a hole.\n\nMindeca",
	drawtype = "mesh",
	selection_box = {
		type = "fixed",
		fixed = {-8/16, -8/16, -8/16, 8/16, -5/16, 8/16},
	},
	visual_scale = 1.1,
	mesh = "mindeca_trap_oak_leaves.obj",
	tiles = {
		"mindeca_trap_oak_leaves.png",
		},
	inventory_image = "mindeca_item_trap_oak_leaves.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	groups = {oddly_breakable_by_hand = 1},
	drop = "mindeca:trap_oak_leaves",
	sounds = {
		footstep = default.node_sound_leaves_defaults(),
		dig = default.node_sound_leaves_defaults(),
		dug = default.node_sound_leaves_defaults(),
	}
})


-----
--Cooking
-----

local hbmod = minetest.global_exists("hbhunger")

minetest.register_node("mindeca:item_cook_pie_tin", {
	description = "Pie Tin\n\nA pie tin made for baking goods such as pies and pastries.\n\nMindeca",
	drawtype = "mesh",
	collision_box = {
		type = "fixed",
		fixed =	{-8/16, -8/16, -8/16, 8/16, -4/16, 8/16},
	},
	selection_box = {
		type = "fixed",
		fixed =	{-8/16, -8/16, -8/16, 8/16, -4/16, 8/16},
	},
	mesh = "mindeca_pie_tin.obj",
	tiles = {"mindeca_cook_pie_apple.png",},
	inventory_image = "mindeca_item_cook_pie_tin.png",
	groups = {oddly_breakable_by_hand = 1},
	drop = "mindeca:item_cook_pie_tin",
	sounds = default.node_sound_stone_defaults()
})

-----
--Spring Fruits


-----
--Summer Fruits


-----
--Autumn Fruits


-----
--Winter Fruits



-----
--Special
-----

-----
--Display

minetest.register_node("mindeca:display", {
	description = ("Display (White)" .. "\n" .. "A pure white display, meant for showing off objects." .. "\n" .. "\n" .. "Mindeca"),
	tiles = {"mindeca_0.png"},
	groups = {crumbly = 3,},
	light_source = 14,
	sounds = default.node_sound_sand_defaults(),
})


-----
--Clouds

minetest.register_node("mindeca:cloud", {
	description = ("Cloud" .. "\n" .. "\n" .. "(Mindeca)"),
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
{-10/16, -10/16, -10/16, 10/16, 10/16, 10/16},
		},
	},
	selection_box = {
		type = "fixed",
		fixed = {
			{-8/16, -8/16, -8/16, 8/16, 8/16, 8/16},
		},
	},
	collision_box = {
		type = "fixed",
		fixed = {
			{-8/16, -8/16, -8/16, 8/16, 0, 8/16},
		},
	},
	tiles = {{name = "mindeca_cloud.png",
		animation = {
			type = "vertical_frames",
			aspect_w = 16,
			aspect_h = 16,
			length = 4,
		},
	}},
	paramtype = "light",
	sunlight_propagates = true,
	is_ground_content = false,
	groups = {oddly_breakable_by_hand = 3, cloud = 1, fall_damage_add_percent=-100},
	flags = "force_placement",
	sounds = default.node_sound_snow_defaults(),
})


-----
--Flower Nodes

minetest.register_node("mindeca:flowerhidden", {
	description = "Hidden Flower Segment\n\nHow did you get this?\n\nMindeca",
	inventory_image = "mindeca_0invis.png",
	wield_image = "mindeca_0invis.png",
	drawtype = "airlike",
	paramtype = "light",
	paramtype2 = "facedir",
	sunlight_propagates = true,
	-- has to be walkable for falling nodes to stop falling.
	walkable = true,
	pointable = false,
	diggable = false,
	buildable_to = false,
	floodable = false,
	drop = "",
	groups = {not_in_creative_inventory = 1},
	on_blast = function() end,
	-- 1px block inside door hinge near node top
	collision_box = {
		type = "fixed",
		fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32},
	},
})
2FullSun Code (that works with saplings JUUUUST fine, but god forbid I try *sunflowers*):

Code: Select all

-----
--'can grow full' function

function mindeca.can_grow_fullsun(pos)
	local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
	if not node_under then
		return false
	end
	if minetest.get_item_group(node_under.name, "soil") == 0 then
		return false
	end
	local light_level = minetest.get_node_light(pos)
	if not light_level or light_level < 12 then
		return false
	end
	return true
end
Error:

Code: Select all

AsyncErr: Lua: Runtime error from mod 'mindeca' in callback item_OnPlace(): ...bin\..\mods\mindeca\Mindeca Main/treegrowth/2fullsun.lua:5: attempt to perform arithmetic on field 'y' (a nil value)
stack traceback:
	...bin\..\mods\mindeca\Mindeca Main/treegrowth/2fullsun.lua:5: in function 'can_grow_fullsun'
	...t-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/nodes.lua:180: in function <...t-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/nodes.lua:179>

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Self contained growing plant + Relative Directional Node Placement

by Skamiz Kazzarch » Post

You are calling can_grow_fullsun from an on_place callback.
But it looks like this in your code:
on_place = function(pos, oldnode, oldmetadata, digger)
When it should look like this:
https://github.com/minetest/minetest/bl ... .txt#L7951
on_place = function(itemstack, placer, pointed_thing)

Basically you are trying to use the y value of an itemstack, which is nil.
Thus y = pos.y - 1 throws an error since nil - 1 is not valid.

Somehow you got the argument list from after_dig_node on your on_place function.
after_dig_node = function(pos, oldnode, oldmetadata, digger)

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Self contained growing plant + Relative Directional Node Placement

by sirrobzeroone » Post

Icalasari wrote:
Mon Aug 15, 2022 00:03
...
Sorry to plug my own stuff by Mod flowers_NT (mostly an api)provides an out of the box ability to register any small plant with 4 growth stages - dosen't need to strictly be a flower can be any small herbaceous type plant you want to grow but not necessarily formally farm.

links here:
viewtopic.php?t=28239&p=411388

gits here:
https://github.com/sirrobzeroone/flowers_nt

If you use it and find any issues just flag I'll fix them no worries :)

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

Skamiz Kazzarch wrote:
Mon Aug 15, 2022 03:53
You are calling can_grow_fullsun from an on_place callback.
But it looks like this in your code:
on_place = function(pos, oldnode, oldmetadata, digger)
When it should look like this:
https://github.com/minetest/minetest/bl ... .txt#L7951
on_place = function(itemstack, placer, pointed_thing)

Basically you are trying to use the y value of an itemstack, which is nil.
Thus y = pos.y - 1 throws an error since nil - 1 is not valid.

Somehow you got the argument list from after_dig_node on your on_place function.
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Guh yeah guess I am getting too blind from staring at my own code and banging my head a bunch, I should have caught that. Thanks
sirrobzeroone wrote:
Mon Aug 15, 2022 04:08
Icalasari wrote:
Mon Aug 15, 2022 00:03
...
Sorry to plug my own stuff by Mod flowers_NT (mostly an api)provides an out of the box ability to register any small plant with 4 growth stages - dosen't need to strictly be a flower can be any small herbaceous type plant you want to grow but not necessarily formally farm.

[SNIP!]

If you use it and find any issues just flag I'll fix them no worries :)
I'll take a look, thanks

EDIT: Ok now definitely need to head to sleep to be up for my shift tomorrow, but had enough time to fix the error in the function

Even with fixing on_place = function(itemstack, placer, pointed_thing) - replacing the digger information, I still get a similar error:

Code: Select all

AsyncErr: Lua: Runtime error from mod 'mindeca' in callback item_OnPlace(): ...bin\..\mods\mindeca\Mindeca Main/treegrowth/2fullsun.lua:5: attempt to index local 'pos' (a nil value)
stack traceback:
	...bin\..\mods\mindeca\Mindeca Main/treegrowth/2fullsun.lua:5: in function 'can_grow_fullsun'
	...t-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/nodes.lua:180: in function <...t-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/nodes.lua:179>
I'm starting to get what the problem may be and why it works with bushes but not this - on_dignode for the bush version has a pos, while on_placenode does not. But then that leaves me fully out of ideas

I have no clue how to make that timer start like it does with bushes instead of being skipped and instantly growing the plant

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Self contained growing plant + Relative Directional Node Placement

by sirrobzeroone » Post

Icalasari wrote:
Mon Aug 15, 2022 04:50
....
This one I can answer :)

on_place is not a valid node callback, so there is no valid pos data

I think your looking for

on_construct = function(pos),

or what i think you meant to use

after_place_node = function(pos, placer, itemstack, pointed_thing),

https://minetest.gitlab.io/minetest/def ... definition

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

I somehow missed the after_place_node function, thanks

Still not getting the result I want though. I managed to also spot I had a bad order - I finally spotted I had the set_node before the time

But now it won't grow?

Code: Select all

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_flower_sunflower1.png"
		},
	inventory_image = "mindeca_item_pl_food_sunflower.png",
	wield_image = "mindeca_item_pl_food_sunflower.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	node_placement_prediction = "mindeca:food_pl_sunflower",
	after_place_node = function(pos, placer, itemstack, pointed_thing)
		if not mindeca.can_grow_fullsun(pos) then
			minetest.get_node_timer(pos):start(math.random(1, 1))
		else
		minetest.get_node_timer(pos):start(math.random(1, 1))
		on_timer = function(pos, elapsed)
			minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower1"})
		end
	end
end
})
Debug Log:

Code: Select all

2022-08-15 18:16:39: WARNING[Server]: Assignment to undeclared global "on_timer" inside a function at ...t-5.5.1-win64\bin\..\mods\mindeca\Mindeca Main/nodes.lua:186.
Which... Extra confuses me now

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Self contained growing plant + Relative Directional Node Placement

by sirrobzeroone » Post

Your on_timer is inside after_place_node, those are seperate should be:

Code: Select all

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_flower_sunflower1.png"
		},
	inventory_image = "mindeca_item_pl_food_sunflower.png",
	wield_image = "mindeca_item_pl_food_sunflower.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	node_placement_prediction = "mindeca:food_pl_sunflower",
	after_place_node = function(pos, placer, itemstack, pointed_thing)
		if not mindeca.can_grow_fullsun(pos) then
			minetest.get_node_timer(pos):start(math.random(1, 1))
		else
			minetest.get_node_timer(pos):start(math.random(1, 1))
		end
	end,
	
	on_timer = function(pos, elapsed)
		minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower1"})
	end
end
})

hope I got those ends sorted right :)

Edit: Note ordering on those node registration callbacks doesn't matter you could reg them in whatever order you like as far as I'm aware. It's just a giant lua table with named keys :)

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

sirrobzeroone wrote:
Tue Aug 16, 2022 01:01
...
It works properly now! I still need to learn a lot about how to combine functions it seems =/ But that's one of the two down!

Now to figure out the watermelon one... I spotted velocity based commands, so that's probably the ticket. Just need to piece together the growth function for that so the melon always grows "opposite" of the stem

Code: Select all

minetest.register_node("mindeca:food_pl_sunflower", {
	description = "Sunflower Seed\n\nA raw sunflower seed. Tasty to snack on.\n\nMindeca",
	drawtype = "plantlike",
	tiles = {
		"mindeca_item_flower_sunflower1.png"
		},
	inventory_image = "mindeca_item_pl_food_sunflower.png",
	wield_image = "mindeca_item_pl_food_sunflower.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	is_ground_content = false,
	selection_box = {
		type = "fixed",
		fixed = {-3 / 16, -7 / 16, -3 / 16, 3 / 16, 4 / 16, 3 / 16}
	},
	groups = {dig_immediate = 3, food_apple = 1},
	on_use = minetest.item_eat(1),
	sounds = default.node_sound_leaves_defaults(),

	node_placement_prediction = "mindeca:food_pl_sunflower",
	after_place_node = function(pos, placer, itemstack, pointed_thing)
		minetest.get_node_timer(pos):start(math.random(5, 5))
	end,
	on_timer = function(pos, elapsed)
		if not mindeca.can_grow_fullsun(pos) then
			minetest.get_node_timer(pos):start(math.random(5, 5))
		return
		else
			minetest.set_node(pos, {name = "mindeca:plant_flower_sunflower1"})
		end
	end
})

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Self contained growing plant + Relative Directional Node Placement

by sirrobzeroone » Post

Glad it worked :)
Icalasari wrote:
Tue Aug 16, 2022 02:10

Now to figure out the watermelon one... I spotted velocity based commands, so that's probably the ticket. Just need to piece together the growth function for that so the melon always grows "opposite" of the stem
you probably don't want velocity, unless your melons are growing at speed. On_timer you want to find a vacant farmland or dirt node 1 distance from the stem. I'd say this function will be a good start:

minetest.find_nodes_in_area_under_air(pos1, pos2, nodenames): returns a list of positions.
nodenames: e.g. {"ignore", "group:tree"} or "default:dirt"
Return value: Table with all node positions with a node air above
Area volume is limited to 4,096,000 nodes

ref: https://minetest.gitlab.io/minetest/min ... reference/

pos1/pos2 in your case will only en-compass 9 nodes? you'd need to discard corners.

That or just manually do a minetest.get_node(pos) for each +-x/z and then check for dirt/farmland codewise either sol'n will be about the same length I think the second might be hair more cpu efficient? the 1st a hair shorter on code?

Have a look at Mineclone2 fairly sure they have pumpkins and melons growing from stems there already, not sure about farming_redo oddly i've never grown pumpkins in farming_redo in game....odd now I think about it.

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

sirrobzeroone wrote:
Tue Aug 16, 2022 03:25
Glad it worked :)
Again, thanks so much ^^
you probably don't want velocity, unless your melons are growing at speed. On_timer you want to find a vacant farmland or dirt node 1 distance from the stem.
Issue is I'm wanting it to make the melon grow only in the direction the player planted it to allow them to control its direction. Then again, maybe I'm overthinking it and making melons and gourds far more complex than a player would care about

Probably the latter XD

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Self contained growing plant + Relative Directional Node Placement

by sirrobzeroone » Post

Icalasari wrote:
Tue Aug 16, 2022 03:58

Issue is I'm wanting it to make the melon grow only in the direction the player planted it to allow them to control its direction. Then again, maybe I'm overthinking it and making melons and gourds far more complex than a player would care about

Probably the latter XD
Just because the player may not care if you asked them, I'd bet they would love a feature like that :). Stop melons growing randomly on your nice grass around the garden - awesome (I know I would).

You can store the look direction as a X/Z +- on seedling plant inside the nodes meta and then on timer expire just check the pos 1 along that direction is clear...you could just store the future spawn pos in the meta for the melon and checks it's air before spawning - either one should work.

Anyways I have some player look direction to axis calculations in one(a few I think) of my mods - not saying it's the most fancy code but it's most readable in this one:

https://github.com/sirrobzeroone/flower ... i.lua#L297

ends at line 306.

Goodluck I certainly like the idea of Melons that don't crush the grass around my veggie garden :)

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: Self contained growing plant + Relative Directional Node Placement

by Blockhead » Post

Rather than use node metadata the stem seedling should use paramtype2 = "facedir" (lua_api ref) so that when it's planted it gets a param2 between 0-3 (verify this with the debug menu). The melon growth code should map the stem's param2 to a direction and place it in that direction; that is easy enough with a table or a series of if statements. Of course, a weird side effect would be that rotating the stem with a screwdriver could cause problems - param2 out of the 0-3 range, or just the weirdness of the idea of rotating the stem of the plant underground with a screwdriver...
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Self contained growing plant + Relative Directional Node Placement

by Skamiz Kazzarch » Post

Pretty sure there is a way to make a node not be rotatable by the screw driver. If there isn't, there should be.

Edit:
Looked it up. You can provide an on_rotate callback in the node definition which prevents rotation by returning false.

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

Blockhead wrote:
Tue Aug 16, 2022 13:48
The melon growth code should map the stem's param2 to a direction and place it in that direction; that is easy enough with a table or a series of if statements.
These past few days have been hectic

Rubenwardy's guide has how to call the param2's number, right?

Thanks for all the help everybody, when I get this working (Pretty sure it's as simple as [very rough example as I need to check a few things first like what direction each number is] if [param2call] = 0 then minetest.set_node({x = pos.x-1, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname}) else if...), I'll mark this as solved then go back to screaming internally over bush 'sapling' code XD

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: Self contained growing plant + Relative Directional Node Placement

by Blockhead » Post

Icalasari wrote:
Thu Aug 18, 2022 02:07
Rubenwardy's guide has how to call the param2's number, right?
param2 should be available in the table you get when you use minetest.get_node_at(pos).
Icalasari wrote:
Thu Aug 18, 2022 02:07
Thanks for all the help everybody, when I get this working (Pretty sure it's as simple as [very rough example as I need to check a few things first like what direction each number is] if [param2call] = 0 then minetest.set_node({x = pos.x-1, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname}) else if...), I'll mark this as solved then go back to screaming internally over bush 'sapling' code XD
That's about the shape of it yes, just working out which param2 maps to which coordinate offset :)
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

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

Re: Self contained growing plant + Relative Directional Node Placement

by Icalasari » Post

Hitting a snag on it. Basically not sure where my syntax is going wrong as it's saying 'then' expected near '=', but I tried a few configurations so it's a syntax error I think?

Code: Select all

for name,def in pairs(mindeca.melon) do
	minetest.register_node("mindeca:fruit_"..def.elonname, {
		description = def.elondesc.."\n\nMindeca",
		tiles = {
			"mindeca_fruit_"..def.elonname.."_top.png",
			"mindeca_fruit_"..def.elonname.."_bot.png",
			"mindeca_fruit_"..def.elonname..".png"
			},
		paramtype = "light",
		groups = {snappy = 3, flammable = 2, melon = 1},
		drop = "mindeca:fruit_"..def.elonname,
		sounds = default.node_sound_leaves_defaults()
	})

	minetest.register_node("mindeca:vine_"..def.elonname, {
		description = def.vinedesc.."\n\nMindeca",
		tiles = {
			"mindeca_vine_"..def.elonname..".png"
			},
		paramtype = "light",
		paramtype2 = "facedir",
		groups = {snappy = 3, flammable = 2, melon = 1},
		drop = "mindeca:fruit_"..def.elonname,
		node_placement_prediction = "mindeca:vine_"..def.elonname,
		after_place_node = function(pos, placer, itemstack, pointed_thing)
			minetest.get_node_timer(pos):start(math.random(5, 5))
		end,
		on_timer = function(pos, elapsed)
			if not mindeca.can_grow_fullsun(pos) then
				minetest.get_node_timer(pos):start(math.random(5, 5))
			return
			else
			minetest.get_node(pos)
				if param2 = 0 then
					minetest.set_node({x = pos.x-1, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname})
				else
				if param2 = 1 then
					minetest.set_node({x = pos.x, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname})
				else
				if param2 = 2 then
					minetest.set_node({x = pos.x, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname})
				else
				if param2 = 3 then
					minetest.set_node({x = pos.x, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname})
			return
			end
		end
	})
end
I know there are some other errors, just can't troubleshoot that one (plus, from what I'm understanding from the Lua, param2 = x is the correct way to reference it)

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Self contained growing plant + Relative Directional Node Placement

by Skamiz Kazzarch » Post

So when I take the 'on_timer' function and format it correctly I get this:

Code: Select all

		on_timer = function(pos, elapsed)
			if not mindeca.can_grow_fullsun(pos) then
				minetest.get_node_timer(pos):start(math.random(5, 5))
				return
			else
				minetest.get_node(pos)
				if param2 = 0 then
					minetest.set_node({x = pos.x-1, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname})
				else
					if param2 = 1 then
						minetest.set_node({x = pos.x, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname})
					else
						if param2 = 2 then
							minetest.set_node({x = pos.x, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname})
						else
							if param2 = 3 then
								minetest.set_node({x = pos.x, y = pos.y, z = pos.z}, {name = "mindeca:fruit_"..def.elonname})
								return
			end
		end
Which should hopefully highlight one of the issues.
Spoiler
Remeber, else if is something different from elseif
That later continues the original if statement. The former creates a new if statement in else block, which then needs its own end.
About the param2 thing.
minetest.get_node(pos) returns a table with information about the node. You want to store it in a variable and then index it for the param2. The way you have it right now it's trying compare a variable which has no relationship with the node you just asked for.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests