Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
select best sword #4
Browse files Browse the repository at this point in the history
  • Loading branch information
cyilin committed Oct 13, 2016
1 parent e279f9b commit 14eb7fe
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/main/java/com/zyin/zyinhud/mods/WeaponSwapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -121,25 +122,45 @@ protected static int GetMostDamagingWeaponSlot(int minInventoryIndex, int maxInv
double highestWeaponDamage = -1;
double highestAttackSpeed = -1;
int highestWeaponDamageSlot = -1;
double highestSwordDamage = -1;
double highestSwordAttackSpeed = -1;
int highestSwordDamageSlot = -1;

for (int i = minInventoryIndex; i <= maxInventoryIndex; i++)
{
ItemStack itemStack = items[i];

if (itemStack != null)
{
if (itemStack.getItem() instanceof ItemSword) {
double swordDamage = GetItemWeaponDamage(itemStack);
double swordAttackSpeed = GetAttackSpeed(itemStack);
if ((swordDamage > highestSwordDamage && swordAttackSpeed >= highestSwordAttackSpeed) ||
(swordDamage >= highestSwordDamage && swordAttackSpeed > highestSwordAttackSpeed)) {
highestSwordDamage = swordDamage;
highestSwordAttackSpeed = swordAttackSpeed;
highestSwordDamageSlot = i;
}
continue;
}
double weaponDamage = GetItemWeaponDamage(itemStack);
double weaponAttackSpeed = GetAttackSpeed(itemStack);
if((weaponDamage > highestWeaponDamage && weaponAttackSpeed >= highestAttackSpeed)||
(weaponDamage >= highestWeaponDamage && weaponAttackSpeed > highestAttackSpeed))
{
highestWeaponDamage = weaponDamage;
if ((weaponDamage > highestWeaponDamage && weaponAttackSpeed >= highestAttackSpeed) ||
(weaponDamage >= highestWeaponDamage && weaponAttackSpeed > highestAttackSpeed)) {
highestWeaponDamage = weaponDamage;
highestAttackSpeed = weaponAttackSpeed;
highestWeaponDamageSlot = i;
highestWeaponDamageSlot = i;
}
}
}
return highestWeaponDamageSlot;
if (highestSwordDamageSlot == -1) {
return highestWeaponDamageSlot;
}else if ((highestAttackSpeed > highestSwordDamage && highestAttackSpeed >= highestSwordAttackSpeed) ||
(highestWeaponDamage >= highestSwordDamage && highestAttackSpeed > highestSwordAttackSpeed)) {
return highestWeaponDamageSlot;
} else {
return highestSwordDamageSlot;
}
}

/**
Expand Down

0 comments on commit 14eb7fe

Please sign in to comment.