Add JEI handlers for Orechid and Orechid Ignem (#2632)

* Add JEI handlers for Orechid and Orechid Ignem

* Make whitespace consistent

* Change lazy-initialized item stacks to init in constructor

* Change `doesOreExist` to take a String instead of an Entry

* Remove `oreDictKey` field since it is only ever used in the constructor

* Add `final` and change access qualifiers where appropriate

* Remove pointless accessor
This commit is contained in:
David Vierra authored and Vincent Lee committed 2018-06-18 19:26:26 -07:00
1 parent ba29aff21e
commit c9f8347299
6 files changed
+337 -4

No files matched your search

@@ -15,7 +15,9 @@ import mezz.jei.api.JEIPlugin;
import mezz.jei.api.recipe.IRecipeCategoryRegistration;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.recipe.RecipeBrew;
import vazkii.botania.api.recipe.RecipeElvenTrade;
@@ -33,6 +35,10 @@ import vazkii.botania.client.integration.jei.elventrade.ElvenTradeRecipeCategory
import vazkii.botania.client.integration.jei.elventrade.ElvenTradeRecipeWrapper;
import vazkii.botania.client.integration.jei.manapool.ManaPoolRecipeCategory;
import vazkii.botania.client.integration.jei.manapool.ManaPoolRecipeWrapper;
import vazkii.botania.client.integration.jei.orechid.OrechidIgnemRecipeCategory;
import vazkii.botania.client.integration.jei.orechid.OrechidIgnemRecipeWrapper;
import vazkii.botania.client.integration.jei.orechid.OrechidRecipeCategory;
import vazkii.botania.client.integration.jei.orechid.OrechidRecipeWrapper;
import vazkii.botania.client.integration.jei.petalapothecary.PetalApothecaryRecipeCategory;
import vazkii.botania.client.integration.jei.petalapothecary.PetalApothecaryRecipeWrapper;
import vazkii.botania.client.integration.jei.puredaisy.PureDaisyRecipeCategory;
@@ -45,6 +51,12 @@ import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
import javax.annotation.Nonnull;
import java.util.Map;
import java.util.stream.Collectors;
import static vazkii.botania.common.lib.LibBlockNames.SUBTILE_ORECHID;
import static vazkii.botania.common.lib.LibBlockNames.SUBTILE_ORECHID_IGNEM;
import static vazkii.botania.common.lib.LibBlockNames.SUBTILE_PUREDAISY;
@JEIPlugin
public class JEIBotaniaPlugin implements IModPlugin {
@@ -63,8 +75,16 @@ public class JEIBotaniaPlugin implements IModPlugin {
new RunicAltarRecipeCategory(registry.getJeiHelpers().getGuiHelper()), // Runic must come before petals. See williewillus/Botania#172
new PetalApothecaryRecipeCategory(registry.getJeiHelpers().getGuiHelper()),
new ElvenTradeRecipeCategory(registry.getJeiHelpers().getGuiHelper()),
new ManaPoolRecipeCategory(registry.getJeiHelpers().getGuiHelper())
);
new ManaPoolRecipeCategory(registry.getJeiHelpers().getGuiHelper()),
new OrechidRecipeCategory(registry.getJeiHelpers().getGuiHelper()),
new OrechidIgnemRecipeCategory(registry.getJeiHelpers().getGuiHelper())
);
}
public static boolean doesOreExist(String key) {
return OreDictionary.doesOreNameExist(key)
&& OreDictionary.getOres(key).stream()
.anyMatch(s -> s.getItem() instanceof ItemBlock);
}
@Override
@@ -84,6 +104,23 @@ public class JEIBotaniaPlugin implements IModPlugin {
registry.addRecipes(BotaniaAPI.runeAltarRecipes, RunicAltarRecipeCategory.UID);
registry.addRecipes(BotaniaAPI.manaInfusionRecipes, ManaPoolRecipeCategory.UID);
registry.addRecipes(
BotaniaAPI.oreWeights.entrySet().stream()
.filter(e -> doesOreExist(e.getKey()))
.map(OrechidRecipeWrapper::new)
.sorted()
.collect(Collectors.toList()),
OrechidRecipeCategory.UID);
registry.addRecipes(
BotaniaAPI.oreWeightsNether.entrySet().stream()
.filter(e -> doesOreExist(e.getKey()))
.map(OrechidIgnemRecipeWrapper::new)
.sorted()
.collect(Collectors.toList()),
OrechidIgnemRecipeCategory.UID);
registry.addRecipeCatalyst(new ItemStack(ModBlocks.brewery), BreweryRecipeCategory.UID);
registry.addRecipeCatalyst(new ItemStack(ModBlocks.alfPortal), ElvenTradeRecipeCategory.UID);
@@ -96,8 +133,12 @@ public class JEIBotaniaPlugin implements IModPlugin {
registry.addRecipeCatalyst(new ItemStack(ModBlocks.altar, 1, v.ordinal()), PetalApothecaryRecipeCategory.UID);
}
registry.addRecipeCatalyst(ItemBlockSpecialFlower.ofType("puredaisy"), PureDaisyRecipeCategory.UID);
registry.addRecipeCatalyst(ItemBlockSpecialFlower.ofType(new ItemStack(ModBlocks.floatingSpecialFlower), "puredaisy"), PureDaisyRecipeCategory.UID);
registry.addRecipeCatalyst(ItemBlockSpecialFlower.ofType(SUBTILE_ORECHID), OrechidRecipeCategory.UID);
registry.addRecipeCatalyst(ItemBlockSpecialFlower.ofType(new ItemStack(ModBlocks.floatingSpecialFlower), SUBTILE_ORECHID), OrechidRecipeCategory.UID);
registry.addRecipeCatalyst(ItemBlockSpecialFlower.ofType(SUBTILE_ORECHID_IGNEM), OrechidIgnemRecipeCategory.UID);
registry.addRecipeCatalyst(ItemBlockSpecialFlower.ofType(new ItemStack(ModBlocks.floatingSpecialFlower), SUBTILE_ORECHID_IGNEM), OrechidIgnemRecipeCategory.UID);
registry.addRecipeCatalyst(ItemBlockSpecialFlower.ofType(SUBTILE_PUREDAISY), PureDaisyRecipeCategory.UID);
registry.addRecipeCatalyst(ItemBlockSpecialFlower.ofType(new ItemStack(ModBlocks.floatingSpecialFlower), SUBTILE_PUREDAISY), PureDaisyRecipeCategory.UID);
registry.addRecipeCatalyst(new ItemStack(ModBlocks.runeAltar), RunicAltarRecipeCategory.UID);
@@ -0,0 +1,92 @@
/**
* This class was created by <codewarrior0>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
* <p/>
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.integration.jei.orechid;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IDrawableStatic;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
import vazkii.botania.common.lib.LibBlockNames;
import vazkii.botania.common.lib.LibMisc;
import javax.annotation.Nonnull;
public class OrechidIgnemRecipeCategory implements IRecipeCategory {
public static final String UID = "botania.orechid_ignem";
private final IDrawableStatic background;
private final String localizedName;
private final IDrawableStatic overlay;
public OrechidIgnemRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.createBlankDrawable(168, 64);
localizedName = I18n.format("botania.nei.orechidIgnem");
overlay = guiHelper.createDrawable(new ResourceLocation("botania", "textures/gui/pureDaisyOverlay.png"),
0, 0, 64, 46);
}
@Nonnull
@Override
public String getUid() {
return UID;
}
@Nonnull
@Override
public String getTitle() {
return localizedName;
}
@Nonnull
@Override
public IDrawable getBackground() {
return background;
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, IRecipeWrapper recipeWrapper, IIngredients ingredients) {
final IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init(0, true, 40, 12);
itemStacks.set(0, ingredients.getInputs(ItemStack.class).get(0));
itemStacks.init(1, true, 70, 12);
itemStacks.set(1, ItemBlockSpecialFlower.ofType(LibBlockNames.SUBTILE_ORECHID_IGNEM));
itemStacks.init(2, true, 99, 12);
itemStacks.set(2, ingredients.getOutputs(ItemStack.class).get(0));
}
@Override
public void drawExtras(@Nonnull Minecraft minecraft) {
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
overlay.draw(minecraft, 48, 0);
GlStateManager.disableBlend();
GlStateManager.disableAlpha();
}
@Nonnull
@Override
public String getModName() {
return LibMisc.MOD_NAME;
}
}
@@ -0,0 +1,32 @@
/**
* This class was created by <codewarrior0>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
* <p/>
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.integration.jei.orechid;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import vazkii.botania.api.BotaniaAPI;
import java.util.Map;
public class OrechidIgnemRecipeWrapper extends OrechidRecipeWrapper {
public OrechidIgnemRecipeWrapper(Map.Entry<String, Integer> entry) {
super(entry);
}
@Override
protected ItemStack getInputStack() {
return new ItemStack(Blocks.NETHERRACK, 64);
}
public Map<String, Integer> getOreWeights() {
return BotaniaAPI.oreWeightsNether;
}
}
@@ -0,0 +1,92 @@
/**
* This class was created by <codewarrior0>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
* <p/>
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.integration.jei.orechid;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IDrawableStatic;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
import vazkii.botania.common.lib.LibBlockNames;
import vazkii.botania.common.lib.LibMisc;
import javax.annotation.Nonnull;
public class OrechidRecipeCategory implements IRecipeCategory {
public static final String UID = "botania.orechid";
private final IDrawableStatic background;
private final String localizedName;
private final IDrawableStatic overlay;
public OrechidRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.createBlankDrawable(168, 64);
localizedName = I18n.format("botania.nei.orechid");
overlay = guiHelper.createDrawable(new ResourceLocation("botania", "textures/gui/pureDaisyOverlay.png"),
0, 0, 64, 46);
}
@Nonnull
@Override
public String getUid() {
return UID;
}
@Nonnull
@Override
public String getTitle() {
return localizedName;
}
@Nonnull
@Override
public IDrawable getBackground() {
return background;
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, IRecipeWrapper recipeWrapper, IIngredients ingredients) {
final IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init(0, true, 40, 12);
itemStacks.set(0, ingredients.getInputs(ItemStack.class).get(0));
itemStacks.init(1, true, 70, 12);
itemStacks.set(1, ItemBlockSpecialFlower.ofType(LibBlockNames.SUBTILE_ORECHID));
itemStacks.init(2, true, 99, 12);
itemStacks.set(2, ingredients.getOutputs(ItemStack.class).get(0));
}
@Override
public void drawExtras(@Nonnull Minecraft minecraft) {
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
overlay.draw(minecraft, 48, 0);
GlStateManager.disableBlend();
GlStateManager.disableAlpha();
}
@Nonnull
@Override
public String getModName() {
return LibMisc.MOD_NAME;
}
}
@@ -0,0 +1,73 @@
/**
* This class was created by <codewarrior0>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
* <p/>
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.integration.jei.orechid;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import vazkii.botania.api.BotaniaAPI;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static vazkii.botania.client.integration.jei.JEIBotaniaPlugin.doesOreExist;
public class OrechidRecipeWrapper implements IRecipeWrapper, Comparable<OrechidRecipeWrapper> {
private final int weight;
private final List<List<ItemStack>> outputStacks;
protected ItemStack getInputStack() {
return new ItemStack(Blocks.STONE, 64);
}
public OrechidRecipeWrapper(Map.Entry<String, Integer> entry) {
this.weight = entry.getValue();
final int amount = Math.max(1, Math.round((float) weight * 64 / getTotalOreWeight()));
// Shouldn't ever return an empty list since the ore weight
// list is filtered to only have ores with ItemBlocks
List<ItemStack> stackList = OreDictionary.getOres(entry.getKey()).stream()
.filter(s -> s.getItem() instanceof ItemBlock)
.map(ItemStack::copy)
.collect(Collectors.toList());
stackList.forEach(s -> s.setCount(amount));
outputStacks = Collections.singletonList(stackList);
}
public Map<String, Integer> getOreWeights() {
return BotaniaAPI.oreWeights;
}
private float getTotalOreWeight() {
return (getOreWeights().entrySet().stream()
.filter(e -> doesOreExist(e.getKey()))
.map(Map.Entry::getValue)
.reduce(Integer::sum)).orElse(weight * 64 * 64);
}
@Override
public void getIngredients(IIngredients ingredients) {
ingredients.setInput(ItemStack.class, getInputStack());
ingredients.setOutputLists(ItemStack.class, outputStacks);
}
@Override
public int compareTo(OrechidRecipeWrapper o) {
return Integer.compare(o.weight, weight);
}
}