use of net.minecraft.item.SwordItem in project minecolonies by Minecolonies.
the class KnightCombatAI method getAttackDamage.
/**
* Calculates the damage to deal
*
* @return attack damage
*/
private int getAttackDamage() {
int addDmg = 0;
final ItemStack heldItem = user.getItemInHand(Hand.MAIN_HAND);
if (ItemStackUtils.doesItemServeAsWeapon(heldItem)) {
if (heldItem.getItem() instanceof SwordItem) {
addDmg += ((SwordItem) heldItem.getItem()).getDamage() + BASE_PHYSICAL_DAMAGE;
} else {
addDmg += TinkersToolHelper.getDamage(heldItem);
}
addDmg += EnchantmentHelper.getDamageBonus(heldItem, target.getMobType()) / 2.5;
}
addDmg += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(MELEE_DAMAGE);
if (user.getHealth() <= user.getMaxHealth() * 0.2D) {
addDmg *= 2;
}
return (int) ((addDmg) * MineColonies.getConfig().getServer().knightDamageMult.get());
}
use of net.minecraft.item.SwordItem in project MCDungeonsWeapons by chronosacaria.
the class PlayerAttackHelper method attackTargetEntityWitCurrentOffhandItemAsSuper.
public static void attackTargetEntityWitCurrentOffhandItemAsSuper(PlayerEntity player, Entity target) {
if (target.isAttackable() && !target.handleAttack(player)) {
// get attack damage attribute value
float f_attackDamage = (float) player.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
float h_enchantmentEffectsTargetBonus;
if (target instanceof LivingEntity) {
h_enchantmentEffectsTargetBonus = EnchantmentHelper.getAttackDamage(player.getOffHandStack(), ((LivingEntity) target).getGroup());
} else {
h_enchantmentEffectsTargetBonus = EnchantmentHelper.getAttackDamage(player.getOffHandStack(), EntityGroup.DEFAULT);
}
float i_cooledAttackStrength = player.getAttackCooldownProgress(0.5F);
f_attackDamage *= 0.2F + i_cooledAttackStrength * i_cooledAttackStrength * 0.8F;
h_enchantmentEffectsTargetBonus *= i_cooledAttackStrength;
if (f_attackDamage > 0.0F || h_enchantmentEffectsTargetBonus > 0.0F) {
boolean bl_flag = i_cooledAttackStrength > 0.9F;
boolean bl2_flag1 = false;
int j = 0;
j = j + EnchantmentHelper.getKnockback(player);
if (player.isSprinting() && bl_flag) {
player.world.playSound(null, target.getX(), target.getY(), target.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, SoundCategory.PLAYERS, 1.0F, 1.0F);
++j;
bl2_flag1 = true;
}
boolean bl3_flag2 = bl_flag && player.fallDistance > 0.0F && !player.isOnGround() && !player.isHoldingOntoLadder() && !player.isSwimming() && !player.hasStatusEffect(StatusEffects.BLINDNESS) && !player.hasVehicle() && target instanceof LivingEntity;
bl3_flag2 = bl3_flag2 && !player.isSprinting();
if (bl3_flag2) {
f_attackDamage *= 1.5f;
}
f_attackDamage += h_enchantmentEffectsTargetBonus;
boolean bl4 = false;
double d = (double) (player.horizontalSpeed - player.prevHorizontalSpeed);
if (bl_flag && !bl3_flag2 && !bl2_flag1 && player.isOnGround() && d < (double) player.getMovementSpeed()) {
ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND);
if (itemStack.getItem() instanceof SwordItem) {
bl4 = true;
}
}
float k = 0.0F;
boolean bl5 = false;
int l = EnchantmentHelper.getFireAspect(player);
if (target instanceof LivingEntity) {
k = ((LivingEntity) target).getHealth();
if (l > 0 && !target.isOnFire()) {
bl5 = true;
target.setOnFireFor(1);
}
}
Vec3d vec3d = target.getVelocity();
boolean bl6 = target.damage(DamageSource.player(player), f_attackDamage);
if (bl6) {
if (j > 0) {
if (target instanceof LivingEntity) {
((LivingEntity) target).takeKnockback((float) j * 0.5F, (double) MathHelper.sin(player.yaw * 0.017453292F), (double) (-MathHelper.cos(player.yaw * 0.017453292F)));
} else {
target.addVelocity((double) (-MathHelper.sin(player.yaw * 0.017453292F) * (float) j * 0.5F), 0.1D, (double) (MathHelper.cos(player.yaw * 0.017453292F) * (float) j * 0.5F));
}
player.setVelocity(player.getVelocity().multiply(0.6D, 1.0D, 0.6D));
player.setSprinting(false);
}
if (bl4) {
float m = 1.0F + EnchantmentHelper.getSweepingMultiplier(player) * f_attackDamage;
List<LivingEntity> list = player.world.getNonSpectatingEntities(LivingEntity.class, target.getBoundingBox().expand(1.0D, 0.25D, 1.0D));
Iterator var19 = list.iterator();
label166: while (true) {
LivingEntity livingEntity;
do {
do {
do {
do {
if (!var19.hasNext()) {
player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, player.getSoundCategory(), 1.0F, 1.0F);
player.spawnSweepAttackParticles();
break label166;
}
livingEntity = (LivingEntity) var19.next();
} while (livingEntity == player);
} while (livingEntity == target);
} while (player.isTeammate(livingEntity));
} while (livingEntity instanceof ArmorStandEntity && ((ArmorStandEntity) livingEntity).isMarker());
if (player.squaredDistanceTo(livingEntity) < 9.0D) {
livingEntity.takeKnockback(0.4F, (double) MathHelper.sin(player.yaw * 0.017453292F), (double) (-MathHelper.cos(player.yaw * 0.017453292F)));
livingEntity.damage(DamageSource.player(player), m);
}
}
}
if (target instanceof ServerPlayerEntity && target.velocityModified) {
((ServerPlayerEntity) target).networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(target));
target.velocityModified = false;
target.setVelocity(vec3d);
}
if (bl3_flag2) {
player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, player.getSoundCategory(), 1.0F, 1.0F);
player.addCritParticles(target);
}
if (!bl3_flag2 && !bl4) {
if (bl_flag) {
player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, player.getSoundCategory(), 1.0F, 1.0F);
} else {
player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, player.getSoundCategory(), 1.0F, 1.0F);
}
}
if (h_enchantmentEffectsTargetBonus > 0.0F) {
player.addEnchantedHitParticles(target);
}
player.onAttacking(target);
if (target instanceof LivingEntity) {
EnchantmentHelper.onUserDamaged((LivingEntity) target, player);
}
EnchantmentHelper.onTargetDamaged(player, target);
ItemStack itemStack2 = player.getMainHandStack();
Entity entity = target;
if (target instanceof EnderDragonPart) {
entity = ((EnderDragonPart) target).owner;
}
if (!player.world.isClient && !itemStack2.isEmpty() && entity instanceof LivingEntity) {
itemStack2.postHit((LivingEntity) entity, player);
if (itemStack2.isEmpty()) {
player.setStackInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
}
}
if (target instanceof LivingEntity) {
float n = k - ((LivingEntity) target).getHealth();
player.increaseStat(Stats.DAMAGE_DEALT, Math.round(n * 10.0F));
if (l > 0) {
target.setOnFireFor(l * 4);
}
if (player.world instanceof ServerWorld && n > 2.0F) {
int o = (int) ((double) n * 0.5D);
((ServerWorld) player.world).spawnParticles(ParticleTypes.DAMAGE_INDICATOR, target.getX(), target.getBodyY(0.5D), target.getZ(), o, 0.1D, 0.0D, 0.1D, 0.2D);
}
}
player.addExhaustion(0.1F);
} else {
player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, player.getSoundCategory(), 1.0F, 1.0F);
if (bl5) {
target.extinguish();
}
}
}
}
}
use of net.minecraft.item.SwordItem in project bioplethora by AquexTheSeal.
the class GaugalemEntity method doHurtTarget.
public boolean doHurtTarget(Entity entity) {
boolean flag = super.doHurtTarget(entity);
World world = entity.level;
if (flag && entity instanceof LivingEntity) {
((LivingEntity) entity).addEffect(new EffectInstance(Effects.WITHER, 100, 2));
this.addEffect(new EffectInstance(Effects.INVISIBILITY, 100, 2));
if (this.level instanceof ServerWorld) {
((ServerWorld) this.level).sendParticles(ParticleTypes.LARGE_SMOKE, this.getX(), this.getY(), this.getZ(), 20, 0.4, 0.4, 0.4, 0.1);
}
}
if (!this.level.isClientSide()) /*&& !(damageSource.getEntity() instanceof LivingEntity) */
{
this.teleport();
}
if (this.getMainHandItem().getItem() instanceof SwordItem) {
world.playSound(null, new BlockPos(entity.getX(), entity.getY(), entity.getZ()), SoundEvents.PLAYER_ATTACK_SWEEP, SoundCategory.PLAYERS, 1, 1);
if (!world.isClientSide) {
world.addParticle(ParticleTypes.SWEEP_ATTACK, entity.getX(), entity.getY() + 2, entity.getZ(), 1, 1, 0.1);
}
if (this.getMainHandItem().getItem() instanceof StellarScytheItem) {
double x = entity.getX(), y = entity.getY(), z = entity.getZ();
if (world instanceof ServerWorld) {
for (Entity entityIterator : world.getEntitiesOfClass(Entity.class, new AxisAlignedBB(x - (10 / 2d), y, z - (10 / 2d), x + (10 / 2d), y + (10 / 2d), z + (10 / 2d)), null)) {
if (entityIterator instanceof LivingEntity && entityIterator != this) {
if (entityIterator != entity) {
entityIterator.hurt(DamageSource.mobAttack(this), ((StellarScytheItem) this.getMainHandItem().getItem()).getDamage() * 0.8F);
}
}
}
}
}
}
return flag;
}
use of net.minecraft.item.SwordItem in project bioplethora by AquexTheSeal.
the class BioItemModelProvider method defaultItem.
/**
* If Item is ToolItem or SwordItem, minecraft/handheld model will be generated for that item.
* Otherwise, minecraft/generated model will be generated for that item.
*/
public void defaultItem(Collection<RegistryObject<Item>> items) {
for (RegistryObject<Item> item : items) {
String name = item.getId().getPath();
Item getItem = item.get();
ResourceLocation datagenLoc = new ResourceLocation(Bioplethora.MOD_ID, "item/" + name);
ModelFile.ExistingModelFile modelType = getItem instanceof ToolItem || getItem instanceof SwordItem ? getMcLoc("item/handheld") : getMcLoc("item/generated");
if (!existingFileHelper.exists(datagenLoc, TEXTURE) || existingFileHelper.exists(datagenLoc, MODEL))
continue;
this.getBuilder(name).parent(modelType).texture("layer0", ITEM_FOLDER + "/" + name);
Bioplethora.LOGGER.info("Generate Item Successful: " + item.getId());
}
}
use of net.minecraft.item.SwordItem in project minecolonies by ldtteam.
the class KnightCombatAI method getAttackDamage.
/**
* Calculates the damage to deal
*
* @return attack damage
*/
private int getAttackDamage() {
int addDmg = 0;
final ItemStack heldItem = user.getItemInHand(Hand.MAIN_HAND);
if (ItemStackUtils.doesItemServeAsWeapon(heldItem)) {
if (heldItem.getItem() instanceof SwordItem) {
addDmg += ((SwordItem) heldItem.getItem()).getDamage() + BASE_PHYSICAL_DAMAGE;
} else {
addDmg += TinkersToolHelper.getDamage(heldItem);
}
addDmg += EnchantmentHelper.getDamageBonus(heldItem, target.getMobType()) / 2.5;
}
addDmg += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(MELEE_DAMAGE);
if (user.getHealth() <= user.getMaxHealth() * 0.2D) {
addDmg *= 2;
}
return (int) ((addDmg) * MineColonies.getConfig().getServer().knightDamageMult.get());
}
Aggregations