use of net.minecraft.util.DamageSource in project Bewitchment by Um-Mitternacht.
the class ItemThornyGarment method onEntityDamage.
@SubscribeEvent
public void onEntityDamage(LivingHurtEvent event) {
if (event.getEntityLiving() instanceof EntityPlayer && BaublesApi.isBaubleEquipped((EntityPlayer) event.getEntityLiving(), this) > 0) {
DamageSource source = event.getSource();
Entity attacker = source.getTrueSource();
if (attacker instanceof EntityLivingBase && !source.getDamageType().equals("thorns")) {
// Don't reflect other forms of thorn dmg, otherwise you get an infinite loop
attacker.attackEntityFrom(DamageSource.causeThornsDamage(event.getEntityLiving()), event.getAmount() * amountReflected);
}
}
}
use of net.minecraft.util.DamageSource in project Tale-of-Kingdoms by Ivasik78.
the class EntitySantaClaus method onDeath.
@Override
public void onDeath(DamageSource damageSource) {
if (!worldObj.isRemote) {
if (damageSource.getSourceOfDamage() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) damageSource.getEntity();
player.addChatMessage(new ChatComponentTranslation("npc.santa.badKid.dialog"));
player.dropItem(Items.coal, worldObj.rand.nextInt(32));
PlayerProvider.get(player).badKid = true;
IntStream.range(1, rand.nextInt(5)).mapToObj(i -> new EntitySnowman(worldObj)).forEach(golem -> {
golem.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
golem.setAttackTarget(player);
worldObj.spawnEntityInWorld(golem);
});
}
}
}
use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.
the class EntityFirechargeChunk method onImpact.
@Override
protected void onImpact(MovingObjectPosition movObjPos) {
if (!this.worldObj.isRemote) {
if (movObjPos.entityHit != null) {
float attackDmg = 1.0F + this.rand.nextFloat();
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);
}
if (movObjPos.entityHit instanceof EntityClayMan) {
movObjPos.entityHit.setFire(3);
movObjPos.entityHit.playSound("random.fizz", 1.0F, 1.0F);
}
} else {
return;
}
}
if (movObjPos.typeOfHit != MovingObjectType.BLOCK || this.getBlockCollisionBox(this.worldObj, movObjPos.blockX, movObjPos.blockY, movObjPos.blockZ) != null) {
// TODO: substitude! change it when
ParticlePacketSender.sendDiggingFx(this.posX, this.posY, this.posZ, this.dimension, Blocks.obsidian);
// TODO: proper texture arrives
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 EntitySnowChunk 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);
}
if ((movObjPos.entityHit == this.target || isEnemy) && movObjPos.entityHit.attackEntityFrom(dmgSrc, 0.0F)) {
if (this.getThrower() instanceof EntityClayMan) {
((EntityClayMan) this.getThrower()).onProjectileHit(this, movObjPos);
}
if (movObjPos.entityHit instanceof EntityClayMan) {
if (((EntityClayMan) movObjPos.entityHit).addEffect(SoldierEffects.getEffect(SoldierEffects.EFF_SLOWMOTION)) != null) {
movObjPos.entityHit.playSound("step.snow", 1.0F, 1.0F);
}
}
} 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 EntityClaySoldier method attackEntityAsMob.
@Override
public boolean attackEntityAsMob(Entity entityIn) {
if (!(entityIn instanceof EntityLivingBase)) {
return false;
}
EntityLivingBase trevor = ((EntityLivingBase) entityIn);
MutableFloat attackDmg = new MutableFloat(this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue());
DamageSource dmgSrc = DamageSource.causeMobDamage(this);
this.callUpgradeFunc(EnumUpgFunctions.ON_ATTACK, upg -> upg.getUpgrade().onAttack(this, upg, trevor, dmgSrc, attackDmg));
boolean attackSuccess = trevor.attackEntityFrom(dmgSrc, attackDmg.floatValue());
if (attackSuccess) {
if (this.i58O55 != null && this.i58O55)
this.world.getEntitiesWithinAABB(EntityClaySoldier.class, this.getEntityBoundingBox().grow(1.0D), entity -> entity != null && entity != trevor && entity.getSoldierTeam() != this.getSoldierTeam()).forEach(entity -> entity.attackEntityFrom(dmgSrc, attackDmg.floatValue()));
int fireAspectMod = EnchantmentHelper.getFireAspectModifier(this);
if (fireAspectMod > 0) {
trevor.setFire(fireAspectMod * 4);
}
this.applyEnchantments(this, trevor);
float additDifficulty = this.world.getDifficultyForLocation(new BlockPos(this)).getAdditionalDifficulty();
if (!ItemStackUtils.isValid(this.getHeldItemMainhand())) {
if (this.isBurning() && this.rand.nextFloat() < additDifficulty * 0.3F) {
trevor.setFire(2 * (int) additDifficulty);
}
}
this.callUpgradeFunc(EnumUpgFunctions.ON_ATTACK_SUCCESS, upg -> upg.getUpgrade().onAttackSuccess(this, upg, trevor));
}
return attackSuccess;
}
Aggregations