Search in sources :

Example 1 with IFakeWeapon

use of team.cqr.cqrepoured.item.IFakeWeapon in project ChocolateQuestRepoured by TeamChocoQuest.

the class AbstractEntityCQR method die.

@Override
public void die(DamageSource cause) {
    if (this.isHoldingPotion()) {
        this.swapWeaponAndPotionSlotItemStacks();
    }
    Item item = this.getMainHandItem().getItem();
    if (item instanceof IFakeWeapon<?>) {
        this.setItemSlot(EquipmentSlotType.MAINHAND, new ItemStack(((IFakeWeapon<?>) item).getOriginalItem()));
    }
    super.die(cause);
    this.updateReputationOnDeath(cause);
}
Also used : AxeItem(net.minecraft.item.AxeItem) NameTagItem(net.minecraft.item.NameTagItem) Item(net.minecraft.item.Item) BowItem(net.minecraft.item.BowItem) IFakeWeapon(team.cqr.cqrepoured.item.IFakeWeapon) ItemStack(net.minecraft.item.ItemStack) IHasTextureOverride(team.cqr.cqrepoured.customtextures.IHasTextureOverride)

Example 2 with IFakeWeapon

use of team.cqr.cqrepoured.item.IFakeWeapon 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 3 with IFakeWeapon

use of team.cqr.cqrepoured.item.IFakeWeapon 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 4 with IFakeWeapon

use of team.cqr.cqrepoured.item.IFakeWeapon in project ChocolateQuestRepoured by TeamChocoQuest.

the class AbstractEntityCQR method setTarget.

@Override
public void setTarget(LivingEntity entitylivingbaseIn) {
    LivingEntity prevAttackTarget = this.getTarget();
    super.setTarget(entitylivingbaseIn);
    LivingEntity attackTarget = this.getTarget();
    if (prevAttackTarget == attackTarget) {
        return;
    }
    if (attackTarget == null) {
        this.entityData.set(HAS_TARGET, false);
        this.lastTimeSeenAttackTarget = Integer.MIN_VALUE;
        this.lastPosAttackTarget = this.position();
        Item item = this.getMainHandItem().getItem();
        if (item instanceof IFakeWeapon<?>) {
            this.setItemSlot(EquipmentSlotType.MAINHAND, new ItemStack(((IFakeWeapon<?>) item).getOriginalItem()));
        }
    } else {
        this.entityData.set(HAS_TARGET, true);
        this.lastTimeSeenAttackTarget = this.tickCount;
        this.lastPosAttackTarget = attackTarget.position();
        Item item = this.getMainHandItem().getItem();
        if (TargetUtil.isAllyCheckingLeaders(this, attackTarget)) {
            if (item instanceof IFakeWeapon<?>) {
                this.setItemSlot(EquipmentSlotType.MAINHAND, new ItemStack(((IFakeWeapon<?>) item).getOriginalItem()));
            }
        } else if (item instanceof ISupportWeapon<?>) {
            this.setItemSlot(EquipmentSlotType.MAINHAND, new ItemStack(((ISupportWeapon<?>) item).getFakeWeapon()));
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) AxeItem(net.minecraft.item.AxeItem) NameTagItem(net.minecraft.item.NameTagItem) Item(net.minecraft.item.Item) BowItem(net.minecraft.item.BowItem) IFakeWeapon(team.cqr.cqrepoured.item.IFakeWeapon) ItemStack(net.minecraft.item.ItemStack) IHasTextureOverride(team.cqr.cqrepoured.customtextures.IHasTextureOverride)

Example 5 with IFakeWeapon

use of team.cqr.cqrepoured.item.IFakeWeapon 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

ItemStack (net.minecraft.item.ItemStack)5 IFakeWeapon (team.cqr.cqrepoured.item.IFakeWeapon)5 LivingEntity (net.minecraft.entity.LivingEntity)4 ISupportWeapon (team.cqr.cqrepoured.item.ISupportWeapon)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 AxeItem (net.minecraft.item.AxeItem)2 BowItem (net.minecraft.item.BowItem)2 Item (net.minecraft.item.Item)2 NameTagItem (net.minecraft.item.NameTagItem)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 IHasTextureOverride (team.cqr.cqrepoured.customtextures.IHasTextureOverride)2 AbstractEntityCQR (team.cqr.cqrepoured.entity.bases.AbstractEntityCQR)2