Search in sources :

Example 11 with TraitInstance

use of net.silentchaos512.gear.api.traits.TraitInstance 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)

Example 12 with TraitInstance

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

the class TraitsCommand method getPartsWithTrait.

private static String getPartsWithTrait(ITrait trait) {
    StringBuilder str = new StringBuilder();
    boolean foundAny = false;
    for (IGearPart part : PartManager.getValues()) {
        PartData partData = PartData.of(part);
        for (TraitInstance inst : partData.getTraits()) {
            if (inst.getTrait().equals(trait) && part.isVisible()) {
                if (foundAny) {
                    str.append(", ");
                }
                foundAny = true;
                str.append("**").append(partData.getDisplayName(ItemStack.EMPTY).getString()).append("**");
            }
        }
    }
    return str.toString();
}
Also used : IGearPart(net.silentchaos512.gear.api.part.IGearPart) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) PartData(net.silentchaos512.gear.gear.part.PartData)

Aggregations

TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)12 TextComponent (net.minecraft.network.chat.TextComponent)3 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 ITrait (net.silentchaos512.gear.api.traits.ITrait)3 PartData (net.silentchaos512.gear.gear.part.PartData)3 Component (net.minecraft.network.chat.Component)2 MutableComponent (net.minecraft.network.chat.MutableComponent)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 IGearPart (net.silentchaos512.gear.api.part.IGearPart)2 PartType (net.silentchaos512.gear.api.part.PartType)2 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 SuggestionProvider (com.mojang.brigadier.suggestion.SuggestionProvider)1 java.io (java.io)1 StandardCharsets (java.nio.charset.StandardCharsets)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1