use of net.silentchaos512.gear.api.traits.TraitActionContext in project Silent-Gear by SilentChaos512.
the class EnchantmentTrait method onRecalculatePost.
@Override
public void onRecalculatePost(TraitActionContext context) {
ItemStack gear = context.getGear();
GearType gearType = GearHelper.getType(gear);
int traitLevel = context.getTraitLevel();
enchantments.forEach((type, list) -> {
if (gearType.matches(type)) {
addEnchantments(gear, traitLevel, list);
}
});
}
use of net.silentchaos512.gear.api.traits.TraitActionContext in project Silent-Gear by SilentChaos512.
the class NBTTrait method onGearCrafted.
@Override
public void onGearCrafted(TraitActionContext context) {
ItemStack gear = context.getGear();
GearType gearType = GearHelper.getType(gear);
int traitLevel = context.getTraitLevel();
data.forEach((type, list) -> {
if (gearType.matches(type) || "all".equals(type)) {
list.stream().filter(e -> e.level == traitLevel).forEach(e -> gear.getOrCreateTag().merge(e.data));
}
});
}
use of net.silentchaos512.gear.api.traits.TraitActionContext in project Silent-Gear by SilentChaos512.
the class GearHelper method damageItem.
public static <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T entity, Consumer<T> onBroken) {
final int preTraitValue;
if (GearHelper.isUnbreakable(stack)) {
preTraitValue = 0;
} else if (!Config.Common.gearBreaksPermanently.get()) {
preTraitValue = Mth.clamp(amount, 0, stack.getMaxDamage() - stack.getDamageValue() - 1);
if (!isBroken(stack) && stack.getDamageValue() + preTraitValue >= stack.getMaxDamage() - 1) {
onBroken.accept(entity);
}
} else {
preTraitValue = amount;
}
final int value = (int) TraitHelper.activateTraits(stack, preTraitValue, (trait, level, val) -> trait.onDurabilityDamage(new TraitActionContext(null, level, stack), (int) val));
GearHelper.damageParts(stack, value);
return value;
}
use of net.silentchaos512.gear.api.traits.TraitActionContext in project Silent-Gear by SilentChaos512.
the class GearHelper method attemptDamage.
public static void attemptDamage(ItemStack stack, int amount, @Nullable LivingEntity entity, EquipmentSlot slot) {
if (isUnbreakable(stack) || (entity instanceof Player && ((Player) entity).getAbilities().instabuild))
return;
ServerPlayer player = entity instanceof ServerPlayer ? (ServerPlayer) entity : null;
final int preTraitAmount = amount;
amount = (int) TraitHelper.activateTraits(stack, preTraitAmount, (trait, level, val) -> trait.onDurabilityDamage(new TraitActionContext(player, level, stack), (int) val));
final int maxDamage = stack.getMaxDamage();
final int preDamageFactor = getDamageFactor(stack, maxDamage);
if (!canBreakPermanently(stack))
amount = Math.min(maxDamage - stack.getDamageValue(), amount);
stack.hurt(amount, SilentGear.RANDOM, player);
// Recalculate stats occasionally
if (getDamageFactor(stack, maxDamage) != preDamageFactor) {
GearData.recalculateStats(stack, player);
if (player != null)
onDamageFactorChange(player, preDamageFactor, getDamageFactor(stack, maxDamage));
}
handleBrokenItem(stack, player, slot);
}
use of net.silentchaos512.gear.api.traits.TraitActionContext in project Silent-Gear by SilentChaos512.
the class GearHelper method getAttributeModifiers.
public static Multimap<Attribute, AttributeModifier> getAttributeModifiers(String slot, ItemStack stack, Multimap<Attribute, AttributeModifier> map, boolean addStandardMainHandMods) {
if (addStandardMainHandMods && isValidSlot(stack, slot) && slot.equals(EquipmentSlot.MAINHAND.getName())) {
// Melee Damage
replaceAttributeModifierInMap(map, Attributes.ATTACK_DAMAGE, getMeleeDamageModifier(stack));
// Melee Speed
replaceAttributeModifierInMap(map, Attributes.ATTACK_SPEED, getAttackSpeedModifier(stack));
// Reach distance
ForgeMod.REACH_DISTANCE.ifPresent(attr -> {
float reachStat = GearData.getStat(stack, ItemStats.REACH_DISTANCE, false);
AttributeModifier mod = new AttributeModifier(REACH_MODIFIER_UUID, "Gear reach", reachStat, AttributeModifier.Operation.ADDITION);
map.put(attr, mod);
});
}
TraitHelper.getCachedTraits(stack).forEach((trait, level) -> trait.onGetAttributeModifiers(new TraitActionContext(null, level, stack), map, slot));
return map;
}
Aggregations