SOLVED: How to Check for Item in Another Mod?

Post Reply
User avatar
Grizzly Adam
Member
Posts: 252
Joined: Sat Aug 05, 2017 01:28
GitHub: Grizzly-Adam
Location: Lost in America
Contact:

SOLVED: How to Check for Item in Another Mod?

by Grizzly Adam » Post

I want to check and see if crops:peppercorn is present, and if so run the below script. Otherwise I want to end.

I just can't quite figure out how to write it and google is failing me.

Code: Select all

--if crops.peppercorn isn't present, then end

	on_place = function(itemstack, placer, pointed_thing)
		local under = minetest.get_node(pointed_thing.under)
		if minetest.get_item_group(under.name, "soil") <= 1 then
			return
		end
		crops.plant(pointed_thing.above, {name="crops:pepper_plant_1", param2 = 1})
		if not minetest.setting_getbool("creative_mode") then
			itemstack:take_item()
		end
		return itemstack
	end
})
Last edited by Grizzly Adam on Sun Jan 07, 2018 16:01, edited 1 time in total.
Check out my Mods: BBQ Mod Crops Plus

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: How to Check for Item in Another Mod?

by Byakuren » Post

First, make sure your mod lists crops as a dependency.
Then check minetest.registered_items["crops:peppercorn"] to see if it is nil or not.
Every time a mod API is left undocumented, a koala dies.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: SOLVED: How to Check for Item in Another Mod?

by stu » Post

I might add that you should only need to 'soft' depend on the crops mod to ensure it gets loaded before yours.

Also, if you are going to check this repeatedly it would be worth storing the result in a local variable, eg.

Code: Select all

local has_peppercorn = minetest.registered_items["crops:peppercorn"] ~= nil

User avatar
Grizzly Adam
Member
Posts: 252
Joined: Sat Aug 05, 2017 01:28
GitHub: Grizzly-Adam
Location: Lost in America
Contact:

Re: SOLVED: How to Check for Item in Another Mod?

by Grizzly Adam » Post

Again, thank you. It worked very well.
Check out my Mods: BBQ Mod Crops Plus

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests