Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] Passing Potion Effects As Potion Effect [1.16.4][Potions Effects][Food]
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Unbreachable

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

By Unbreachable, January 14 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Unbreachable    0

Unbreachable

Unbreachable    0

  • Tree Puncher
  • Unbreachable
  • Members
  • 0
  • 2 posts
Posted January 14 (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 January 14 by Unbreachable
solved
  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    160

ChampionAsh5357

ChampionAsh5357    160

  • World Shaper
  • ChampionAsh5357
  • Members
  • 160
  • 1019 posts
Posted January 14
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.

  • Quote

Share this post


Link to post
Share on other sites

Unbreachable    0

Unbreachable

Unbreachable    0

  • Tree Puncher
  • Unbreachable
  • Members
  • 0
  • 2 posts
Posted January 14
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.

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Linky132
      [1.16.5] How do I set entity attributes?

      By Linky132 · Posted 13 minutes ago

      Hi, could anyone tell me how to set entity attributes for my custom mob, please? I copied the code that most of the vanilla mobs use, but judging from the log, it doesn't seem to be working. I found this post, but it appears to be out of date.   Thanks.
    • Woodside
      [1.15.2] Render as 2D icon in GUI, 3D model in hand

      By Woodside · Posted 46 minutes ago

      In the BakedModel class in SeparatePerspectiveModel, I changed func_230044_c_()/isSideLit() to return always false. That fixed the lighting issue with the GUI icon, but I cannot tell if it had any effect on the 3D model or not. It doesn't seem to have.
    • juggler
      Modded server stall on startup

      By juggler · Posted 1 hour ago

      I'm very sorry this was entirely user error and something else on my network was causing me to think that the server was not starting but actually it was running and waiting for client connections but clients weren't seeing it.   I'll close this issue and again sorry for the confusion.
    • diesieben07
      game launch fail

      By diesieben07 · Posted 2 hours ago

      User was banned for piracy. Buy the game.
    • C0nnieD
      game launch fail

      By C0nnieD · Posted 2 hours ago

  • Topics

    • Linky132
      0
      [1.16.5] How do I set entity attributes?

      By Linky132
      Started 13 minutes ago

    • Woodside
      16
      [1.15.2] Render as 2D icon in GUI, 3D model in hand

      By Woodside
      Started Sunday at 08:26 PM

    • juggler
      1
      Modded server stall on startup

      By juggler
      Started 3 hours ago

    • C0nnieD
      13
      game launch fail

      By C0nnieD
      Started 5 hours ago

    • Klarks
      18
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By Klarks
      Started 10 hours ago

  • Who's Online (See full list)

    • diesieben07
    • Jake_Titan
    • CHRISTMASDOG24
    • ozi
    • Nite_Shad0w
    • Fars3O_
    • El_Redstoniano
    • thorstenschwager
    • gabiskyland youtube fr
    • dollarflower1
    • dotifo7120
    • Linky132
    • MemeMan
    • FloweyTF
    • Moomallowz
    • magn919
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] Passing Potion Effects As Potion Effect [1.16.4][Potions Effects][Food]
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community