Fix IProjectile Events

Thank you @somehussar
This commit is contained in:
Kam committed 2023-12-31 16:10:38 -05:00
1 parent 782f21f1fe
commit 24d12e25a9
6 files changed
+57 -6

No files matched your search

+16
View File
@@ -262,6 +262,14 @@ public class EventHooks {
script.run(EnumScriptType.PROJECTILE_TICK, event);
}
}
EntityLivingBase thrower = projectile.getThrower();
if(thrower != null){
if(thrower instanceof EntityNPCInterface){
((EntityNPCInterface) thrower).script.callScript(EnumScriptType.PROJECTILE_TICK, event);
}
}
NpcAPI.EVENT_BUS.post(event);
}
@@ -272,6 +280,14 @@ public class EventHooks {
script.run(EnumScriptType.PROJECTILE_IMPACT, event);
}
}
EntityLivingBase thrower = projectile.getThrower();
if(thrower != null){
if(thrower instanceof EntityNPCInterface){
((EntityNPCInterface) thrower).script.callScript(EnumScriptType.PROJECTILE_IMPACT, event);
}
}
NpcAPI.EVENT_BUS.post(event);
}
@@ -29,6 +29,7 @@ import noppes.npcs.DataStats;
import noppes.npcs.EventHooks;
import noppes.npcs.api.IPos;
import noppes.npcs.api.IWorld;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IProjectile;
import noppes.npcs.constants.EnumParticleType;
import noppes.npcs.constants.EnumPotionType;
@@ -449,7 +450,8 @@ public class EntityProjectile extends EntityThrowable {
if (!this.worldObj.isRemote) {
ProjectileEvent.ImpactEvent event;
if (movingobjectposition.entityHit != null) {
event = new ProjectileEvent.ImpactEvent((IProjectile) NpcAPI.Instance().getIEntity(this), 0, movingobjectposition.entityHit);
IEntity target = NpcAPI.Instance().getIEntity(movingobjectposition.entityHit);
event = new ProjectileEvent.ImpactEvent((IProjectile) NpcAPI.Instance().getIEntity(this), 0, target);
} else {
IPos pos = NpcAPI.Instance().getIPos(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
IWorld world = NpcAPI.Instance().getIWorld(this.worldObj);
@@ -79,6 +79,10 @@ public class ScriptProjectile<T extends EntityProjectile> extends ScriptEntity<T
return type == EntityType.PROJECTILE || super.typeOf(type);
}
public IEntity getThrower() {
return NpcAPI.Instance().getIEntity(entity.getThrower());
}
public void enableEvents() {
if(ScriptContainer.Current == null)
throw new CustomNPCsException("Can only be called during scripts");
@@ -1,18 +1,31 @@
package noppes.npcs.scripted.event;
import noppes.npcs.api.IBlock;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IProjectile;
import noppes.npcs.api.event.IProjectileEvent;
public class ProjectileEvent extends CustomNPCsEvent {
public class ProjectileEvent extends CustomNPCsEvent implements IProjectileEvent {
public IProjectile projectile;
public IEntity source;
public ProjectileEvent(IProjectile projectile) {
this.projectile = projectile;
this.source = projectile.getThrower();
}
public IProjectile getProjectile() {
return projectile;
}
public IEntity getSource() {
return source;
}
/**
* projectileTick
*/
public static class UpdateEvent extends ProjectileEvent {
public static class UpdateEvent extends ProjectileEvent implements IProjectileEvent.UpdateEvent {
public UpdateEvent(IProjectile projectile) {
super(projectile);
}
@@ -21,7 +34,7 @@ public class ProjectileEvent extends CustomNPCsEvent {
/**
* projectileImpact
*/
public static class ImpactEvent extends ProjectileEvent {
public static class ImpactEvent extends ProjectileEvent implements IProjectileEvent.ImpactEvent {
/**
* 0:entity, 1:block
*/
@@ -33,5 +46,21 @@ public class ProjectileEvent extends CustomNPCsEvent {
this.type = type;
this.target = target;
}
public int getType() {
return type;
}
public IEntity getEntity() {
if(type == 0)
return (IEntity) target;
return null;
}
public IBlock getBlock() {
if(type == 1)
return (IBlock) target;
return null;
}
}
}