Search in sources :

Example 46 with PartData

use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.

the class PartsCommand method partToTsvLine.

private static String partToTsvLine(IGearPart part) {
    StringBuilder builder = new StringBuilder();
    PartData partData = PartData.of(part);
    appendTsv(builder, part.getDisplayName(partData, ItemStack.EMPTY).getString());
    appendTsv(builder, part.getId().toString());
    appendTsv(builder, part.getType().getName());
    appendTsv(builder, partData.getTier());
    // Stats
    for (ItemStat stat : ItemStats.allStatsOrdered()) {
        Collection<StatInstance> statModifiers = partData.getStatModifiers(StatGearKey.of(stat, GearType.ALL), ItemStack.EMPTY);
        appendTsv(builder, FORMAT_CODES.matcher(StatModifierMap.formatText(statModifiers, stat, 5).getString()).replaceAll(""));
    }
    // Traits
    appendTsv(builder, partData.getTraits().stream().map(t -> t.getTrait().getDisplayName(t.getLevel()).getString()).collect(Collectors.joining(", ")));
    return builder.toString();
}
Also used : PartData(net.silentchaos512.gear.gear.part.PartData) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 47 with PartData

use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.

the class GearModelOverrideList method addSimplePartLayers.

private static void addSimplePartLayers(List<MaterialLayer> list, PartData part, ItemStack stack) {
    IPartDisplay model = GearDisplayManager.get(part.get());
    if (model != null) {
        GearType gearType = GearHelper.getType(stack);
        List<MaterialLayer> layers = model.getLayers(gearType, part).getLayers();
        addColorBlendedLayers(list, part, stack, layers);
    }
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) IPartDisplay(net.silentchaos512.gear.api.part.IPartDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Example 48 with PartData

use of net.silentchaos512.gear.gear.part.PartData 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 49 with PartData

use of net.silentchaos512.gear.gear.part.PartData 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 50 with PartData

use of net.silentchaos512.gear.gear.part.PartData 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)

Aggregations

PartData (net.silentchaos512.gear.gear.part.PartData)36 ItemStack (net.minecraft.world.item.ItemStack)16 IPartData (net.silentchaos512.gear.api.part.IPartData)14 PartDataList (net.silentchaos512.gear.api.part.PartDataList)13 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)12 PartType (net.silentchaos512.gear.api.part.PartType)9 GearType (net.silentchaos512.gear.api.item.GearType)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)6 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)6 ArrayList (java.util.ArrayList)5 Component (net.minecraft.network.chat.Component)5 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)5 TextComponent (net.minecraft.network.chat.TextComponent)4 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)4 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)4 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)4 Nullable (javax.annotation.Nullable)3 CompoundTag (net.minecraft.nbt.CompoundTag)3 MutableComponent (net.minecraft.network.chat.MutableComponent)3