Search in sources :

Example 31 with MaterialInstance

use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.

the class CompoundPartModelOverrideList method addWithBlendedColor.

@SuppressWarnings("TypeMayBeWeakened")
private void addWithBlendedColor(List<MaterialLayer> list, PartData part, MaterialInstance material, ItemStack stack) {
    IMaterialDisplay materialModel = material.getDisplayProperties();
    List<MaterialLayer> layers = materialModel.getLayerList(this.model.gearType, part, material).getLayers();
    for (int i = 0; i < layers.size(); i++) {
        MaterialLayer layer = layers.get(i);
        if ((layer.getColor() & 0xFFFFFF) < 0xFFFFFF) {
            int blendedColor = part.getColor(stack, i, 0);
            list.add(new MaterialLayer(layer.getTextureId(), part.getType(), blendedColor, false));
        } else {
            list.add(layer);
        }
    }
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Example 32 with MaterialInstance

use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.

the class TooltipHandler method getMaterialStatLines.

private static void getMaterialStatLines(ItemTooltipEvent event, PartType partType, MaterialInstance material) {
    TextListBuilder builder = new TextListBuilder();
    for (ItemStat stat : ItemStats.allStatsOrdered()) {
        if (stat.isVisible()) {
            getMaterialStatModLines(event, partType, material, builder, stat);
        }
    }
    event.getToolTip().addAll(builder.build());
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 33 with MaterialInstance

use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.

the class TooltipHandler method getMaterialStatModLines.

private static void getMaterialStatModLines(ItemTooltipEvent event, PartType partType, MaterialInstance material, TextListBuilder builder, ItemStat stat) {
    Collection<StatInstance> modsAll = material.getStatModifiers(partType, StatGearKey.of(stat, GearType.ALL));
    Optional<MutableComponent> head = getStatTooltipLine(event, partType, stat, modsAll);
    builder.add(head.orElseGet(() -> TextUtil.withColor(stat.getDisplayName(), stat.getNameColor())));
    builder.indent();
    int subCount = 0;
    List<StatGearKey> keysForStat = material.get().getStatKeys(material, partType).stream().filter(key -> key.getStat().equals(stat)).collect(Collectors.toList());
    for (StatGearKey key : keysForStat) {
        if (key.getGearType() != GearType.ALL) {
            ItemStat stat1 = ItemStats.get(key.getStat());
            if (stat1 != null) {
                Collection<StatInstance> mods = material.getStatModifiers(partType, key);
                Optional<MutableComponent> line = getSubStatTooltipLine(event, partType, stat1, key.getGearType(), mods);
                if (line.isPresent()) {
                    builder.add(line.get());
                    ++subCount;
                }
            }
        }
    }
    if (subCount == 0 && !head.isPresent()) {
        builder.removeLast();
    }
    builder.unindent();
}
Also used : GraderTileEntity(net.silentchaos512.gear.block.grader.GraderTileEntity) java.util(java.util) ChargerTileEntity(net.silentchaos512.gear.block.charger.ChargerTileEntity) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) StatModifierMap(net.silentchaos512.gear.api.stats.StatModifierMap) IMaterialModifier(net.silentchaos512.gear.api.material.modifier.IMaterialModifier) MutableComponent(net.minecraft.network.chat.MutableComponent) PartData(net.silentchaos512.gear.gear.part.PartData) I18n(net.minecraft.client.resources.language.I18n) AbstractGearPart(net.silentchaos512.gear.gear.part.AbstractGearPart) Config(net.silentchaos512.gear.config.Config) ChatFormatting(net.minecraft.ChatFormatting) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) IMaterialCategory(net.silentchaos512.gear.api.material.IMaterialCategory) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) KeyTracker(net.silentchaos512.gear.client.KeyTracker) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) TextUtil(net.silentchaos512.gear.util.TextUtil) ItemStats(net.silentchaos512.gear.api.stats.ItemStats) Component(net.minecraft.network.chat.Component) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) ModTags(net.silentchaos512.gear.init.ModTags) Collectors(java.util.stream.Collectors) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) TextComponent(net.minecraft.network.chat.TextComponent) Color(net.silentchaos512.utils.Color) ItemTooltipEvent(net.minecraftforge.event.entity.player.ItemTooltipEvent) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) ItemStack(net.minecraft.world.item.ItemStack) ClientTicks(net.silentchaos512.lib.event.ClientTicks) TagUtils(net.silentchaos512.lib.util.TagUtils) TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) MutableComponent(net.minecraft.network.chat.MutableComponent) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 34 with MaterialInstance

