Jump to content

[1.9.4/1.10.2] Adding potion effect when a player eat food


TheMulti

Recommended Posts

Hi!

    My name is TheMulti. I have a problem with adding effects to food class. I want to give a player INSTANT_DAMAGE effect, but I can't do it.

Thank you in advance.

 

Here is my Solvent.java (If you need any other file , let me know - I will send them :) )

 

 

package themulti.gunwo.init;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameRegistry;
import themulti.gunwo.Gunwo;
import themulti.gunwo.Reference;

public class Solvent
{
public static Item SOLVENT;

public static void init()
{
	SOLVENT = registerItem(new ItemFood(-20, 1, true), "Solvent").setUnlocalizedName("Solvent").setMaxStackSize(16).setCreativeTab(ColorTabCraft.ColorTab);
}


public static void registerRenders()
{
	registerRender(SOLVENT);
}

public static void registerRender(Item item)
{
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}

public static Item registerItem(Item item, String name)
{
	return registerItem(item, name, null);
}

public static Item registerItem(Item item, String name, CreativeTabs tab)
	{

	GameRegistry.register(item, new ResourceLocation(Reference.MODID, name));
	Gunwo.proxy.registerItemSided(item);
	return item;
}

}

 

I would ask you to send me a revised file. :)

 

//

Sorry for my English , but I am from Poland.  :-\

Sorry for my English, I'm from Poland :)

Link to comment
Share on other sites

You need to create a class that extends ItemFood and use that to initialize your food item.

 

What should I put in this class?

 

Whether it should look like a client/commonproxy but with ItemFood extends?

Sorry for my English, I'm from Poland :)

Link to comment
Share on other sites

And in that class you will need to overwrite the @Override onFoodEaten and have something kinda like this

 

    protected void onFoodEaten(ItemStack itemStack, World world, EntityPlayer player)
    {	
        if (!world.isRemote)
        {
        		player.addPotionEffect(new PotionEffect(Potion.getPotionById(3), 5400, 0));
        }
    }

 

Use the Potion ID of the effect you want and the duration/strenght you need.

Link to comment
Share on other sites

Unless you want the food to only have one then you don't even have to make a new class apparently

 

// the 1 is for percentage as a decimal
customFoodItem = new ItemFood(5, false).setPotionEffect(PotionEffects.INVISIBLITY, 1);

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Unless you want the food to only have one then you don't even have to make a new class apparently

 

// the 1 is for percentage as a decimal
customFoodItem = new ItemFood(5, false).setPotionEffect(PotionEffects.INVISIBLITY, 1);

 

PotionEffects is not working in 1.10.2, but I found a counterpart: MobEffects.INSTANT_DAMAGE.

eyFnNtW.png

 

Here's a tutorial about making custom food, it's for 1.8, but shouldn't be too hard to fix up for 1.10, as long as you know some programming/java.

 

http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/custom-food/

 

I tried it, but It's not working to me... Maybe I'm stupid or too old Minecraft version. Rather, the first... :)

 

 

Sorry for my English, I'm from Poland :)

Link to comment
Share on other sites

It's telling you what's wrong, you have an int where you need a float.

That is not the problem it is true that PotionEffects doesn't exist in 1.10 instead use

 

//The numbers are Duration then level
(new PotionEffect(MobEffects.REGENERATION, 400, 1);

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

It's telling you what's wrong, you have an int where you need a float.

That is not the problem it is true that PotionEffects doesn't exist in 1.10 instead use

 

//The numbers are Duration then level
(new PotionEffect(MobEffects.REGENERATION, 400, 1);

 

 

Partially it works... Partially... :'(

 

xujN34F.png

Sorry for my English, I'm from Poland :)

Link to comment
Share on other sites

That is not the problem it is true that PotionEffects doesn't exist in 1.10 instead use

 

//The numbers are Duration then level
(new PotionEffect(MobEffects.REGENERATION, 400, 1);

 

Did you not see my post?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • hey, I'm trying to make a server with mods and it's not working. when I run it without mods, it works normally Log:[27maj2024 17:53:12.540] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 40.2.0, --fml.mcVersion, 1.18.2, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20220404.173914] [27maj2024 17:53:12.544] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 9.1.3+9.1.3+main.9b69c82a starting: java version 22.0.1 by Oracle Corporation [27maj2024 17:53:12.660] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/kamil/Desktop/server/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2314!/ Service=ModLauncher Env=SERVER [27maj2024 17:53:13.006] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\kamil\Desktop\server\libraries\net\minecraftforge\fmlcore\1.18.2-40.2.0\fmlcore-1.18.2-40.2.0.jar is missing mods.toml file [27maj2024 17:53:13.010] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\kamil\Desktop\server\libraries\net\minecraftforge\javafmllanguage\1.18.2-40.2.0\javafmllanguage-1.18.2-40.2.0.jar is missing mods.toml file [27maj2024 17:53:13.013] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\kamil\Desktop\server\libraries\net\minecraftforge\lowcodelanguage\1.18.2-40.2.0\lowcodelanguage-1.18.2-40.2.0.jar is missing mods.toml file [27maj2024 17:53:13.015] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\kamil\Desktop\server\libraries\net\minecraftforge\mclanguage\1.18.2-40.2.0\mclanguage-1.18.2-40.2.0.jar is missing mods.toml file [27maj2024 17:53:13.101] [main/INFO] [net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator/]: No dependencies to load found. Skipping! [27maj2024 17:53:15.035] [main/INFO] [mixin/]: Compatibility level set to JAVA_17 [27maj2024 17:53:15.075] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeserver' with arguments [] [27maj2024 17:53:15.139] [main/WARN] [mixin/]: Reference map 'bloodmagic.refmap.json' for bloodmagic.mixins.json could not be read. If this is a development environment you can ignore this message [27maj2024 17:53:15.415] [main/WARN] [mixin/]: Error loading class: net/minecraft/world/item/ItemStack (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.416] [main/WARN] [mixin/]: @Mixin target net.minecraft.world.item.ItemStack was not found placebo.mixins.json:ItemStackMixin [27maj2024 17:53:15.439] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.447] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.449] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.456] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.457] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.461] [main/WARN] [mixin/]: Error loading class: java/util/Map$Entry (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.461] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.463] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:15.463] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 66) [27maj2024 17:53:16.436] [main/WARN] [mixin/]: Error loading class: java/lang/Boolean (java.lang.IllegalArgumentException: Unsupported class file major version 66) Mods:https://ibb.co/xj5qHYK
    • How did you manage to get it working?
    • Hi Everyone! I was playing in modded singleplayer, and suddenly mobs stopped moving, I couldn't hit them, basically I could do things but nothing happened, like destroying blocks didn't drop it, things like that. When I tried to quit and save my world, it was just writing Saving World but nothing happened, and eventually I always had to restart my computer to stop minecraft. Can someone please help me find out what could cause the issue? Here is my debug log: https://pastebin.com/X9F0M9sq This is not the complete debug log, I was pasting the last couple of hundreds of rows because of the size. In case it's needed, I will repaste rows earlier. Thank you very much in advance!  
    • As stated in the Title, I can't download forge for minecraft 1.20.06. When I click on the install button i get the AD wall, but after 10 seconds i don't get the red button to install forge.  This problem also implies the older versions of Forge I also don't see any ads on the site. Does anybode know what to do?  
    • I want to download Forge 1.20.6, but when I press download, it redirects me to Adfocus and does not provide any download. I have never encountered such a problem when I downloaded Forge 1.18.2 at least 12 months ago.
  • Topics

×
×
  • Create New...

Important Information

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