Jump to content

Recommended Posts

Posted (edited)

For the deferred registry method, you can do:

public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(ForgeRegistries.POTION_TYPES, Main.MOD_ID);
  
public static final RegistryObject<Potion> EFFECT_NAME = POTIONS.register("effect_name", () -> new Potion(new EffectInstance[] {new EffectInstance(Effects.RESISTANCE, 9600), new EffectInstance(Effects.REGENERATION, 9600), new EffectInstance(Effects.FIRE_RESISTANCE, 9600)}));

 

Where 9600 is the duration, and can be different values for each one.

 

To create a brewing recipe for this, you have 2 options: using an access transformer, or reflection. These are required because we can't directly access the registry method Minecraft uses for brewing. Reflection is less buggy, but requires more code. To do this, copy:

private static Method brewing_mixes;

private static void addMix(Potion start, Item ingredient, Potion result) {
    if(brewing_mixes == null) {
        brewing_mixes = ObfuscationReflectionHelper.findMethod(PotionBrewing.class, "addMix", Potion.class, Item.class, Potion.class);
        brewing_mixes.setAccessible(true);
    }

    try {
        brewing_mixes.invoke(null, start, ingredient, result);
    } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        e.printStackTrace();
    }
}

And then your recipe:

public static void addBrewingRecipes() {
    addMix(Potions.AWKWARD, ModItems.ITEM_NAME, EFFECT_NAME.get()); }

Where the first entry is the input potion, second is the brewing item, and third is the output.

 

Edited by urbanxx001
Posted
6 hours ago, urbanxx001 said:

For the deferred registry method, you can do:


public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(ForgeRegistries.POTION_TYPES, Main.MOD_ID);
  
public static final RegistryObject<Potion> EFFECT_NAME = POTIONS.register("effect_name", () -> new Potion(new EffectInstance[] {new EffectInstance(Effects.RESISTANCE, 9600), new EffectInstance(Effects.REGENERATION, 9600), new EffectInstance(Effects.FIRE_RESISTANCE, 9600)}));

 

Where 9600 is the duration, and can be different values for each one.

 

To create a brewing recipe for this, you have 2 options: using an access transformer, or reflection. These are required because we can't directly access the registry method Minecraft uses for brewing. Reflection is less buggy, but requires more code. To do this, copy:


private static Method brewing_mixes;

private static void addMix(Potion start, Item ingredient, Potion result) {
    if(brewing_mixes == null) {
        brewing_mixes = ObfuscationReflectionHelper.findMethod(PotionBrewing.class, "addMix", Potion.class, Item.class, Potion.class);
        brewing_mixes.setAccessible(true);
    }

    try {
        brewing_mixes.invoke(null, start, ingredient, result);
    } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        e.printStackTrace();
    }
}

And then your recipe:


public static void addBrewingRecipes() {
    addMix(Potions.AWKWARD, ModItems.ITEM_NAME, EFFECT_NAME.get()); }

Where the first entry is the input potion, second is the brewing item, and third is the output.

 

I put that without the recipe, because i want the effect to be given when a player eats a certain food, but it didn't add anything. Is it an effect? Is it a potion item? I didn't add anything that relates to those both

Posted (edited)
7 hours ago, SonPlaying said:

it didn't add anything. Is it an effect? Is it a potion item?

When you register it as a potion without a brewing recipe, it's technically just an effect, because there's no way to access it in-game.So normally when you want to register an effect on it's own, you do it as a potion.

 

7 hours ago, SonPlaying said:

 i want the effect to be given when a player eats a certain food

In that case, we can register items with effects attached. To do so, we add the effects as part of the item's food properties. First the item:

 

public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Reference.MOD_ID);

public static final RegistryObject<Item> ITEM_NAME = ITEMS.register("item_name", () -> new Item(new Item.Properties().food(ModFood.ITEM_NAME).group(ItemGroup.FOOD)));

And now we add the food properties in a separate class, ModFood:

 

public static final Food ITEM_NAME = new Food.Builder().hunger(1).saturation(2.0f).effect(new EffectInstance(Effects.RESISTANCE, 1200, 3), 1.0F).effect(new EffectInstance(Effects.REGENERATION, 300, 2), 1.0F).effect(new EffectInstance(Effects.FIRE_RESISTANCE, 300, 1), 1.0F).build();

When modifying the effects, (we'll look at resistance as an example), the first value is the duration, the second is the amplifier (Resistance I, Resistance II, etc.), and the last is the probability it will occur upon eating (a value between 0 and 1).

Edited by urbanxx001
Posted (edited)
13 minutes ago, urbanxx001 said:

 

In that case, we can register items with effects attached. To do so, we add the effects as part of the item's food properties. First the item:

 


public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Reference.MOD_ID);

public static final RegistryObject<Item> ITEM_NAME = ITEMS.register("item_name", () -> new Item(new Item.Properties().food(ModFood.ITEM_NAME).group(ItemGroup.FOOD)));

And now we add the food properties in a separate class, ModFood:

 


