Search in sources :

Example 31 with DamageSource

use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.

the class UpgradeQuartz method onDamagedSuccess.

@Override
public void onDamagedSuccess(ISoldier<?> soldier, ISoldierUpgradeInst upgradeInst, Entity attacker, DamageSource dmgSource, float damage) {
    int hitsTaken = upgradeInst.getNbtData().getInteger("hitsTaken") + 1;
    long lastCooldown = upgradeInst.getNbtData().getLong("cooldownTime");
    upgradeInst.getNbtData().setLong("cooldownTime", System.currentTimeMillis());
    if (System.currentTimeMillis() - lastCooldown < 2_000) {
        if (hitsTaken >= 5) {
            EntityCreature john = soldier.getEntity();
            hitsTaken = 0;
            short uses = (short) (upgradeInst.getNbtData().getShort("uses") - 1);
            if (uses < 1) {
                soldier.destroyUpgrade(upgradeInst.getUpgrade(), upgradeInst.getUpgradeType(), false);
                john.playSound(SoundEvents.ENTITY_ITEM_BREAK, 0.8F, 0.8F + MiscUtils.RNG.randomFloat() * 0.4F);
            } else {
                upgradeInst.getNbtData().setShort("uses", uses);
            }
            AxisAlignedBB surroundingBB = john.getEntityBoundingBox().grow(1.0D);
            Predicate<EntityCreature> entityChk = entity -> entity instanceof ISoldier && entity != john;
            soldier.getEntity().world.getEntitiesWithinAABB(EntityCreature.class, surroundingBB, entityChk::test).forEach(entity -> entity.knockBack(john, 0.5F, john.posX - entity.posX, john.posZ - entity.posZ));
            ClaySoldiersMod.proxy.spawnParticle(EnumParticle.SHOCKWAVE, john.world.provider.getDimension(), john.posX, john.posY, john.posZ);
        }
        upgradeInst.getNbtData().setInteger("hitsTaken", hitsTaken);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) SoundEvents(net.minecraft.init.SoundEvents) Items(net.minecraft.init.Items) Predicate(java.util.function.Predicate) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumUpgFunctions(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.EnumUpgFunctions) UpgradeFunctions(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.UpgradeFunctions) DamageSource(net.minecraft.util.DamageSource) MiscUtils(de.sanandrew.mods.sanlib.lib.util.MiscUtils) ItemStack(net.minecraft.item.ItemStack) ISoldier(de.sanandrew.mods.claysoldiers.api.soldier.ISoldier) ISoldierUpgradeInst(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst) EnumUpgradeType(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.EnumUpgradeType) CsmConstants(de.sanandrew.mods.claysoldiers.api.CsmConstants) ClaySoldiersMod(de.sanandrew.mods.claysoldiers.util.ClaySoldiersMod) ISoldierUpgrade(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgrade) EntityCreature(net.minecraft.entity.EntityCreature) NonNullList(net.minecraft.util.NonNullList) EnumParticle(de.sanandrew.mods.claysoldiers.util.EnumParticle) Nonnull(javax.annotation.Nonnull) ISoldier(de.sanandrew.mods.claysoldiers.api.soldier.ISoldier) EntityCreature(net.minecraft.entity.EntityCreature)

Example 32 with DamageSource

use of net.minecraft.util.DamageSource in project Random-Things by lumien231.

the class EntityFallingBlockSpecial method fall.

public void fall(float distance, float damageMultiplier) {
    Block block = this.fallTile.getBlock();
    if (this.hurtEntities) {
        int i = MathHelper.ceil(distance - 1.0F);
        if (i > 0) {
            List<Entity> list = Lists.newArrayList(this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox()));
            boolean flag = block == Blocks.ANVIL;
            DamageSource damagesource = flag ? DamageSource.ANVIL : DamageSource.FALLING_BLOCK;
            for (Entity entity : list) {
                entity.attackEntityFrom(damagesource, (float) Math.min(MathHelper.floor((float) i * this.fallHurtAmount), this.fallHurtMax));
            }
            if (flag && (double) this.rand.nextFloat() < 0.05000000074505806D + (double) i * 0.05D) {
                int j = ((Integer) this.fallTile.getValue(BlockAnvil.DAMAGE)).intValue();
                ++j;
                if (j > 2) {
                    this.dontSetBlock = true;
                } else {
                    this.fallTile = this.fallTile.withProperty(BlockAnvil.DAMAGE, Integer.valueOf(j));
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) DamageSource(net.minecraft.util.DamageSource) Block(net.minecraft.block.Block)

Example 33 with DamageSource

use of net.minecraft.util.DamageSource in project ManaCraft by Yaossg.

the class ItemManaApple method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand) {
    if (target instanceof EntityPig && hand == EnumHand.MAIN_HAND && Config.PES > 0) {
        if (playerIn.getServer() != null)
            playerIn.getServer().getPlayerList().sendMessage(new TextComponentTranslation("message.pig"));
        EntityPig pig = (EntityPig) target;
        playerIn.attackEntityFrom(new DamageSource("byPig").setDifficultyScaled().setExplosion().setMagicDamage().setFireDamage(), 16);
        ItemManaApple.appleExplosin(pig);
        Util.giveManaCraftAdvancement(playerIn, "pig_bomb");
        stack.shrink(1);
        return true;
    }
    return false;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) DamageSource(net.minecraft.util.DamageSource) EntityPig(net.minecraft.entity.passive.EntityPig)

Example 34 with DamageSource

use of net.minecraft.util.DamageSource in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class AttackEntity method attackTargetEntityWithCurrentItem.

/**
 * Slightly modified {@link EntityPlayer#attackTargetEntityWithCurrentItem(Entity)} for off hand
 * @param player The player
 * @param targetEntity The entity to attack
 */
public void attackTargetEntityWithCurrentItem(EntityPlayer player, Entity targetEntity) {
    if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget(player, targetEntity))
        return;
    if (targetEntity.canBeAttackedWithItem()) {
        if (!targetEntity.hitByEntity(player)) {
            // float f = (float)player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
            float f = DamageCalculation.getStrengthDamage(player, (ItemKeyblade) player.getHeldItemOffhand().getItem());
            // f += (float)(player.getCapability(ModCapabilities.PLAYER_STATS, null).getStrength() + ((ItemKeyblade)player.getHeldItemOffhand().getItem()).getStrength());
            float f1;
            if (targetEntity instanceof EntityLivingBase) {
                f1 = EnchantmentHelper.getModifierForCreature(player.getHeldItemOffhand(), ((EntityLivingBase) targetEntity).getCreatureAttribute());
            } else {
                f1 = EnchantmentHelper.getModifierForCreature(player.getHeldItemOffhand(), EnumCreatureAttribute.UNDEFINED);
            }
            if (player.getHeldItemMainhand().getItem() instanceof ItemKeyblade) {
            // f -= 3;
            }
            // player.getCooledAttackStrength(0.5F);
            float f2 = 1;
            f = f * (0.2F + f2 * f2 * 0.8F);
            f1 = f1 * f2;
            player.resetCooldown();
            if (f > 0.0F || f1 > 0.0F) {
                boolean flag = f2 > 0.9F;
                boolean flag1 = false;
                int i = 0;
                i = i + EnchantmentHelper.getKnockbackModifier(player);
                if (player.isSprinting() && flag) {
                    player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, player.getSoundCategory(), 1.0F, 1.0F);
                    ++i;
                    flag1 = true;
                }
                boolean flag2 = flag && player.fallDistance > 0.0F && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(MobEffects.BLINDNESS) && !player.isRiding() && targetEntity instanceof EntityLivingBase;
                flag2 = flag2 && !player.isSprinting();
                if (flag2) {
                    f *= 1.5F;
                }
                f = f + f1;
                boolean flag3 = false;
                double d0 = (double) (player.distanceWalkedModified - player.prevDistanceWalkedModified);
                if (flag && !flag2 && !flag1 && player.onGround && d0 < (double) player.getAIMoveSpeed()) {
                    ItemStack itemstack = player.getHeldItem(EnumHand.OFF_HAND);
                    if (itemstack.getItem() instanceof ItemKeyblade) {
                        flag3 = true;
                    }
                }
                float f4 = 0.0F;
                boolean flag4 = false;
                int j = EnchantmentHelper.getFireAspectModifier(player);
                if (targetEntity instanceof EntityLivingBase) {
                    f4 = ((EntityLivingBase) targetEntity).getHealth();
                    if (j > 0 && !targetEntity.isBurning()) {
                        flag4 = true;
                        targetEntity.setFire(1);
                    }
                }
                double d1 = targetEntity.motionX;
                double d2 = targetEntity.motionY;
                double d3 = targetEntity.motionZ;
                DamageSource playerDamage = DamageSource.causePlayerDamage(player);
                playerDamage.damageType = EnumHand.OFF_HAND.name();
                boolean flag5 = targetEntity.attackEntityFrom(playerDamage, f);
                if (flag5) {
                    if (i > 0) {
                        if (targetEntity instanceof EntityLivingBase) {
                            ((EntityLivingBase) targetEntity).knockBack(player, (float) i * 0.5F, (double) MathHelper.sin(player.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(player.rotationYaw * 0.017453292F)));
                        } else {
                            targetEntity.addVelocity((double) (-MathHelper.sin(player.rotationYaw * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(player.rotationYaw * 0.017453292F) * (float) i * 0.5F));
                        }
                        player.motionX *= 0.6D;
                        player.motionZ *= 0.6D;
                        player.setSprinting(false);
                    }
                    if (flag3) {
                        float f3 = 1.0F + EnchantmentHelper.getSweepingDamageRatio(player) * f;
                        for (EntityLivingBase entitylivingbase : player.world.getEntitiesWithinAABB(EntityLivingBase.class, targetEntity.getEntityBoundingBox().grow(1.0D, 0.25D, 1.0D))) {
                            if (entitylivingbase != player && entitylivingbase != targetEntity && !player.isOnSameTeam(entitylivingbase) && player.getDistanceSqToEntity(entitylivingbase) < 9.0D) {
                                entitylivingbase.knockBack(player, 0.4F, (double) MathHelper.sin(player.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(player.rotationYaw * 0.017453292F)));
                                entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage(player), f3);
                            }
                        }
                        player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, player.getSoundCategory(), 1.0F, 1.0F);
                        player.spawnSweepParticles();
                    }
                    if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
                        ((EntityPlayerMP) targetEntity).connection.sendPacket(new SPacketEntityVelocity(targetEntity));
                        targetEntity.velocityChanged = false;
                        targetEntity.motionX = d1;
                        targetEntity.motionY = d2;
                        targetEntity.motionZ = d3;
                    }
                    if (flag2) {
                        player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, player.getSoundCategory(), 1.0F, 1.0F);
                        player.onCriticalHit(targetEntity);
                    }
                    if (!flag2 && !flag3) {
                        if (flag) {
                            player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, player.getSoundCategory(), 1.0F, 1.0F);
                        } else {
                            player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, player.getSoundCategory(), 1.0F, 1.0F);
                        }
                    }
                    if (f1 > 0.0F) {
                        player.onEnchantmentCritical(targetEntity);
                    }
                    player.setLastAttackedEntity(targetEntity);
                    if (targetEntity instanceof EntityLivingBase) {
                        EnchantmentHelper.applyThornEnchantments((EntityLivingBase) targetEntity, player);
                    }
                    EnchantmentHelper.applyArthropodEnchantments(player, targetEntity);
                    ItemStack itemstack1 = player.getHeldItemOffhand();
                    Entity entity = targetEntity;
                    if (targetEntity instanceof MultiPartEntityPart) {
                        IEntityMultiPart ientitymultipart = ((MultiPartEntityPart) targetEntity).parent;
                        if (ientitymultipart instanceof EntityLivingBase) {
                            entity = (EntityLivingBase) ientitymultipart;
                        }
                    }
                    if (!itemstack1.isEmpty() && entity instanceof EntityLivingBase) {
                        ItemStack beforeHitCopy = itemstack1.copy();
                        itemstack1.hitEntity((EntityLivingBase) entity, player);
                        if (itemstack1.isEmpty()) {
                            net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, beforeHitCopy, EnumHand.OFF_HAND);
                            player.setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY);
                        }
                    }
                    if (targetEntity instanceof EntityLivingBase) {
                        float f5 = f4 - ((EntityLivingBase) targetEntity).getHealth();
                        player.addStat(StatList.DAMAGE_DEALT, Math.round(f5 * 10.0F));
                        if (j > 0) {
                            targetEntity.setFire(j * 4);
                        }
                        if (player.world instanceof WorldServer && f5 > 2.0F) {
                            int k = (int) ((double) f5 * 0.5D);
                            ((WorldServer) player.world).spawnParticle(EnumParticleTypes.DAMAGE_INDICATOR, targetEntity.posX, targetEntity.posY + (double) (targetEntity.height * 0.5F), targetEntity.posZ, k, 0.1D, 0.0D, 0.1D, 0.2D);
                        }
                    }
                    player.addExhaustion(0.1F);
                } else {
                    player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, player.getSoundCategory(), 1.0F, 1.0F);
                    if (flag4) {
                        targetEntity.extinguish();
                    }
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) DamageSource(net.minecraft.util.DamageSource) ItemKeyblade(uk.co.wehavecookies56.kk.common.item.base.ItemKeyblade) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) WorldServer(net.minecraft.world.WorldServer) SPacketEntityVelocity(net.minecraft.network.play.server.SPacketEntityVelocity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IEntityMultiPart(net.minecraft.entity.IEntityMultiPart) ItemStack(net.minecraft.item.ItemStack)

Example 35 with DamageSource

use of net.minecraft.util.DamageSource in project BloodMagic by WayofTime.

the class GenericHandler method onLivingDrops.

// Drop Blood Shards
@SubscribeEvent
public static void onLivingDrops(LivingDropsEvent event) {
    EntityLivingBase attackedEntity = event.getEntityLiving();
    DamageSource source = event.getSource();
    Entity entity = source.getTrueSource();
    if (entity != null && entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        ItemStack heldStack = player.getHeldItemMainhand();
        if (!heldStack.isEmpty() && heldStack.getItem() == RegistrarBloodMagicItems.BOUND_SWORD && !(attackedEntity instanceof EntityAnimal))
            for (int i = 0; i <= EnchantmentHelper.getLootingModifier(player); i++) if (attackedEntity.getEntityWorld().rand.nextDouble() < 0.2)
                event.getDrops().add(new EntityItem(attackedEntity.getEntityWorld(), attackedEntity.posX, attackedEntity.posY, attackedEntity.posZ, new ItemStack(RegistrarBloodMagicItems.BLOOD_SHARD, 1, 0)));
    }
}
Also used : Entity(net.minecraft.entity.Entity) DamageSource(net.minecraft.util.DamageSource) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

DamageSource (net.minecraft.util.DamageSource)61 EntityLivingBase (net.minecraft.entity.EntityLivingBase)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)29 Entity (net.minecraft.entity.Entity)28 ItemStack (net.minecraft.item.ItemStack)15 BlockPos (net.minecraft.util.math.BlockPos)11 World (net.minecraft.world.World)10 IBlockState (net.minecraft.block.state.IBlockState)9 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Item (net.minecraft.item.Item)8 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)7 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)7 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 MobEffects (net.minecraft.init.MobEffects)6 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)6 EntityDamageSourceIndirect (net.minecraft.util.EntityDamageSourceIndirect)6 MathHelper (net.minecraft.util.math.MathHelper)6 Collection (java.util.Collection)5