Search in sources :

Example 1 with ITraitCondition

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

the class TraitsCommand method runDumpMdClient.

public static void runDumpMdClient() {
    Player player = SilentGear.PROXY.getClientPlayer();
    if (player == null) {
        SilentGear.LOGGER.error("TraitsCommand#runDumpMcClient: player is null?");
        return;
    }
    String fileName = "traits_list.md";
    String dirPath = "output/silentgear";
    File output = new File(dirPath, fileName);
    File directory = output.getParentFile();
    if (!directory.exists() && !directory.mkdirs()) {
        player.sendMessage(new TextComponent("Could not create directory: " + output.getParent()), Util.NIL_UUID);
        return;
    }
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UTF_8)) {
        writer.write("# Traits\n\n");
        writer.write("Generated in-game by `sgear_traits dump_md` command on " + getCurrentDateTime() + "\n\n");
        writer.write("This data may or may not be accurate depending on the mod pack you are playing and the mods or data packs installed.\n\n");
        writer.write("## Data Sources\n\n");
        writer.write("The following mods and data packs have added traits to the output. Running the dump command yourself may produce different results.\n\n");
        writer.write(getDataSources() + "\n");
        writer.write("## Trait Types\n\n");
        writer.write("These are trait serializers. You can define custom instances of these types using data packs.\n");
        writer.write("Code for traits and their serializers can be found in `net.silentchaos512.gear.gear.trait`.\n\n");
        writer.write("Note that \"simple\" traits are often used where custom code is required.\n");
        writer.write("They are not especially useful when just defined by a data pack.\n\n");
        for (ITraitSerializer<?> serializer : TraitSerializers.getSerializers()) {
            String typeName = serializer instanceof SimpleTrait.Serializer ? ((SimpleTrait.Serializer) serializer).getTypeName() : "";
            writer.write("- `" + serializer.getName() + "`");
            if (!typeName.isEmpty()) {
                writer.write(" _(" + typeName + ")_");
            }
            writer.write("\n");
        }
        writer.write("\n## List of Traits");
        List<ResourceLocation> ids = new ArrayList<>(TraitManager.getKeys());
        ids.sort(Comparator.comparing(id -> Objects.requireNonNull(TraitManager.get(id)).getDisplayName(0).getString()));
        for (ResourceLocation id : ids) {
            ITrait trait = TraitManager.get(id);
            assert trait != null;
            writer.write("\n");
            writer.write("### " + getLinkToBuiltinTraitJson(id, trait.getDisplayName(0).getString()) + "\n");
            writer.write("- " + trait.getDescription(0).getString() + "\n");
            String materialsWithTrait = getMaterialsWithTrait(trait);
            writer.write("- Found On:\n  - Materials: " + (materialsWithTrait.isEmpty() ? "Nothing" : materialsWithTrait) + "\n");
            String partsWithTrait = getPartsWithTrait(trait);
            if (!partsWithTrait.isEmpty()) {
                writer.write("  - Parts: " + partsWithTrait + "\n");
            }
            if (!trait.getConditions().isEmpty()) {
                // Just wrap all of them inside an AND condition, since that's how the logic works anyway
                AndTraitCondition condition = new AndTraitCondition(trait.getConditions().toArray(new ITraitCondition[0]));
                writer.write("- Conditions: " + condition.getDisplayText().getString() + "\n");
            }
            writer.write("- ID: `" + id + "`\n");
            writer.write("- Type: `" + trait.getSerializer().getName() + "`\n");
            writer.write("- Max Level: " + trait.getMaxLevel() + "\n");
            Collection<String> cancelsWithSet = trait.getCancelsWithSet().stream().map(s -> "`" + s + "`").collect(Collectors.toList());
            if (!cancelsWithSet.isEmpty()) {
                writer.write("- Cancels With: " + String.join(", ", cancelsWithSet) + "\n");
            }
            Collection<String> wikiLines = trait.getExtraWikiLines();
            if (!wikiLines.isEmpty()) {
                writer.write("- Extra Info:\n");
                for (String line : wikiLines) {
                    writer.write(line + "\n");
                }
            }
        }
        writer.write("\n");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        Component fileNameText = (new TextComponent(output.getAbsolutePath())).withStyle(ChatFormatting.UNDERLINE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, output.getAbsolutePath())));
        player.sendMessage(new TextComponent("Wrote to ").append(fileNameText), Util.NIL_UUID);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) 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) ServerPlayer(net.minecraft.server.level.ServerPlayer) Player(net.minecraft.world.entity.player.Player) ITrait(net.silentchaos512.gear.api.traits.ITrait) ITraitCondition(net.silentchaos512.gear.api.traits.ITraitCondition) SimpleTrait(net.silentchaos512.gear.gear.trait.SimpleTrait) AndTraitCondition(net.silentchaos512.gear.gear.trait.condition.AndTraitCondition) ClickEvent(net.minecraft.network.chat.ClickEvent) ResourceLocation(net.minecraft.resources.ResourceLocation) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent)

Example 2 with ITraitCondition

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

the class MaterialBuilder method trait.

@Deprecated
public MaterialBuilder trait(PartType partType, ResourceLocation traitId, int level, ITraitCondition... conditions) {
    ITraitInstance inst = TraitInstance.lazy(traitId, level, conditions);
    List<ITraitInstance> list = traits.computeIfAbsent(partType, pt -> new ArrayList<>());
    list.add(inst);
    return this;
}
Also used : ITraitInstance(net.silentchaos512.gear.api.traits.ITraitInstance)

Example 3 with ITraitCondition

use of net.silentchaos512.gear.api.traits.ITraitCondition 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 4 with ITraitCondition

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

the class MaterialBuilder method trait.

public MaterialBuilder trait(PartType partType, DataResource<ITrait> trait, int level, ITraitCondition... conditions) {
    ITraitInstance inst = TraitInstance.of(trait, level, conditions);
    List<ITraitInstance> list = traits.computeIfAbsent(partType, pt -> new ArrayList<>());
    list.add(inst);
    return this;
}
Also used : ITraitInstance(net.silentchaos512.gear.api.traits.ITraitInstance)

Aggregations

ITraitInstance (net.silentchaos512.gear.api.traits.ITraitInstance)3 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 Collectors (java.util.stream.Collectors)1 ChatFormatting (net.minecraft.ChatFormatting)1 Util (net.minecraft.Util)1 CommandSourceStack (net.minecraft.commands.CommandSourceStack)1 Commands (net.minecraft.commands.Commands)1 SharedSuggestionProvider (net.minecraft.commands.SharedSuggestionProvider)1 ResourceLocationArgument (net.minecraft.commands.arguments.ResourceLocationArgument)1 ClickEvent (net.minecraft.network.chat.ClickEvent)1 Component (net.minecraft.network.chat.Component)1 TextComponent (net.minecraft.network.chat.TextComponent)1