Jump to content

Recommended Posts

Posted

I have a sword and want it to do more damage to something if the player hits it while the player is sprinting. How would I do so?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

You would most likely use the hitEntity method in Item.java and then tell the game:

if(player.isSpriniting) {
    //do your stuff
}

 

Alternatively, you could use the LivingAttackEvent but, not really useful considering you have a sword class. :P

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

With custom sword:

 

public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
    {
if (attacker instanceof EntityPlayer)
	if (sprinting - post above)
		target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 1.0F);

        stack.damageItem(1, attacker); // this or super.hitEntity is NEEDED, otherwise sword will not lose durability.
        return true;
    }

 

For vanilla

LivingAttackEvent (strongly prefered) or LivingHurtEvent if you want to apply damage after hit.

 

Disclaimer - I have no idea how #causePlayerDamage actually works, just noticed method in eclipse. There are several others if you want to know and also you can define your own (simply make new DamageSource).

1.7.10 is no longer supported by forge, you are on your own.

Posted

To be clear, the 1.0F in the attackEntityFrom() method should be changed to the amount of damage you want to do. You probably want to make it a multiplier of the base damage -- i.e. if sprinting doubles the damage, then multiply the base damage by 2.0F.

 

And the causePlayerDamage() method doesn't actually do any damage, it just makes sure the DamageSource has the player field properly filled in.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Nope none of that worked

 

Heres the code:

public boolean hitEntity(ItemStack p_77644_1_, EntityLivingBase target, EntityLivingBase attacker)
    {
	if(attacker.isSprinting()){
		System.out.println("sprint");
		target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer)attacker), 15);
	}
        return true;
    }

 

"sprint" never comes up in the console. And I don't need to damage the sword so that's why that's not there.

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Does it not detect the player is sprinting or, not add the damage? You need to be more specific instead of just saying. "Nope none of that worked". :P

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Does it not detect the player is sprinting or, not add the damage? You need to be more specific instead of just saying. "Nope none of that worked". :P

"sprint" never comes up in the console.

If I am reading that right, it does not pass the
if(attacker.isSprinting())

, so it does not detect that the player is sprinting.

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/

Posted

I seemed to of missed the bottom line of his post. Are you sure the entity you are using is the attacker? First, try switching them by using

if(target.isSpriniting())

just to see if the target is actually the attacker. After that make sure you are sprinting when you try to attack something. xD I know that may sound a bit silly but, the game could be stopping your sprinting as you hit.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

If you look at the call hierarchy for the hitEntity() method, it seems that the attacker is the last parameter (ItemStack calls it with the EntityPlayer), so I think that is correct.

 

I think the question is whether the method is being called at all. I would put another console statement at the beginning of the method.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Tested here.. this function cannot be used for this...

 

Same if trying with onLeftClickEntity()..

 

 

Probably when you hit anything you stop the sprint action.

 

Try a sync with onupdate call to create a "ghost sprint status" inside the sword...

 

example:

 

on update: if player is sprinting set flag to true.. if player not sprinting count 3 ticks and set flag to false.

 

onhit/onleftclickentity: if flag true, do more damage.

 

 

Maybe it can work...

// BSc CIS, hardcore gamer and a big fan of Minecraft.

 

TmzOS ::..

Posted

@TamzOS That could work. But, how would he be able to get the instance of EntityPlayer? He couldn't use Minecraft.getMinecraft() considering it needs to be ran server-side.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Try something like this..

 

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) 
{
	if(!world.isRemote && entity instanceof EntityPlayer && ((EntityPlayer) entity).getCurrentEquippedItem() != null)
	{

		if(((EntityPlayer) entity).isSprinting())
		{
			this.sprint = true;
			System.out.println("aaaa");
		}
		else
		{
			this.counter++;
			if(this.counter>5)
			{
				this.counter=0;
				this.sprint = false;
			}
		}
	}
}

 

 

// BSc CIS, hardcore gamer and a big fan of Minecraft.

 

TmzOS ::..

Posted

Oh! Didn't realize onUpdate had params. O.o Most update functions I use don't carry those.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

You can't hold fields inside Item itself.

You need to store them into NBT of given ItemStack (there is one on onUpdate()).

onUpdate() is called always when item is in player's inventory, do additional check if player is holding given item (the one that actually check for sprinting).

 

1.7.10 is no longer supported by forge, you are on your own.

Posted

You can't hold fields inside Item itself.

You need to store them into NBT of given ItemStack (there is one on onUpdate()).

onUpdate() is called always when item is in player's inventory, do additional check if player is holding given item (the one that actually check for sprinting).

 

Since the sprinting status is temporary (no need to save whether player is sprinting) and because it is not tied specifically to an item, I would simply create a static field in my main mod class and use that.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Bad, bad, bad :o

 

I corrected him, because he used Item#onUpdate method with this.sprint, which obviously points out to field in Item.class which is NOT acceptable.

 

Try something like this..

@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) 
{
	....
	this.sprint = true;
	this.counter++;
	...
}

 

Your idea is bad, jabelar. Holding value in MainMod.class is ridiculus since it'll be for client, both onUpdate() and damage-dealing runs on server.

 

Yes, field is temporary and doesn't need saving, it still needs to be saved per-player, your would need either IExtendedItemProperties to get that working per-player (and like said before, no need to save it) or simplier way which I wrote in previous post - save temporary value in Item's NBT itself. Note: Simplier != Better, IEEP is always superior in stufff like that.

1.7.10 is no longer supported by forge, you are on your own.

Posted

You're right about multiplayer, it would have to be an map field or something. So I guess it isn't that simple.

 

Are you sure the field wouldn't be available on the server though? I think it would but that the problem would be that a single boolean couldn't cover all the players..

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.