Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Adding more damage to a sword if a player is sprinting


Asweez
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Whenever I try to start my server I get this crash: [14:05:21] [main/FATAL]: Failed to start the minecraft server com.google.gson.JsonParseException: Error loading registry data: Not a valid resource location: #minecraft:infiniburn_end Non [a-z0-9_.-] character in namespace of location: #minecraft:infiniburn_end         at net.minecraft.core.RegistryAccess.m_175498_(RegistryAccess.java:156) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]         at net.minecraft.core.RegistryAccess.m_175503_(RegistryAccess.java:155) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at net.minecraft.core.RegistryAccess.m_175500_(RegistryAccess.java:146) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at net.minecraft.resources.RegistryReadOps.m_195841_(RegistryReadOps.java:37) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at net.minecraft.resources.RegistryReadOps.m_179866_(RegistryReadOps.java:31) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at net.minecraft.server.Main.main(Main.java:161) ~[server-1.18.1-20211210.034407-srg.jar%2390!/:?]         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:46) ~[fmlloader-1.18.1-39.0.75.jar%2361!/:?]         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-9.1.0.jar%2343!/:?]         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) ~[bootstraplauncher-1.0.0.jar:?]         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]         at org.jmt.mcmt.modlauncher.FastUtilTransformerService.argumentValues(FastUtilTransformerService.java:200) ~[jmt_mcmt-1.18.1-0.24.2-118-packaged.jar%2375!/:?]         at cpw.mods.modlauncher.TransformationServicesHandler.lambda$offerArgumentResultsToServices$5(TransformationServicesHandler.java:80) ~[modlauncher-9.1.0.jar%235!/:?]         at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[?:?]         at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[?:?]         at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779) ~[?:?]         at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?]         at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?]         at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?]         at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?]         at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]         at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[?:?]         at cpw.mods.modlauncher.TransformationServicesHandler.offerArgumentResultsToServices(TransformationServicesHandler.java:80) ~[modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.ArgumentHandler.processArguments(ArgumentHandler.java:71) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.TransformationServicesHandler.processArguments(TransformationServicesHandler.java:68) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:50) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.Launcher.run(Launcher.java:87) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.0.jar%235!/:?]         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] container@pterodactyl~ Server marked as offline... [Game2 Daemon]: ---------- Detected server process in a crashed state! ---------- [Game2 Daemon]: Exit code: 1 [Game2 Daemon]: Out of memory: false [Game2 Daemon]: Aborting automatic restart, last crash occurred less than 120 seconds ago.
    • why, you have Event instance so call the getters we all have the code of the Event the Event exist to perform an action at a specific 'time'/'action' in the game what are you talking about
    • I am sorry, but I have zero idea what you are trying to say.
    • Thanks for the tip, I managed to get the data I wanted in the return parameters of the listened event. Here is part of the code @SubscribeEvent public static void Demo02(LivingHurtEvent event) { System.out.println("sadawedawdawdawdadwa" + '\n' + event.getAmount()); }  
    • update Forge to the latest version and do not put your server on OneDrive
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.