Search in sources :

Example 1 with TraitActionContext

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);
        }
    });
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with TraitActionContext

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));
        }
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) TagParser(net.minecraft.nbt.TagParser) GearHelper(net.silentchaos512.gear.util.GearHelper) HashMap(java.util.HashMap) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ArrayList(java.util.ArrayList) GearType(net.silentchaos512.gear.api.item.GearType) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ITraitSerializer(net.silentchaos512.gear.api.traits.ITraitSerializer) Map(java.util.Map) GsonHelper(net.minecraft.util.GsonHelper) ItemStack(net.minecraft.world.item.ItemStack) TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext) com.google.gson(com.google.gson) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) GearType(net.silentchaos512.gear.api.item.GearType) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with TraitActionContext

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;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) LivingEntity(net.minecraft.world.entity.LivingEntity) AABB(net.minecraft.world.phys.AABB) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) ForgeMod(net.minecraftforge.common.ForgeMod) LibTriggers(net.silentchaos512.lib.advancements.LibTriggers) IGearIngredient(net.silentchaos512.gear.crafting.ingredient.IGearIngredient) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) ItemStats(net.silentchaos512.gear.api.stats.ItemStats) Predicate(java.util.function.Predicate) InteractionResult(net.minecraft.world.InteractionResult) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Player(net.minecraft.world.entity.player.Player) Util(net.minecraft.Util) TextComponent(net.minecraft.network.chat.TextComponent) Stream(java.util.stream.Stream) BlockPos(net.minecraft.core.BlockPos) TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext) Level(net.minecraft.world.level.Level) SoundSource(net.minecraft.sounds.SoundSource) java.util(java.util) PartDataList(net.silentchaos512.gear.api.part.PartDataList) BlockState(net.minecraft.world.level.block.state.BlockState) Multimap(com.google.common.collect.Multimap) GearNamePrefixesEvent(net.silentchaos512.gear.api.event.GearNamePrefixesEvent) Function(java.util.function.Function) Ingredient(net.minecraft.world.item.crafting.Ingredient) TagKey(net.minecraft.tags.TagKey) ServerPlayer(net.minecraft.server.level.ServerPlayer) ICoreTool(net.silentchaos512.gear.api.item.ICoreTool) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) IPartData(net.silentchaos512.gear.api.part.IPartData) Config(net.silentchaos512.gear.config.Config) AttributeModifier(net.minecraft.world.entity.ai.attributes.AttributeModifier) ToolAction(net.minecraftforge.common.ToolAction) net.minecraft.world.item(net.minecraft.world.item) PartManager(net.silentchaos512.gear.gear.part.PartManager) BiConsumer(java.util.function.BiConsumer) SoundEvents(net.minecraft.sounds.SoundEvents) UseOnContext(net.minecraft.world.item.context.UseOnContext) Nullable(javax.annotation.Nullable) Component(net.minecraft.network.chat.Component) EntityHitResult(net.minecraft.world.phys.EntityHitResult) Material(net.minecraft.world.level.material.Material) Attribute(net.minecraft.world.entity.ai.attributes.Attribute) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) Consumer(java.util.function.Consumer) MinecraftForge(net.minecraftforge.common.MinecraftForge) Entity(net.minecraft.world.entity.Entity) ITrait(net.silentchaos512.gear.api.traits.ITrait) Vec3(net.minecraft.world.phys.Vec3) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) Attributes(net.minecraft.world.entity.ai.attributes.Attributes) Block(net.minecraft.world.level.block.Block) InteractionHand(net.minecraft.world.InteractionHand) TierSortingRegistry(net.minecraftforge.common.TierSortingRegistry) Mth(net.minecraft.util.Mth) TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext)

Example 4 with TraitActionContext

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);
}
Also used : TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext) Player(net.minecraft.world.entity.player.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Example 5 with TraitActionContext

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;
}
Also used : TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext) AttributeModifier(net.minecraft.world.entity.ai.attributes.AttributeModifier)

Aggregations

TraitActionContext (net.silentchaos512.gear.api.traits.TraitActionContext)8 GearType (net.silentchaos512.gear.api.item.GearType)5 ItemStack (net.minecraft.world.item.ItemStack)4 CompoundTag (net.minecraft.nbt.CompoundTag)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 ITrait (net.silentchaos512.gear.api.traits.ITrait)3 ArrayList (java.util.ArrayList)2 ListTag (net.minecraft.nbt.ListTag)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 AttributeModifier (net.minecraft.world.entity.ai.attributes.AttributeModifier)2 Player (net.minecraft.world.entity.player.Player)2 SilentGear (net.silentchaos512.gear.SilentGear)2 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)2 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 com.google.gson (com.google.gson)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 java.util (java.util)1 HashMap (java.util.HashMap)1