Jump to content

[1.12] Making a Strength-like potion effect


Heen

Recommended Posts

Hello again!

 

I hope this isn't too difficult to conquer, but I'm trying to make a potion effect that is similar to strength. Specifically trying to take the current damage being done by the player and multiply it by 1.75 while under the effect.

The potion effect is being applied to the player, but the effect of it is not working as intended.

This is my not quite exciting attempt: 

@SubscribeEvent
	public void newPotionHandling(AttackEntityEvent e){
	if(e.getEntityPlayer().isPotionActive(MyMod.Strengthlikepotion)){
		if(e.getEntityPlayer().getActivePotionEffect(MyMod.Strengthlikepotion).getDuration()==0){
			e.getEntityPlayer().removePotionEffect(MyMod.Strengthlikepotion);
			return;
		}
		else{
			EntityPlayer inquesiton = e.getEntityPlayer();
			ItemStack primary = inquesiton.getHeldItemMainhand();
			ItemStack seconary = inquesiton.getHeldItemOffhand();
			if(primary.isItemStackDamageable())
			primary.damageItem(1, inquesiton);
			if(seconary.isItemStackDamageable())
			seconary.damageItem(1, inquesiton);
			//System.out.println(e.getEntityPlayer().getHeldItemOffhand().toString());
			e.getTarget().attackEntityFrom(DamageSource.GENERIC,(float) (e.getEntityPlayer().getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()*1.75));
		}
	}
	}

The attackEntityFrom() call is entirely preventing the damage type from the weapon/empty hand/tool from taking effect at all and is only doing the damage done with the method. Sort of like assigning damage to the target on attack.

I feel as though this approach is not the right way of doing it, any experience or even better the reference to how the vanilla strength potion works would be greatly appreciated because I can't seem to get to it with my IDE.

 

Thanks!

Link to comment
Share on other sites

2 hours ago, diesieben07 said:

Why are you damaging the player's current items?

I'm not doing all the specific handling of which items are getting damaged (like checking to see if they are the ones applicable), but at the moment the only thing applying the potion effect is when the player has set items equipped in the mainhand + offhand. Like dual wielding weapons. Will report back when I change the event parameters.

 

EDIT: Works perfectly now! Thanks diesieben07!

Edited by Heen
Link to comment
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.
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.