use of net.minecraftforge.common.crafting.IShapedRecipe in project CraftTweaker by CraftTweaker.
the class MCRecipeWrapper method getIngredients2D.
@Override
public IIngredient[][] getIngredients2D() {
IIngredient[] ingredients = getIngredients1D();
if (!isShaped) {
return new IIngredient[][] { ingredients };
}
IShapedRecipe shapedRecipe = (IShapedRecipe) recipe;
int heigth = shapedRecipe.getRecipeHeight();
int width = shapedRecipe.getRecipeWidth();
IIngredient[][] out = new IIngredient[heigth][width];
for (int row = 0; row < heigth; row++) {
for (int column = 0; column < width; column++) {
out[row][column] = ingredients[row * width + column];
}
}
return out;
}
use of net.minecraftforge.common.crafting.IShapedRecipe in project BuildCraft by BuildCraft.
the class GuideCraftingFactory method getFactory.
public static GuidePartFactory getFactory(IRecipe recipe) {
ItemStack output = recipe.getRecipeOutput();
NonNullList<Ingredient> input = recipe.getIngredients();
if (input == null || input.isEmpty() || output.isEmpty()) {
return null;
}
Ingredient[][] matrix = new Ingredient[3][3];
int maxX = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeWidth() : 3;
int maxY = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeHeight() : 3;
int offsetX = maxX == 1 ? 1 : 0;
int offsetY = maxY == 1 ? 1 : 0;
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
if (x < offsetX || y < offsetY) {
matrix[x][y] = Ingredient.EMPTY;
continue;
}
int i = x - offsetX + (y - offsetY) * maxX;
if (i >= input.size() || x - offsetX >= maxX) {
matrix[x][y] = Ingredient.EMPTY;
} else {
matrix[x][y] = input.get(i);
}
}
}
return new GuideCraftingFactory(matrix, output);
}
use of net.minecraftforge.common.crafting.IShapedRecipe in project BuildCraft by BuildCraft.
the class GuiAdvancedCraftingTable method sendRecipe.
private void sendRecipe(IRecipe recipe) {
List<ItemStack> stacks = new ArrayList<>(9);
int maxX = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeWidth() : 3;
int maxY = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeHeight() : 3;
int offsetX = maxX == 1 ? 1 : 0;
int offsetY = maxY == 1 ? 1 : 0;
List<Ingredient> ingredients = recipe.getIngredients();
if (ingredients.isEmpty()) {
return;
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
if (x < offsetX || y < offsetY) {
stacks.add(ItemStack.EMPTY);
continue;
}
int i = x - offsetX + (y - offsetY) * maxX;
if (i >= ingredients.size() || x - offsetX >= maxX) {
stacks.add(ItemStack.EMPTY);
} else {
Ingredient ing = ingredients.get(i);
ItemStack[] matching = ing.getMatchingStacks();
if (matching.length >= 1) {
stacks.add(matching[0]);
} else {
stacks.add(ItemStack.EMPTY);
}
}
}
}
container.sendSetPhantomSlots(container.tile.invBlueprint, stacks);
}
use of net.minecraftforge.common.crafting.IShapedRecipe in project BuildCraft by BuildCraft.
the class GuiAutoCraftItems method sendRecipe.
private void sendRecipe(IRecipe recipe) {
List<ItemStack> stacks = new ArrayList<>(9);
int maxX = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeWidth() : 3;
int maxY = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeHeight() : 3;
int offsetX = maxX == 1 ? 1 : 0;
int offsetY = maxY == 1 ? 1 : 0;
List<Ingredient> ingredients = recipe.getIngredients();
if (ingredients.isEmpty()) {
return;
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
if (x < offsetX || y < offsetY) {
stacks.add(ItemStack.EMPTY);
continue;
}
int i = x - offsetX + (y - offsetY) * maxX;
if (i >= ingredients.size() || x - offsetX >= maxX) {
stacks.add(ItemStack.EMPTY);
} else {
Ingredient ing = ingredients.get(i);
ItemStack[] matching = ing.getMatchingStacks();
if (matching.length >= 1) {
stacks.add(matching[0]);
} else {
stacks.add(ItemStack.EMPTY);
}
}
}
}
container.sendSetPhantomSlots(container.tile.invBlueprint, stacks);
}
use of net.minecraftforge.common.crafting.IShapedRecipe in project CraftTweaker by CraftTweaker.
the class MCRecipeWrapper method toCommandString.
@Override
public String toCommandString() {
StringBuilder commandString = new StringBuilder("recipes.addShape");
if (isShaped) {
IShapedRecipe shapedRecipe = (IShapedRecipe) recipe;
int width = shapedRecipe.getRecipeWidth();
int height = shapedRecipe.getRecipeHeight();
commandString.append("d(\"").append(this.getRegistryName()).append("\", ");
IItemStack output = getOutput();
commandString.append(output == null ? "null" : output.toCommandString()).append(", [");
if (height > 0 && width > 0) {
for (int row = 0; row < height; row++) {
commandString.append("[");
for (int column = 0; column < width; column++) {
IIngredient ingredient = CraftTweakerMC.getIIngredient(shapedRecipe.getIngredients().get(row * width + column));
commandString.append(ingredient == null ? "null" : ingredient.toCommandString()).append(", ");
}
// Remove last ,
commandString.deleteCharAt(commandString.length() - 1);
commandString.deleteCharAt(commandString.length() - 1);
commandString.append("], ");
}
// Remove last ,
commandString.deleteCharAt(commandString.length() - 1);
commandString.deleteCharAt(commandString.length() - 1);
}
} else {
commandString.append("less(\"").append(this.getRegistryName()).append("\", ");
IItemStack output = getOutput();
commandString.append(output == null ? "null" : output.toCommandString()).append(", [");
if (recipe.getIngredients().size() > 0) {
for (Ingredient ingredient : recipe.getIngredients()) {
IIngredient iIngredient = CraftTweakerMC.getIIngredient(ingredient);
commandString.append(iIngredient == null ? "null" : iIngredient.toCommandString()).append(", ");
}
// Remove last ,
commandString.deleteCharAt(commandString.length() - 1);
commandString.deleteCharAt(commandString.length() - 1);
}
}
return commandString.append("]);").toString();
}
Aggregations