Search in sources :

Example 1 with ISupportWeapon

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);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ISupportWeapon(team.cqr.cqrepoured.item.ISupportWeapon) IFakeWeapon(team.cqr.cqrepoured.item.IFakeWeapon) AbstractEntityCQR(team.cqr.cqrepoured.entity.bases.AbstractEntityCQR) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with ISupportWeapon

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);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ISupportWeapon(team.cqr.cqrepoured.item.ISupportWeapon) IFakeWeapon(team.cqr.cqrepoured.item.IFakeWeapon) AbstractEntityCQR(team.cqr.cqrepoured.entity.bases.AbstractEntityCQR) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with ISupportWeapon

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;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ISupportWeapon(team.cqr.cqrepoured.item.ISupportWeapon) IFakeWeapon(team.cqr.cqrepoured.item.IFakeWeapon) ItemStack(net.minecraft.item.ItemStack)

Aggregations

LivingEntity (net.minecraft.entity.LivingEntity)3 ItemStack (net.minecraft.item.ItemStack)3 IFakeWeapon (team.cqr.cqrepoured.item.IFakeWeapon)3 ISupportWeapon (team.cqr.cqrepoured.item.ISupportWeapon)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 AbstractEntityCQR (team.cqr.cqrepoured.entity.bases.AbstractEntityCQR)2