use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.

the class TooltipHandler method onTooltip.

@SubscribeEvent(receiveCanceled = true)
public void onTooltip(ItemTooltipEvent event) {
    /*
        LoaderState state = Loader.instance().getLoaderState();
        if (state == LoaderState.INITIALIZATION || state == LoaderState.SERVER_ABOUT_TO_START || state == LoaderState.SERVER_STOPPING) {
            // Skip tooltips during block/item remapping
            // JEI tooltip caches are done in AVAILABLE, in-game is SERVER_STARTED
            return;
        }
        */
    ItemStack stack = event.getItemStack();
    if (TagUtils.contains(ModTags.Items.GRADER_CATALYSTS, stack)) {
        onGraderCatalystTooltip(event);
    }
    if (TagUtils.contains(ModTags.Items.STARLIGHT_CHARGER_CATALYSTS, stack)) {
        onStarlightChargerCatalystTooltip(event);
    }
    MaterialInstance material = MaterialInstance.from(stack);
    if (material != null) {
        onMaterialTooltip(event, stack, material);
        return;
    }
    PartData part = PartData.from(stack);
    if (part != null) /*&& !part.isBlacklisted(stack)*/
    {
        onPartTooltip(event, stack, part);
        return;
    }
    // Nerfed gear?
    if (Config.Common.isNerfedItem(stack.getItem())) {
        List<Component> toolTip = event.getToolTip();
        toolTip.add(Math.min(1, toolTip.size()), new TranslatableComponent("misc.silentgear.poorlyMade").withStyle(ChatFormatting.RED));
    }
}
Also used : TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) PartData(net.silentchaos512.gear.gear.part.PartData) ItemStack(net.minecraft.world.item.ItemStack) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 35 with MaterialInstance

use of net.silentchaos512.gear.gear.material.MaterialInstance in project Silent-Gear by SilentChaos512.

the class GearModel method buildFakeModel.

private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
    // This method will display an example tool for items with no data (ie, for advancements)
    MaterialInstance mat = MaterialInstance.of(material);
    IMaterialDisplay model = mat.getDisplayProperties();
    if (!gearType.isArmor()) {
        MaterialLayer exampleRod = model.getLayerList(this.gearType, PartType.ROD, mat).getFirstLayer();
        if (exampleRod != null) {
            builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleRod.getTexture(gearType, 0))), rotation, exampleRod.getColor()));
        }
    }
    MaterialLayer exampleMain = model.getLayerList(this.gearType, PartType.MAIN, mat).getFirstLayer();
    if (exampleMain != null) {
        builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(gearType, 0))), rotation, exampleMain.getColor()));
    }
    if (gearType.matches(GearType.RANGED_WEAPON)) {
        MaterialLayer exampleBowstring = model.getLayerList(this.gearType, PartType.CORD, mat).getFirstLayer();
        if (exampleBowstring != null) {
            builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleBowstring.getTexture(gearType, 0))), rotation, exampleBowstring.getColor()));
        }
    }
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance)

Aggregations

MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)25 ItemStack (net.minecraft.world.item.ItemStack)12 IMaterial (net.silentchaos512.gear.api.material.IMaterial)10 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)10 PartType (net.silentchaos512.gear.api.part.PartType)9 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)8 PartData (net.silentchaos512.gear.gear.part.PartData)8 Component (net.minecraft.network.chat.Component)7 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)7 TextComponent (net.minecraft.network.chat.TextComponent)6 ResourceLocation (net.minecraft.resources.ResourceLocation)6 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)6 Collectors (java.util.stream.Collectors)5 Nullable (javax.annotation.Nullable)5 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)5 GearType (net.silentchaos512.gear.api.item.GearType)5 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)5 LazyMaterialInstance (net.silentchaos512.gear.gear.material.LazyMaterialInstance)5 java.util (java.util)4 ArrayList (java.util.ArrayList)4