Search in sources :

Example 26 with ICoreItem

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

the class GearClientHelper method addStatsInfo.

public static void addStatsInfo(ItemStack stack, List<Component> tooltip, GearTooltipFlag flag, ICoreItem item) {
    if (KeyTracker.isDisplayStatsDown() && flag.showStats) {
        tooltip.add(TextUtil.withColor(misc("tooltip.stats"), Color.GOLD));
        tooltip.add(TextUtil.withColor(misc("tier", GearData.getTier(stack)), Color.DEEPSKYBLUE));
        // Display only stats relevant to the item class
        Collection<ItemStat> relevantStats = item.getRelevantStats(stack);
        Collection<ItemStat> displayStats = flag.isAdvanced() && SilentGear.isDevBuild() ? ItemStats.allStatsOrdered() : relevantStats;
        TextListBuilder builder = new TextListBuilder();
        for (ItemStat stat : displayStats) {
            if (stat == ItemStats.ENCHANTABILITY && !Config.Common.allowEnchanting.get()) {
                // Enchanting not allowed, so hide the stat
                continue;
            }
            float statValue = GearData.getStat(stack, stat);
            StatInstance inst = StatInstance.of(statValue, StatInstance.Operation.AVG, StatInstance.DEFAULT_KEY);
            Color nameColor = relevantStats.contains(stat) ? stat.getNameColor() : TooltipHandler.MC_DARK_GRAY;
            Component textName = TextUtil.withColor(stat.getDisplayName(), nameColor);
            MutableComponent textStat = inst.getFormattedText(stat, stat.isDisplayAsInt() ? 0 : 2, false);
            // TODO: The stats should probably handle this instead
            if (stat == ItemStats.DURABILITY) {
                int durabilityLeft = stack.getMaxDamage() - stack.getDamageValue();
                int durabilityMax = stack.getMaxDamage();
                textStat = statText("durabilityFormat", durabilityLeft, durabilityMax);
            } else if (stat == ItemStats.HARVEST_LEVEL) {
                textStat = TooltipHandler.harvestLevelWithHint(textStat, statValue);
            }
            builder.add(statText("displayFormat", textName, textStat));
        }
        tooltip.addAll(builder.build());
    } else if (flag.showStats) {
        tooltip.add(TextUtil.withColor(TextUtil.misc("tooltip.stats"), Color.GOLD).append(new TextComponent(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_STATS), ChatFormatting.GRAY))));
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) MutableComponent(net.minecraft.network.chat.MutableComponent) Color(net.silentchaos512.utils.Color) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 27 with ICoreItem

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

the class GearModelOverrideList method getCrossbowCharge.

private static Optional<MaterialLayer> getCrossbowCharge(ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity) {
    // TODO: Maybe should add an ICoreItem method to get additional layers?
    ItemPropertyFunction chargedProperty = ItemProperties.getProperty(stack.getItem(), new ResourceLocation("charged"));
    ItemPropertyFunction fireworkProperty = ItemProperties.getProperty(stack.getItem(), new ResourceLocation("firework"));
    if (chargedProperty != null && fireworkProperty != null) {
        boolean charged = chargedProperty.call(stack, world, entity, 0) > 0;
        boolean firework = fireworkProperty.call(stack, world, entity, 0) > 0;
        if (charged) {
            if (firework) {
                return Optional.of(new MaterialLayer(PartTextures.CHARGED_FIREWORK, Color.VALUE_WHITE));
            }
            return Optional.of(new MaterialLayer(PartTextures.CHARGED_ARROW, Color.VALUE_WHITE));
        }
    }
    return Optional.empty();
}
Also used : MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ResourceLocation(net.minecraft.resources.ResourceLocation) ItemPropertyFunction(net.minecraft.client.renderer.item.ItemPropertyFunction)

Example 28 with ICoreItem

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

the class GearModelOverrideList method getOverrideModel.

