Minor improvements for AE2 recipe logging

This commit is contained in:
Zixxl 2015-06-30 18:04:26 +02:00
parent 152fa40b9a
commit a0a8f2f26e
4 changed files with 87 additions and 48 deletions

View file

@ -4,7 +4,7 @@ import minetweaker.MineTweakerAPI;
import minetweaker.api.player.IPlayer;
import minetweaker.api.server.ICommandFunction;
import modtweaker2.commands.EntityMappingLogger;
import modtweaker2.mods.appeng.Commands.AppliedEnergisticsLogger;
import modtweaker2.mods.appeng.commands.AppliedEnergisticsLogger;
import modtweaker2.mods.auracascade.aura.AuraLogger;
import modtweaker2.mods.botania.commands.BotaniaBrewLogger;
import modtweaker2.mods.botania.commands.BotaniaOrechidLogger;
@ -34,7 +34,7 @@ public class Commands {
MineTweakerAPI.server.addMineTweakerCommand("entities", new String[] { "/minetweaker entities", " Outputs a list of entities class mapping keys and the entity IDs" }, new EntityMappingLogger());
if (TweakerPlugin.isLoaded("appliedenergistics2-core")) {
MineTweakerAPI.server.addMineTweakerCommand("ae2", new String[] {"/minetweaker ae2 ([Grinder/Inscriber])", " Outputs a list of all Applied Energistics 2 recipes."}, new AppliedEnergisticsLogger());
MineTweakerAPI.server.addMineTweakerCommand("ae2", new String[] {"/minetweaker ae2 [FILTER]", " Outputs a list of all Applied Energistics 2 recipes."}, new AppliedEnergisticsLogger());
}
if (TweakerPlugin.isLoaded("Mekanism")) {

View file

@ -1,8 +1,12 @@
package modtweaker2.helpers;
import java.util.List;
import java.util.ListIterator;
import minetweaker.MineTweakerAPI;
import minetweaker.MineTweakerImplementationAPI;
import minetweaker.api.player.IPlayer;
import net.minecraft.item.ItemStack;
public class LogHelper {
public static void logPrinted(IPlayer player) {
@ -37,4 +41,44 @@ public class LogHelper {
public static void logInfo(String message) {
MineTweakerAPI.logInfo("[ModTweaker2] " + message);
}
public static String getArrayDescription(List<ItemStack> stacks) {
StringBuilder sb = new StringBuilder();
sb.append('[');
for(ItemStack stack : stacks) {
sb.append(InputHelper.getStackDescription(stack)).append(", ");
}
sb.setLength(sb.length() - 2);
sb.append(']');
return sb.toString();
}
public static List<String> toLowerCase(List<String> stringList) {
ListIterator<String> iterator = stringList.listIterator();
while(iterator.hasNext()) {
iterator.set(iterator.next().toLowerCase());
}
return stringList;
}
public static String join(List<String> list, String conjunction) {
StringBuilder sb = new StringBuilder();
if(conjunction == null) {
conjunction = ", ";
}
if(list != null && !list.isEmpty()) {
for(String string : list) {
sb.append(string).append(conjunction);
}
sb.setLength(sb.length() - conjunction.length());
}
return sb.toString();
}
}

View file

@ -1,66 +1,62 @@
package modtweaker2.mods.appeng.Commands;
package modtweaker2.mods.appeng.commands;
import java.util.LinkedList;
import java.util.List;
import java.util.Arrays;
import minetweaker.MineTweakerAPI;
import minetweaker.MineTweakerImplementationAPI;
import minetweaker.api.player.IPlayer;
import minetweaker.api.server.ICommandFunction;
import modtweaker2.helpers.InputHelper;
import net.minecraft.item.ItemStack;
import modtweaker2.helpers.LogHelper;
import appeng.api.AEApi;
import appeng.api.features.IGrinderEntry;
import appeng.api.features.IInscriberRecipe;
public class AppliedEnergisticsLogger implements ICommandFunction {
private static final List<String> validArguments = new LinkedList<String>();
static {
validArguments.add("grinder");
validArguments.add("inscriber");
}
@Override
public void execute(String[] arguments, IPlayer player) {
List<String> args = new LinkedList<String>();
List<String> args = LogHelper.toLowerCase(Arrays.asList(arguments));
for(String arg : arguments) {
args.add(arg.toLowerCase());
if(!validArguments.containsAll(args)) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + LogHelper.join(validArguments, ", ")));
} else {
if(args.isEmpty() || args.contains("grinder")) {
for(IGrinderEntry recipe : AEApi.instance().registries().grinder().getRecipes()) {
MineTweakerAPI.logCommand(String.format("mods.appeng.Grinder.addRecipe(%s, %s, %d, %s, %s, %s, %s);",
InputHelper.getStackDescription(recipe.getInput()),
InputHelper.getStackDescription(recipe.getOutput()),
recipe.getEnergyCost(),
InputHelper.getStackDescription(recipe.getOptionalOutput()),
recipe.getOptionalChance(),
InputHelper.getStackDescription(recipe.getSecondOptionalOutput()),
recipe.getSecondOptionalChance()));
}
}
if(args.isEmpty() || args.contains("inscriber")) {
for(IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes()) {
MineTweakerAPI.logCommand(String.format("mods.appeng.Inscriber.addRecipe(%s, %s, %s, %s, \"%s\");",
LogHelper.getArrayDescription(recipe.getInputs()),
InputHelper.getStackDescription(recipe.getTopOptional().orNull()),
InputHelper.getStackDescription(recipe.getBottomOptional().orNull()),
InputHelper.getStackDescription(recipe.getOutput()),
recipe.getProcessType().toString()));
}
}
if (player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
}
}
if(args.isEmpty() || args.contains("grinder")) {
for(IGrinderEntry recipe : AEApi.instance().registries().grinder().getRecipes()) {
MineTweakerAPI.logCommand(String.format("mods.appeng.Grinder.addRecipe(%s, %s, %d, %s, %s, %s, %s);",
InputHelper.getStackDescription(recipe.getInput()),
InputHelper.getStackDescription(recipe.getOutput()),
recipe.getEnergyCost(),
InputHelper.getStackDescription(recipe.getOptionalOutput()),
recipe.getOptionalChance(),
InputHelper.getStackDescription(recipe.getSecondOptionalOutput()),
recipe.getSecondOptionalChance()));
}
}
if(args.isEmpty() || args.contains("inscriber")) {
for(IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes()) {
MineTweakerAPI.logCommand(String.format("mods.appeng.Inscriber.addRecipe(%s, %s, %s, %s, \"%s\");",
getArrayDescription(recipe.getInputs()),
InputHelper.getStackDescription(recipe.getTopOptional().orNull()),
InputHelper.getStackDescription(recipe.getBottomOptional().orNull()),
InputHelper.getStackDescription(recipe.getOutput()),
recipe.getProcessType().toString()));
}
}
if (player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
}
}
private String getArrayDescription(List<ItemStack> stacks) {
StringBuilder sb = new StringBuilder();
sb.append('[');
for(ItemStack stack : stacks) {
sb.append(InputHelper.getStackDescription(stack)).append(", ");
}
sb.setLength(sb.length() - 2);
sb.append(']');
return sb.toString();
}
}

View file

@ -6,7 +6,6 @@ import static modtweaker2.helpers.InputHelper.toStack;
import static modtweaker2.helpers.InputHelper.toStacks;
import static modtweaker2.helpers.StackHelper.matches;
import java.util.LinkedList;
import minetweaker.MineTweakerAPI;