use of net.minecraft.item.crafting.ShapedRecipes in project Railcraft by Railcraft.
the class CraftingPlugin method makeVanillaShapedRecipe.
public static IRecipe makeVanillaShapedRecipe(ItemStack output, Object... components) {
String s = "";
int index = 0;
int width = 0;
int height = 0;
if (components[index] instanceof String[]) {
String[] as = (String[]) components[index++];
for (String s2 : as) {
height++;
width = s2.length();
s = (new StringBuilder()).append(s).append(s2).toString();
}
} else {
while (components[index] instanceof String) {
String s1 = (String) components[index++];
height++;
width = s1.length();
s = (new StringBuilder()).append(s).append(s1).toString();
}
}
HashMap<Character, ItemStack> hashMap = new HashMap<Character, ItemStack>();
for (; index < components.length; index += 2) {
Character character = (Character) components[index];
ItemStack itemStack = InvTools.emptyStack();
if (components[index + 1] instanceof Item) {
itemStack = new ItemStack((Item) components[index + 1]);
} else if (components[index + 1] instanceof Block) {
itemStack = new ItemStack((Block) components[index + 1], 1, -1);
} else if (components[index + 1] instanceof ItemStack) {
itemStack = (ItemStack) components[index + 1];
}
hashMap.put(character, itemStack);
}
ItemStack[] recipeArray = new ItemStack[width * height];
for (int i1 = 0; i1 < width * height; i1++) {
char c = s.charAt(i1);
if (hashMap.containsKey(c)) {
recipeArray[i1] = hashMap.get(c).copy();
} else {
recipeArray[i1] = InvTools.emptyStack();
}
}
return new ShapedRecipes(width, height, recipeArray, output);
}
use of net.minecraft.item.crafting.ShapedRecipes in project SecurityCraft by Geforce132.
the class GuiSCManual method updateRecipeAndIcons.
private void updateRecipeAndIcons() {
if (currentPage < 0) {
recipe = null;
hoverCheckers.clear();
return;
}
hoverCheckers.clear();
if (SecurityCraft.instance.manualPages.get(currentPage).hasCustomRecipe())
recipe = SecurityCraft.instance.manualPages.get(currentPage).getRecipe();
else
for (Object object : CraftingManager.getInstance().getRecipeList()) {
if (object instanceof ShapedRecipes) {
ShapedRecipes recipe = (ShapedRecipes) object;
if (recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == SecurityCraft.instance.manualPages.get(currentPage).getItem()) {
this.recipe = recipe.recipeItems;
break;
}
} else if (object instanceof ShapelessRecipes) {
ShapelessRecipes recipe = (ShapelessRecipes) object;
if (recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == SecurityCraft.instance.manualPages.get(currentPage).getItem()) {
this.recipe = toItemStackArray(recipe.recipeItems);
break;
}
}
recipe = null;
}
if (recipe != null) {
outer: for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if ((i * 3) + j == recipe.length)
break outer;
if (recipe[(i * 3) + j] != null)
hoverCheckers.add(new CustomHoverChecker(144 + (i * 20), 144 + (i * 20) + 16, (k + 100) + (j * 20), (k + 100) + (j * 20) + 16, 20, recipe[(i * 3) + j].getDisplayName()));
}
}
} else if (SecurityCraft.instance.manualPages.get(currentPage).isRecipeDisabled())
hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.disabled")));
else if (SecurityCraft.instance.manualPages.get(currentPage).getHelpInfo().equals("help.reinforced.info"))
hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.recipe.reinforced")));
else {
String name = SecurityCraft.instance.manualPages.get(currentPage).getItem().getUnlocalizedName().substring(5);
hoverCheckers.add(new CustomHoverChecker(144, 144 + (2 * 20) + 16, k + 100, (k + 100) + (2 * 20) + 16, 20, StatCollector.translateToLocal("gui.scManual.recipe." + name)));
}
Item item = SecurityCraft.instance.manualPages.get(currentPage).getItem();
TileEntity te = ((item instanceof ItemBlock && ((ItemBlock) item).getBlock() instanceof ITileEntityProvider) ? ((ITileEntityProvider) ((ItemBlock) item).getBlock()).createNewTileEntity(Minecraft.getMinecraft().theWorld, 0) : null);
Block itemBlock = ((item instanceof ItemBlock) ? ((ItemBlock) item).getBlock() : null);
if (te != null) {
if (te instanceof IOwnable)
hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 29, (k + 29) + 16, 20, StatCollector.translateToLocal("gui.scManual.ownableBlock")));
if (te instanceof IPasswordProtected)
hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 55, (k + 55) + 16, 20, StatCollector.translateToLocal("gui.scManual.passwordProtectedBlock")));
if (te instanceof TileEntitySCTE && ((TileEntitySCTE) te).isActivatedByView())
hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 81, (k + 81) + 16, 20, StatCollector.translateToLocal("gui.scManual.viewActivatedBlock")));
if (itemBlock instanceof IExplosive)
hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 107, (k + 107) + 16, 20, StatCollector.translateToLocal("gui.scManual.explosiveBlock")));
if (te instanceof CustomizableSCTE)
hoverCheckers.add(new CustomHoverChecker(118, 118 + 16, k + 213, (k + 213) + 16, 20, StatCollector.translateToLocal("gui.scManual.customizableBlock")));
}
}
use of net.minecraft.item.crafting.ShapedRecipes in project Tropicraft by Tropicraft.
the class Encyclopedia method getFormattedRecipe.
public RecipeEntry getFormattedRecipe(IRecipe recipe) {
// TODO support other kinds of recipes
if (recipe instanceof ShapedRecipes) {
ShapedRecipes shaped = (ShapedRecipes) recipe;
int width = shaped.recipeWidth;
int height = shaped.recipeHeight;
NonNullList<Ingredient> items = shaped.recipeItems;
ItemStack output = recipe.getRecipeOutput();
return new RecipeEntry(width, height, items, output);
} else if (recipe instanceof ShapelessRecipes) {
return new RecipeEntry(3, 3, recipe.getIngredients(), recipe.getRecipeOutput());
}
return null;
}
use of net.minecraft.item.crafting.ShapedRecipes in project EnderIO by SleepyTrousers.
the class Crafting method register.
@Override
public void register(@Nonnull String recipeName) {
if (valid && active) {
final ResourceLocation recipeRL = mkRL(recipeName);
final IForgeRegistry<IRecipe> registry = ForgeRegistries.RECIPES;
if (grid != null) {
if (upgrade) {
log("ShapedRecipe.Upgrade", recipeName, recipeRL, getOutput().getItemStack(), grid.getIngredients());
registry.register(new ShapedRecipe.Upgrade(recipeRL, grid.getWidth(), grid.getHeight(), grid.getIngredients(), getOutput().getThing()));
} else {
log("ShapedRecipe", recipeName, recipeRL, getOutput().getItemStack(), grid.getIngredients());
registry.register(new ShapedRecipe(recipeRL, grid.getWidth(), grid.getHeight(), grid.getIngredients(), getOutput().getThing()));
}
if (getOutput().hasAlternatives()) {
getOutput().getAlternatives().apply(new Callback<ItemStack>() {
@Override
public void apply(@Nonnull ItemStack alternative) {
Log.debug("Providing synthetic alternative recipe to JEI for oredicted output: " + alternative + ": " + grid.getIngredients());
JeiAccessor.addAlternativeRecipe(new ShapedRecipes("", grid.getWidth(), grid.getHeight(), grid.getIngredients(), alternative));
}
});
}
} else {
if (upgrade) {
log("GenericUpgradeRecipeShapeless", recipeName, recipeRL, getOutput().getItemStack(), shapeless.getIngredients());
registry.register(new ShapelessRecipe.Upgrade(recipeRL, shapeless.getIngredients(), getOutput().getThing()));
} else {
log("ShapelessOreRecipe", recipeName, recipeRL, getOutput().getItemStack(), shapeless.getIngredients());
registry.register(new ShapelessRecipe(recipeRL, shapeless.getIngredients(), getOutput().getThing()));
}
if (getOutput().hasAlternatives()) {
getOutput().getAlternatives().apply(new Callback<ItemStack>() {
@Override
public void apply(@Nonnull ItemStack alternative) {
Log.debug("Providing synthetic alternative recipe to JEI for oredicted output: " + alternative + ": " + shapeless.getIngredients());
JeiAccessor.addAlternativeRecipe(new ShapelessRecipes("", alternative, shapeless.getIngredients()));
}
});
}
}
} else {
Log.debug("Skipping Crafting '" + (getOutput() == null ? "null" : getOutput().getItemStack()) + "' (valid=" + valid + ", active=" + active + ")");
}
}
use of net.minecraft.item.crafting.ShapedRecipes in project Galacticraft by micdoodle8.
the class ShapedRecipeHandler method loadCraftingRecipes.
@Override
public void loadCraftingRecipes(ItemStack result) {
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
CachedShapedRecipe recipe = null;
if (irecipe instanceof ShapedRecipes) {
recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
} else if (irecipe instanceof ShapedOreRecipe) {
recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
}
if (recipe == null) {
continue;
}
recipe.computeVisuals();
arecipes.add(recipe);
}
}
}
Aggregations