public static final Food ITEM_NAME = new Food.Builder().hunger(1).saturation(2.0f).effect(new EffectInstance(Effects.RESISTANCE, 1200, 3), 1.0F).effect(new EffectInstance(Effects.REGENERATION, 300, 2), 1.0F).effect(new EffectInstance(Effects.FIRE_RESISTANCE, 300, 1), 1.0F).build();

When modifying the effects, (we'll look at resistance as an example), the first value is the duration, the second is the amplifier (Resistance I, Resistance II, etc.), and the last is the probability it will occur upon eating (a value between 0 and 1).

It just adds the food that gives the effect separately one by one.

 

Main question is, how to make a custom single effect(such as absorption, regeneration) that reduces the damage received on the user, regenerates the user, and makes the player fireproof. In other words, a mix of all those effects(regeneration, resistance, fire resitance) in one custom effect, so the food doesn't give the effects separately.

 

 

Edited by SonPlaying
Posted
10 minutes ago, SonPlaying said:

It just adds the food that gives the effect separately one by one.

It should give you them all at the same time. I tested it myself and it works. Have you done anything else related to effects, like a custom item class, that's affecting it?

Posted
8 minutes ago, urbanxx001 said:

It should give you them all at the same time. I tested it myself and it works. Have you done anything else related to effects, like a custom item class, that's affecting it?

Yes, it does work but that's not what i want.

Posted (edited)

Ohh I gotcha, sorry. In that case, register the effect like a potion in my first reply, and then access it in the food properties like:

public static final Food ITEM_NAME = new Food.Builder().hunger(1).saturation(0.8f).effect(new EffectInstance(ModEffects.EFFECT_NAME, 1200, 3), 1.0F).build();

 

Where ModEffects is the class you registered the effect in. Edit: fixed the line from being cut-off.

Edited by urbanxx001
Posted
4 minutes ago, urbanxx001 said:

Ohh I gotcha, sorry. In that case, register the effect like a potion in my first post, and then access it in the food properties like:


public static final Food ITEM_NAME = new Food.Builder().hunger(1).saturation(0.8f).effect(new EffectInstance(ModEffects.EFFECT_NAME, 1200, 3), 1.0F).build();

 

Where ModEffects is the class you registered the effect in. Edit: fixed the line from being cut-off.

I'm not in my PC right now, so I'll try it later.

Posted (edited)
20 hours ago, urbanxx001 said:

Did it work for you?

It says i should change my effect registry to Effect. You told me to register it as a Potion, right?

I registered the items as

Quote

public static final RegistryObject<Potion> INVULNERABILITY_EFFECT = POTIONS.register("invulnerability_effect", () -> new Potion(new EffectInstance[]
            {new EffectInstance(Effects.REGENERATION, 15*20), new EffectInstance(Effects.RESISTANCE, 15*20),
                    new EffectInstance(Effects.FIRE_RESISTANCE, 15*20)}));

 

then i put it in my item :

Quote

.effect(new EffectInstance(Registry.INVULNERABILITY_EFFECT, 15*20, 1), 1.0F)

But it errors and says that i should change the effect type to Effect

Edited by SonPlaying
more info
Posted
Just now, Beethoven92 said:

You are getting a RegistryObject from this, not the actual object..you need to chain also the get() method

That errors too for some reason, saying that EffectInstance is undefined. I'm not on my PC right now.

Posted (edited)

I'm not sure if this will hide the effect names like you want, but try:

public static final DeferredRegister<Effect> EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, Main.MOD_ID);

public static RegistryObject<Effect> INVULNERABILITY = EFFECTS.register("invulnerability", InvulnerabilityEffect::new);

 

(Yes, ForgeRegistries.POTIONS). And then, in the InvulnerabilityEffect class:

public class InvulnerabilityEffect extends Effect {

    public InvulnerabilityEffect() {
        super(EffectType.BENEFICIAL, color);
    }

    @Override
    public void performEffect(LivingEntity entityLivingBaseIn, int amplifier) {
    entityLivingBaseIn.addPotionEffect(new EffectInstance(Effects.REGENERATION, 432, 1));
    entityLivingBaseIn.addPotionEffect(new EffectInstance(Effects.RESISTANCE, 432, 1));
    entityLivingBaseIn.addPotionEffect(new EffectInstance(Effects.FIRE_RESISTANCE, 432, 1));
}

    @Override
    public void affectEntity(@Nullable Entity source, @Nullable Entity indirectSource, LivingEntity entityLivingBaseIn, int amplifier, double health) {
    this.performEffect(entityLivingBaseIn, amplifier);
}

 

Where color must be replaced with a hex number. Then the item food properties will accept it with:

ModEffects.INVULNERABILITY.get()

If this doesn't work, you'll probably need to delve in the source code and replicate the 3 effects that way. You're right that heal() is tied to regeneration. Resistance and fire resistance are handled by attackEntityfrom() and applyPotionDamageCalculation() methods, respectively.

Edited by urbanxx001

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.