Search in sources :

Example 16 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.

the class ColorUtils method getBlendedColor.

public static int getBlendedColor(ICoreItem item, IPartData part, Collection<? extends IMaterialInstance> materials, int layer) {
    int[] componentSums = new int[3];
    int maxColorSum = 0;
    int colorCount = 0;
    int i = 0;
    for (IMaterialInstance mat : materials) {
        IMaterialDisplay model = mat.getDisplayProperties();
        int color = model.getLayerColor(item.getGearType(), part, mat, layer);
        int r = (color >> 16) & 0xFF;
        int g = (color >> 8) & 0xFF;
        int b = color & 0xFF;
        int colorWeight = (materials.size() - i) * (materials.size() - i);
        for (int j = 0; j < colorWeight; ++j) {
            maxColorSum += Math.max(r, Math.max(g, b));
            componentSums[0] += r;
            componentSums[1] += g;
            componentSums[2] += b;
            ++colorCount;
        }
        ++i;
    }
    return blendColors(componentSums, maxColorSum, colorCount);
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay)

Example 17 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.

the class GearClientHelper method addInformation.

public static void addInformation(ItemStack stack, Level world, List<Component> tooltip, GearTooltipFlag flag) {
    if (!(stack.getItem() instanceof ICoreItem))
        return;
    ICoreItem item = (ICoreItem) stack.getItem();
    if (GearHelper.isBroken(stack)) {
        tooltip.add(Math.min(1, tooltip.size()), TextUtil.withColor(misc("broken"), Color.FIREBRICK));
    }
    if (GearData.isExampleGear(stack)) {
        tooltip.add(Math.min(1, tooltip.size()), TextUtil.withColor(misc("exampleOutput1"), Color.YELLOW));
        tooltip.add(Math.min(2, tooltip.size()), TextUtil.withColor(misc("exampleOutput2"), Color.YELLOW));
    }
    PartDataList constructionParts = GearData.getConstructionParts(stack);
    if (constructionParts.getMains().isEmpty()) {
        tooltip.add(TextUtil.withColor(misc("invalidParts"), Color.FIREBRICK));
        tooltip.add(TextUtil.withColor(misc("lockedStats"), Color.FIREBRICK));
    } else if (GearData.hasLockedStats(stack)) {
        tooltip.add(TextUtil.withColor(misc("lockedStats"), Color.YELLOW));
    }
    if (!Config.Client.vanillaStyleTooltips.get()) {
        // Let parts add information if they need to
        Collections.reverse(constructionParts);
        for (PartData data : constructionParts) {
            data.get().addInformation(data, stack, tooltip, flag);
        }
    }
    // Traits
    addTraitsInfo(stack, tooltip, flag);
    if (!Config.Client.vanillaStyleTooltips.get()) {
        // Stats
        addStatsInfo(stack, tooltip, flag, item);
    }
    // Tool construction
    if (KeyTracker.isDisplayConstructionDown() && flag.showConstruction) {
        tooltip.add(TextUtil.withColor(misc("tooltip.construction"), Color.GOLD));
        Collections.reverse(constructionParts);
        tooltipListParts(stack, tooltip, constructionParts, flag);
    } else if (flag.showConstruction) {
        tooltip.add(TextUtil.withColor(TextUtil.misc("tooltip.construction"), Color.GOLD).append(new TextComponent(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_CONSTRUCTION), ChatFormatting.GRAY))));
    }
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) TextComponent(net.minecraft.network.chat.TextComponent) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem)

Example 18 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.

the class WielderEffectTrait method onUpdate.

@Override
public void onUpdate(TraitActionContext context, boolean isEquipped) {
    if (!isEquipped || context.getPlayer() == null || context.getPlayer().tickCount % 10 != 0)
        return;
    GearType gearType = ((ICoreItem) context.getGear().getItem()).getGearType();
    for (Map.Entry<String, List<PotionData>> entry : potions.entrySet()) {
        String type = entry.getKey();
        List<PotionData> list = entry.getValue();
        applyEffects(context, gearType, type, list);
    }
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem)

Example 19 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.

the class StatsCommand method runInfo.

private static int runInfo(CommandContext<CommandSourceStack> context, ServerPlayer player) {
    ItemStack stack = player.getMainHandItem();
    if (!GearHelper.isGear(stack)) {
        context.getSource().sendFailure(TextUtil.translate("command", "invalidItemType", stack.getHoverName()));
        return 0;
    }
    context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.header", player.getName(), stack.getHoverName()).withStyle(ChatFormatting.BOLD), true);
    ICoreItem item = (ICoreItem) stack.getItem();
    PartDataList parts = GearData.getConstructionParts(stack);
    StatModifierMap stats = GearData.getStatModifiers(stack, item, parts);
    for (ItemStat stat : ItemStats.allStatsOrderedExcluding((item).getExcludedStats(stack))) {
        StatGearKey key = StatGearKey.of(stat, item.getGearType());
        Collection<StatInstance> mods = stats.get(key);
        if (!mods.isEmpty()) {
            Component name = TextUtil.withColor(stat.getDisplayName(), stat.getNameColor());
            Component modsText = StatModifierMap.formatText(mods, stat, 5, true);
            float statValue = stat.compute(0f, true, item.getGearType(), mods);
            Component valueText = TextUtil.withColor(StatInstance.of(statValue, StatInstance.Operation.AVG, key).getFormattedText(stat, 5, false), ChatFormatting.YELLOW);
            context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.format", name, modsText, valueText), true);
            for (PartData part : parts) {
                Collection<StatInstance> partMods = part.getStatModifiers(key, stack);
                if (!partMods.isEmpty()) {
                    Component partName = part.getDisplayName(stack);
                    Component partModsText = StatModifierMap.formatText(partMods, stat, 5, true);
                    context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.formatPart", partName, partModsText), true);
                }
            }
        }
    }
    return 1;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartData(net.silentchaos512.gear.gear.part.PartData) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack) Component(net.minecraft.network.chat.Component) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) StatModifierMap(net.silentchaos512.gear.api.stats.StatModifierMap) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 20 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.

the class CuriosCompat method getHighestTraitLevel.

public static int getHighestTraitLevel(LivingEntity entity, DataResource<ITrait> trait) {
    LazyOptional<IItemHandlerModifiable> lazy = CuriosApi.getCuriosHelper().getEquippedCurios(entity);
    int max = 0;
    if (lazy.isPresent()) {
        IItemHandlerModifiable handler = lazy.orElseThrow(IllegalStateException::new);
        for (int i = 0; i < handler.getSlots(); ++i) {
            ItemStack stack = handler.getStackInSlot(i);
            if (stack.getItem() instanceof ICoreItem) {
                max = Math.max(max, TraitHelper.getTraitLevel(stack, trait));
            }
        }
    }
    return max;
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)25 ItemStack (net.minecraft.world.item.ItemStack)16 PartData (net.silentchaos512.gear.gear.part.PartData)12 PartType (net.silentchaos512.gear.api.part.PartType)10 PartDataList (net.silentchaos512.gear.api.part.PartDataList)7 Component (net.minecraft.network.chat.Component)5 TextComponent (net.minecraft.network.chat.TextComponent)5 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)5 ArrayList (java.util.ArrayList)4 GearType (net.silentchaos512.gear.api.item.GearType)4 ResourceLocation (net.minecraft.resources.ResourceLocation)3 Item (net.minecraft.world.item.Item)3 IPartData (net.silentchaos512.gear.api.part.IPartData)3 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)3 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)3 StackList (net.silentchaos512.lib.collection.StackList)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 Level (net.minecraft.world.level.Level)2 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)2