summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/ftbsc/bscv/tools/Inventory.java51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/main/java/ftbsc/bscv/tools/Inventory.java b/src/main/java/ftbsc/bscv/tools/Inventory.java
index 5948773..8f1e2f5 100644
--- a/src/main/java/ftbsc/bscv/tools/Inventory.java
+++ b/src/main/java/ftbsc/bscv/tools/Inventory.java
@@ -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);
}
}