use of net.minecraft.entity.damage.DamageSource in project EnvironmentZ by Globox1997.
the class ColdEffect method applyUpdateEffect.
@Override
public void applyUpdateEffect(LivingEntity entity, int amplifier) {
if (!entity.world.isClient && !isWarmBlockNearBy(entity)) {
float wetMultiplicator = 1.0F;
if (entity.hasStatusEffect(EffectInit.WET)) {
wetMultiplicator = 2.0F;
}
DamageSource damageSource = createDamageSource();
entity.damage(damageSource, ConfigInit.CONFIG.cold_damage * wetMultiplicator);
if (entity instanceof PlayerEntity) {
((PlayerEntity) entity).addExhaustion(0.005F);
}
}
}
use of net.minecraft.entity.damage.DamageSource in project MCDoom by AzureDoom.
the class ChaingunBulletEntity method onEntityHit.
@Override
protected void onEntityHit(EntityHitResult entityHitResult) {
Entity entity = entityHitResult.getEntity();
if (entityHitResult.getType() != HitResult.Type.ENTITY || !((EntityHitResult) entityHitResult).getEntity().isPartOf(entity)) {
if (!this.world.isClient) {
this.remove(Entity.RemovalReason.DISCARDED);
}
}
Entity entity2 = this.getOwner();
DamageSource damageSource2;
if (entity2 == null) {
damageSource2 = DamageSource.arrow(this, this);
} else {
damageSource2 = DamageSource.arrow(this, entity2);
if (entity2 instanceof LivingEntity) {
((LivingEntity) entity2).onAttacking(entity);
}
}
if (entity.damage(damageSource2, projectiledamage)) {
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
if (!this.world.isClient && entity2 instanceof LivingEntity) {
EnchantmentHelper.onUserDamaged(livingEntity, entity2);
EnchantmentHelper.onTargetDamaged((LivingEntity) entity2, livingEntity);
this.remove(Entity.RemovalReason.DISCARDED);
}
this.onHit(livingEntity);
if (entity2 != null && livingEntity != entity2 && livingEntity instanceof PlayerEntity && entity2 instanceof ServerPlayerEntity && !this.isSilent()) {
((ServerPlayerEntity) entity2).networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PROJECTILE_HIT_PLAYER, 0.0F));
}
}
} else {
if (!this.world.isClient) {
this.remove(Entity.RemovalReason.DISCARDED);
}
}
}
use of net.minecraft.entity.damage.DamageSource in project MCDoom by AzureDoom.
the class ShotgunShellEntity method onEntityHit.
@Override
protected void onEntityHit(EntityHitResult entityHitResult) {
Entity entity = entityHitResult.getEntity();
if (entityHitResult.getType() != HitResult.Type.ENTITY || !((EntityHitResult) entityHitResult).getEntity().isPartOf(entity)) {
if (!this.world.isClient) {
this.remove(Entity.RemovalReason.DISCARDED);
}
}
Entity entity2 = this.getOwner();
DamageSource damageSource2;
if (entity2 == null) {
damageSource2 = DamageSource.arrow(this, this);
} else {
damageSource2 = DamageSource.arrow(this, entity2);
if (entity2 instanceof LivingEntity) {
((LivingEntity) entity2).onAttacking(entity);
}
}
if (entity.damage(damageSource2, shelldamage)) {
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
if (!this.world.isClient && entity2 instanceof LivingEntity) {
EnchantmentHelper.onUserDamaged(livingEntity, entity2);
EnchantmentHelper.onTargetDamaged((LivingEntity) entity2, livingEntity);
this.remove(Entity.RemovalReason.DISCARDED);
}
this.onHit(livingEntity);
if (entity2 != null && livingEntity != entity2 && livingEntity instanceof PlayerEntity && entity2 instanceof ServerPlayerEntity && !this.isSilent()) {
((ServerPlayerEntity) entity2).networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PROJECTILE_HIT_PLAYER, 0.0F));
}
}
} else {
if (!this.world.isClient) {
this.remove(Entity.RemovalReason.DISCARDED);
}
}
}
use of net.minecraft.entity.damage.DamageSource in project MCDoom by AzureDoom.
the class LivingEntityMixin method tryUseTotem.
@Inject(method = "tryUseTotem", at = @At(value = "HEAD"), cancellable = true)
private void tryUseTotem(DamageSource source, CallbackInfoReturnable<Boolean> ci) {
LivingEntity livingEntity = (LivingEntity) (Object) this;
if (source.isOutOfWorld()) {
ci.setReturnValue(false);
} else {
ItemStack stack = TrinketsApi.getTrinketComponent(livingEntity).map(component -> {
List<Pair<SlotReference, ItemStack>> res = component.getEquipped(DoomItems.SOULCUBE);
return res.size() > 0 ? res.get(0).getRight() : ItemStack.EMPTY;
}).orElse(ItemStack.EMPTY);
if (!stack.isEmpty()) {
stack.damage(1, livingEntity, p -> p.sendToolBreakStatus(livingEntity.getActiveHand()));
livingEntity.setHealth(20.0F);
livingEntity.clearStatusEffects();
livingEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, 100, 4));
livingEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 100, 4));
livingEntity.world.sendEntityStatus(livingEntity, (byte) 95);
ci.setReturnValue(true);
}
}
}
use of net.minecraft.entity.damage.DamageSource in project MCDungeonsArmors by chronosacaria.
the class RecyclerEnchantment method onUserDamaged.
@Override
public void onUserDamaged(LivingEntity user, Entity attacker, int level) {
DamageSource damageSource = user.getRecentDamageSource();
if (damageSource != null && damageSource.isProjectile()) {
float recyclerRand = user.getRandom().nextFloat();
float recyclerChance = level * 0.1F;
if (recyclerRand <= recyclerChance) {
ItemEntity arrowDrop = new ItemEntity(user.world, user.getX(), user.getY(), user.getZ(), new ItemStack(Items.ARROW));
user.world.spawnEntity(arrowDrop);
}
}
}
Aggregations