Jump to content

Recommended Posts

Posted (edited)

I'm just new in modding Minecraft. And I want to edit the sugar. When the player eats the sugar, he should get an effect (like speed).

Edited by Luis_ST
Posted

You have to create your custom item class, with your custom logic (apply potion effect when consumed) and make it be a food item (you can see how vanilla specifies that some items are to be treated as food in the Items class). Then you have to register your custom item with the same registry name as vanilla sugar, so it will replace it

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Posted

okay i creat the item class :

 

package net.luis.cave.items.vanilla;

import net.minecraft.item.Food;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;

public class Sugar extends Item {

	public Sugar() {
		
		super(new Item.Properties()
				.group(ItemGroup.FOOD)
				.food(new Food.Builder()
						.hunger(2)
						.saturation(1.0f)
						.effect(new EffectInstance(Effects.SPEED, 300, 3), 1)
						.setAlwaysEdible()
						.build()));

	}

}

 

and I register the item with the same vanilla name but it dosen't work

and I don't know where is the error :

 

	public static final RegistryObject<Sugar> SUGAR = ITEMS.register("sugar", Sugar::new);
Posted
Quote

You have to create your custom item class, with your custom logic (apply potion effect when consumed) and make it be a food item (you can see how vanilla specifies that some items are to be treated as food in the Items class). Then you have to register your custom item with the same registry name as vanilla sugar, so it will replace it

Just for curiosity, wouldn't that cause issues if multiple mods override the same item?

Posted
29 minutes ago, poopoodice said:

Although I've never done one before, but if you register with your mod id it won't work.

	public static final DeferredRegister<Item> VANILLA_ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "minecraft");
      
    public static final RegistryObject<Sugar> SUGAR = VANILLA_ITEMS.register("sugar", Sugar::new);

 

It doesent work with the minecraft id

Posted
7 hours ago, MostafaSabry55 said:

Just for curiosity, wouldn't that cause issues if multiple mods override the same item?

Yes, there could be issues and incompatibilities..

 

7 hours ago, Luis_ST said:

	public static final DeferredRegister<Item> VANILLA_ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "minecraft");
      
    public static final RegistryObject<Sugar> SUGAR = VANILLA_ITEMS.register("sugar", Sugar::new);

 

It doesent work with the minecraft id

Define "doesn't work". Maybe show your complete code? Also i found this post where a similar question has been asked. There may another solution to edit the food property of vanilla items without replacing the item: https://forums.minecraftforge.net/topic/90655-making-leaves-edible/?tab=comments#comment-420705

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Posted
2 minutes ago, Beethoven92 said:

Yes, there could be issues and incompatibilities..

 

Define "doesn't work". Maybe show your complete code? Also i found this post where a similar question has been asked. There may another solution to edit the food property of vanilla items without replacing the item: https://forums.minecraftforge.net/topic/90655-making-leaves-edible/?tab=comments#comment-420705

This is the code of the item (sugar):

 

package net.luis.cave.items.vanilla;

import net.minecraft.item.Food;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;

public class Sugar extends Item {

	public Sugar() {
		
		super(new Item.Properties()
				.group(ItemGroup.FOOD)
				.food(new Food.Builder()
						.hunger(2)
						.saturation(1.0f)
						.effect(new EffectInstance(Effects.SPEED, 300, 3), 1)
						.setAlwaysEdible()
						.build()));
		setRegistryName("minecraft", "sugar");

	}

}

 

and this is the code of the Registry:

 

package net.luis.cave.init;

import net.luis.cave.Cave;
import net.luis.cave.items.BaseItem;
import net.luis.cave.items.RubyApple;
import net.luis.cave.items.vanilla.Sugar;
import net.minecraft.item.Item;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class CaveItems {
	
	public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Cave.Mod_Id);
	public static final DeferredRegister<Item> VANILLA_ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "minecraft");
	
	//Item
	public static final RegistryObject<Item> RUBY = ITEMS.register("ruby", BaseItem::new);
	
	public static final RegistryObject<Item> ENDERITE_SCRAP = ITEMS.register("enderite_scrap", BaseItem::new);
	
	public static final RegistryObject<Item> ENDERITE_INGOT = ITEMS.register("enderite_ingot", BaseItem::new);
	
	public static final RegistryObject<RubyApple> RUBY_APPLE = ITEMS.register("ruby_apple", RubyApple::new);
	
	public static final RegistryObject<Item> SUGAR = VANILLA_ITEMS.register("sugar", Sugar::new);
	
}

 

Posted (edited)
31 minutes ago, Beethoven92 said:

setRegistryName("minecraft", "sugar");

	

You don't need this in your item class. Your deferred register already handles that

okay

6 minutes ago, Danebi said:

Are you registering VANILLA_ITEMS on the mod bus?

it already set the mod id to minecraft because when i use my mod id (cave) i creat a new item but i want to replace a vanilla item(suger)

 

Edited by Luis_ST
Posted
1 minute ago, Luis_ST said:

it already set the mod id to minecraft

Do you have a line like this?

VANILLA_ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

 

  • Thanks 1
Posted (edited)
5 minutes ago, Danebi said:

Do you have a line like this?


VANILLA_ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

 

no I forgot it

thanks for helping

Edited by Luis_ST

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.

Announcements



×
×
  • Create New...

Important Information

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