-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented LivingKnockBackEvent event and hook #4503
Changes from all commits
7a04fa5
e967d43
462e558
78cdcde
e77c5c0
7448711
483cfd2
dbc1392
8ce55bd
b5c620c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Minecraft Forge | ||
* Copyright (c) 2017. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation version 2.1 | ||
* of the License. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package net.minecraftforge.event.entity.living; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.entity.monster.EntityMob; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.util.DamageSource; | ||
import net.minecraftforge.common.ForgeHooks; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.fml.common.eventhandler.Cancelable; | ||
|
||
/** | ||
* LivingKnockBackEvent is fired when a living entity is about to be knocked back. <br> | ||
* This event is fired whenever an Entity is knocked back in | ||
* {@link EntityLivingBase#attackEntityFrom(DamageSource, float)}, | ||
* {@link EntityLivingBase#blockWithShield(EntityLivingBase)}, | ||
* {@link EntityMob#attackEntityAsMob(Entity)} and | ||
* {@link EntityPlayer#attackTargetEntityWithCurrentItem(Entity)} <br> | ||
* <br> | ||
* This event is fired via {@link ForgeHooks#onLivingKnockBack(EntityLivingBase, Entity, float, double, double)}.<br> | ||
* <br> | ||
* {@link #attacker} contains the Entity that caused the knock back. <br> | ||
* {@link #strength} contains the strength of the knock back. <br> | ||
* {@link #ratioX} contains the x ratio of the knock back. <br> | ||
* {@link #ratioZ} contains the z ratio of the knock back. <br> | ||
* <br> | ||
* This event is {@link Cancelable}.<br> | ||
* If this event is canceled, the entity is not knocked back.<br> | ||
* <br> | ||
* This event does not have a result. {@link HasResult}<br> | ||
*<br> | ||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}. | ||
**/ | ||
@Cancelable | ||
public class LivingKnockBackEvent extends LivingEvent | ||
{ | ||
protected Entity attacker; | ||
protected float strength; | ||
protected double ratioX, ratioZ; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. protected final Entity attacker;
protected float strength;
protected double ratioX, ratioZ;
protected final float originalStrength;
protected final double originalRatioX, originalRatioZ;
public LivingKnockBackEvent(EntityLivingBase target, Entity attacker, float strength, double ratioX, double ratioZ)
{
super(target);
this.attacker = attacker;
this.originalStrength = strength;
this.originalRatioX = ratioX;
this.originalRatioZ = ratioZ;
this.strength = strength;
this.ratioX = ratioX;
this.ratioZ = ratioZ;
} In case of multiple mods modifying the same event. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good suggestion from liach, please add the "original" values as final values, so mods using the events can have more information about modifications to the values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed now. |
||
protected final Entity originalAttacker; | ||
protected final float originalStrength; | ||
protected final double originalRatioX, originalRatioZ; | ||
|
||
public LivingKnockBackEvent(EntityLivingBase target, Entity attacker, float strength, double ratioX, double ratioZ) | ||
{ | ||
super(target); | ||
this.attacker = this.originalAttacker = attacker; | ||
this.strength = this.originalStrength = strength; | ||
this.ratioX = this.originalRatioX = ratioX; | ||
this.ratioZ = this.originalRatioZ = ratioZ; | ||
} | ||
|
||
public Entity getAttacker() {return this.attacker;} | ||
|
||
public float getStrength() {return this.strength;} | ||
|
||
public double getRatioX() {return this.ratioX;} | ||
|
||
public double getRatioZ() {return this.ratioZ;} | ||
|
||
public Entity getOriginalAttacker() {return this.originalAttacker;} | ||
|
||
public float getOriginalStrength() {return this.originalStrength;} | ||
|
||
public double getOriginalRatioX() {return this.originalRatioX;} | ||
|
||
public double getOriginalRatioZ() {return this.originalRatioZ;} | ||
|
||
public void setAttacker(Entity attacker) {this.attacker = attacker;} | ||
|
||
public void setStrength(float strength) {this.strength = strength;} | ||
|
||
public void setRatioX(double ratioX) {this.ratioX = ratioX;} | ||
|
||
public void setRatioZ(double ratioZ) {this.ratioZ = ratioZ;} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.minecraftforge.debug; | ||
|
||
import net.minecraft.entity.passive.EntityCow; | ||
import net.minecraft.entity.passive.EntitySheep; | ||
import net.minecraftforge.event.entity.living.LivingKnockBackEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
|
||
@Mod(modid = "kbhtest", name = "Knock Back Hook Test", version = "1.0") | ||
@Mod.EventBusSubscriber | ||
public class KnockBackHookTest | ||
{ | ||
private static final boolean ENABLED = false; | ||
|
||
@SubscribeEvent | ||
public static void onKnockBack(LivingKnockBackEvent event) | ||
{ | ||
if(ENABLED) | ||
{ | ||
if(event.getEntityLiving() instanceof EntitySheep) | ||
{ | ||
event.setStrength(0.2F); | ||
} | ||
else if(event.getEntityLiving() instanceof EntityCow) | ||
{ | ||
event.setCanceled(true); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs a license header.