Search in sources :

Example 1 with DamageSourceBridge

use of org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge 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 DamageSourceBridge

use of org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge in project SpongeCommon by SpongePowered.

the class CampfireBlockMixin method impl$spongeRedirectForFireDamage.

@Redirect(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private boolean impl$spongeRedirectForFireDamage(final Entity self, final DamageSource source, final float damage, final BlockState blockState, final Level world, final BlockPos blockPos, final Entity entity) {
    if (self.level.isClientSide) {
        // Short Circuit
        return self.hurt(source, damage);
    }
    try {
        final ServerLocation location = ServerLocation.of((ServerWorld) world, blockPos.getX(), blockPos.getY(), blockPos.getZ());
        final DamageSource fire = MinecraftBlockDamageSource.ofFire("inFire", location, true);
        ((DamageSourceBridge) fire).bridge$setFireSource();
        return self.hurt(DamageSource.IN_FIRE, damage);
    } finally {
        // Since "source" is already the DamageSource.IN_FIRE object, we can re-use it to re-assign.
        ((DamageSourceBridge) source).bridge$setFireSource();
    }
}
Also used : DamageSource(net.minecraft.world.damagesource.DamageSource) MinecraftBlockDamageSource(org.spongepowered.common.util.MinecraftBlockDamageSource) DamageSourceBridge(org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge) ServerLocation(org.spongepowered.api.world.server.ServerLocation) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with DamageSourceBridge

use of org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge in project SpongeCommon by SpongePowered.

the class EntityMixin method impl$ThrowDamageEventWithLightingSource.

@Redirect(method = "thunderHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private boolean impl$ThrowDamageEventWithLightingSource(final Entity entity, final DamageSource source, final float damage, final ServerLevel level, final LightningBolt lightningBolt) {
    if (!this.level.isClientSide) {
        return entity.hurt(source, damage);
    }
    try {
        final EntityDamageSource lightning = new EntityDamageSource("lightningBolt", lightningBolt);
        ((DamageSourceBridge) lightning).bridge$setLightningSource();
        return entity.hurt(DamageSource.LIGHTNING_BOLT, damage);
    } finally {
        ((DamageSourceBridge) source).bridge$setLightningSource();
    }
}
Also used : DamageSourceBridge(org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge) EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with DamageSourceBridge

use of org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge 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 5 with DamageSourceBridge

use of org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge in project SpongeCommon by SpongePowered.

the class BaseFireBlockMixin method impl$spongeRedirectForFireDamage.

@Redirect(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private boolean impl$spongeRedirectForFireDamage(final Entity self, final DamageSource source, final float damage, final BlockState blockState, final Level world, final BlockPos blockPos, final Entity entity) {
    if (self.level.isClientSide) {
        // Short Circuit
        return self.hurt(source, damage);
    }
    try {
        final ServerLocation location = ServerLocation.of((ServerWorld) world, blockPos.getX(), blockPos.getY(), blockPos.getZ());
        final DamageSource fire = MinecraftBlockDamageSource.ofFire("inFire", location, true);
        ((DamageSourceBridge) fire).bridge$setFireSource();
        return self.hurt(DamageSource.IN_FIRE, damage);
    } finally {
        // Since "source" is already the DamageSource.IN_FIRE object, we can re-use it to re-assign.
        ((DamageSourceBridge) source).bridge$setFireSource();
    }
}
Also used : DamageSource(net.minecraft.world.damagesource.DamageSource) MinecraftBlockDamageSource(org.spongepowered.common.util.MinecraftBlockDamageSource) DamageSourceBridge(org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge) ServerLocation(org.spongepowered.api.world.server.ServerLocation) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

Redirect (org.spongepowered.asm.mixin.injection.Redirect)7 DamageSourceBridge (org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge)7 ServerLocation (org.spongepowered.api.world.server.ServerLocation)5 MinecraftBlockDamageSource (org.spongepowered.common.util.MinecraftBlockDamageSource)5 DamageSource (net.minecraft.world.damagesource.DamageSource)4 EntityDamageSource (net.minecraft.world.damagesource.EntityDamageSource)2 AABB (net.minecraft.world.phys.AABB)1 MinecraftFallingBlockDamageSource (org.spongepowered.common.util.MinecraftFallingBlockDamageSource)1