Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import net.minecraft.world.item.ItemStack;

public interface ZaniteBuff {
default double calculateZaniteBuff(ItemStack stack, double baseValue) {
return baseValue * (2.0 * ((double) stack.getDamageValue()) / ((double) stack.getMaxDamage()) + 0.5);
/// Added Multiplier buff (1 => + 100%, .5 => + 50%, etc.)
double buff = 1.0;

default double calculateZaniteBuff(ItemStack stack) {
return 1.0e-10 + buff * stack.getDamageValue() / (double) stack.getMaxDamage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ZanitePendantItem(Properties properties) {
@Override
public Set<ConditionalAttribute> gatherAttributes(Set<ConditionalAttribute> attributes) {
attributes = super.gatherAttributes(attributes);
attributes.add(new ConditionalAttribute(Attributes.MINING_EFFICIENCY, new ConditionalModifier(MINING_EFFICIENCY, (stack) -> 0.25 + (1.75 * stack.getDamageValue() / (stack.getMaxDamage() + 0.5)), AttributeModifier.Operation.ADD_VALUE), (stack, wearer) -> true));
attributes.add(new ConditionalAttribute(Attributes.BLOCK_BREAK_SPEED, new ConditionalModifier(MINING_EFFICIENCY, (stack) -> 0.25 + .50 * stack.getDamageValue() / (stack.getMaxDamage()), AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL), (stack, wearer) -> true));
return attributes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@

import com.aetherteam.aetherii.AetherII;
import com.aetherteam.aetherii.item.equipment.ZaniteBuff;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.neoforged.neoforge.event.ItemAttributeModifierEvent;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

public interface ZaniteTool extends ZaniteBuff {
ResourceLocation MINING_EFFICIENCY_MODIFIER_ID = ResourceLocation.fromNamespaceAndPath(AetherII.MODID, "zanite_modified_mining_efficiency");

static void updateToolAttributes(ItemAttributeModifierEvent event) {
ItemStack stack = event.getItemStack();
ItemAttributeModifiers defaultModifiers = event.getDefaultModifiers();
List<ItemAttributeModifiers.Entry> modifiers = event.getModifiers();

if (stack.getItem() instanceof ZaniteTool zaniteTool) {
ItemAttributeModifiers.Entry updatedEntry = null;
ItemAttributeModifiers.Entry newEntry = zaniteTool.increaseSpeed(defaultModifiers, stack, 6.0F);
ItemAttributeModifiers.Entry newEntry = zaniteTool.increaseSpeed(stack);
double newAmount = newEntry.modifier().amount();
boolean flag = true;
for (ItemAttributeModifiers.Entry oldEntry : modifiers) {
Expand All @@ -46,17 +42,7 @@ static void updateToolAttributes(ItemAttributeModifierEvent event) {
}
}

default ItemAttributeModifiers.Entry increaseSpeed(ItemAttributeModifiers modifiers, ItemStack stack, double baseValue) {
return new ItemAttributeModifiers.Entry(Attributes.MINING_EFFICIENCY, new AttributeModifier(MINING_EFFICIENCY_MODIFIER_ID, this.calculateSpeedIncrease(Attributes.MINING_EFFICIENCY, baseValue, MINING_EFFICIENCY_MODIFIER_ID, modifiers, stack), AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND);
}

default double calculateSpeedIncrease(Holder<Attribute> base, double baseValue, ResourceLocation bonusModifier, ItemAttributeModifiers modifiers, ItemStack stack) {
AtomicReference<Double> baseStat = new AtomicReference<>(baseValue);
modifiers.forEach(EquipmentSlotGroup.MAINHAND, (attribute, modifier) -> {
if (attribute.value() == base.value() && !modifier.id().equals(bonusModifier)) {
baseStat.updateAndGet(v -> v + modifier.amount());
}
});
return this.calculateZaniteBuff(stack, baseStat.get()) - baseStat.get();
default ItemAttributeModifiers.Entry increaseSpeed(ItemStack stack) {
return new ItemAttributeModifiers.Entry(Attributes.BLOCK_BREAK_SPEED, new AttributeModifier(MINING_EFFICIENCY_MODIFIER_ID, this.calculateZaniteBuff(stack), AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL), EquipmentSlotGroup.MAINHAND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.neoforged.neoforge.event.ItemAttributeModifierEvent;

import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

public interface ZaniteWeapon extends ZaniteBuff {
ResourceLocation DAMAGE_MODIFIER_ID = ResourceLocation.fromNamespaceAndPath(AetherII.MODID, "zanite_modified_attack_damage");
Expand All @@ -30,12 +29,11 @@ public interface ZaniteWeapon extends ZaniteBuff {

static void updateWeaponAttributes(ItemAttributeModifierEvent event) {
ItemStack stack = event.getItemStack();
ItemAttributeModifiers defaultModifiers = event.getDefaultModifiers();
List<ItemAttributeModifiers.Entry> modifiers = event.getModifiers();

if (stack.getItem() instanceof ZaniteWeapon zaniteWeapon) {
Set<ItemAttributeModifiers.Entry> updatedEntries = new HashSet<>();
Set<ItemAttributeModifiers.Entry> newEntries = new HashSet<>(zaniteWeapon.increaseDamage(zaniteWeapon.getDamageType(), defaultModifiers, stack));
Set<ItemAttributeModifiers.Entry> newEntries = new HashSet<>(zaniteWeapon.increaseDamage(zaniteWeapon.getDamageType(), stack));
for (ItemAttributeModifiers.Entry newEntry : newEntries) {
boolean flag = true;
for (ItemAttributeModifiers.Entry oldEntry : modifiers) {
Expand All @@ -58,33 +56,14 @@ static void updateWeaponAttributes(ItemAttributeModifierEvent event) {
}
}

default List<ItemAttributeModifiers.Entry> increaseDamage(Holder<Attribute> typeAttribute, ItemAttributeModifiers modifiers, ItemStack stack) {
default List<ItemAttributeModifiers.Entry> increaseDamage(Holder<Attribute> typeAttribute, ItemStack stack) {
List<ItemAttributeModifiers.Entry> modifierEntryList = new ArrayList<>();

modifierEntryList.add(new ItemAttributeModifiers.Entry(typeAttribute, new AttributeModifier(DAMAGE_TYPES.get(typeAttribute), this.calculateDamageIncrease(typeAttribute, DAMAGE_TYPES.get(typeAttribute), modifiers, stack), AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND));
modifierEntryList.add(new ItemAttributeModifiers.Entry(Attributes.ATTACK_DAMAGE, new AttributeModifier(DAMAGE_MODIFIER_ID, this.calculateDamageIncrease(Attributes.ATTACK_DAMAGE, DAMAGE_MODIFIER_ID, modifiers, stack), AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND));
modifierEntryList.add(new ItemAttributeModifiers.Entry(typeAttribute, new AttributeModifier(DAMAGE_TYPES.get(typeAttribute), this.calculateZaniteBuff(stack), AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL), EquipmentSlotGroup.MAINHAND));
modifierEntryList.add(new ItemAttributeModifiers.Entry(Attributes.ATTACK_DAMAGE, new AttributeModifier(DAMAGE_MODIFIER_ID, this.calculateZaniteBuff(stack), AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL), EquipmentSlotGroup.MAINHAND));

return modifierEntryList;
}

default int calculateDamageIncrease(Holder<Attribute> base, ResourceLocation bonusModifier, ItemAttributeModifiers modifiers, ItemStack stack) {
AtomicReference<Double> baseStat = new AtomicReference<>(0.0);
modifiers.forEach(EquipmentSlotGroup.MAINHAND, (attribute, modifier) -> {
if (attribute.value() == base.value() && !modifier.id().equals(bonusModifier)) {
baseStat.updateAndGet(v -> v + modifier.amount());
}
});
return this.calculateDamageIncrease(stack, baseStat.get());
}

default int calculateDamageIncrease(ItemStack stack, double baseDamage) {
double boostedDamage = this.calculateZaniteBuff(stack, baseDamage);
boostedDamage -= baseDamage;
if (boostedDamage < 0.0) {
boostedDamage = 0.0;
}
return (int) Math.round(boostedDamage);
}

Holder<Attribute> getDamageType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected Projectile createProjectile(Level level, LivingEntity shooter, ItemSta
Projectile projectile = super.createProjectile(level, shooter, weapon, ammo, isCrit);
if (shooter.getData(AetherIIDataAttachments.ABILITY_BEHAVIOR).isCrossbowSpecial()) {
if (projectile instanceof AbstractArrow arrow) {
arrow.setBaseDamage(this.calculateZaniteBuff(weapon, ((AbstractArrowAccessor) arrow).aether$getBaseDamage()));
arrow.setBaseDamage((this.calculateZaniteBuff(weapon) + 1) * ((AbstractArrowAccessor) arrow).aether$getBaseDamage());
}
}
return projectile;
Expand Down