use of net.minecraft.util.DamageSource in project BaseMetals by MinecraftModDevelopmentMods.
the class MMDToolEffects method extraEffectsOnAttack.
/**
* @param material
* The material
* @param itemStack
* The item
* @param target
* The target
* @param attacker
* The attacker
*/
public static void extraEffectsOnAttack(final MMDMaterial material, final ItemStack itemStack, final EntityLivingBase target, final EntityLivingBase attacker) {
final String materialName = material.getName();
if (materialName.equals(MaterialNames.COLDIRON)) {
if (target.isImmuneToFire()) {
final DamageSource extraDamage = DamageSource.GENERIC;
target.attackEntityFrom(extraDamage, 3f);
}
} else if (materialName.equals(MaterialNames.ADAMANTINE)) {
if (target.getMaxHealth() > 20f) {
final DamageSource extraDamage = DamageSource.GENERIC;
target.attackEntityFrom(extraDamage, 4f);
}
} else if (materialName.equals(MaterialNames.MITHRIL)) {
if (target.getCreatureAttribute() == EnumCreatureAttribute.UNDEAD) {
final PotionEffect wither = new PotionEffect(MobEffects.WITHER, 60, 3);
final PotionEffect blind = new PotionEffect(MobEffects.BLINDNESS, 60, 1);
target.addPotionEffect(wither);
target.addPotionEffect(blind);
}
} else if ((materialName.equals(MaterialNames.AQUARIUM)) && (target.canBreatheUnderwater())) {
final DamageSource extraDamage = DamageSource.GENERIC;
target.attackEntityFrom(extraDamage, 4f);
}
}
use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.
the class EntityEmeraldChunk method onImpact.
@Override
protected void onImpact(MovingObjectPosition movObjPos) {
if (movObjPos.entityHit != null) {
boolean isEnemy = movObjPos.entityHit instanceof EntityClayMan && this.target instanceof EntityClayMan && !((EntityClayMan) movObjPos.entityHit).getClayTeam().equals(((EntityClayMan) this.target).getClayTeam());
DamageSource dmgSrc = DamageSource.causeThrownDamage(this, this.getThrower());
if (this.getThrower() == null) {
dmgSrc = DamageSource.causeThrownDamage(this, this);
}
dmgSrc.setDamageBypassesArmor();
if (movObjPos.entityHit == this.target || isEnemy) {
float attackDmg = 3.0F + this.rand.nextFloat();
if (movObjPos.entityHit.isWet()) {
attackDmg *= 2.0F;
}
if (movObjPos.entityHit.attackEntityFrom(dmgSrc, attackDmg)) {
if (this.getThrower() instanceof EntityClayMan) {
((EntityClayMan) this.getThrower()).onProjectileHit(this, movObjPos);
}
if (movObjPos.entityHit instanceof EntityClayMan) {
EntityClayMan iChun = (EntityClayMan) movObjPos.entityHit;
movObjPos.entityHit.playSound("ambient.weather.thunder", 1.0F, 8.0F);
SoldierEffectInst effect = iChun.addEffect(SoldierEffects.getEffect(SoldierEffects.EFF_THUNDER));
if (effect != null && this.origin != null) {
effect.getNbtTag().setDouble("originX", this.origin.getValue0());
effect.getNbtTag().setDouble("originY", this.origin.getValue1());
effect.getNbtTag().setDouble("originZ", this.origin.getValue2());
}
iChun.updateUpgradeEffectRenders();
}
}
} else {
return;
}
}
if (!this.worldObj.isRemote) {
if (movObjPos.typeOfHit != MovingObjectType.BLOCK || this.getBlockCollisionBox(this.worldObj, movObjPos.blockX, movObjPos.blockY, movObjPos.blockZ) != null) {
ParticlePacketSender.sendDiggingFx(this.posX, this.posY, this.posZ, this.dimension, Blocks.snow);
this.setDead();
}
this.dataWatcher.updateObject(DW_DEAD, (byte) (this.isDead ? 1 : 0));
}
}
use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.
the class EntityGravelChunk method onImpact.
@Override
protected void onImpact(MovingObjectPosition movObjPos) {
if (movObjPos.entityHit != null) {
float attackDmg = 2.0F + this.rand.nextFloat() * 2.0F;
boolean isEnemy = movObjPos.entityHit instanceof EntityClayMan && this.target instanceof EntityClayMan && ((EntityClayMan) movObjPos.entityHit).getClayTeam().equals(((EntityClayMan) this.target).getClayTeam());
DamageSource dmgSrc = DamageSource.causeThrownDamage(this, this.getThrower());
if (this.getThrower() == null) {
dmgSrc = DamageSource.causeThrownDamage(this, this);
}
if ((movObjPos.entityHit == this.target || isEnemy) && movObjPos.entityHit.attackEntityFrom(dmgSrc, attackDmg)) {
if (this.getThrower() instanceof EntityClayMan) {
((EntityClayMan) this.getThrower()).onProjectileHit(this, movObjPos);
}
} else {
return;
}
}
if (!this.worldObj.isRemote) {
if (movObjPos.typeOfHit != MovingObjectType.BLOCK || this.getBlockCollisionBox(this.worldObj, movObjPos.blockX, movObjPos.blockY, movObjPos.blockZ) != null) {
ParticlePacketSender.sendDiggingFx(this.posX, this.posY, this.posZ, this.dimension, Blocks.gravel);
this.setDead();
}
this.dataWatcher.updateObject(DW_DEAD, (byte) (this.isDead ? 1 : 0));
}
}
use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.
the class EntityClayProjectile method doCollisionCheck.
private void doCollisionCheck() {
Vec3d posVec = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d futurePosVec = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult hitObj = this.world.rayTraceBlocks(posVec, futurePosVec, false, true, false);
posVec = new Vec3d(this.posX, this.posY, this.posZ);
futurePosVec = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (hitObj != null) {
futurePosVec = new Vec3d(hitObj.hitVec.x, hitObj.hitVec.y, hitObj.hitVec.z);
}
Entity entity = null;
AxisAlignedBB checkBB = this.getEntityBoundingBox().offset(this.motionX, this.motionY, this.motionZ).grow(1.0D, 1.0D, 1.0D);
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, checkBB);
double minDist = 0.0D;
float collisionRange;
for (Entity collidedEntity : list) {
if (collidedEntity.canBeCollidedWith() && collidedEntity != this.shooterCache) {
collisionRange = 0.1F;
AxisAlignedBB collisionAABB = collidedEntity.getEntityBoundingBox().grow(collisionRange, collisionRange, collisionRange);
RayTraceResult interceptObj = collisionAABB.calculateIntercept(posVec, futurePosVec);
if (interceptObj != null) {
double vecDistance = posVec.distanceTo(interceptObj.hitVec);
if (collidedEntity == this.targetCache && (vecDistance < minDist || minDist == 0.0D)) {
entity = collidedEntity;
minDist = vecDistance;
}
}
}
}
if (entity != null) {
hitObj = new RayTraceResult(entity);
}
if (hitObj != null && hitObj.entityHit != null && hitObj.entityHit instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) hitObj.entityHit;
if (player.capabilities.disableDamage) {
hitObj = null;
}
}
if (hitObj != null) {
if (hitObj.entityHit != null) {
MutableFloat dmg = new MutableFloat(this.getDamage(hitObj.entityHit));
DamageSource damagesource = this.getProjDamageSource(hitObj.entityHit);
if (this.isBurning() && !(hitObj.entityHit instanceof EntityEnderman)) {
hitObj.entityHit.setFire(5);
}
if (this.shooterCache instanceof EntityClaySoldier) {
EntityClaySoldier soldier = (EntityClaySoldier) this.shooterCache;
final Entity target = hitObj.entityHit;
soldier.callUpgradeFunc(EnumUpgFunctions.ON_ATTACK, upg -> upg.getUpgrade().onAttack(soldier, upg, target, damagesource, dmg));
}
boolean preHitVelocityChanged = hitObj.entityHit.velocityChanged;
boolean preHitAirBorne = hitObj.entityHit.isAirBorne;
double preHitMotionX = hitObj.entityHit.motionX;
double preHitMotionY = hitObj.entityHit.motionY;
double preHitMotionZ = hitObj.entityHit.motionZ;
if (this.onPreHit(hitObj.entityHit, damagesource, dmg) && hitObj.entityHit.attackEntityFrom(damagesource, dmg.floatValue())) {
if (this.shooterCache instanceof EntityClaySoldier) {
EntityClaySoldier soldier = (EntityClaySoldier) this.shooterCache;
final Entity target = hitObj.entityHit;
soldier.callUpgradeFunc(EnumUpgFunctions.ON_ATTACK_SUCCESS, upg -> upg.getUpgrade().onAttackSuccess(soldier, upg, target));
}
hitObj.entityHit.velocityChanged = preHitVelocityChanged;
hitObj.entityHit.isAirBorne = preHitAirBorne;
hitObj.entityHit.motionX = preHitMotionX;
hitObj.entityHit.motionY = preHitMotionY;
hitObj.entityHit.motionZ = preHitMotionZ;
this.onPostHit(hitObj.entityHit, damagesource);
if (hitObj.entityHit instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) hitObj.entityHit;
if (!this.world.isRemote) {
living.setArrowCountInEntity(living.getArrowCountInEntity() + 1);
}
double deltaX = this.posX - living.posX;
double deltaZ = this.posZ - living.posZ;
while (deltaX * deltaX + deltaZ * deltaZ < 0.0001D) {
deltaZ = (Math.random() - Math.random()) * 0.01D;
deltaX = (Math.random() - Math.random()) * 0.01D;
}
this.knockBackEntity(living, deltaX, deltaZ);
if (this.shooterCache instanceof EntityLivingBase) {
EnchantmentHelper.applyThornEnchantments(living, this.shooterCache);
EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase) this.shooterCache, living);
}
}
}
} else {
this.onBlockHit(hitObj.getBlockPos());
}
this.processHit(hitObj);
}
}
use of net.minecraft.util.DamageSource in project BloodMagic by WayofTime.
the class StatTrackerHandler method entityHurt.
// Tracks: Fall Protect, Arrow Protect, Physical Protect, Grave Digger, Sprint Attack, Critical Strike, Nocturnal Prowess
@SubscribeEvent
public static void entityHurt(LivingHurtEvent event) {
DamageSource source = event.getSource();
Entity sourceEntity = event.getSource().getTrueSource();
EntityLivingBase attackedEntity = event.getEntityLiving();
if (attackedEntity instanceof EntityPlayer) {
EntityPlayer attackedPlayer = (EntityPlayer) attackedEntity;
// Living Armor Handling
if (LivingArmour.hasFullSet(attackedPlayer)) {
float amount = Math.min(Utils.getModifiedDamage(attackedPlayer, event.getSource(), event.getAmount()), attackedPlayer.getHealth());
ItemStack chestStack = attackedPlayer.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
if (armour != null) {
if (sourceEntity != null && !source.isMagicDamage() && !source.isProjectile())
StatTrackerPhysicalProtect.incrementCounter(armour, amount);
if (source.equals(DamageSource.FALL))
StatTrackerFallProtect.incrementCounter(armour, amount);
if (source.isProjectile())
StatTrackerArrowProtect.incrementCounter(armour, amount);
}
} else {
ItemStack chestStack = attackedPlayer.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
if (chestStack.getItem() instanceof ItemSentientArmour) {
ItemSentientArmour armour = (ItemSentientArmour) chestStack.getItem();
armour.onPlayerAttacked(chestStack, source, attackedPlayer);
}
}
}
if (sourceEntity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sourceEntity;
// Living Armor Handling
if (LivingArmour.hasFullSet(player)) {
ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
if (armour != null) {
ItemStack mainWeapon = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
event.setAmount((float) (event.getAmount() + lastPlayerSwingStrength * armour.getAdditionalDamageOnHit(event.getAmount(), player, attackedEntity, mainWeapon)));
float amount = Math.min(Utils.getModifiedDamage(attackedEntity, event.getSource(), event.getAmount()), attackedEntity.getHealth());
if (!source.isProjectile()) {
StatTrackerMeleeDamage.incrementCounter(armour, amount);
if (player.getEntityWorld().getLight(player.getPosition()) <= 9)
StatTrackerNightSight.incrementCounter(armour, amount);
if (mainWeapon.getItem() instanceof ItemSpade)
StatTrackerGraveDigger.incrementCounter(armour, amount);
if (player.isSprinting())
StatTrackerSprintAttack.incrementCounter(armour, amount);
boolean isCritical = lastPlayerSwingStrength > 0.9 && player.fallDistance > 0.0F && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(MobEffects.BLINDNESS) && !player.isRiding() && !player.isSprinting();
if (isCritical)
StatTrackerCriticalStrike.incrementCounter(armour, amount);
double kb = armour.getKnockbackOnHit(player, attackedEntity, mainWeapon);
if (kb > 0)
attackedEntity.knockBack(player, (float) kb * 0.5F, (double) MathHelper.sin(player.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(player.rotationYaw * 0.017453292F)));
}
}
}
}
}
Aggregations