Search in sources :

Example 1 with MinecraftFallingBlockDamageSource

use of org.spongepowered.common.util.MinecraftFallingBlockDamageSource in project SpongeCommon by SpongePowered.

the class FallingBlockEntityMixin method spongeAttackFallingOrAnvil.

// @formatter:on
@SuppressWarnings("ConstantConditions")
@Redirect(method = "causeFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private boolean spongeAttackFallingOrAnvil(final Entity entity, final DamageSource source, final float damage) {
    if (entity.level.isClientSide) {
        return entity.hurt(source, damage);
    }
    final boolean isAnvil = this.blockState.getBlock().is(BlockTags.ANVIL);
    try {
        if (isAnvil) {
            final MinecraftFallingBlockDamageSource anvil = new MinecraftFallingBlockDamageSource("anvil", (FallingBlockEntity) (Object) this);
            ((DamageSourceBridge) (Object) anvil).bridge$setAnvilSource();
            return entity.hurt(DamageSource.ANVIL, damage);
        } else {
            final MinecraftFallingBlockDamageSource fallingblock = new MinecraftFallingBlockDamageSource("fallingblock", (FallingBlockEntity) (Object) this);
            ((DamageSourceBridge) (Object) fallingblock).bridge$setFallingBlockSource();
            return entity.hurt(DamageSource.FALLING_BLOCK, damage);
        }
    } finally {
        if (isAnvil) {
            ((DamageSourceBridge) source).bridge$setAnvilSource();
        } else {
            ((DamageSourceBridge) source).bridge$setFallingBlockSource();
        }
    }
}
Also used : DamageSourceBridge(org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge) MinecraftFallingBlockDamageSource(org.spongepowered.common.util.MinecraftFallingBlockDamageSource) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 2 with MinecraftFallingBlockDamageSource

use of org.spongepowered.common.util.MinecraftFallingBlockDamageSource in project SpongeCommon by SpongePowered.

the class SpongeFallingBlockDamgeSourceBuilder method build.

@SuppressWarnings("ConstantConditions")
@Override
public FallingBlockDamageSource build() throws IllegalStateException {
    checkState(this.reference.get() != null);
    checkState(this.damageType != null);
    final MinecraftFallingBlockDamageSource damageSource = new MinecraftFallingBlockDamageSource(this.damageType.name(), (FallingBlockEntity) this.reference.get());
    final DamageSourceAccessor accessor = (DamageSourceAccessor) (Object) damageSource;
    if (this.creative) {
        accessor.invoker$bypassInvul();
    }
    if (this.scales) {
        damageSource.setScalesWithDifficulty();
    }
    if (this.magical) {
        damageSource.setMagic();
    }
    if (this.bypasses) {
        accessor.invoker$bypassArmor();
    }
    if (this.absolute) {
        accessor.invoker$bypassMagic();
    }
    if (this.explosion) {
        damageSource.setExplosion();
    }
    if (this.exhaustion != null) {
        accessor.accessor$exhaustion(this.exhaustion.floatValue());
    }
    return (FallingBlockDamageSource) (Object) damageSource;
}
Also used : FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) MinecraftFallingBlockDamageSource(org.spongepowered.common.util.MinecraftFallingBlockDamageSource) DamageSourceAccessor(org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor) MinecraftFallingBlockDamageSource(org.spongepowered.common.util.MinecraftFallingBlockDamageSource)

Aggregations

MinecraftFallingBlockDamageSource (org.spongepowered.common.util.MinecraftFallingBlockDamageSource)2 FallingBlockDamageSource (org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 DamageSourceAccessor (org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor)1 DamageSourceBridge (org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge)1