Jump to content

can i set the critical hit damage on a sword/tool


TwIxToR_TiTaN

Recommended Posts

Can you check the player's equipped weapon/tool, and whether a hit is a crit? If so, you might be able to work something in a LivingHurtEvent.

 

If [DamageSource is Player]
    if [Hit is a Crit]     //Not sure if/how this can be checked. EntityPlayer.java line 1330 may be a start
         If [Player Equipping Proper Weapon]          // If you only want the buffed criticals to apply to certain weapons/tools          
            ammount = weapon.base + crit bonus             //Yes. ammount is misspelled. 

Link to comment
Share on other sites

you do: [.code]YOUR TEXT[/.code]

(remove the dots)

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

maybe this works:

 

@ForgeSubscribe
public void onEntityHit(LivingHurtEvent event)
{
	if (!(event.source instanceof EntityDamageSource))
	{
		return;
	}

	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();

	if (!(ent instanceof EntityPlayer))
	{
		return;
	}

	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();

	if (!(weapon.getItem() instanceof *PUT_YOUR_SWORD_CLASS_HERE*)) //EDIT: forgot the .getItem()
	{
		return null;
	}

	/**
	 * Copied from {@link EntityPlayer#1345}
	 */
	boolean flag = player.fallDistance > 0.0f && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(Potion.blindness) && !player.isRiding();

	if (flag)
	{
		event.ammount += *PUT_CRIT_AMOUNT_HERE*;
	}
}

 

 

If I was any help please hit that "Thank You" button.

Link to comment
Share on other sites

maybe this works:

 

@ForgeSubscribe
public void onEntityHit(LivingHurtEvent event)
{
	if (!(event.source instanceof EntityDamageSource))
	{
		return;
	}

	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();

	if (!(ent instanceof EntityPlayer))
	{
		return;
	}

	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();

	if (!(weapon.getItem() instanceof *PUT_YOUR_SWORD_CLASS_HERE*)) //EDIT: forgot the .getItem()
	{
		return null;
	}

	/**
	 * Copied from {@link EntityPlayer#1345}
	 */
	boolean flag = player.fallDistance > 0.0f && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(Potion.blindness) && !player.isRiding();

	if (flag)
	{
		event.ammount += *PUT_CRIT_AMOUNT_HERE*;
	}
}

do i need to put this code in a eventhandler class or somthing?

Only code when your having fun doing it.

Link to comment
Share on other sites

ok so i modified your code to eliminate errors but i cant seem to make it work xD this is funny coincidence i was trying to do this before i cam on here so yeah.

 

@EventHandler
public void onEntityHit(LivingHurtEvent event)
{
	if (!(event.source instanceof EntityDamageSource))
	{
		return;
	}

	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();

	if (!(ent instanceof EntityPlayer))
	{
		return;
	}

	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();

	if (!(weapon.getItem() instanceof LightSteelRapier))
	{
		return;
	}


	Random random1Generator = new Random();
	int ran1 = random1Generator.nextInt(25);{

	if (ran1 == 10)
	{
		event.ammount += 10000000;
	}}
}

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

i found a problem with you code? a bug or somthing?

 

if (!(weapon.getItem() instanceof *PUT_YOUR_SWORD_CLASS_HERE*)) //EDIT: forgot the .getItem()

{

return null;

}

 

 

on this part, the return null is an error, it suggests you remove the "null" but if you do when you hit something with your hand it crashed the game saying ee al one method not closed or something like that and it says that this line is the problem? anyone got any ideas?

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

i figured out the void bit, i was questioning the code, i didnt write it if you read the above parts of the post. Also would the null check be something like this?

 

@ForgeSubscribe
public void onEntityHit1(LivingHurtEvent event)
{
	if (!(event.source instanceof EntityDamageSource))
	{
		return;
	}
	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();
	if (!(ent instanceof EntityPlayer))
	{
		return;
	}
	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();
	if (!(weapon.getItem() == null)){
	if (weapon.getItem() instanceof ImmortalTheSkewer)
	{
	Random random1Generator = new Random();
	int ran1 = random1Generator.nextInt(100);{
	if (ran1 < 2){
		event.ammount += 100;
	}}}}
}

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

but if the weapon = null i dont want it do do anything xD

 

this works with my old version of the event, but when i attack with the hand it crashes and says AL lib: (EE) alc_cleanup: 1 device not closed.

 

any other tool or item works fine, so i understand what your saying but isnt it if whats in my hand isn't the specified item it should not do anything? and surly hand does not equal weapon of choice so why the crash???

 

maybe because they hand isnt an item at all...

 

so, i put if weapon item doesnt equal nothing (hand) then check if its the specified item, so why does this not worl?

((!(weapon.getItem() == null)){

 

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

and finally just for luck,

can you see any errors or modifications that would make the code better?

 

@ForgeSubscribe
public void onEntityHit1(LivingHurtEvent event)
{
	if (!(event.source instanceof EntityDamageSource))
	{
		return;
	}
	EntityDamageSource dmgSource = (EntityDamageSource) event.source;
	Entity ent = dmgSource.getEntity();
	if (!(ent instanceof EntityPlayer))
	{return;}
	Random random1Generator = new Random();
	int ran1 = random1Generator.nextInt(100);
	EntityPlayer player = (EntityPlayer) ent;
	ItemStack weapon = player.getCurrentEquippedItem();
	if (!(weapon == null)){
if (weapon.getItem() instanceof MythicalVampiricBlade)
		{if (ran1 < 13){
		player.addPotionEffect(new PotionEffect(Potion.field_76444_x.getId(), 600, 4));}}
if (weapon.getItem() instanceof ImmortalTheSkewer)
		{if (ran1 < 2){
		event.ammount += 100;}}
if (!(weapon.getItem() instanceof MythicalSteelRapier))
		{if (ran1 < 80)
		{event.ammount += 10;}}
if (!(weapon.getItem() instanceof SharpWoodSword) || (weapon.getItem() instanceof SharpStoneSword) || (weapon.getItem() instanceof SharpIronSword )|| (weapon.getItem() instanceof SharpSteelSword) || (weapon.getItem() instanceof SharpDiamondSword) || (weapon.getItem() instanceof SharpGoldSword))
		{if (ran1 < 2){
			event.ammount += 100;
		}}}}

 

btw please don't steal my ideas D:

 

-EDIT i just found a misplaced construct have changed the code above, and again xD

Use examples, i have aspergers.

Examples make sense to me.

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.