| 1 | package net.minecraft.world.entity.monster.hoglin;
|
| 2 |
|
| 3 | import net.minecraft.server.level.ServerLevel;
|
| 4 | import net.minecraft.util.RandomSource;
|
| 5 | import net.minecraft.world.damagesource.DamageSource;
|
| 6 | import net.minecraft.world.entity.LivingEntity;
|
| 7 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 8 | import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
| 9 | import net.minecraft.world.phys.Vec3;
|
| 10 |
|
| 11 | public interface HoglinBase {
|
| 12 | int ATTACK_ANIMATION_DURATION = 10;
|
| 13 | float PROBABILITY_OF_SPAWNING_AS_BABY = 0.2F;
|
| 14 |
|
| 15 | int getAttackAnimationRemainingTicks();
|
| 16 |
|
| 17 | static boolean hurtAndThrowTarget(final ServerLevel level, final LivingEntity body, final LivingEntity target) {
|
| 18 | float attackDamage = (float)body.getAttributeValue(Attributes.ATTACK_DAMAGE);
|
| 19 | float actualDamage;
|
| 20 | if (!body.isBaby() && (int)attackDamage > 0) {
|
| 21 | actualDamage = attackDamage / 2.0F + level.getRandom().nextInt((int)attackDamage);
|
| 22 | } else {
|
| 23 | actualDamage = attackDamage;
|
| 24 | }
|
| 25 |
|
| 26 | DamageSource damageSource = body.damageSources().mobAttack(body);
|
| 27 | boolean wasHurt = target.hurtServer(level, damageSource, actualDamage);
|
| 28 | if (wasHurt) {
|
| 29 | EnchantmentHelper.doPostAttackEffects(level, target, damageSource);
|
| 30 | if (!body.isBaby()) {
|
| 31 | throwTarget(body, target);
|
| 32 | }
|
| 33 | }
|
| 34 |
|
| 35 | return wasHurt;
|
| 36 | }
|
| 37 |
|
| 38 | static void throwTarget(final LivingEntity body, final LivingEntity target) {
|
| 39 | double knockbackPower = body.getAttributeValue(Attributes.ATTACK_KNOCKBACK);
|
| 40 | double knockbackResistance = target.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
|
| 41 | double effectiveKnockbackPower = knockbackPower - knockbackResistance;
|
| 42 | if (!(effectiveKnockbackPower <= 0.0)) {
|
| 43 | double xd = target.getX() - body.getX();
|
| 44 | double zd = target.getZ() - body.getZ();
|
| 45 | RandomSource random = body.level().getRandom();
|
| 46 | float horizontalPushAngle = random.nextInt(21) - 10;
|
| 47 | double horizontalScale = effectiveKnockbackPower * (random.nextFloat() * 0.5F + 0.2F);
|
| 48 | Vec3 horizontalPushVector = new Vec3(xd, 0.0, zd).normalize().scale(horizontalScale).yRot(horizontalPushAngle);
|
| 49 | double verticalScale = effectiveKnockbackPower * random.nextFloat() * 0.5;
|
| 50 | target.push(horizontalPushVector.x, verticalScale, horizontalPushVector.z);
|
| 51 | target.syncVelocity = true;
|
| 52 | }
|
| 53 | }
|
| 54 | }
|
| 55 |
|