use of net.silentchaos512.gear.SilentGear 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.SilentGear in project Silent-Gear by SilentChaos512.
the class MaterialsCommand method runDumpClient.
public static void runDumpClient(boolean includeChildren) {
Player player = SilentGear.PROXY.getClientPlayer();
if (player == null) {
SilentGear.LOGGER.error("MaterialsCommand#runDumpClient: player is null?");
return;
}
String fileName = "material_export.tsv";
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)) {
StringBuilder builder = new StringBuilder("Pack\tName\tType\tID\tParent\tTraits\tTier\t");
ItemStats.allStatsOrdered().forEach(s -> builder.append(s.getDisplayName().getString()).append("\t"));
writer.write(builder + "\n");
List<PartType> partTypes = new ArrayList<>(PartType.getValues());
partTypes.sort((o1, o2) -> Comparator.comparing(o -> ((PartType) o).getDisplayName(0).getString()).compare(o1, o2));
for (PartType partType : partTypes) {
for (IMaterial material : MaterialManager.getValues()) {
if (includeChildren || getParentId(material).isEmpty()) {
MaterialInstance inst = MaterialInstance.of(material);
if (material.allowedInPart(inst, partType)) {
writer.write(makeTsvLine(inst, partType) + "\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 materials info to ").append(fileNameText), Util.NIL_UUID);
}
}
use of net.silentchaos512.gear.SilentGear in project Silent-Gear by SilentChaos512.
the class PartsCommand method runDump.
private static int runDump(CommandContext<CommandSourceStack> context) {
String fileName = "part_export.tsv";
String dirPath = "output/silentgear";
File output = new File(dirPath, fileName);
File directory = output.getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
context.getSource().sendFailure(new TextComponent("Could not create directory: " + output.getParent()));
return 0;
}
try (Writer writer = new OutputStreamWriter(new FileOutputStream(output), StandardCharsets.UTF_8)) {
StringBuilder builder = new StringBuilder("Name\tID\tType\tTier\t");
ItemStats.allStatsOrdered().forEach(s -> builder.append(s.getDisplayName().getString()).append("\t"));
builder.append("Traits");
writer.write(builder.toString());
for (IGearPart part : PartManager.getValues()) {
writer.write(partToTsvLine(part) + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
context.getSource().sendSuccess(new TextComponent("Wrote to " + output.getAbsolutePath()), true);
}
return 1;
}
Aggregations