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();
}
}
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();
}
}
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();
}
}
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();
}
}
}
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();
}
}
Aggregations