feat: include sharpness in dps calculation

This commit is contained in:
əlemi 2023-03-04 01:22:13 +01:00
parent 60cb2dcfd8
commit 976659d310
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -2,11 +2,15 @@ package ftbsc.bscv.tools;
import ftbsc.bscv.ICommons;
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.Attributes;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import java.util.Collection;
import java.util.List;
@ -19,18 +23,49 @@ public class Inventory implements ICommons {
return player.inventoryMenu.slots.subList(36, 45);
}
// TODO ????????????? wtf is this is there an easier way?
public static double itemDamage(ItemStack item) {
// TODO this is hideous, there must be a proper way??????
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 =
item.getAttributeModifiers(EquipmentSlotType.MAINHAND)
.get(Attributes.ATTACK_DAMAGE);
if (damage_attrs.isEmpty()) return 0.;
double damage = Math.abs(damage_attrs.iterator().next().getAmount());
Collection<AttributeModifier> speed_attrs =
item.getAttributeModifiers(EquipmentSlotType.MAINHAND)
.get(Attributes.ATTACK_SPEED);
if (speed_attrs.isEmpty()) return damage;
double speed = Math.abs(speed_attrs.iterator().next().getAmount());
return Math.abs(damage_attrs.iterator().next().getAmount());
}
public static double itemDPS(ItemStack item) {
double damage = Inventory.itemAttackDamage(item);
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);
}
}