Files
ModTweaker/src/main/java/modtweaker2/helpers/InputHelper.java
T

198 lines
4.9 KiB
Java
Raw Normal View History

package modtweaker2.helpers;
2015-01-11 21:59:45 +02:00
2015-07-09 11:28:40 +02:00
import java.lang.reflect.Array;
2015-04-27 04:16:18 +02:00
import java.util.ArrayList;
import minetweaker.api.entity.IEntity;
2015-01-11 21:59:45 +02:00
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.oredict.IOreDictEntry;
2015-06-29 16:36:35 +02:00
import minetweaker.mc1710.item.MCItemStack;
import minetweaker.mc1710.liquid.MCLiquidStack;
import net.minecraft.entity.Entity;
2015-01-11 21:59:45 +02:00
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
2015-01-14 20:50:51 +02:00
import net.minecraftforge.fluids.Fluid;
2015-01-11 21:59:45 +02:00
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
public class InputHelper {
2015-01-14 20:50:51 +02:00
public static boolean isABlock(IItemStack block) {
if (!(isABlock(toStack(block)))) {
return false;
} else
return true;
}
2015-06-29 16:36:35 +02:00
2015-07-09 11:28:40 +02:00
public static <T> T[][] getMultiDimensionalArray(Class<T> clazz, T[] array, int height, int width) {
@SuppressWarnings("unchecked")
T[][] multiDim = (T[][])Array.newInstance(clazz, new int[] {height, width});
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
multiDim[y][x] = array[x + (y * width)];
2015-07-01 13:55:19 +02:00
}
2015-06-29 16:36:35 +02:00
}
2015-07-09 11:28:40 +02:00
return multiDim;
2015-06-29 16:36:35 +02:00
}
2015-03-17 23:06:34 +02:00
public static IItemStack[] toStacks(IIngredient[] iIngredient) {
ArrayList<IItemStack> stacks = new ArrayList<IItemStack>();
2015-07-20 09:03:48 +02:00
2015-03-17 23:06:34 +02:00
for (IIngredient ing : iIngredient) {
for (IItemStack stack : ing.getItems()) {
stacks.add(stack);
}
}
2015-07-20 09:03:48 +02:00
return stacks.toArray(new IItemStack[stacks.size()]);
2015-03-17 23:06:34 +02:00
}
2015-01-14 20:50:51 +02:00
public static boolean isABlock(ItemStack block) {
return block.getItem() instanceof ItemBlock;
}
2015-03-17 23:06:34 +02:00
2015-04-27 04:16:18 +02:00
public static Entity toEntity(IEntity iEntity) {
return null;
}
2015-01-14 20:50:51 +02:00
public static ItemStack toStack(IItemStack iStack) {
2015-07-20 09:03:48 +02:00
if (iStack == null) {
2015-01-14 20:50:51 +02:00
return null;
2015-07-20 09:03:48 +02:00
} else {
2015-01-14 20:50:51 +02:00
Object internal = iStack.getInternal();
2015-07-20 09:03:48 +02:00
if (!(internal instanceof ItemStack)) {
2015-06-29 16:36:35 +02:00
LogHelper.logError("Not a valid item stack: " + iStack);
2015-01-14 20:50:51 +02:00
}
return (ItemStack) internal;
}
}
2015-06-29 16:36:35 +02:00
public static IIngredient toIngredient(ItemStack stack) {
return toIItemStack(stack);
}
public static IIngredient toIngredient(FluidStack stack) {
2015-07-20 09:03:48 +02:00
if(stack == null) {
2015-06-29 16:36:35 +02:00
return null;
2015-07-20 09:03:48 +02:00
}
2015-06-29 16:36:35 +02:00
return new MCLiquidStack(stack);
}
public static IItemStack toIItemStack(ItemStack stack) {
if(stack == null) {
return null;
}
return new MCItemStack(stack);
}
public static ILiquidStack toILiquidStack(FluidStack stack) {
if(stack == null) {
return null;
}
return new MCLiquidStack(stack);
}
2015-01-14 20:50:51 +02:00
public static ItemStack[] toStacks(IItemStack[] iStack) {
2015-07-20 09:03:48 +02:00
if (iStack == null) {
2015-01-14 20:50:51 +02:00
return null;
2015-07-20 09:03:48 +02:00
} else {
2015-01-14 20:50:51 +02:00
ItemStack[] output = new ItemStack[iStack.length];
for (int i = 0; i < iStack.length; i++) {
output[i] = toStack(iStack[i]);
}
return output;
}
}
public static Object toObject(IIngredient iStack) {
if (iStack == null)
return null;
else {
if (iStack instanceof IOreDictEntry) {
return toString((IOreDictEntry) iStack);
} else if (iStack instanceof IItemStack) {
return toStack((IItemStack) iStack);
} else
return null;
}
}
public static Object[] toObjects(IIngredient[] ingredient) {
if (ingredient == null)
return null;
else {
Object[] output = new Object[ingredient.length];
for (int i = 0; i < ingredient.length; i++) {
if (ingredient[i] != null) {
output[i] = toObject(ingredient[i]);
} else
output[i] = "";
}
return output;
}
}
2015-07-07 12:00:17 +02:00
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object[] toShapedObjects(IIngredient[][] ingredients) {
2015-01-14 20:50:51 +02:00
if (ingredients == null)
return null;
else {
ArrayList prep = new ArrayList();
prep.add("abc");
prep.add("def");
prep.add("ghi");
2015-03-17 23:06:34 +02:00
char[][] map = new char[][]{{'a', 'b', 'c'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}};
2015-01-14 20:50:51 +02:00
for (int x = 0; x < ingredients.length; x++) {
if (ingredients[x] != null) {
for (int y = 0; y < ingredients[x].length; y++) {
if (ingredients[x][y] != null && x < map.length && y < map[x].length) {
prep.add(map[x][y]);
prep.add(toObject(ingredients[x][y]));
}
}
}
}
return prep.toArray();
}
}
public static String toString(IOreDictEntry entry) {
return ((IOreDictEntry) entry).getName();
}
public static FluidStack toFluid(ILiquidStack iStack) {
if (iStack == null) {
return null;
} else
return FluidRegistry.getFluidStack(iStack.getName(), iStack.getAmount());
}
public static Fluid getFluid(ILiquidStack iStack) {
if (iStack == null) {
return null;
} else
return FluidRegistry.getFluid(iStack.getName());
}
public static FluidStack[] toFluids(IIngredient[] input) {
return toFluids((IItemStack[]) input);
}
public static FluidStack[] toFluids(ILiquidStack[] iStack) {
FluidStack[] stack = new FluidStack[iStack.length];
for (int i = 0; i < stack.length; i++)
stack[i] = toFluid(iStack[i]);
return stack;
}
2015-01-11 21:59:45 +02:00
}