1818package com.lambda.util.combat
1919
2020import com.lambda.context.SafeContext
21- import com.lambda.core.annotations.InternalApi
2221import com.lambda.util.math.distSq
23- import com.lambda.util.math.minus
24- import com.lambda.util.math.times
25- import com.lambda.util.world.WorldUtils.internalGetFastEntities
2622import com.lambda.util.world.fastEntitySearch
27- import com.lambda.util .world.toFastVec
23+ import net.minecraft.client .world.ClientWorld
2824import net.minecraft.entity.EquipmentSlot
2925import net.minecraft.entity.LivingEntity
3026import net.minecraft.entity.damage.DamageSource
@@ -35,8 +31,10 @@ import net.minecraft.registry.tag.DamageTypeTags.IS_FIRE
3531import net.minecraft.registry.tag.DamageTypeTags.IS_FREEZING
3632import net.minecraft.registry.tag.EntityTypeTags.FREEZE_HURTS_EXTRA_TYPES
3733import net.minecraft.util.math.Vec3d
34+ import net.minecraft.world.Difficulty
35+ import net.minecraft.world.World
3836import net.minecraft.world.explosion.Explosion
39- import net.minecraft.world.explosion.ExplosionImpl
37+ import kotlin.math.min
4038
4139object CombatUtils {
4240 /* *
@@ -45,11 +43,11 @@ object CombatUtils {
4543 * @param entity The entity to calculate the damage for
4644 * @param damage The damage to apply
4745 */
48- fun DamageSource.scale (entity : LivingEntity , damage : Double ): Double {
46+ fun DamageSource.scale (world : ClientWorld , entity : LivingEntity , damage : Double ): Double {
4947 if (damage.isNaN() || damage.isInfinite())
5048 return Double .MAX_VALUE
5149
52- if (entity.isAlwaysInvulnerableTo (this ) ||
50+ if (entity.isInvulnerableTo (this ) ||
5351 entity.isDead ||
5452 entity.blockedByShield(this ) ||
5553 isIn(IS_FIRE ) && entity.hasStatusEffect(FIRE_RESISTANCE )) return 0.0
@@ -60,10 +58,22 @@ object CombatUtils {
6058 if (isIn(DAMAGES_HELMET ) && ! entity.getEquippedStack(EquipmentSlot .HEAD ).isEmpty)
6159 return damage * 0.75
6260
63- return entity.applyArmorToDamage(this ,
64- entity.modifyAppliedDamage(this , damage.toFloat())).toDouble()
61+ return world.scaleDamage(
62+ entity.applyArmorToDamage(this ,
63+ entity.modifyAppliedDamage(this , damage.toFloat())).toDouble()
64+ )
6565 }
6666
67+ /* *
68+ * Scales the damage depending on the world difficulty
69+ */
70+ fun World.scaleDamage (damage : Double ): Double =
71+ when (difficulty) {
72+ Difficulty .EASY -> min(damage / 2 + 1 , damage)
73+ Difficulty .HARD -> damage * 3 / 2
74+ else -> damage
75+ }
76+
6777 /* *
6878 * Returns whether there is a deadly end crystal in proximity of the player
6979 *
@@ -101,9 +111,9 @@ object CombatUtils {
101111 val distance = entity distSq position
102112
103113 val range = power * 2
104- val impact = (1 - distance / range) * ExplosionImpl .calculateReceivedDamage (position, entity) * 0.4
114+ val impact = (1 - distance / range) * Explosion .getExposure (position, entity) * 0.4
105115 val damage = (impact * impact + impact) / 2.0 * 7.0 * range + 1
106116
107- return Explosion .createDamageSource(world, null ).scale(entity, damage)
117+ return Explosion .createDamageSource(world, null ).scale(world, entity, damage)
108118 }
109119}
0 commit comments