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.

Featured Replies

Posted
comment_145556

I got it working, but when the time goes to 0 the potion effect still lasts. I'm trying to make an immortal potion so when they drink it nothing can damage them for 25 seconds.

 

Main:

 

 

 

        public static Potion ImmortalPotion;

 

@PreInit

public void load(FMLPreInitializationEvent event)

{

Potion[] potionTypes = null;

 

for (Field f : Potion.class.getDeclaredFields())

{

f.setAccessible(true);

try

{

if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a"))

{

Field modfield = Field.class.getDeclaredField("modifiers");

modfield.setAccessible(true);

modfield.setInt(f, f.getModifiers() & ~Modifier.FINAL);

 

potionTypes = (Potion[])f.get(null);

final Potion[] newPotionTypes = new Potion[256];

System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length);

f.set(null, newPotionTypes);

}

}

catch (Exception e)

{

System.err.println("Severe error, please report this to the mod author:");

System.err.println(e);

}

 

 

MinecraftForge.EVENT_BUS.register(new AlchemyMainEventHooks());

}

}

 

@Init

public void load(FMLInitializationEvent event)

{

ImmortalPotion = (new PotionAlchemy(32, false, 0)).setIconIndex(0, 0).setPotionName("potion.ImmortalPotion");

}

 

 

 

Event Hook:

 

 

        @ForgeSubscribe

public void onEntityUpdate(LivingUpdateEvent event)

{

if (event.entityLiving.isPotionActive(AlchemyMain.ImmortalPotion))

{

if (event.entityLiving.worldObj.rand.nextInt(20) == 0)

{

PlayerCapabilities.disableDamage = true;

}

 

if (event.entityLiving.getActivePotionEffect(AlchemyMain.ImmortalPotion).getDuration() == 0)

{

event.entityLiving.removePotionEffect(AlchemyMain.ImmortalPotion.id);

PlayerCapabilities.disableDamage = false;

return;

}

 

}

}

 

 

 

If im missing anything let me know, thanks.

comment_145569

Where did you registered the potion to the array? You didn't in Main class.

If you didn't, try adding the potion to the array.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

comment_145588

It seems that PotionEfect#getDuration() does not return 0 when LivingUpdateEvent called.

Maybe changing 0 to 1 would solve your problem.

 

EDIT: No, Don't do the suggestion above.

There is some methods in Potion meeting your needs.

 

So.

1. Make your own Potion class,

2. Override applyAttributesModifiersToEntity, and add ability there.

3. Override removeAttributesModifiersFromEntity, and remove ability there.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • Author
comment_145620

Like this?

 

@Override

public void applyAttributesModifiersToEntity(EntityLivingBase par1EntityLivingBase, BaseAttributeMap par2BaseAttributeMap, int par3)

    {

PlayerCapabilities.disableDamage = true;

    }

 

@Override

public void removeAttributesModifiersFromEntity(EntityLivingBase par1EntityLivingBase, BaseAttributeMap par2BaseAttributeMap, int par3)

    {

PlayerCapabilities.disableDamage = false;

    }

comment_145825

Like this?

 

@Override

public void applyAttributesModifiersToEntity(EntityLivingBase par1EntityLivingBase, BaseAttributeMap par2BaseAttributeMap, int par3)

    {

PlayerCapabilities.disableDamage = true;

    }

 

@Override

public void removeAttributesModifiersFromEntity(EntityLivingBase par1EntityLivingBase, BaseAttributeMap par2BaseAttributeMap, int par3)

    {

PlayerCapabilities.disableDamage = false;

    }

 

Correct, try that.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

comment_145884

Sorry, there was some mistakes I did.

1. You have to check if the Entity is player, and get the PlayerCapabilities for the player, and disable Damage for that.

2. Does applyAttributesModifiersToEntity not called? Check it.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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.