use of org.spongepowered.common.util.MinecraftBlockDamageSource in project SpongeCommon by SpongePowered.
the class CactusBlockMixin method impl$reAssignForBlockDamageSource.
@Redirect(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private boolean impl$reAssignForBlockDamageSource(final Entity self, final DamageSource source, float damage, final net.minecraft.world.level.block.state.BlockState state, final net.minecraft.world.level.Level world, final BlockPos pos, final Entity entity) {
if (world.isClientSide()) {
return entity.hurt(source, damage);
}
try {
final ServerLocation location = ServerLocation.of((ServerWorld) world, pos.getX(), pos.getY(), pos.getZ());
final MinecraftBlockDamageSource cactus = new MinecraftBlockDamageSource("cactus", location);
((DamageSourceBridge) (Object) cactus).bridge$setCactusSource();
return entity.hurt(DamageSource.CACTUS, damage);
} finally {
((DamageSourceBridge) source).bridge$setCactusSource();
}
}
use of org.spongepowered.common.util.MinecraftBlockDamageSource in project SpongeCommon by SpongePowered.
the class SpongeBlockDamageSourceBuilder method build.
@SuppressWarnings("ConstantConditions")
@Override
public BlockDamageSource build() throws IllegalStateException {
checkState(this.location != null);
checkState(this.blockSnapshot != null);
checkState(this.damageType != null);
final MinecraftBlockDamageSource damageSource = new MinecraftBlockDamageSource(this.damageType.name(), this.location);
final DamageSourceAccessor accessor = (DamageSourceAccessor) (Object) damageSource;
if (this.absolute) {
accessor.invoker$bypassMagic();
}
if (this.bypasses) {
accessor.invoker$bypassArmor();
}
if (this.scales) {
damageSource.setScalesWithDifficulty();
}
if (this.explosion) {
damageSource.setExplosion();
}
if (this.magical) {
damageSource.setMagic();
}
if (this.creative) {
accessor.invoker$bypassInvul();
}
if (this.exhaustion != null) {
accessor.accessor$exhaustion(this.exhaustion.floatValue());
}
if (this.fire) {
accessor.invoker$setIsFire();
}
return (BlockDamageSource) (Object) damageSource;
}
Aggregations