Jump to content

Recommended Posts

Posted

UPDATE - Cleared up

In case anyone else new to modding was confused about this topic, this thread taught me that Forge events provide "after-the-fact" information.  You can do whatever you want with this information, and in some cases you can cancel the event itself, but you cannot modify what actually happened in the event.  So, as in my situation here, you cannot use an event to increase (or modify in any way) mob damage.

 

I thought I could hook into the event, change its fields, and then have the event resolve.  But no, the event resolves first, and then passes that information to your handler class, where you can make use of it.  Events are still useful; they're just not useful for the application I had in mind.

 

Original thread below:

 

 

Alright, so I want to make it so any time a mob attacks, that mob makes a damage roll instead of doing flat damage.

 

To my understanding (and I've searched and read and looked up tutorials and videos for 2-3 days, honestly), the best way to do this is to use the LivingAttackEvent event.

 

I know how to set this up.  I have my event handler (below) and I have the event registered properly in my mod.

 

What I want to know is: what do I even do with the limited number of fields the event gives me?  For example, I have this:

 

public class LivingAttackHandler {
@ForgeSubscribe
public void onEntityAttack(LivingAttackEvent event)
{
	Entity entity = event.entity;
	DamageSource source = event.source;
	int amount = event.ammount;
}
}

 

So, that's cool and all.  But I get errors when I actually try to change the event's fields.  Case in point, if I try this code:

 

event.ammount = 4;

 

Eclipse gives me an error saying "The final field LivingAttackEvent.ammount cannot be assigned."  So I can't actually change the event fields.  I'm having this problem with pretty much all events.  It seems to me I can only get information from events, which I can then subsequently do nothing with.

 

I know I'm approaching this the wrong way.  Events sound like they're useful, but I'm not "getting" it.  I honestly have been at this for at least 2 days now, and there are frustratingly few resources online about Forge events and how to actually use them.

Posted

I take it that this was not enough for your needs?

 

     /**
     * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack.
     */
     attackEntity(Entity par1Entity, float par2) {
        int i = this.rand.nextInt(this.maxDamage - this.minDamage) + this.minDamage +1;
        return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), i);
     }

 

Events are NOT useful of your needs.

 

It seems to me I can only get information from events, which I can then subsequently do nothing with.

 

Um...duh?  Events are "hey, this thing happened.  Here's what it was."  They are a after-the-fact alert.  Now, you can cancel them (prevents other code up the chain from receiving the event and doing things with it--doing so may prevent the effects of the event, e.g. the player wouldn't actually take the damage) but you can't alter the event details: the damage was already assigned.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I take it that this was not enough for your needs?

 

     /**
     * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack.
     */
     attackEntity(Entity par1Entity, float par2) {
        int i = this.rand.nextInt(this.maxDamage - this.minDamage) + this.minDamage +1;
        return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), i);
     }

 

Events are NOT useful of your needs.

I was under the impression that you couldn't do that without access transformers.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Posted

I take it that this was not enough for your needs?

 

     /**
     * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack.
     */
     attackEntity(Entity par1Entity, float par2) {
        int i = this.rand.nextInt(this.maxDamage - this.minDamage) + this.minDamage +1;
        return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), i);
     }

 

Events are NOT useful of your needs.

 

It seems to me I can only get information from events, which I can then subsequently do nothing with.

 

Um...duh?  Events are "hey, this thing happened.  Here's what it was."  They are a after-the-fact alert.  Now, you can cancel them (prevents other code up the chain from receiving the event and doing things with it--doing so may prevent the effects of the event, e.g. the player wouldn't actually take the damage) but you can't alter the event details: the damage was already assigned.

 

Excellent, thank you for the fast response and the clarification.  The only thing that this leaves me wondering is where you'd put the basic mob attack you quoted above.  It looks like you took the default mob basic attack code and modified it, but I certainly do not want to do that in the base classes and I'm not adding new mobs.  I want to affect the vanilla mobs' damage.

Posted

Excellent, thank you for the fast response and the clarification.  The only thing that this leaves me wondering is where you'd put the basic mob attack you quoted above.  It looks like you took the default mob basic attack code and modified it, but I certainly do not want to do that in the base classes and I'm not adding new mobs.  I want to affect the vanilla mobs' damage.

 

It's inside my custom mob entity class.

If you want to edit vanilla mobs you're going to need to look elsewhere.  I'm not sure this is doable without base class editing.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Excellent, thank you for the fast response and the clarification.  The only thing that this leaves me wondering is where you'd put the basic mob attack you quoted above.  It looks like you took the default mob basic attack code and modified it, but I certainly do not want to do that in the base classes and I'm not adding new mobs.  I want to affect the vanilla mobs' damage.

 

It's inside my custom mob entity class.

If you want to edit vanilla mobs you're going to need to look elsewhere.  I'm not sure this is doable without base class editing.

What if you cancelled the event then added a new one with the amount changed?

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Posted

What if you cancelled the event then added a new one with the amount changed?

 

You may be able to.  I don't know how the event system of Minecraft works internally so I can't say for sure if the new event would get picked up or not.  I know that in Flash it wouldn't because the listening object isn't listening to the intermediary object that snagged the event first.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

What if you cancelled the event then added a new one with the amount changed?

 

You may be able to.  I don't know how the event system of Minecraft works internally so I can't say for sure if the new event would get picked up or not.  I know that in Flash it wouldn't because the listening object isn't listening to the intermediary object that snagged the event first.

Or you could bypass the event and just damage the player directly. If that works.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Posted

Or you could bypass the event and just damage the player directly. If that works.

 

Should be able to.  You'd have to make sure not to intercept your own events!

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.