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);
}
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);
}
}
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);
}
}
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()));
}
}
}
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;
}
Aggregations