Jump to content

[SOLVED] Passing Potion Effects As Potion Effect [1.16.4][Potions Effects][Food]


Recommended Posts

Posted (edited)

Up front, I am very new to modding in forge, dabbled a bit in 1.6 (years ago) and just now getting back into it.

 

I have created the following abstracted class for new foods.

 

Quote

package com.unbreachable.mcplus.item;

import com.unbreachable.mcplus.MCPlusMod;
import net.minecraft.item.Food;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;

public class FoodItemBase extends Item {

    public FoodItemBase(ItemGroup group, int hunger, float saturation,
                        Effect item_effect, int duration, int amp, float propability){
        super(new Properties().group(group)
                .food(new Food.Builder()
                        .hunger(hunger).saturation(saturation)
                        .effect(() -> new EffectInstance(item_effect, duration, amp), propability)
                        .build()));
    }
}

 

This gets called when registering the item/food in the differed register class. See below.

Quote

public static final RegistryObject<Item> COPPERED_APPLE =
     Registration.ITEMS.register("coppered_apple", () -> new FoodItemBase(MCPlusMod.MCPLUS_TAB, 5,
     1.5f, Effects.GLOWING, 300, 1, 0.5f));

 

This works as intended, in the FoodItemBase class, the .effect() call is looking for a Effects.XXX variable to get passed, however it must get passed into a Effect object in order to work. if you try to pass it as an Effects variable it throws an error stating "Effects can not be converted to effect"

 

So my question is why does EffectInstance want a Effects variable to declare the type of potion effect in a normal none abstracted call, but when abstracted it wants the Effects variable passed as a Effect object?

Thanks in advance!

 

 

Example: This does not work

Quote

package com.unbreachable.mcplus.item;

import com.unbreachable.mcplus.MCPlusMod;
import net.minecraft.item.Food;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;

public class FoodItemBase extends Item {

    public FoodItemBase(ItemGroup group, int hunger, float saturation,
                        Effects item_effect, int duration, int amp, float propability){
        super(new Properties().group(group)
                .food(new Food.Builder()
                        .hunger(hunger).saturation(saturation)
                        .effect(() -> new EffectInstance(item_effect, duration, amp), propability)
                        .build()));
    }
}

 

Quote

public static final RegistryObject<Item> COPPERED_APPLE =
     Registration.ITEMS.register("coppered_apple", () -> new FoodItemBase(MCPlusMod.MCPLUS_TAB, 5,
     1.5f, Effects.GLOWING, 300, 1, 0.5f));

ERROR:"Effects type can not be converted the Effect type"

Edited by Unbreachable
solved
Posted
1 hour ago, Unbreachable said:

So my question is why does EffectInstance want a Effects variable to declare the type of potion effect in a normal none abstracted call, but when abstracted it wants the Effects variable passed as a Effect object?

It doesn't want an Effects object nor does it matter what class its passed from. It just wants an Effect of some kind. MCP names classes their object type appended with an s if its holding those specific objects (e.g. All vanilla Block are found in Blocks, Item in Items, etc.). There is no error that can occur with your code. Although, this will error anyways during registration if you ever decide to supply your own effect. This is because an Item is registered before an Effect. This parameter/argument should properly be wrapped in a supplier to avoid this issue.

Posted
8 hours ago, ChampionAsh5357 said:

It doesn't want an Effects object nor does it matter what class its passed from. It just wants an Effect of some kind. MCP names classes their object type appended with an s if its holding those specific objects (e.g. All vanilla Block are found in Blocks, Item in Items, etc.). There is no error that can occur with your code. Although, this will error anyways during registration if you ever decide to supply your own effect. This is because an Item is registered before an Effect. This parameter/argument should properly be wrapped in a supplier to avoid this issue.

Okay cool. Makes sense. Thanks! and Ill change that parameter to a supplier.

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.