Jump to content

[Solved] [1.7.2] Custom Combat - Better alternative to entity.setHealth()?


Recommended Posts

Posted

So I have been working on a mod that adds lots of stuff that I randomly think up or that gets suggested to me. Anyway I have started work on adding Dungeons and Dragons type skills. The problem is when I use them for combat it is really buggy. For example I am an Elf who is level 1 with 1 Constitution, 2 Strength, and 3 Dexterity. IN my code i have some equations to calculate the resulting damage. Then I use entity.setHealth(calcHealth); (float health = entity.getHealth();    float calcHealth = health - getTotal(a, d); ) which looks good on the outside but when the entity "dies" it sometimes does a spazzy death animation and keeps fighting.

 

Sorry if this is confusing, and thanks in advance.

Posted

Usually (read: almost always), the crash log will be helpful in figuring out why it crashes.

 

Usually (read: always), the crash log should be accompanying reports of crashes on the forums.\

 

Please either use [ spoiler ] tags, or paste your crashlog somewhere meaningful, such as http://gist.github.com/.

Posted
  On 7/4/2014 at 7:01 PM, Elyon said:

Usually (read: almost always), the crash log will be helpful in figuring out why it crashes.

 

Usually (read: always), the crash log should be accompanying reports of crashes on the forums.\

 

Please either use [ spoiler ] tags, or paste your crashlog somewhere meaningful, such as http://gist.github.com/.

 

 

  Reveal hidden contents

 

Posted

The crash log tells you exactly what is wrong:

 

java.lang.StackOverflowError: Unexpected error

 

and

 

  at com.sirniloc.sirs.events.SirPlayerEvent.onCombat(SirPlayerEvent.java:86)

 

If you cannot figure out how to avoid the stack overflow yourself, post either the

SirPlayerEvent

class, or the

onCombat

method from that class, or line 86 in SirPlayerEvent.java.

Posted
  On 7/4/2014 at 7:48 PM, Elyon said:

The crash log tells you exactly what is wrong:

 

java.lang.StackOverflowError: Unexpected error

 

and

 

  at com.sirniloc.sirs.events.SirPlayerEvent.onCombat(SirPlayerEvent.java:86)

 

If you cannot figure out how to avoid the stack overflow yourself, post either the

SirPlayerEvent

class, or the

onCombat

method from that class, or line 86 in SirPlayerEvent.java.

 

I do know that is the problem I can go through the crashlogs. I just don't know exactly how to use line 86.

 

 

  Reveal hidden contents

 

Posted

Please use http://gist.github.com/ for longer code pasting.

 

Which line is line 86?

 

If it is this line:

defender.attackEntityFrom(event.source, getComabtDamage((EntityLivingBase) event.entity, event.source, event.ammount));

, will that not trigger the

onCombat

event, which will call the line above, which will trigger the

onCombat

event again, and so on?

Posted
  On 7/4/2014 at 7:56 PM, Elyon said:

Please use http://gist.github.com/ for longer code pasting.

 

Which line is line 86?

 

If it is this line:

defender.attackEntityFrom(event.source, getComabtDamage((EntityLivingBase) event.entity, event.source, event.ammount));

, will that not trigger the

onCombat

event, which will call the line above, which will trigger the

onCombat

event again, and so on?

 

Yes that's what I thought it would do, the thing is I don't know where to put it, I have been using the .setHealth in there becasue I don't know were else to put .attackEntityFrom.

Posted

Hint: The quote functionality is most useful for quoting posts earlier than the most recent post, as well as for specifically quoting part of a post :)

 

As

attackEntityFrom

will trigger the

onCombat

event, you could give

damageEntity

a try instead.

Posted

There are two solutions:

1. Use a custom DamageSource in your call to attackEntityFrom and don't call attackEntityFrom from the event when event.source is an instanceof your CustomDamageSource

 

2. Like mentioned above, use damageEntity directly by creating a class 'DirtyEntityAccessor' and for its package declaration put 'package net.minecraft.entity' - this will give you access to protected methods in the Entity folder of MC, without actually changing any vanilla code, and the file/folder is still in your project, not in MC's folder. It's a neat trick I learned from diesieben07 xD

Posted
  On 7/4/2014 at 10:24 PM, coolAlias said:

There are two solutions:

1. Use a custom DamageSource in your call to attackEntityFrom and don't call attackEntityFrom from the event when event.source is an instanceof your CustomDamageSource

 

2. Like mentioned above, use damageEntity directly by creating a class 'DirtyEntityAccessor' and for its package declaration put 'package net.minecraft.entity' - this will give you access to protected methods in the Entity folder of MC, without actually changing any vanilla code, and the file/folder is still in your project, not in MC's folder. It's a neat trick I learned from diesieben07 xD

 

Thank you so much I used the 2nd and it worked great!

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.