mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 21:59:05 +00:00
PlayerEvent:
-Added PlayerEvent.AttackEvent & PlayerEvent.AttackedEvent, preventing any knockback from happening from attacks.
This commit is contained in:
1 parent
5e0b1282f7
commit
12a3fffeab
5 files changed
+62
-16
No files matched your search
@@ -351,6 +351,11 @@ public class EventHooks {
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAttacked(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.AttackedEvent event) {
|
||||
handler.callScript(EnumScriptType.ATTACKED, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerDamaged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.DamagedEvent event) {
|
||||
handler.callScript(EnumScriptType.DAMAGED, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
@@ -431,6 +436,11 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAttack(PlayerDataScript handler, PlayerEvent.AttackEvent event) {
|
||||
handler.callScript(EnumScriptType.ATTACK, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerDamagedEntity(PlayerDataScript handler, DamagedEntityEvent event) {
|
||||
handler.callScript(EnumScriptType.DAMAGED_ENTITY, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
|
||||
@@ -22,10 +22,7 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
|
||||
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.event.entity.living.*;
|
||||
import net.minecraftforge.event.entity.player.*;
|
||||
import net.minecraftforge.event.world.*;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
@@ -394,6 +391,26 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(LivingAttackEvent event) {
|
||||
if(event.entityLiving == null || event.entityLiving.worldObj == null)
|
||||
return;
|
||||
|
||||
if(event.entityLiving.worldObj instanceof WorldServer) {
|
||||
Entity source = NoppesUtilServer.GetDamageSourcee(event.source);
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
if(event.entityLiving instanceof EntityPlayer) {
|
||||
noppes.npcs.scripted.event.PlayerEvent.AttackedEvent pevent = new noppes.npcs.scripted.event.PlayerEvent.AttackedEvent((IPlayer)NpcAPI.Instance().getIEntity((EntityPlayer)event.entityLiving), source, event.ammount, event.source);
|
||||
event.setCanceled(EventHooks.onPlayerAttacked(handler, pevent));
|
||||
}
|
||||
|
||||
if(source instanceof EntityPlayer) {
|
||||
noppes.npcs.scripted.event.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.AttackEvent((IPlayer)NpcAPI.Instance().getIEntity((EntityPlayer)event.source.getEntity()), event.entityLiving, event.ammount, event.source);
|
||||
event.setCanceled(EventHooks.onPlayerAttack(handler, pevent1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(LivingHurtEvent event) {
|
||||
if(event.entityLiving == null || event.entityLiving.worldObj == null)
|
||||
|
||||
@@ -103,6 +103,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("attack");
|
||||
hookList.add("attacked");
|
||||
hookList.add("damagedEntity");
|
||||
hookList.add("damaged");
|
||||
hookList.add("kills");
|
||||
|
||||
@@ -14,6 +14,7 @@ public enum EnumScriptType {
|
||||
DIALOG_CLOSE("dialogClose"),
|
||||
TIMER("timer"),
|
||||
|
||||
ATTACKED("attacked"),
|
||||
ATTACK_MELEE("meleeAttack"),
|
||||
TARGET_LOST("targetLost"),
|
||||
ROLE("role"),
|
||||
|
||||
@@ -137,6 +137,20 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class AttackedEvent extends PlayerEvent {
|
||||
public final IDamageSource damageSource;
|
||||
public final IEntity source;
|
||||
public final float damage;
|
||||
|
||||
public AttackedEvent(IPlayer player, Entity source, float damage, DamageSource damagesource) {
|
||||
super(player);
|
||||
this.source = NpcAPI.Instance().getIEntity(source);
|
||||
this.damage = damage;
|
||||
this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource);
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class DamagedEvent extends PlayerEvent {
|
||||
public final IDamageSource damageSource;
|
||||
@@ -223,6 +237,20 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class AttackEvent extends PlayerEvent {
|
||||
public final IDamageSource damageSource;
|
||||
public final IEntity target;
|
||||
public float damage;
|
||||
|
||||
public AttackEvent(IPlayer player, Entity target, float damage, DamageSource damagesource) {
|
||||
super(player);
|
||||
this.target = NpcAPI.Instance().getIEntity(target);
|
||||
this.damage = damage;
|
||||
this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource);
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class DamagedEntityEvent extends PlayerEvent {
|
||||
public final IDamageSource damageSource;
|
||||
@@ -285,18 +313,6 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class AttackEvent extends PlayerEvent {
|
||||
public final int type;
|
||||
public final Object target;
|
||||
|
||||
public AttackEvent(IPlayer player, int type, Object target) {
|
||||
super(player);
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class InteractEvent extends PlayerEvent {
|
||||
public final int type;
|
||||
|
||||
Reference in new issue
Block a user