diff --git a/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidIgnemRecipeCategory.java b/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidIgnemRecipeCategory.java index 735923bc1..00312e016 100644 --- a/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidIgnemRecipeCategory.java +++ b/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidIgnemRecipeCategory.java @@ -8,37 +8,23 @@ */ package vazkii.botania.client.integration.jei.orechid; -import com.mojang.blaze3d.platform.GlStateManager; -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableStatic; -import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +import vazkii.botania.api.BotaniaAPI; import vazkii.botania.common.block.ModSubtiles; import vazkii.botania.common.lib.LibMisc; import javax.annotation.Nonnull; +import java.util.Map; -public class OrechidIgnemRecipeCategory implements IRecipeCategory { +public class OrechidIgnemRecipeCategory extends OrechidRecipeCategoryBase { public static final ResourceLocation UID = new ResourceLocation(LibMisc.MOD_ID, "orechid_ignem"); - private final IDrawableStatic background; - private final String localizedName; - private final IDrawableStatic overlay; - private final IDrawable icon; public OrechidIgnemRecipeCategory(IGuiHelper guiHelper) { - background = guiHelper.createBlankDrawable(168, 64); - localizedName = I18n.format("botania.nei.orechidIgnem"); - overlay = guiHelper.createDrawable(new ResourceLocation("botania", "textures/gui/pure_daisy_overlay.png"), - 0, 0, 64, 46); - icon = guiHelper.createDrawableIngredient(new ItemStack(ModSubtiles.orechidIgnem)); + super(guiHelper, new ItemStack(ModSubtiles.orechidIgnem), I18n.format("botania.nei.orechidIgnem")); } @Nonnull @@ -53,50 +39,9 @@ public class OrechidIgnemRecipeCategory implements IRecipeCategory getOreWeights() { + return BotaniaAPI.oreWeightsNether; } - @Nonnull - @Override - public IDrawable getBackground() { - return background; - } - - @Nonnull - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public void setIngredients(OrechidIgnemRecipeWrapper recipe, IIngredients ingredients) { - - } - - - @Override - public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull OrechidIgnemRecipeWrapper recipeWrapper, @Nonnull IIngredients ingredients) { - final IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); - - itemStacks.init(0, true, 40, 12); - itemStacks.set(0, ingredients.getInputs(VanillaTypes.ITEM).get(0)); - - itemStacks.init(1, true, 70, 12); - itemStacks.set(1, new ItemStack(ModSubtiles.orechidIgnem)); - - itemStacks.init(2, true, 99, 12); - itemStacks.set(2, ingredients.getOutputs(VanillaTypes.ITEM).get(0)); - } - - @Override - public void draw(OrechidIgnemRecipeWrapper recipe, double mouseX, double mouseY) { - GlStateManager.enableAlphaTest(); - GlStateManager.enableBlend(); - overlay.draw(48, 0); - GlStateManager.disableBlend(); - GlStateManager.disableAlphaTest(); - } } diff --git a/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidRecipeCategory.java b/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidRecipeCategory.java index 90ba59d91..d748d2f97 100644 --- a/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidRecipeCategory.java +++ b/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidRecipeCategory.java @@ -8,46 +8,22 @@ */ package vazkii.botania.client.integration.jei.orechid; -import com.mojang.blaze3d.platform.GlStateManager; -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableStatic; -import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.ingredients.IIngredients; -import mezz.jei.api.recipe.category.IRecipeCategory; -import net.minecraft.block.Blocks; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.tags.BlockTags; import net.minecraft.util.ResourceLocation; import vazkii.botania.api.BotaniaAPI; -import vazkii.botania.client.integration.jei.JEIBotaniaPlugin; import vazkii.botania.common.block.ModSubtiles; import vazkii.botania.common.lib.LibMisc; import javax.annotation.Nonnull; -import java.util.Collections; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; - -public class OrechidRecipeCategory implements IRecipeCategory { +public class OrechidRecipeCategory extends OrechidRecipeCategoryBase { public static final ResourceLocation UID = new ResourceLocation(LibMisc.MOD_ID, "orechid"); - private final IDrawableStatic background; - private final String localizedName; - private final IDrawableStatic overlay; - private final IDrawable icon; - + public OrechidRecipeCategory(IGuiHelper guiHelper) { - background = guiHelper.createBlankDrawable(168, 64); - localizedName = I18n.format("botania.nei.orechid"); - overlay = guiHelper.createDrawable(new ResourceLocation("botania", "textures/gui/pure_daisy_overlay.png"), - 0, 0, 64, 46); - icon = guiHelper.createDrawableIngredient(new ItemStack(ModSubtiles.orechid)); + super(guiHelper, new ItemStack(ModSubtiles.orechid), I18n.format("botania.nei.orechid")); } @Nonnull @@ -62,72 +38,8 @@ public class OrechidRecipeCategory implements IRecipeCategory getOreWeights() { + return BotaniaAPI.oreWeights; } - - @Nonnull - @Override - public IDrawable getBackground() { - return background; - } - - @Nonnull - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public void setIngredients(OrechidRecipeWrapper recipe, IIngredients ingredients) { - ingredients.setInput(VanillaTypes.ITEM, new ItemStack(Blocks.STONE, 64)); - - final int myWeight = recipe.entry.getValue(); - final int amount = Math.max(1, Math.round((float) myWeight * 64 / getTotalOreWeight(BotaniaAPI.oreWeights, myWeight))); - - // Shouldn't ever return an empty list since the ore weight - // list is filtered to only have ores with ItemBlocks - List stackList = BlockTags.getCollection().getOrCreate(recipe.entry.getKey()) - .getAllElements() - .stream() - .filter(s -> s.asItem() != Items.AIR) - .map(ItemStack::new) - .collect(Collectors.toList()); - - stackList.forEach(s -> s.setCount(amount)); - ingredients.setOutputLists(VanillaTypes.ITEM, Collections.singletonList(stackList)); - } - - public static float getTotalOreWeight(Map weights, int myWeight) { - return (weights.entrySet().stream() - .filter(e -> JEIBotaniaPlugin.doesOreExist(e.getKey())) - .map(Map.Entry::getValue) - .reduce(Integer::sum)).orElse(myWeight * 64 * 64); - } - - @Override - public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull OrechidRecipeWrapper recipeWrapper, @Nonnull IIngredients ingredients) { - final IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); - - itemStacks.init(0, true, 40, 12); - itemStacks.set(0, ingredients.getInputs(VanillaTypes.ITEM).get(0)); - - itemStacks.init(1, true, 70, 12); - itemStacks.set(1, new ItemStack(ModSubtiles.orechid)); - - itemStacks.init(2, true, 99, 12); - itemStacks.set(2, ingredients.getOutputs(VanillaTypes.ITEM).get(0)); - } - - @Override - public void draw(OrechidRecipeWrapper recipe, double mouseX, double mouseY) { - GlStateManager.enableAlphaTest(); - GlStateManager.enableBlend(); - overlay.draw(48, 0); - GlStateManager.disableBlend(); - GlStateManager.disableAlphaTest(); - } - } diff --git a/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidRecipeCategoryBase.java b/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidRecipeCategoryBase.java new file mode 100644 index 000000000..b1655d59c --- /dev/null +++ b/src/main/java/vazkii/botania/client/integration/jei/orechid/OrechidRecipeCategoryBase.java @@ -0,0 +1,124 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + *

+ * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + */ +package vazkii.botania.client.integration.jei.orechid; + +import com.mojang.blaze3d.platform.GlStateManager; +import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.gui.drawable.IDrawableStatic; +import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; +import mezz.jei.api.helpers.IGuiHelper; +import mezz.jei.api.ingredients.IIngredients; +import mezz.jei.api.recipe.category.IRecipeCategory; +import net.minecraft.block.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.tags.BlockTags; +import net.minecraft.util.ResourceLocation; +import vazkii.botania.client.integration.jei.JEIBotaniaPlugin; + +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public abstract class OrechidRecipeCategoryBase implements IRecipeCategory { + + private final IDrawableStatic background; + private final String localizedName; + private final IDrawableStatic overlay; + private final IDrawable icon; + private final ItemStack iconStack; + + public OrechidRecipeCategoryBase(IGuiHelper guiHelper, ItemStack iconStack, String localizedName) { + overlay = guiHelper.createDrawable(new ResourceLocation("botania", "textures/gui/pure_daisy_overlay.png"), + 0, 0, 64, 46); + background = guiHelper.createBlankDrawable(168, 64); + this.localizedName = localizedName; + this.icon = guiHelper.createDrawableIngredient(iconStack); + this.iconStack = iconStack; + } + + @Nonnull + @Override + public abstract Class getRecipeClass(); + + @Nonnull + @Override + public String getTitle() { + return localizedName; + } + + @Nonnull + @Override + public IDrawable getBackground() { + return background; + } + + @Nonnull + @Override + public IDrawable getIcon() { + return icon; + } + + @Override + public void setIngredients(T recipe, IIngredients ingredients) { + ingredients.setInput(VanillaTypes.ITEM, new ItemStack(Blocks.STONE, 64)); + + final int myWeight = recipe.entry.getValue(); + final int amount = Math.max(1, Math.round((float) myWeight * 64 / getTotalOreWeight(getOreWeights(), myWeight))); + + // Shouldn't ever return an empty list since the ore weight + // list is filtered to only have ores with ItemBlocks + List stackList = BlockTags.getCollection().getOrCreate(recipe.entry.getKey()) + .getAllElements() + .stream() + .filter(s -> s.asItem() != Items.AIR) + .map(ItemStack::new) + .collect(Collectors.toList()); + + stackList.forEach(s -> s.setCount(amount)); + ingredients.setOutputLists(VanillaTypes.ITEM, Collections.singletonList(stackList)); + } + + public static float getTotalOreWeight(Map weights, int myWeight) { + return (weights.entrySet().stream() + .filter(e -> JEIBotaniaPlugin.doesOreExist(e.getKey())) + .map(Map.Entry::getValue) + .reduce(Integer::sum)).orElse(myWeight * 64 * 64); + } + + protected abstract Map getOreWeights(); + + @Override + public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull T recipeWrapper, @Nonnull IIngredients ingredients) { + final IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); + + itemStacks.init(0, true, 40, 12); + itemStacks.set(0, ingredients.getInputs(VanillaTypes.ITEM).get(0)); + + itemStacks.init(1, true, 70, 12); + itemStacks.set(1, iconStack); + + itemStacks.init(2, true, 99, 12); + itemStacks.set(2, ingredients.getOutputs(VanillaTypes.ITEM).get(0)); + } + + @Override + public void draw(T recipe, double mouseX, double mouseY) { + GlStateManager.enableAlphaTest(); + GlStateManager.enableBlend(); + overlay.draw(48, 0); + GlStateManager.disableBlend(); + GlStateManager.disableAlphaTest(); + } + +}