Posted October 23, 20204 yr 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 October 23, 20204 yr by Luis_ST
October 23, 20204 yr You would need to create your custom edible sugar item and register it in place of the vanilla sugar Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
October 23, 20204 yr 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
October 23, 20204 yr 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
October 24, 20204 yr 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);
October 24, 20204 yr Although I've never done one before, but if you register with your mod id it won't work.
October 24, 20204 yr 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?
October 24, 20204 yr 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
October 24, 20204 yr 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
October 24, 20204 yr 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); }
October 24, 20204 yr setRegistryName("minecraft", "sugar"); You don't need this in your item class. Your deferred register already handles that Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
October 24, 20204 yr 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 October 24, 20204 yr by Luis_ST
October 24, 20204 yr 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());
October 24, 20204 yr 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 October 24, 20204 yr 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.