use of io.izzel.arclight.common.bridge.util.DamageSourceBridge in project Arclight by IzzelAliz.
the class PlayerEntityMixin method attackTargetEntityWithCurrentItem.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void attackTargetEntityWithCurrentItem(final Entity entity) {
if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget((PlayerEntity) (Object) this, entity))
return;
if (entity.canBeAttackedWithItem() && !entity.hitByEntity((PlayerEntity) (Object) this)) {
float f = (float) this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getValue();
float f2;
if (entity instanceof LivingEntity) {
f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((LivingEntity) entity).getCreatureAttribute());
} else {
f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), CreatureAttribute.UNDEFINED);
}
final float f3 = this.getCooledAttackStrength(0.5f);
f *= 0.2f + f3 * f3 * 0.8f;
f2 *= f3;
this.resetCooldown();
if (f > 0.0f || f2 > 0.0f) {
final boolean flag = f3 > 0.9f;
boolean flag2 = false;
final byte b0 = 0;
int i = b0 + EnchantmentHelper.getKnockbackModifier((PlayerEntity) (Object) this);
if (this.isSprinting() && flag) {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0f, 1.0f);
++i;
flag2 = true;
}
boolean flag3 = flag && this.fallDistance > 0.0f && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Effects.BLINDNESS) && !this.isPassenger() && entity instanceof LivingEntity;
net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit((PlayerEntity) (Object) this, entity, flag3, flag3 ? 1.5F : 1.0F);
flag3 = hitResult != null;
if (flag3) {
f *= hitResult.getDamageModifier();
}
f += f2;
boolean flag4 = false;
final double d0 = this.distanceWalkedModified - this.prevDistanceWalkedModified;
if (flag && !flag3 && !flag2 && this.onGround && d0 < this.getAIMoveSpeed()) {
final ItemStack itemstack = this.getHeldItem(Hand.MAIN_HAND);
if (itemstack.getItem() instanceof SwordItem) {
flag4 = true;
}
}
float f4 = 0.0f;
boolean flag5 = false;
final int j = EnchantmentHelper.getFireAspectModifier((PlayerEntity) (Object) this);
if (entity instanceof LivingEntity) {
f4 = ((LivingEntity) entity).getHealth();
if (j > 0 && !entity.isBurning()) {
final EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 1);
Bukkit.getPluginManager().callEvent(combustEvent);
if (!combustEvent.isCancelled()) {
flag5 = true;
((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false);
}
}
}
final Vec3d vec3d = entity.getMotion();
final boolean flag6 = entity.attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity) (Object) this), f);
if (flag6) {
if (i > 0) {
if (entity instanceof LivingEntity) {
((LivingEntity) entity).knockBack((PlayerEntity) (Object) this, i * 0.5f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
} else {
entity.addVelocity(-MathHelper.sin(this.rotationYaw * 0.017453292f) * i * 0.5f, 0.1, MathHelper.cos(this.rotationYaw * 0.017453292f) * i * 0.5f);
}
this.setMotion(this.getMotion().mul(0.6, 1.0, 0.6));
this.setSprinting(false);
}
if (flag4) {
final float f5 = 1.0f + EnchantmentHelper.getSweepingDamageRatio((PlayerEntity) (Object) this) * f;
final List<LivingEntity> list = this.world.getEntitiesWithinAABB((Class<? extends LivingEntity>) LivingEntity.class, entity.getBoundingBox().grow(1.0, 0.25, 1.0));
for (final LivingEntity entityliving : list) {
if (entityliving != (Object) this && entityliving != entity && !this.isOnSameTeam(entityliving) && (!(entityliving instanceof ArmorStandEntity) || !((ArmorStandEntity) entityliving).hasMarker()) && this.getDistanceSq(entityliving) < 9.0 && entityliving.attackEntityFrom(((DamageSourceBridge) DamageSource.causePlayerDamage((PlayerEntity) (Object) this)).bridge$sweep(), f5)) {
entityliving.knockBack((PlayerEntity) (Object) this, 0.4f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
}
}
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0f, 1.0f);
this.spawnSweepParticles();
}
if (entity instanceof ServerPlayerEntity && entity.velocityChanged) {
boolean cancelled = false;
final Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity();
final Vector velocity = CraftVector.toBukkit(vec3d);
final PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
cancelled = true;
} else if (!velocity.equals(event.getVelocity())) {
player.setVelocity(event.getVelocity());
}
if (!cancelled) {
((ServerPlayerEntity) entity).connection.sendPacket(new SEntityVelocityPacket(entity));
entity.velocityChanged = false;
entity.setMotion(vec3d);
}
}
if (flag3) {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0f, 1.0f);
this.onCriticalHit(entity);
}
if (!flag3 && !flag4) {
if (flag) {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0f, 1.0f);
} else {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0f, 1.0f);
}
}
if (f2 > 0.0f) {
this.onEnchantmentCritical(entity);
}
this.setLastAttackedEntity(entity);
if (entity instanceof LivingEntity) {
EnchantmentHelper.applyThornEnchantments((LivingEntity) entity, (PlayerEntity) (Object) this);
}
EnchantmentHelper.applyArthropodEnchantments((PlayerEntity) (Object) this, entity);
final ItemStack itemstack2 = this.getHeldItemMainhand();
Object object = entity;
if (entity instanceof EnderDragonPartEntity) {
object = ((EnderDragonPartEntity) entity).dragon;
}
if (!this.world.isRemote && !itemstack2.isEmpty() && object instanceof LivingEntity) {
ItemStack copy = itemstack2.copy();
itemstack2.hitEntity((LivingEntity) object, (PlayerEntity) (Object) this);
if (itemstack2.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((PlayerEntity) (Object) this, copy, Hand.MAIN_HAND);
this.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY);
}
}
if (entity instanceof LivingEntity) {
final float f6 = f4 - ((LivingEntity) entity).getHealth();
this.addStat(Stats.DAMAGE_DEALT, Math.round(f6 * 10.0f));
if (j > 0) {
final EntityCombustByEntityEvent combustEvent2 = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), j * 4);
Bukkit.getPluginManager().callEvent(combustEvent2);
if (!combustEvent2.isCancelled()) {
((EntityBridge) entity).bridge$setOnFire(combustEvent2.getDuration(), false);
}
}
if (this.world instanceof ServerWorld && f6 > 2.0f) {
final int k = (int) (f6 * 0.5);
((ServerWorld) this.world).spawnParticle(ParticleTypes.DAMAGE_INDICATOR, entity.posX, entity.posY + entity.getHeight() * 0.5f, entity.posZ, k, 0.1, 0.0, 0.1, 0.2);
}
}
this.addExhaustion(0.1f);
} else {
this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0f, 1.0f);
if (flag5) {
entity.extinguish();
}
if (this instanceof ServerPlayerEntityBridge) {
((ServerPlayerEntityBridge) this).bridge$getBukkitEntity().updateInventory();
}
}
}
}
}
Aggregations