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

    • diesieben07
      Cannot create a modded forge server for 1.16.4

      By diesieben07 · Posted 2 minutes ago

      1.16.4-35.1.37 and onwards should work on Java 15.
    • DeNub
      Cannot create a modded forge server for 1.16.4

      By DeNub · Posted 7 minutes ago

      Update to which version? 1.16.4 - 35.1.37?
    • Dr.Nickenstein
      Method to get the current durability?

      By Dr.Nickenstein · Posted 20 minutes ago

      Thank you so much!
    • diesieben07
      Method to get the current durability?

      By diesieben07 · Posted 40 minutes ago

      ItemStack#getDamage
    • diesieben07
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By diesieben07 · Posted 41 minutes ago

      You can use RangedWrapper to expose only a range of another IItemHandler.
  • Topics

    • DeNub
      3
      Cannot create a modded forge server for 1.16.4

      By DeNub
      Started 2 hours ago

    • Dr.Nickenstein
      2
      Method to get the current durability?

      By Dr.Nickenstein
      Started 2 hours ago

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

      By Klarks
      Started Thursday at 06:22 AM

    • Gubipe
      3
      Minecraft.getMinecraft().thePlayer.swingItem(); wont attack

      By Gubipe
      Started 9 hours ago

    • TurtlesAreHot
      4
      [1.16.4] License Issue..

      By TurtlesAreHot
      Started 11 hours ago

  • Who's Online (See full list)

    • diesieben07
    • DeNub
    • Dr.Nickenstein
    • LK1905
    • P0SCH1T0
    • loordgek
    • Novârch
  • 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