Search in sources :

Example 1 with MinecraftBlockDamageSource

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();
    }
}
Also used : DamageSourceBridge(org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge) ServerLocation(org.spongepowered.api.world.server.ServerLocation) MinecraftBlockDamageSource(org.spongepowered.common.util.MinecraftBlockDamageSource) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 2 with MinecraftBlockDamageSource

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;
}
Also used : MinecraftBlockDamageSource(org.spongepowered.common.util.MinecraftBlockDamageSource) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) MinecraftBlockDamageSource(org.spongepowered.common.util.MinecraftBlockDamageSource) DamageSourceAccessor(org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor)

Aggregations

MinecraftBlockDamageSource (org.spongepowered.common.util.MinecraftBlockDamageSource)2 BlockDamageSource (org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource)1 ServerLocation (org.spongepowered.api.world.server.ServerLocation)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