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.

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

Featured Replies

Posted

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

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.

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

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.