Jump to content

[SOLVED][1.6.4] Trying to make a custom potion effect


Recommended Posts

Posted

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.

Posted

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.

Posted

Oh I misread the Potion class. The constructor would automatically registers the potion.

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

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

Posted

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.

Posted

In my main class

@Init

  public void load(FMLInitializationEvent event)

  {

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

  }

 

is the "PotionAlchemy" the potion class?

Posted

Of course it is your potion class :  PotionAlchemy class.

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

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

Posted

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;

    }

Posted

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.

Posted

What was problem.? Doesn't the code work?

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

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

Posted

Ah yes of course.

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

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

Posted

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

×   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.