Jump to content

[Solved][1.15.2] can't use food properties in an item.


axilirate

Recommended Posts

package com.mod.axilirate_mobs;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.item.Food;
import net.minecraft.item.Food.Builder;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.ObjectHolder;


@Mod("axilirate_mobs")
@EventBusSubscriber(modid = "axilirate_mobs", bus = Bus.MOD)
public class main {
	public Logger LOGGER = LogManager.getLogger("axilirate_mobs");
	public main() {
		LOGGER.debug("Working!");
	}
	@ObjectHolder("axilirate_mobs"+"example_item"+"example_item_black") 
	public Item example_item;
	public Item example_item_black;
	@SubscribeEvent
	public static void onRegisterItems(RegistryEvent.Register<Item> event) {
		event.getRegistry().registerAll(
				setup(new Item(new Item.Properties().group(ItemGroup.MISC)),"example_item"),
>>>>>>>>>>>			setup(new Item(new Item.Properties().group(ItemGroup.MISC).food(new Food.Builder().setAlwaysEdible().hunger(6).meat())),"example_item_black")
			);

	}

	public static <T extends IForgeRegistryEntry<T>> T setup(final T entry, final String name) {
		return setup(entry, new ResourceLocation("axilirate_mobs", name));
	}

	public static <T extends IForgeRegistryEntry<T>> T setup(final T entry, final ResourceLocation registryName) {
		entry.setRegistryName(registryName);
		return entry;
	}

}

I am getting this "The method food(Food) in the type Item.Properties is not applicable for the arguments (Food.Builder)" and "The method setup(T, String) in the type main is not applicable for the arguments (Item, String)".
What is the problem?

Edit: can be fixed by adding build() at the end.
 

setup(new Item(new Item.Properties().group(ItemGroup.MISC).food(new Food.Builder().setAlwaysEdible().hunger(6).meat().build())),"example_item_black")

 

Edited by axilirate
Link to comment
Share on other sites

7 hours ago, diesieben07 said:

Did you read the error message? It tells you exactly whats wrong.

You are trying to call food(Food) with a parameter of type Food.Builder. You need to give it an instance of Food instead.

 

The 2nd one should work though.

However you should use DeferredRegistry to register your things anyways.

Edit: Fixed the error by adding .build() at the end.

 

 

So what do I do exactly?, I'm not that good with the forge API where I can understand 100% of the code, the tutorial I used to follow was short and unfinished.

Edited by axilirate
Link to comment
Share on other sites

1 hour ago, axilirate said:

So what do I do exactly?, I'm not that good with the forge API where I can understand 100% of the code, the tutorial I used to follow was short and unfinished.

I know you edited and now it work, but if you can then stop using the old registration method and make as diesieben07 has say: Use DeferredRegister. You can find tutorials videos on youtube.

New in Modding? == Still learning!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.