Search in sources :

Example 1 with DamageSourceAccessor

use of org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor in project SpongeCommon by SpongePowered.

the class SpongeIndirectEntityDamageSourceBuilder method build.

@Override
public IndirectEntityDamageSource build() throws IllegalStateException {
    checkState(this.reference.get() != null);
    checkState(this.proxy.get() != null);
    checkState(this.damageType != null);
    final net.minecraft.world.damagesource.IndirectEntityDamageSource damageSource = new net.minecraft.world.damagesource.IndirectEntityDamageSource(this.damageType.name(), (net.minecraft.world.entity.Entity) this.reference.get(), (net.minecraft.world.entity.Entity) this.proxy.get());
    final DamageSourceAccessor accessor = (DamageSourceAccessor) 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 (IndirectEntityDamageSource) damageSource;
}
Also used : DamageSourceAccessor(org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)

Example 2 with DamageSourceAccessor

use of org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor in project SpongeCommon by SpongePowered.

the class SpongeDamageSourceBuilder method build.

@SuppressWarnings("ConstantConditions")
@Override
public DamageSource build() throws IllegalStateException {
    checkState(this.damageType != null, "DamageType was null!");
    final net.minecraft.world.damagesource.DamageSource source = DamageSourceAccessor.invoker$new(this.damageType.toString());
    final DamageSourceAccessor accessor = (DamageSourceAccessor) source;
    if (!this.scales && this.bypasses && !this.explosion && !this.absolute && !this.magical && !this.creative && !this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.DROWN)) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.DROWN;
    }
    if (!this.scales && !this.bypasses && !this.explosion && !this.absolute && !this.magical && !this.creative && !this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.DRYOUT.get())) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.DRY_OUT;
    }
    if (!this.scales && !this.bypasses && !this.explosion && !this.absolute && !this.magical && !this.creative && !this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.FALL.get())) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.FALL;
    }
    if (!this.scales && !this.bypasses && !this.explosion && !this.absolute && !this.magical && !this.creative && this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.FIRE.get())) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.ON_FIRE;
    }
    if (!this.scales && this.bypasses && !this.explosion && !this.absolute && !this.magical && !this.creative && !this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.GENERIC.get())) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.GENERIC;
    }
    if (!this.scales && this.bypasses && !this.explosion && !this.absolute && this.magical && !this.creative && !this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.MAGIC.get())) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.MAGIC;
    }
    if (!this.scales && this.bypasses && !this.explosion && this.absolute && !this.magical && !this.creative && !this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.HUNGER.get())) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.STARVE;
    }
    if (!this.scales && this.bypasses && !this.explosion && !this.absolute && !this.magical && this.creative && !this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.VOID.get())) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.OUT_OF_WORLD;
    }
    if (!this.scales && !this.bypasses && !this.explosion && !this.absolute && this.magical && !this.creative && !this.fire && this.exhaustion == null && this.damageType.equals(DamageTypes.MAGIC.get())) {
        return (DamageSource) net.minecraft.world.damagesource.DamageSource.WITHER;
    }
    if (this.absolute) {
        accessor.invoker$bypassMagic();
    }
    if (this.bypasses) {
        accessor.invoker$bypassArmor();
    }
    if (this.creative) {
        accessor.invoker$bypassInvul();
    }
    if (this.magical) {
        source.setMagic();
    }
    if (this.scales) {
        source.setScalesWithDifficulty();
    }
    if (this.explosion) {
        source.setExplosion();
    }
    if (this.exhaustion != null) {
        accessor.accessor$exhaustion(this.exhaustion.floatValue());
    }
    if (this.fire) {
        accessor.invoker$setIsFire();
    }
    return (DamageSource) source;
}
Also used : DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) DamageSourceAccessor(org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor)

Example 3 with DamageSourceAccessor

use of org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor 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)

Example 4 with DamageSourceAccessor

use of org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor 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)

Example 5 with DamageSourceAccessor

use of org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor in project SpongeCommon by SpongePowered.

the class SpongeEntityDamageSourceBuilder method build.

@SuppressWarnings("ConstantConditions")
@Override
public EntityDamageSource build() throws IllegalStateException {
    checkState(this.damageType != null, "Damage type cannot be null!");
    checkState(this.reference.get() != null);
    final net.minecraft.world.damagesource.EntityDamageSource damageSource = new net.minecraft.world.damagesource.EntityDamageSource(this.damageType.name(), (net.minecraft.world.entity.Entity) this.reference.get());
    final DamageSourceAccessor accessor = (DamageSourceAccessor) 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 (EntityDamageSource) damageSource;
}
Also used : DamageSourceAccessor(org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)

Aggregations

DamageSourceAccessor (org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor)5 BlockDamageSource (org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource)1 DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)1 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)1 FallingBlockDamageSource (org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource)1 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)1 MinecraftBlockDamageSource (org.spongepowered.common.util.MinecraftBlockDamageSource)1 MinecraftFallingBlockDamageSource (org.spongepowered.common.util.MinecraftFallingBlockDamageSource)1