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();
}
}
}
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;
}
Aggregations