net.minecraftforge.common.crafting.IShapedRecipe Java Examples

The following examples show how to use net.minecraftforge.common.crafting.IShapedRecipe. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardRecipePage.java    From OpenModsLib with MIT License 5 votes vote down vote up
public StandardRecipePage(String title, String description, @Nonnull ItemStack resultingItem) {
	addComponent(new GuiComponentSprite(75, 40, iconArrow));
	addComponent(new GuiComponentItemStackSpinner(140, 30, resultingItem));

	{
		final IRecipe recipe = RecipeUtils.getFirstRecipeForItemStack(resultingItem);
		if (recipe != null) {
			final ItemStack[][] input = RecipeUtils.getFullRecipeInput(recipe);
			if (input != null) {
				final int width = (recipe instanceof IShapedRecipe)? ((IShapedRecipe)recipe).getRecipeWidth() : 3;
				addComponent(new GuiComponentCraftingGrid(10, 20, input, width, iconCraftingGrid));
			}
		}
	}

	{
		String translatedTitle = TranslationUtils.translateToLocal(title);
		final GuiComponentLabel titleLabel = new GuiComponentLabel(0, 0, translatedTitle);
		titleLabel.setScale(BookScaleConfig.getPageTitleScale());
		addComponent(new GuiComponentHCenter(0, 2, getWidth()).addComponent(titleLabel));
	}

	{
		String translatedDescription = TranslationUtils.translateToLocal(description).replaceAll("\\\\n", "\n");
		GuiComponentLabel lblDescription = new GuiComponentLabel(10, 80, getWidth() - 5, 200, translatedDescription);
		lblDescription.setScale(BookScaleConfig.getPageContentScale());
		lblDescription.setAdditionalLineHeight(BookScaleConfig.getRecipePageSeparator());
		addComponent(lblDescription);
	}
}
 
Example #2
Source File: MixinRecipeGridAligner.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @author qouteall
 * @reason https://github.com/FabricMC/Mixin/issues/15
 */
@Overwrite
default void alignRecipeToGrid(
		int gridWidth, int gridHeight, int gridOutputSlot,
		Recipe<?> recipe, Iterator<?> inputs, int amount
) {
	int width = gridWidth;
	int height = gridHeight;

	// change start
	if (recipe instanceof IShapedRecipe) {
		IShapedRecipe<?> shapedRecipe = (IShapedRecipe<?>) recipe;
		width = shapedRecipe.getRecipeWidth();
		height = shapedRecipe.getRecipeHeight();
	}

	// change end

	int slot = 0;

	for (int y = 0; y < gridHeight; ++y) {
		if (slot == gridOutputSlot) {
			++slot;
		}

		boolean bl = (float) height < (float) gridHeight / 2.0F;

		int m = MathHelper.floor((float) gridHeight / 2.0F - (float) height / 2.0F);

		if (bl && m > y) {
			slot += gridWidth;
			++y;
		}

		for (int x = 0; x < gridWidth; ++x) {
			if (!inputs.hasNext()) {
				return;
			}

			bl = (float) width < (float) gridWidth / 2.0F;
			m = MathHelper.floor((float) gridWidth / 2.0F - (float) width / 2.0F);
			int o = width;

			boolean bl2 = x < width;

			if (bl) {
				o = m + width;
				bl2 = m <= x && x < m + width;
			}

			if (bl2) {
				this.acceptAlignedInput(inputs, slot, amount, y, x);
			} else if (o == x) {
				slot += gridWidth - x;
				break;
			}

			++slot;
		}
	}
}