private BakedModel getOverrideModel(CacheKey key, ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn, int animationFrame) {
    boolean broken = GearHelper.isBroken(stack);
    if (isDebugLoggingEnabled()) {
        SilentGear.LOGGER.info("getOverrideModel for {} ({})", stack.getHoverName().getString(), broken ? "broken" : "normal");
        SilentGear.LOGGER.info("- model key {}", key.data);
    }
    List<MaterialLayer> layers = new ArrayList<>();
    for (PartData part : getPartsInRenderOrder(stack)) {
        if (((ICoreItem) stack.getItem()).hasTexturesFor(part.getType())) {
            addSimplePartLayers(layers, part, stack);
            if (part.get() instanceof CompoundPart) {
                MaterialInstance mat = CompoundPart.getPrimaryMaterial(part);
                if (mat != null) {
                    addWithBlendedColor(layers, part, mat, stack);
                }
            }
        }
    }
    // TODO: Make this not a special case...
    if (stack.getItem() instanceof GearCrossbowItem) {
        getCrossbowCharge(stack, worldIn, entityIn).ifPresent(layers::add);
    }
    return model.bake(stack, layers, animationFrame, "test", owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
Also used : MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ArrayList(java.util.ArrayList) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart) GearCrossbowItem(net.silentchaos512.gear.item.gear.GearCrossbowItem) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 29 with ICoreItem

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

the class GearModelOverrideList method getPartsInRenderOrder.

private static PartDataList getPartsInRenderOrder(ItemStack stack) {
    PartDataList unsorted = GearData.getConstructionParts(stack);
    PartDataList ret = PartDataList.of();
    ICoreItem item = (ICoreItem) stack.getItem();
    for (PartType partType : item.getRenderParts()) {
        ret.addAll(unsorted.getPartsOfType(partType));
    }
    for (PartData part : unsorted) {
        if (!ret.contains(part)) {
            ret.add(part);
        }
    }
    return ret;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartType(net.silentchaos512.gear.api.part.PartType) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem)

Example 30 with ICoreItem

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

the class ColorHandlers method onItemColors.

public static void onItemColors(ColorHandlerEvent.Item event) {
    ItemColors itemColors = event.getItemColors();
    if (itemColors == null) {
        SilentGear.LOGGER.error("ItemColors is null?", new IllegalStateException("wat?"));
        return;
    }
    // Tools, armor, shields, etc.
    ForgeRegistries.ITEMS.getValues().stream().filter(item -> item instanceof GearArmorItem || item instanceof GearShieldItem).map(item -> (ICoreItem) item).forEach(item -> itemColors.register(item.getItemColors(), item));
    Registration.getItems(item -> item instanceof IColoredMaterialItem).forEach(item -> {
        IColoredMaterialItem coloredMaterialItem = (IColoredMaterialItem) item;
        itemColors.register(coloredMaterialItem::getColor, item);
    });
}
Also used : SilentGear(net.silentchaos512.gear.SilentGear) GearData(net.silentchaos512.gear.util.GearData) IColoredMaterialItem(net.silentchaos512.gear.item.IColoredMaterialItem) ItemRegistryObject(net.silentchaos512.lib.registry.ItemRegistryObject) Item(net.minecraft.world.item.Item) GearShieldItem(net.silentchaos512.gear.item.gear.GearShieldItem) HashMap(java.util.HashMap) GearArmorItem(net.silentchaos512.gear.item.gear.GearArmorItem) ItemColors(net.minecraft.client.color.item.ItemColors) PartType(net.silentchaos512.gear.api.part.PartType) Registration(net.silentchaos512.gear.init.Registration) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) Color(net.silentchaos512.utils.Color) Map(java.util.Map) ItemStack(net.minecraft.world.item.ItemStack) ColorHandlerEvent(net.minecraftforge.client.event.ColorHandlerEvent) ItemColor(net.minecraft.client.color.item.ItemColor) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) GearShieldItem(net.silentchaos512.gear.item.gear.GearShieldItem) ItemColors(net.minecraft.client.color.item.ItemColors) GearArmorItem(net.silentchaos512.gear.item.gear.GearArmorItem) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) IColoredMaterialItem(net.silentchaos512.gear.item.IColoredMaterialItem)

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