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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • That seems to have fixed it, thank you!
    • I am having some issues starting an RLCraft server on a minimal install of Debian 12. I have Java installed and I'm able to start the vanilla Minecraft server jar no problem and people can join and play without any issues, as soon as I try to create a new directory with the Forge jar the initial install with the INSTALLER jar works when I use the java command with the --installServer flag, but as soon as I try to start the server using the forge jar that is NOT labelled with installer I get the following error: A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.base/java.lang.reflect.Method.invoke(Method.java:569)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:70)         at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:34) Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')         at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34)         at net.minecraft.launchwrapper.Launch.main(Launch.java:28)         ... 6 more   I have tried using newer versions of Java directly from Oracle as well. Has anybody been successful in starting and running a RLCraft server from the terminal on a Linux machine? I cannot figure out why it doesn't want to work but the vanilla jar works without issue. Thank you in advance!
    • This is my latest attempt :  public class ManaScreen extends Screen { Mana mana = new Mana(); boolean removeManaBar = false; ResourceLocation manaBar = ResourceLocation.fromNamespaceAndPath(RSGArmoury.MOD_ID, "/textures/block/spawnable_arena_wall.png"); public ManaScreen() { super(Component.literal("Mana")); } @Override protected void init() { super.init(); Minecraft.getInstance().setScreen(this); } @Override public boolean isPauseScreen() { return false; } @Override public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) { pGuiGraphics.blit(manaBar, 10, -10, 0, 0, mana.getMana(), 10, mana.getMana(), 10); if (removeManaBar) { this.onClose(); return; } super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick); } public void addManaBar() { removeManaBar = false; Minecraft.getInstance().setScreen(new ManaScreen()); } public boolean removeManaBar() { return removeManaBar = true; } }
    • I tried a few different things that all didnt work. Right now I have nothing but what I had that seemed most likely to work was just a guiOverlay.blit(x, y, z, vx, vy, getMana()). I dont remember the exact code but it was somthing along those lines. It was in a new class extending screen I believe.
  • Topics

×
×
  • Create New...

Important Information

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