-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Rule: endermanDontTakeExplosionDamageFix (#134)
This commit adds a new rule "endermanDontTakeExplosionDamageFix" that fixes https://bugs.mojang.com/browse/MC-258561 by using the same behavior as Minecraft 1.19.4.
- Loading branch information
Showing
4 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/carpetfixes/mixins/entityFixes/EndermanEntity_explosionDamageMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package carpetfixes.mixins.entityFixes; | ||
|
||
import carpetfixes.CFSettings; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.mob.EndermanEntity; | ||
import net.minecraft.entity.projectile.thrown.PotionEntity; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
/** | ||
* Fixes the endermen not being able to take damage from wither and tnt explosions | ||
* (<a href="https://bugs.mojang.com/browse/MC-258561">MC-258561</a>) | ||
*/ | ||
|
||
@Mixin(EndermanEntity.class) | ||
public abstract class EndermanEntity_explosionDamageMixin extends LivingEntity { | ||
|
||
protected EndermanEntity_explosionDamageMixin(EntityType<? extends LivingEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
|
||
@SuppressWarnings("UnusedReturnValue") | ||
@Invoker("teleportRandomly") | ||
public abstract boolean invokeTeleportRandomly(); | ||
|
||
|
||
@Inject( | ||
method = "damage", | ||
at = @At(value = "HEAD"), | ||
cancellable = true | ||
) | ||
private void damageFromExplosion(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) { | ||
if (CFSettings.endermanDontTakeExplosionDamageFix | ||
&& !source.isProjectile() | ||
&& !(source.getSource() instanceof PotionEntity)) { | ||
boolean bl = super.damage(source, amount); | ||
if (!this.world.isClient() && !(source.getAttacker() instanceof LivingEntity) && this.random.nextInt(10) != 0) { | ||
this.invokeTeleportRandomly(); | ||
} | ||
cir.setReturnValue(bl); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters