Search in sources :

Example 41 with PartData

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

the class GearData method removeExcessParts.

public static void removeExcessParts(ItemStack gear, PartType partType) {
    // Mostly just to correct https://github.com/SilentChaos512/Silent-Gear/issues/242
    PartDataList parts = getConstructionParts(gear);
    List<PartData> partsOfType = new ArrayList<>(parts.getPartsOfType(partType));
    int maxCount = partType.getMaxPerItem(GearHelper.getType(gear));
    int removed = 0;
    while (partsOfType.size() > maxCount) {
        PartData toRemove = partsOfType.get(0);
        partsOfType.remove(toRemove);
        parts.remove(toRemove);
        toRemove.onRemoveFromGear(gear);
        ++removed;
        SilentGear.LOGGER.debug("Removed excess part '{}' from '{}'", toRemove.getDisplayName(gear).getString(), gear.getHoverName().getString());
    }
    if (removed > 0) {
        writeConstructionParts(gear, parts);
    }
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 42 with PartData

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

the class GearData method getPartOfType.

/**
 * Gets the first part in the construction parts list that is of the given type.
 *
 * @param stack The gear item
 * @param type  The part type
 * @return The first part of the given type, or null if there is none
 */
@Nullable
public static PartData getPartOfType(ItemStack stack, PartType type) {
    CompoundTag tags = getData(stack, NBT_ROOT_CONSTRUCTION);
    ListTag tagList = tags.getList(NBT_CONSTRUCTION_PARTS, Tag.TAG_COMPOUND);
    for (int i = 0; i < tagList.size(); ++i) {
        CompoundTag nbt = tagList.getCompound(i);
        PartData part = PartData.read(nbt);
        if (part != null && part.getType() == type) {
            return part;
        }
    }
    return null;
}
Also used : PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) Nullable(javax.annotation.Nullable)

Example 43 with PartData

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

the class GearElytraItem method supportsPart.

@Override
public boolean supportsPart(ItemStack gear, PartData part) {
    PartType type = part.getType();
    boolean canAdd = part.get().canAddToGear(gear, part);
    boolean supported = (requiresPartOfType(part.getType()) && canAdd) || canAdd;
    return (type == PartType.MAIN && supported) || type == PartType.LINING || supported;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType)

Example 44 with PartData

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

the class SetPartsFunction method run.

@Override
protected ItemStack run(ItemStack stack, LootContext context) {
    if (!(stack.getItem() instanceof ICoreItem))
        return stack;
    ItemStack result = stack.copy();
    List<PartData> parts = LazyPartData.createPartList(this.parts);
    parts.forEach(p -> p.onAddToGear(result));
    GearData.writeConstructionParts(result, parts);
    GearData.recalculateStats(result, null);
    return result;
}
Also used : LazyPartData(net.silentchaos512.gear.gear.part.LazyPartData) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 45 with PartData

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

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