Search in sources :

Example 1 with CompoundPart

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

the class SalvagingRecipe method salvage.

/**
 * Salvages parts into their respective material items, or fragments if appropriate. This does
 * not necessarily give back the original item used for the material, but an item that matches
 * it.
 *
 * @param part The part
 * @return The list of items to return
 */
public static List<ItemStack> salvage(PartData part) {
    if (part.get() instanceof CompoundPart && part.getItem().getItem() instanceof CompoundPartItem) {
        int craftedCount = ((CompoundPartItem) part.getItem().getItem()).getCraftedCount(part.getItem());
        if (craftedCount < 1) {
            SilentGear.LOGGER.warn("Compound part's crafted count is less than 1? {}", part.getItem());
            return Collections.singletonList(part.getItem());
        }
        List<IMaterialInstance> materials = part.getMaterials();
        Map<IMaterialInstance, Integer> fragments = new LinkedHashMap<>();
        for (IMaterialInstance material : materials) {
            int fragmentCount = 8 / craftedCount;
            fragments.merge(material.onSalvage(), fragmentCount, Integer::sum);
        }
        List<ItemStack> ret = new ArrayList<>();
        for (Map.Entry<IMaterialInstance, Integer> entry : fragments.entrySet()) {
            IMaterialInstance material = entry.getKey();
            int count = entry.getValue();
            int fulls = count / 8;
            int frags = count % 8;
            if (fulls > 0) {
                ret.add(material.getItem());
            }
            if (frags > 0) {
                ret.add(ModItems.FRAGMENT.get().create(material, frags));
            }
        }
        return ret;
    }
    return Collections.singletonList(part.getItem());
}
Also used : CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with CompoundPart

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

the class GearClientHelper method tooltipListParts.

public static void tooltipListParts(ItemStack gear, List<Component> tooltip, Collection<PartData> parts, GearTooltipFlag flag) {
    TextListBuilder builder = new TextListBuilder();
    for (PartData part : parts) {
        if (part.get().isVisible()) {
            int partNameColor = Color.blend(part.getColor(gear), Color.VALUE_WHITE, 0.25f) & 0xFFFFFF;
            MutableComponent partNameText = TextUtil.withColor(part.getDisplayName(gear).copy(), partNameColor);
            builder.add(flag.isAdvanced() ? partNameText.append(TextUtil.misc("spaceBrackets", part.getType().getName()).withStyle(ChatFormatting.DARK_GRAY)) : partNameText);
            // List materials for compound parts
            if (part.get() instanceof CompoundPart) {
                builder.indent();
                for (IMaterialInstance material : CompoundPartItem.getMaterials(part.getItem())) {
                    int nameColor = material.getNameColor(part.getType(), GearType.ALL);
                    builder.add(TextUtil.withColor(material.getDisplayNameWithModifiers(part.getType(), ItemStack.EMPTY), nameColor));
                }
                builder.unindent();
            }
        }
    }
    tooltip.addAll(builder.build());
}
Also used : MutableComponent(net.minecraft.network.chat.MutableComponent) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) PartData(net.silentchaos512.gear.gear.part.PartData) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart)

Example 3 with CompoundPart

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

Aggregations

CompoundPart (net.silentchaos512.gear.gear.part.CompoundPart)3 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)2 PartData (net.silentchaos512.gear.gear.part.PartData)2 ArrayList (java.util.ArrayList)1 MutableComponent (net.minecraft.network.chat.MutableComponent)1 ItemStack (net.minecraft.world.item.ItemStack)1 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)1 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)1 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)1 CompoundPartItem (net.silentchaos512.gear.item.CompoundPartItem)1 GearCrossbowItem (net.silentchaos512.gear.item.gear.GearCrossbowItem)1