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);
}
}
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;
}
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;
}
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;
}
Aggregations