Search in sources :

Example 1 with DamageSource

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);
        }
    }
}
Also used : DamageSource(net.minecraft.entity.damage.DamageSource) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with DamageSource

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);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) IconofsinEntity(mod.azure.doom.entity.tierboss.IconofsinEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) GameStateChangeS2CPacket(net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket) DamageSource(net.minecraft.entity.damage.DamageSource) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 3 with DamageSource

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);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) IconofsinEntity(mod.azure.doom.entity.tierboss.IconofsinEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) GameStateChangeS2CPacket(net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket) DamageSource(net.minecraft.entity.damage.DamageSource) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 4 with DamageSource

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);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) TrinketsApi(dev.emi.trinkets.api.TrinketsApi) Pair(net.minecraft.util.Pair) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) Inject(org.spongepowered.asm.mixin.injection.Inject) LivingEntity(net.minecraft.entity.LivingEntity) StatusEffects(net.minecraft.entity.effect.StatusEffects) DamageSource(net.minecraft.entity.damage.DamageSource) DoomItems(mod.azure.doom.util.registry.DoomItems) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) SlotReference(dev.emi.trinkets.api.SlotReference) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Mixin(org.spongepowered.asm.mixin.Mixin) At(org.spongepowered.asm.mixin.injection.At) SlotReference(dev.emi.trinkets.api.SlotReference) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with DamageSource

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);
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) DamageSource(net.minecraft.entity.damage.DamageSource) ItemStack(net.minecraft.item.ItemStack)

Aggregations

DamageSource (net.minecraft.entity.damage.DamageSource)11 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 LivingEntity (net.minecraft.entity.LivingEntity)7 IconofsinEntity (mod.azure.doom.entity.tierboss.IconofsinEntity)6 Entity (net.minecraft.entity.Entity)6 PersistentProjectileEntity (net.minecraft.entity.projectile.PersistentProjectileEntity)6 GameStateChangeS2CPacket (net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket)6 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)6 BlockEntity (net.minecraft.block.entity.BlockEntity)3 TickingLightEntity (mod.azure.doom.entity.tileentity.TickingLightEntity)2 ItemStack (net.minecraft.item.ItemStack)2 ElectricShockDamageSource (chronosacaria.mcdw.damagesource.ElectricShockDamageSource)1 AetherNonLivingEntity (com.aether.entities.AetherNonLivingEntity)1 SlotReference (dev.emi.trinkets.api.SlotReference)1 TrinketsApi (dev.emi.trinkets.api.TrinketsApi)1 List (java.util.List)1 DoomItems (mod.azure.doom.util.registry.DoomItems)1 AreaEffectCloudEntity (net.minecraft.entity.AreaEffectCloudEntity)1 ItemEntity (net.minecraft.entity.ItemEntity)1 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)1