feat: include sharpness in dps calculation
This commit is contained in:
parent
60cb2dcfd8
commit
976659d310
1 changed files with 43 additions and 8 deletions
|
@ -2,11 +2,15 @@ package ftbsc.bscv.tools;
|
||||||
|
|
||||||
import ftbsc.bscv.ICommons;
|
import ftbsc.bscv.ICommons;
|
||||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||||
|
import net.minecraft.enchantment.Enchantment;
|
||||||
|
import net.minecraft.enchantment.Enchantments;
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.entity.ai.attributes.Attributes;
|
import net.minecraft.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.inventory.EquipmentSlotType;
|
import net.minecraft.inventory.EquipmentSlotType;
|
||||||
import net.minecraft.inventory.container.Slot;
|
import net.minecraft.inventory.container.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
import net.minecraft.nbt.INBT;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -19,18 +23,49 @@ public class Inventory implements ICommons {
|
||||||
return player.inventoryMenu.slots.subList(36, 45);
|
return player.inventoryMenu.slots.subList(36, 45);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO ????????????? wtf is this is there an easier way?
|
// TODO this is hideous, there must be a proper way??????
|
||||||
public static double itemDamage(ItemStack item) {
|
private static String enchId(Enchantment ench) {
|
||||||
|
return ench.getDescriptionId().replace("enchantment.", "").replace(".", ":");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getEnchLevel(ItemStack item, Enchantment enchant) {
|
||||||
|
for (INBT tag : item.getEnchantmentTags()) {
|
||||||
|
if (tag instanceof CompoundNBT) {
|
||||||
|
CompoundNBT compound = (CompoundNBT) tag;
|
||||||
|
String ench_id = compound.getString("id");
|
||||||
|
if (Inventory.enchId(enchant).equals(ench_id)) {
|
||||||
|
return compound.getInt("lvl");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double itemAttackSpeed(ItemStack item) {
|
||||||
|
Collection<AttributeModifier> speed_attrs =
|
||||||
|
item.getAttributeModifiers(EquipmentSlotType.MAINHAND)
|
||||||
|
.get(Attributes.ATTACK_SPEED);
|
||||||
|
if (speed_attrs.isEmpty()) return 0.;
|
||||||
|
return Math.abs(speed_attrs.iterator().next().getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double itemAttackDamage(ItemStack item) {
|
||||||
Collection<AttributeModifier> damage_attrs =
|
Collection<AttributeModifier> damage_attrs =
|
||||||
item.getAttributeModifiers(EquipmentSlotType.MAINHAND)
|
item.getAttributeModifiers(EquipmentSlotType.MAINHAND)
|
||||||
.get(Attributes.ATTACK_DAMAGE);
|
.get(Attributes.ATTACK_DAMAGE);
|
||||||
if (damage_attrs.isEmpty()) return 0.;
|
if (damage_attrs.isEmpty()) return 0.;
|
||||||
double damage = Math.abs(damage_attrs.iterator().next().getAmount());
|
return Math.abs(damage_attrs.iterator().next().getAmount());
|
||||||
Collection<AttributeModifier> speed_attrs =
|
}
|
||||||
item.getAttributeModifiers(EquipmentSlotType.MAINHAND)
|
|
||||||
.get(Attributes.ATTACK_SPEED);
|
public static double itemDPS(ItemStack item) {
|
||||||
if (speed_attrs.isEmpty()) return damage;
|
double damage = Inventory.itemAttackDamage(item);
|
||||||
double speed = Math.abs(speed_attrs.iterator().next().getAmount());
|
double speed = Inventory.itemAttackSpeed(item);
|
||||||
|
|
||||||
|
int sharpness = getEnchLevel(item, Enchantments.SHARPNESS);
|
||||||
|
if (sharpness > 0) {
|
||||||
|
damage += 0.5 * Math.max(0, sharpness - 1) + 1.;
|
||||||
|
}
|
||||||
|
|
||||||
return damage / (1. + speed);
|
return damage / (1. + speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue