Search in sources :

Example 11 with ITrait

use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.

the class PartBuilder method trait.

public PartBuilder trait(DataResource<ITrait> trait, int level, ITraitCondition... conditions) {
    ITraitInstance inst = TraitInstance.of(trait, level, conditions);
    this.traits.add(inst);
    return this;
}
Also used : ITraitInstance(net.silentchaos512.gear.api.traits.ITraitInstance)

Example 12 with ITrait

use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.

the class GearClientHelper method addTraitsInfo.

private static void addTraitsInfo(ItemStack stack, List<Component> tooltip, GearTooltipFlag flag) {
    Map<ITrait, Integer> traits = TraitHelper.getCachedTraits(stack);
    List<ITrait> visibleTraits = new ArrayList<>();
    for (ITrait t : traits.keySet()) {
        if (t != null && t.showInTooltip(flag)) {
            visibleTraits.add(t);
        }
    }
    int traitIndex = getTraitDisplayIndex(visibleTraits.size(), flag);
    MutableComponent textTraits = TextUtil.withColor(misc("tooltip.traits"), Color.GOLD);
    if (traitIndex < 0) {
        if (!Config.Client.vanillaStyleTooltips.get()) {
            tooltip.add(textTraits);
        }
    }
    int i = 0;
    for (ITrait trait : visibleTraits) {
        if (traitIndex < 0 || traitIndex == i) {
            final int level = traits.get(trait);
            trait.addInformation(level, tooltip, flag, text -> {
                if (Config.Client.vanillaStyleTooltips.get()) {
                    return TextUtil.withColor(new TextComponent(TextListBuilder.VANILLA_BULLET + " "), Color.GRAY).append(text);
                }
                if (traitIndex >= 0) {
                    return textTraits.append(TextUtil.withColor(new TextComponent(": "), ChatFormatting.GRAY).append(text));
                }
                return new TextComponent(TextListBuilder.BULLETS[0] + " ").append(text);
            });
        }
        ++i;
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ITrait(net.silentchaos512.gear.api.traits.ITrait) MutableComponent(net.minecraft.network.chat.MutableComponent)

Example 13 with ITrait

use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.

the class TraitSerializers method write.

@SuppressWarnings("unchecked")
public static <T extends ITrait> void write(T trait, FriendlyByteBuf buffer) {
    ResourceLocation id = trait.getId();
    ResourceLocation type = trait.getSerializer().getName();
    log(() -> "write " + id + " (type " + type + ")");
    buffer.writeResourceLocation(id);
    buffer.writeResourceLocation(type);
    ITraitSerializer<T> serializer = (ITraitSerializer<T>) trait.getSerializer();
    serializer.write(buffer, trait);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) ITraitSerializer(net.silentchaos512.gear.api.traits.ITraitSerializer)

Example 14 with ITrait

use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.

the class MaterialRatioTraitCondition method matches.

@Override
public boolean matches(ITrait trait, PartGearKey key, ItemStack gear, List<? extends IGearComponentInstance<?>> components) {
    int count = 0;
    for (IGearComponentInstance<?> comp : components) {
        Collection<TraitInstance> traits = comp.getTraits(key, gear);
        for (TraitInstance inst : traits) {
            if (inst.getTrait() == trait) {
                ++count;
                break;
            }
        }
    }
    float ratio = (float) count / components.size();
    return ratio >= this.requiredRatio;
}
Also used : TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance)

Example 15 with ITrait

use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.

the class TraitsCommand method getMaterialsWithTrait.

private static String getMaterialsWithTrait(ITrait trait) {
    StringBuilder str = new StringBuilder();
    boolean foundAny = false;
    for (IMaterial material : MaterialManager.getValues(false)) {
        MaterialInstance instance = MaterialInstance.of(material);
        Collection<PartType> typesWithTrait = new ArrayList<>();
        for (PartType partType : PartType.getValues()) {
            Collection<TraitInstance> traits = instance.getTraits(partType);
            for (TraitInstance inst : traits) {
                if (inst.getTrait().equals(trait) && material.isVisible(partType)) {
                    typesWithTrait.add(partType);
                    break;
                }
            }
        }
        if (!typesWithTrait.isEmpty()) {
            if (foundAny) {
                str.append(", ");
            }
            foundAny = true;
            str.append("**").append(instance.getDisplayName(PartType.MAIN).getString()).append("**").append(" _(").append(typesWithTrait.stream().map(pt -> pt.getDisplayName(0).getString()).collect(Collectors.joining(", "))).append(")_");
        }
    }
    return str.toString();
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) ModContainer(net.minecraftforge.fml.ModContainer) java.util(java.util) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) CommandSourceStack(net.minecraft.commands.CommandSourceStack) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LocalDateTime(java.time.LocalDateTime) MaterialManager(net.silentchaos512.gear.gear.material.MaterialManager) NetworkDirection(net.minecraftforge.network.NetworkDirection) ResourceLocationArgument(net.minecraft.commands.arguments.ResourceLocationArgument) ServerPlayer(net.minecraft.server.level.ServerPlayer) PartData(net.silentchaos512.gear.gear.part.PartData) ITraitCondition(net.silentchaos512.gear.api.traits.ITraitCondition) ChatFormatting(net.minecraft.ChatFormatting) ITraitSerializer(net.silentchaos512.gear.api.traits.ITraitSerializer) PartManager(net.silentchaos512.gear.gear.part.PartManager) ClientOutputCommandPacket(net.silentchaos512.gear.network.ClientOutputCommandPacket) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) IGearPart(net.silentchaos512.gear.api.part.IGearPart) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TraitManager(net.silentchaos512.gear.gear.trait.TraitManager) CommandContext(com.mojang.brigadier.context.CommandContext) SimpleTrait(net.silentchaos512.gear.gear.trait.SimpleTrait) Commands(net.minecraft.commands.Commands) ModList(net.minecraftforge.fml.ModList) AndTraitCondition(net.silentchaos512.gear.gear.trait.condition.AndTraitCondition) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Player(net.minecraft.world.entity.player.Player) PartType(net.silentchaos512.gear.api.part.PartType) IMaterial(net.silentchaos512.gear.api.material.IMaterial) Util(net.minecraft.Util) TextComponent(net.minecraft.network.chat.TextComponent) ITrait(net.silentchaos512.gear.api.traits.ITrait) java.io(java.io) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) DateTimeFormatter(java.time.format.DateTimeFormatter) TraitSerializers(net.silentchaos512.gear.gear.trait.TraitSerializers) Network(net.silentchaos512.gear.network.Network) ItemStack(net.minecraft.world.item.ItemStack) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) ClickEvent(net.minecraft.network.chat.ClickEvent) IMaterial(net.silentchaos512.gear.api.material.IMaterial) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Aggregations

ITrait (net.silentchaos512.gear.api.traits.ITrait)14 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)6 ResourceLocation (net.minecraft.resources.ResourceLocation)5 CompoundTag (net.minecraft.nbt.CompoundTag)4 ListTag (net.minecraft.nbt.ListTag)4 TextComponent (net.minecraft.network.chat.TextComponent)4 PartData (net.silentchaos512.gear.gear.part.PartData)4 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)3 ItemStack (net.minecraft.world.item.ItemStack)3 IModInfo (net.minecraftforge.forgespi.language.IModInfo)3 IGearPart (net.silentchaos512.gear.api.part.IGearPart)3 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)2 CommandContext (com.mojang.brigadier.context.CommandContext)2 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)2 SuggestionProvider (com.mojang.brigadier.suggestion.SuggestionProvider)2 java.io (java.io)2 StandardCharsets (java.nio.charset.StandardCharsets)2 LocalDateTime (java.time.LocalDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 java.util (java.util)2