Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

okay

 

"edible sugar item and register it in place of the vanilla sugar" Whats the best way to do this

 

Sorry but I'm new

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

  • Author

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);
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?

  • Author
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

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

  • Author
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);
	
}

 

  • Author
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

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());

 

  • Author
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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.