Skip to content

Commit

Permalink
Move reinforced-calculations to the damage-dealing function from the …
Browse files Browse the repository at this point in the history
…hitting-stuff function #1367
  • Loading branch information
bonii-xx committed Jan 30, 2015
1 parent 1992829 commit 2812f80
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/main/java/tconstruct/library/tools/AbilityHelper.java
Expand Up @@ -129,14 +129,8 @@ public static boolean onLeftClickEntity (ItemStack stack, EntityLivingBase playe

if (causedDamage)
{
int reinforced = 0;
if (toolTags.hasKey("Unbreaking"))
reinforced = tags.getCompoundTag("InfiTool").getInteger("Unbreaking");
damageTool(stack, 1, tags, player, false);

if (random.nextInt(10) < 10 - reinforced)
{
damageTool(stack, 1, tags, player, false);
}
// damageTool(stack, 1, player, false);
tool.onEntityDamaged(player.worldObj, player, entity);
if (!necroticUHS || (entity instanceof IMob && entity instanceof EntityLivingBase && ((EntityLivingBase) entity).getHealth() <= 0))
Expand Down Expand Up @@ -365,6 +359,25 @@ public static void damageTool (ItemStack stack, int dam, NBTTagCompound tags, En
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode || tags == null)
return;

// calculate in reinforced/unbreaking
int reinforced = 0;
if(tags.hasKey("InfiTool"))
{
NBTTagCompound toolTags = tags.getCompoundTag("InfiTool");
if(toolTags.hasKey("Unbreaking"))
{
reinforced = tags.getCompoundTag("InfiTool").getInteger("Unbreaking");
// for each point of damage we deal, we separately decide if reinforced takes effect
for(int i = dam; i > 0; i--)
if(random.nextInt(10) < reinforced)
dam--;

// we prevented all damage with reinforced
if(dam <= 0)
return;
}
}

if (ignoreCharge || !damageEnergyTool(stack, tags, entity))
{
boolean damagedTool = false;
Expand Down

0 comments on commit 2812f80

Please sign in to comment.