Java Code Examples for net.minecraft.enchantment.EnchantmentHelper#getModifierForCreature()
The following examples show how to use
net.minecraft.enchantment.EnchantmentHelper#getModifierForCreature() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityToroNpc.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
public boolean attackEntityAsMob(Entity entityIn) { float f = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); int knockback = 0; if (entityIn instanceof EntityLivingBase) { f += EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase) entityIn).getCreatureAttribute()); knockback += EnchantmentHelper.getKnockbackModifier(this); } boolean successfulAttack = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), f); if (successfulAttack) { handleSuccessfulAttack(entityIn, knockback); } return successfulAttack; }
Example 2
Source File: DataHelper.java From GokiStats with MIT License | 6 votes |
public static float getDamageDealt(EntityPlayer player, Entity target, DamageSource source) { float damage = (float) player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); float bonusDamage = 0.0F; boolean targetIsLiving = target instanceof EntityLivingBase; boolean critical; ItemStack stack = player.getHeldItemMainhand(); if (targetIsLiving) { bonusDamage = EnchantmentHelper.getModifierForCreature(stack, ((EntityLivingBase) target).getCreatureAttribute()); } if ((damage > 0.0F) || (bonusDamage > 0.0F)) { critical = (player.fallDistance > 0.0F) && (!player.onGround) && (!player.isOnLadder()) && (!player.isInWater()) && (!player.isPotionActive(Potion.getPotionFromResourceLocation("blindness"))) && (player.getRidingEntity() == null) && (targetIsLiving); if ((critical) && (damage > 0.0F)) { damage *= 1.5F; } damage += bonusDamage; } return damage; }
Example 3
Source File: ItemSheathKatana.java From Sakura_mod with MIT License | 5 votes |
@Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { EnumHand hand = entityLiving.getActiveHand(); //big sweep!!! entityLiving.swingArm(hand); float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F; float f3 = 4.0F + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f; float sweepingRatio = 1f+EnchantmentHelper.getSweepingDamageRatio(entityLiving); for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.4D + sweepingRatio * 1.2D, 0.3D + sweepingRatio * 0.15D, 1.4D + sweepingRatio * 1.2D))) { if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) { if (entitylivingbase instanceof EntityLivingBase) { if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer) entitylivingbase).isActiveItemStackBlocking()) { //disable shield ((EntityPlayer) entitylivingbase).disableShield(false); } ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.4F * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F))); entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } if (entitylivingbase instanceof MultiPartEntityPart) { entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } } } worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F); if (worldIn instanceof WorldServer) { double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F)); double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F); ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D); } dropHand(entityLiving, hand, setKatana(stack)); ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(katana, 15); }
Example 4
Source File: ItemShinai.java From Sakura_mod with MIT License | 5 votes |
@Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { int i = this.getMaxItemUseDuration(stack) - timeLeft; if (i < 0) return; entityLiving.swingArm(entityLiving.getActiveHand()); float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F; float f1 = i / 15F; f1 = (f1 * f1 + f1 * 2.0F) / 2F; if(f1>8F) f1=8f; float f3 = f1 + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f ; float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving); for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.6D + sweepingRatio * 1.2D, 0.5D + sweepingRatio * 0.15D, 1.6D + sweepingRatio * 1.2D))) { if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) { if (entitylivingbase instanceof EntityLivingBase) { f1 = f1/10; ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.6F * f1 * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F))); entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } if (entitylivingbase instanceof MultiPartEntityPart) { entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } } } worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F); if (worldIn instanceof WorldServer) { double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F)); double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F); ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D); } stack.damageItem(2, entityLiving); ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 25); }
Example 5
Source File: AutoTool.java From ForgeHax with MIT License | 5 votes |
private double getEntityAttackModifier(InvItem item, Entity target) { return EnchantmentHelper.getModifierForCreature( item.getItemStack(), Optional.ofNullable(target) .filter(EntityLivingBase.class::isInstance) .map(EntityLivingBase.class::cast) .map(EntityLivingBase::getCreatureAttribute) .orElse(EnumCreatureAttribute.UNDEFINED)); }
Example 6
Source File: ItemKotachi.java From Sakura_mod with MIT License | 4 votes |
@Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.SWEEPING, stack); if (k > 0) { //big sweep!!! entityLiving.swingArm(entityLiving.getActiveHand()); float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.5F; float f3 = EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f; float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving); for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.4D + sweepingRatio * 1.2D, 0.3D + sweepingRatio * 0.15D, 1.4D + sweepingRatio * 1.2D))) { if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) { if (entitylivingbase instanceof EntityLivingBase) { if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer) entitylivingbase).isActiveItemStackBlocking()) { //disable shield ((EntityPlayer) entitylivingbase).disableShield(false); } ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.1F * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F))); entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } if (entitylivingbase instanceof MultiPartEntityPart) { entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } } } worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F); if (worldIn instanceof WorldServer) { double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F)); double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F); ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D); } stack.damageItem(2, entityLiving); ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 16); } }
Example 7
Source File: ItemKatana.java From Sakura_mod with MIT License | 4 votes |
@Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.SWEEPING, stack); if (k > 0) { //big sweep!!! entityLiving.swingArm(entityLiving.getActiveHand()); float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F; float f3 = 2.0F + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f; float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving); for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.4D + sweepingRatio * 1.2D, 0.3D + sweepingRatio * 0.15D, 1.4D + sweepingRatio * 1.2D))) { if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) { if (entitylivingbase instanceof EntityLivingBase) { if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer) entitylivingbase).isActiveItemStackBlocking()) { //disable shield ((EntityPlayer) entitylivingbase).disableShield(false); } ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.4F * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F))); entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } if (entitylivingbase instanceof MultiPartEntityPart) { entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3); } } } worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F); if (worldIn instanceof WorldServer) { double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F)); double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F); ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D); } stack.damageItem(2, entityLiving); ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 25); } }
Example 8
Source File: EntityToro.java From ToroQuest with GNU General Public License v3.0 | 4 votes |
@Override public boolean attackEntityAsMob(Entity victim) { float attackDamage = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); int knockback = 2; if (victim instanceof EntityLivingBase) { attackDamage += EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase) victim).getCreatureAttribute()); knockback += EnchantmentHelper.getKnockbackModifier(this); } boolean wasDamaged = victim.attackEntityFrom(DamageSource.causeMobDamage(this), attackDamage); if (wasDamaged) { setRevengeTarget(getAttackTarget()); setAttackTarget(null); if (knockback > 0 && victim instanceof EntityLivingBase) { ((EntityLivingBase) victim).knockBack(this, (float) knockback * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F))); this.motionX *= 0.6D; this.motionZ *= 0.6D; } if (victim instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer) victim; ItemStack itemstack = this.getHeldItemMainhand(); ItemStack itemstack1 = entityplayer.isHandActive() ? entityplayer.getActiveItemStack() : null; if (itemstack != null && itemstack1 != null && itemstack.getItem() instanceof ItemAxe && itemstack1.getItem() == Items.SHIELD) { float f1 = 0.25F + (float) EnchantmentHelper.getEfficiencyModifier(this) * 0.05F; if (this.rand.nextFloat() < f1) { entityplayer.getCooldownTracker().setCooldown(Items.SHIELD, 100); this.world.setEntityState(entityplayer, (byte) 30); } } } this.applyEnchantments(this, victim); } return wasDamaged; }