Search in sources :

Example 6 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)

Example 7 with DamageSourceBridge

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

the class MagmaBlockMixin method impl$swapDamageSourceForMagma.

@Redirect(method = "stepOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private boolean impl$swapDamageSourceForMagma(Entity entity, DamageSource source, float damage, Level world, BlockPos pos, Entity original) {
    if (!world.isClientSide) {
        try {
            final ServerLocation location = ServerLocation.of((ServerWorld) world, pos.getX(), pos.getY(), pos.getZ());
            final DamageSource hotFloor = MinecraftBlockDamageSource.ofFire("hotFloor", location, false);
            ((DamageSourceBridge) (Object) hotFloor).bridge$setHotFloorSource();
            return entity.hurt(DamageSource.HOT_FLOOR, damage);
        } finally {
            ((DamageSourceBridge) source).bridge$setHotFloorSource();
        }
    }
    return entity.hurt(source, damage);
}
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