mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-17 03:05:03 +00:00
More Logging rework
This commit is contained in:
1 parent
ece7dca426
commit
2dd8e910f4
60 files changed
+464
-322
No files matched your search
@@ -1,8 +1,21 @@
|
||||
package modtweaker2.helpers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
public class LogHelper {
|
||||
public static void logPrinted(IPlayer player) {
|
||||
@@ -37,4 +50,121 @@ public class LogHelper {
|
||||
public static void logInfo(String message) {
|
||||
MineTweakerAPI.logInfo("[ModTweaker2] " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the item which can also be used in scripts
|
||||
*/
|
||||
public static String getStackDescription(Object object) {
|
||||
if(object instanceof ItemStack) {
|
||||
ItemStack stack = (ItemStack)object;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// Creates a name like <minecraft:piston> or <appliedenergistics2:item.ItemMultiMaterial:156>
|
||||
sb.append('<');
|
||||
sb.append(Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
if(stack.getItemDamage() == 32767) {
|
||||
sb.append(":*");
|
||||
} else if (stack.getItemDamage() > 0) {
|
||||
sb.append(":").append(stack.getItemDamage());
|
||||
}
|
||||
sb.append('>');
|
||||
|
||||
// Do we have a tag? (e.g. <Botania:specialFlower>.withTag({}) )
|
||||
if(stack.getTagCompound() != null)
|
||||
{
|
||||
sb.append(".withTag(");
|
||||
sb.append(NBTConverter.from(stack.getTagCompound(), true));
|
||||
sb.append(')');
|
||||
}
|
||||
|
||||
// Do we have a stack size > 1?
|
||||
if(stack.stackSize > 1) {
|
||||
sb.append(" * ").append(stack.stackSize);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
} else if (object instanceof FluidStack) {
|
||||
FluidStack stack = (FluidStack)object;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<liquid:").append(stack.getFluid().getName()).append('>');
|
||||
|
||||
if(stack.amount > 1) {
|
||||
sb.append(" * ").append(stack.amount);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
} else if (object instanceof String) {
|
||||
List<ItemStack> ores = OreDictionary.getOres((String)object);
|
||||
|
||||
// Check if string specifies an oredict entry
|
||||
if(!ores.isEmpty()) {
|
||||
return "<ore:" + (String)object + ">";
|
||||
} else {
|
||||
return "\"" + (String)object + "\"";
|
||||
}
|
||||
} else if (object != null) {
|
||||
return "\"" + object.toString() + "\"";
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getListDescription(List<?> objects) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if(objects.isEmpty()) {
|
||||
sb.append("[]");
|
||||
} else {
|
||||
sb.append('[');
|
||||
for(Object object : objects) {
|
||||
if(object instanceof List) {
|
||||
sb.append(getListDescription((List)object)).append(", ");
|
||||
} else if(object instanceof Object[]) {
|
||||
sb.append(getListDescription(Arrays.asList((Object[])object))).append(", ");
|
||||
} else {
|
||||
sb.append(getStackDescription(object)).append(", ");
|
||||
}
|
||||
}
|
||||
sb.setLength(sb.length() - 2);
|
||||
sb.append(']');
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getCraftingDescription(IRecipe recipe) {
|
||||
if(recipe instanceof ShapelessOreRecipe)
|
||||
return LogHelper.getCraftingDescription((ShapelessOreRecipe)recipe);
|
||||
else if(recipe instanceof ShapedOreRecipe)
|
||||
return LogHelper.getCraftingDescription((ShapedOreRecipe)recipe);
|
||||
else if(recipe instanceof ShapelessRecipes)
|
||||
return LogHelper.getCraftingDescription((ShapelessRecipes)recipe);
|
||||
else if(recipe instanceof ShapedRecipes)
|
||||
return LogHelper.getCraftingDescription((ShapedRecipes)recipe);
|
||||
|
||||
return recipe.toString();
|
||||
}
|
||||
|
||||
public static String getCraftingDescription(ShapelessOreRecipe recipe) {
|
||||
return getListDescription(recipe.getInput());
|
||||
}
|
||||
|
||||
public static String getCraftingDescription(ShapelessRecipes recipe) {
|
||||
return getListDescription(recipe.recipeItems);
|
||||
}
|
||||
|
||||
public static String getCraftingDescription(ShapedOreRecipe recipe) {
|
||||
int height = ReflectionHelper.<Integer>getObject(recipe, "width");
|
||||
int width = ReflectionHelper.<Integer>getObject(recipe, "height");
|
||||
|
||||
Object[][] recipes = InputHelper.getMultiDimensionalArray(Object.class, recipe.getInput(), height, width);
|
||||
|
||||
return getListDescription(Arrays.asList(recipes));
|
||||
}
|
||||
|
||||
public static String getCraftingDescription(ShapedRecipes recipe) {
|
||||
ItemStack[][] recipes = InputHelper.getMultiDimensionalArray(ItemStack.class, recipe.recipeItems, recipe.recipeHeight, recipe.recipeWidth);
|
||||
return getListDescription(Arrays.asList(recipes));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user