@Override /** * Called when the entity is attacked. */ public boolean attackEntityFrom(DamageSource source, float amount) { if (this.isEntityInvulnerable(source)) { return false; } else { if (source.getEntity() == null || !(source.getEntity() instanceof EntityEndermite)) { if (!this.worldObj.isRemote) { this.setScreaming(true); } if (source instanceof EntityDamageSource && source.getEntity() instanceof EntityPlayer) { if (source.getEntity() instanceof EntityPlayerMP && ((EntityPlayerMP)source.getEntity()).theItemInWorldManager.isCreative()) { this.setScreaming(false); } else { this.isAggressive = true; } } if (source instanceof EntityDamageSourceIndirect) { this.isAggressive = false; for (int i = 0; i < 64; ++i) { if (this.teleportRandomly()) { return true; } } return false; } } boolean flag = super.attackEntityFrom(source, amount); if (source.isUnblockable() && this.rand.nextInt(10) != 0) { this.teleportRandomly(); } return flag; } }
/** Returns true if the shield can block this kind of damage */ public boolean canBlockDamage(ItemStack shield, DamageSource source) { boolean flag = source.isUnblockable() && !(source instanceof DamageSourceArmorBreak); if (toolMaterial == ToolMaterial.WOOD) { return !flag; } return !flag || source.isMagicDamage() || source.isFireDamage() || (source.isProjectile() && toolMaterial == ToolMaterial.EMERALD); }
@Override public ArmorProperties getProperties( EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) { if (source.isUnblockable()) { return new net.minecraftforge.common.ISpecialArmor.ArmorProperties(0, 0.0D, 3); } else { double absorptionRatio = getBaseAbsorptionRatio() * getDamageAbsorptionRatio(); int energyPerDamage = getEnergyPerDamage(); int damageLimit = energyPerDamage <= 0 ? 0 : (25 * ElectricItem.manager.getCharge(armor)) / energyPerDamage; return new net.minecraftforge.common.ISpecialArmor.ArmorProperties( 3, absorptionRatio, damageLimit); } }
@Override public ArmorProperties getProperties( EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) { if (source.isUnblockable()) { return new ArmorProperties(0, 0.0, 10000000); } if (armor.getItem() == Wildycraft.DragonChestPlate) { return new ArmorProperties(0, 0.367, 10000000); } else if (armor.getItem() == Wildycraft.DragonBoots) { return new ArmorProperties(0, 0.163, 10000000); } else if (armor.getItem() == Wildycraft.DragonHelmet) { return new ArmorProperties(0, 0.163, 10000000); } else if (armor.getItem() == Wildycraft.DragonLegs) { return new ArmorProperties(0, 0.287, 10000000); } return null; }
public static Optional<Tuple<DamageModifier, Function<? super Double, Double>>> createBlockingModifier(EntityLivingBase entityLivingBase, DamageSource damageSource) { if (!damageSource.isUnblockable() && (entityLivingBase instanceof EntityPlayer && ((EntityPlayer) entityLivingBase).isBlocking())) { DamageModifier modifier = DamageModifier.builder() .cause( Cause.of( NamedCause.of( DamageEntityEvent.BLOCKING, ((ItemStack) ((EntityPlayer) entityLivingBase).getCurrentEquippedItem()) .createSnapshot()))) .type(DamageModifierTypes.BLOCKING) .build(); return Optional.of(new Tuple<>(modifier, BLOCKING_FUNCTION)); } return Optional.empty(); }
@Override public ArmorProperties getProperties( EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) { int priority = 0; int absorbRatio = 0; int absorbMax = 0; NBTTagCompound nbt = getOrCreateTagCompound(armor); for (int i = 0; i < nbt.getInteger("moduleCount"); i++) { IArmorModule module = (IArmorModule) ModuleRegistry.getModule(nbt.getString("module" + i)); if ((module != null) && (module.getArmorEffectType() == EnumArmorEffectType.DEFENSIVE)) { IDefensiveArmorModule defmodule = (IDefensiveArmorModule) module; absorbRatio = defmodule.getDamageAbsorbRatio(); absorbMax = defmodule.getMaxDamageAbsorb(); } if (source.isUnblockable()) { absorbMax = 0; absorbRatio = 0; } } return new ArmorProperties(priority, absorbRatio, absorbMax); }
@Override public void damageArmor( EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) { if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound()); if (stack.getItemDamage() >= stack.getMaxDamage() - 2) { NBTTagCompound tag = stack.getTagCompound(); tag.setBoolean("destroyed", true); stack.setTagCompound(tag); return; } if (stack.getTagCompound().getByte("all") > 0) stack.damageItem(1, entity); else if (stack.getTagCompound().getByte("blast") > 0 && source.isExplosion()) stack.damageItem(1, entity); else if (stack.getTagCompound().getByte("fire") > 0 && source.isFireDamage()) stack.damageItem(1, entity); else if (stack.getTagCompound().getByte("magic") > 0 && source.isMagicDamage()) stack.damageItem(1, entity); else if (stack.getTagCompound().getByte("projectile") > 0 && source.isProjectile()) stack.damageItem(1, entity); else if (!source.isUnblockable()) stack.damageItem(2, entity); }
/** * Called when the shield blocks an attack when held in the normal fashion (i.e. non-BG2) used by * Deku Shield to damage / destroy the stack and by Mirror Shield to reflect projectiles * * @return Return the amount of damage remaining, if any; 0 cancels the hurt event */ public float onBlock(EntityPlayer player, ItemStack shield, DamageSource source, float damage) { ZSSPlayerInfo.get(player).onAttackBlocked(shield, damage); WorldUtils.playSoundAtEntity(player, Sounds.HAMMER, 0.4F, 0.5F); float damageBlocked = damage; if (toolMaterial == ToolMaterial.WOOD) { if (source.isProjectile() && !source.isExplosion() && source.getSourceOfDamage() instanceof IProjectile) { if (ZSSMain.isBG2Enabled && player.getHeldItem() == shield && shield.getItem() instanceof IArrowCatcher) { if (((IArrowCatcher) shield.getItem()) .catchArrow(shield, player, (IProjectile) source.getSourceOfDamage())) { ((InventoryPlayerBattle) player.inventory).hasChanged = true; } } } else if (source instanceof IDamageAoE && ((IDamageAoE) source).isAoEDamage()) { damageBlocked *= magicReduction; } int dmg = Math.round(source.isFireDamage() ? damage + 10.0F : damage - 2.0F); if (dmg > 0) { shield.damageItem(dmg, player); if (shield.stackSize <= 0) { ForgeEventFactory.onPlayerDestroyItem(player, shield); if (ZSSMain.isBG2Enabled && BattlegearUtils.isPlayerInBattlemode(player)) { BattlegearUtils.setPlayerOffhandItem(player, null); } else { player.destroyCurrentEquippedItem(); } } } } else if (toolMaterial == ToolMaterial.EMERALD) { if (source.isProjectile() && !source.isExplosion() && source.getSourceOfDamage() != null) { float chance = (source.isMagicDamage() ? (1F / 3F) : 1.0F); if (source.getSourceOfDamage() instanceof IReflectable) { ((IReflectable) source.getSourceOfDamage()) .getReflectChance(shield, player, source.getEntity()); } if (player.worldObj.rand.nextFloat() < chance) { Entity projectile = null; try { projectile = source .getSourceOfDamage() .getClass() .getConstructor(World.class) .newInstance(player.worldObj); } catch (Exception e) {; } if (projectile != null) { NBTTagCompound data = new NBTTagCompound(); source.getSourceOfDamage().writeToNBT(data); projectile.readFromNBT(data); projectile.getEntityData().setBoolean("isReflected", true); projectile.posX -= projectile.motionX; projectile.posY -= projectile.motionY; projectile.posZ -= projectile.motionZ; double motionX = (double) (-MathHelper.sin(player.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI)); double motionZ = (double) (MathHelper.cos(player.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI)); double motionY = (double) (-MathHelper.sin(player.rotationPitch / 180.0F * (float) Math.PI)); TargetUtils.setEntityHeading( projectile, motionX, motionY, motionZ, 1.0F, 2.0F + (20.0F * player.worldObj.rand.nextFloat()), false); if (projectile instanceof IReflectable) { ((IReflectable) projectile) .onReflected(shield, player, source.getEntity(), source.getSourceOfDamage()); } player.worldObj.spawnEntityInWorld(projectile); } } else if (source.isUnblockable() || (source instanceof IDamageAoE && ((IDamageAoE) source).isAoEDamage())) { // failed to reflect projectile damageBlocked *= magicReduction; } } } else if (source.isUnblockable() || (source instanceof IDamageAoE && ((IDamageAoE) source).isAoEDamage())) { damageBlocked *= magicReduction; // default shield behavior blocks half damage from AoE magic attacks } return (damage - damageBlocked); }
protected int applyArmorCalculations( EntityLivingBase entity, DamageSource source, float originalDamage) { ItemStack[] armor = entity.getLastActiveItems(); int pierceRating = 0; int slashRating = 0; int crushRating = 0; EntityArmorCalcEvent eventPre = new EntityArmorCalcEvent(entity, originalDamage, EntityArmorCalcEvent.EventType.PRE); MinecraftForge.EVENT_BUS.post(eventPre); float damage = eventPre.incomingDamage; if (!source.isUnblockable() && armor != null) { // 1. Get Random Hit Location int location = getRandomSlot(entity.getRNG()); // 2. Get Armor Rating for armor in hit Location if (armor[location] != null && armor[location].getItem() instanceof ItemTFCArmor) { pierceRating = ((ItemTFCArmor) armor[location].getItem()).armorTypeTFC.getPiercingAR(); slashRating = ((ItemTFCArmor) armor[location].getItem()).armorTypeTFC.getSlashingAR(); crushRating = ((ItemTFCArmor) armor[location].getItem()).armorTypeTFC.getCrushingAR(); if (entity instanceof IInnateArmor) { pierceRating += ((IInnateArmor) entity).getPierceArmor(); slashRating += ((IInnateArmor) entity).getSlashArmor(); crushRating += ((IInnateArmor) entity).getCrushArmor(); } // 3. Convert the armor rating to % damage reduction float pierceMult = getDamageReduction(pierceRating); float slashMult = getDamageReduction(slashRating); float crushMult = getDamageReduction(crushRating); // 4. Reduce incoming damage damage = processDamageSource(source, damage, pierceMult, slashMult, crushMult); // 5. Damage the armor that was hit armor[location].damageItem((int) processArmorDamage(armor[location], damage), entity); } else if (armor[location] == null || armor[location] != null && !(armor[location].getItem() instanceof ItemTFCArmor)) { if (entity instanceof IInnateArmor) { pierceRating += ((IInnateArmor) entity).getPierceArmor(); slashRating += ((IInnateArmor) entity).getSlashArmor(); crushRating += ((IInnateArmor) entity).getCrushArmor(); } // 1. Convert the armor rating to % damage reduction float pierceMult = getDamageReduction(pierceRating); float slashMult = getDamageReduction(slashRating); float crushMult = getDamageReduction(crushRating); // 4. Reduce incoming damage damage = processDamageSource(source, damage, pierceMult, slashMult, crushMult); // a. If the attack hits an unprotected head, it does 75% more damage // b. If the attack hits unprotected feet, it applies a slow to the player if (location == 3) damage *= 1.75f; else if (location == 0) entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.getId(), 100, 1)); } // 6. Apply the damage to the player EntityArmorCalcEvent eventPost = new EntityArmorCalcEvent(entity, damage, EntityArmorCalcEvent.EventType.POST); MinecraftForge.EVENT_BUS.post(eventPost); // TerraFirmaCraft.log.info(entity.getClass()+", "+eventPre.incomingDamage+", // "+eventPost.incomingDamage); float hasHealth = entity.getHealth(); entity.setHealth(entity.getHealth() - eventPost.incomingDamage); entity.func_110142_aN().func_94547_a(source, hasHealth, eventPost.incomingDamage); } return 0; }