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