use of net.minecraft.world.damagesource.IndirectEntityDamageSource in project SpongeCommon by SpongePowered.
the class DamageSourceMixin method onSetExplosionSource.
@Inject(method = "explosion(Lnet/minecraft/world/level/Explosion;)Lnet/minecraft/world/damagesource/DamageSource;", at = @At("HEAD"), cancellable = true)
private static void onSetExplosionSource(@Nullable final Explosion explosion, final CallbackInfoReturnable<net.minecraft.world.damagesource.DamageSource> cir) {
if (explosion != null) {
final Entity entity = ((ExplosionAccessor) explosion).accessor$source();
if (entity != null && !((LevelBridge) ((ExplosionAccessor) explosion).accessor$level()).bridge$isFake()) {
if (explosion.getSourceMob() == null && entity instanceof CreatorTrackedBridge) {
// check creator
final CreatorTrackedBridge creatorBridge = (CreatorTrackedBridge) entity;
creatorBridge.tracker$getCreatorUUID().flatMap(x -> Sponge.server().player(x)).ifPresent(player -> {
final IndirectEntityDamageSource damageSource = new IndirectEntityDamageSource("explosion.player", entity, (Entity) player);
damageSource.setScalesWithDifficulty().setExplosion();
cir.setReturnValue(damageSource);
});
}
}
}
}
Aggregations