use of team.cqr.cqrepoured.item.ISupportWeapon in project ChocolateQuestRepoured by TeamChocoQuest.
the class EventsHandler method onPlayerLeaderAttackedEvent.
@SubscribeEvent
public static void onPlayerLeaderAttackedEvent(LivingAttackEvent event) {
if (event.getEntity().level.isClientSide) {
return;
}
if (!(event.getEntity() instanceof PlayerEntity)) {
return;
}
if (!(event.getSource().getEntity() instanceof LivingEntity)) {
return;
}
PlayerEntity player = (PlayerEntity) event.getEntity();
LivingEntity attacker = (LivingEntity) event.getSource().getEntity();
double x = player.getX();
double y = player.getY() + player.getEyeHeight();
double z = player.getZ();
double r = 8.0D;
AxisAlignedBB aabb = new AxisAlignedBB(x - r, y - r * 0.5D, z - r, x + r, y + r * 0.5D, z + r);
for (AbstractEntityCQR entity : player.level.getEntitiesOfClass(AbstractEntityCQR.class, aabb, e -> (e.getLeader() == player))) {
ItemStack stack = entity.getMainHandItem();
if (stack.getItem() instanceof ISupportWeapon) {
continue;
}
if (stack.getItem() instanceof IFakeWeapon) {
continue;
}
if (entity.hasAttackTarget()) {
continue;
}
entity.setTarget(attacker);
}
}
use of team.cqr.cqrepoured.item.ISupportWeapon in project ChocolateQuestRepoured by TeamChocoQuest.
the class EventsHandler method onPlayerLeaderAttackingEvent.
@SubscribeEvent
public static void onPlayerLeaderAttackingEvent(AttackEntityEvent event) {
if (event.getPlayer().level.isClientSide) {
return;
}
if (!(event.getTarget() instanceof LivingEntity)) {
return;
}
PlayerEntity player = event.getPlayer();
LivingEntity target = (LivingEntity) event.getTarget();
double x = player.getX();
double y = player.getY() + player.getEyeHeight();
double z = player.getZ();
double r = 8.0D;
AxisAlignedBB aabb = new AxisAlignedBB(x - r, y - r * 0.5D, z - r, x + r, y + r * 0.5D, z + r);
for (AbstractEntityCQR entity : player.level.getEntitiesOfClass(AbstractEntityCQR.class, aabb, e -> (e.getLeader() == player))) {
ItemStack stack = entity.getMainHandItem();
if (stack.getItem() instanceof ISupportWeapon) {
continue;
}
if (stack.getItem() instanceof IFakeWeapon) {
continue;
}
entity.setTarget(target);
}
}
use of team.cqr.cqrepoured.item.ISupportWeapon in project ChocolateQuestRepoured by TeamChocoQuest.
the class EntityAIHurtByTarget method trySetAttackTarget.
protected boolean trySetAttackTarget(AbstractEntityCQR ally) {
ItemStack stack = ally.getMainHandItem();
if (stack.getItem() instanceof ISupportWeapon) {
return false;
}
if (stack.getItem() instanceof IFakeWeapon) {
return false;
}
if (!isEnemyCheckingLeadersWhenAttacked(ally, this.attackTarget)) {
return false;
}
LivingEntity oldAttackTarget = ally.getTarget();
if (oldAttackTarget != null && ally.getSensing().canSee(oldAttackTarget) && ally.distanceToSqr(oldAttackTarget) < ally.distanceToSqr(this.attackTarget)) {
return false;
}
ally.setTarget(this.attackTarget);
return true;
}
Aggregations