mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
Added LivingKnockBackEvent event to allow better control over knock back effects. (#4503)
This commit is contained in:
1 parent
441ece67bd
commit
bbf1bef7d3
4 files changed
+161
-18
No files matched your search
@@ -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;
|
||||
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;}
|
||||
}
|
||||
Reference in new issue
Block a user