From b10a642297704fe6b95c6470cb126e8c9f0573bc Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sun, 3 Jan 2016 22:02:02 -0600 Subject: [PATCH] Brewery recipe support --- build.gradle | 6 ++ .../integration/jei/JEIBotaniaPlugin.java | 63 ++++++++++++++ .../jei/brewery/BreweryRecipeCategory.java | 87 +++++++++++++++++++ .../jei/brewery/BreweryRecipeHandler.java | 34 ++++++++ .../jei/brewery/BreweryRecipeWrapper.java | 58 +++++++++++++ 5 files changed, 248 insertions(+) create mode 100644 src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java create mode 100644 src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeCategory.java create mode 100644 src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeHandler.java create mode 100644 src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeWrapper.java diff --git a/build.gradle b/build.gradle index c307243fb..48540666b 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,9 @@ repositories { name = "chickenbones" url = "http://chickenbones.net/maven/" } + maven { + url "http://dvs1.progwml6.com/files/maven" + } } apply plugin: 'net.minecraftforge.gradle.forge' @@ -46,6 +49,7 @@ minecraft { replace 'GRADLE:VERSION', config.version replaceIn 'LibMisc.java' //I may have missed another file, though I can only find it in here. + useDepAts = true } //This here is for SCP @@ -67,6 +71,8 @@ dependencies { //compile "codechicken:NotEnoughItems:1.8-1.0.5.104:dev" //compile "codechicken:ForgeMultipart:1.7.10-1.1.1.320:dev" + deobfCompile "mezz.jei:jei_1.8.9:2.13.7.64" + //and a bit more for SCP sshAntTask "org.apache.ant:ant-jsch:1.7.1", "jsch:jsch:0.1.29" } diff --git a/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java b/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java new file mode 100644 index 000000000..3c7ada357 --- /dev/null +++ b/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java @@ -0,0 +1,63 @@ +/** + * 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 + * + * File Created @ [Jan 3, 2016, 2:32:39 AM (GMT)] + */ + +package vazkii.botania.client.integration.jei; + +import mezz.jei.api.IItemRegistry; +import mezz.jei.api.IJeiHelpers; +import mezz.jei.api.IModPlugin; +import mezz.jei.api.IModRegistry; +import mezz.jei.api.IRecipeRegistry; +import mezz.jei.api.JEIPlugin; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.client.integration.jei.brewery.BreweryRecipeCategory; +import vazkii.botania.client.integration.jei.brewery.BreweryRecipeHandler; + +@JEIPlugin +public class JEIBotaniaPlugin implements IModPlugin { + + private IJeiHelpers jeiHelpers; + private IItemRegistry itemRegistry; + + @Override + public boolean isModLoaded() { + return true; + } + + @Override + public void onJeiHelpersAvailable(IJeiHelpers jeiHelpers) { + this.jeiHelpers = jeiHelpers; + } + + @Override + public void onItemRegistryAvailable(IItemRegistry itemRegistry) { + this.itemRegistry = itemRegistry; + } + + @Override + public void register(IModRegistry registry) { + registry.addRecipeCategories( + new BreweryRecipeCategory(jeiHelpers.getGuiHelper()) + ); + + registry.addRecipeHandlers( + new BreweryRecipeHandler() + ); + + registry.addRecipes(BotaniaAPI.brewRecipes); + } + + @Override + public void onRecipeRegistryAvailable(IRecipeRegistry recipeRegistry) { + + } + +} diff --git a/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeCategory.java b/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeCategory.java new file mode 100644 index 000000000..5ac5f76ff --- /dev/null +++ b/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeCategory.java @@ -0,0 +1,87 @@ +package vazkii.botania.client.integration.jei.brewery; + +import mezz.jei.api.IGuiHelper; +import mezz.jei.api.gui.IDrawable; +import mezz.jei.api.gui.IDrawableStatic; +import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.recipe.IRecipeCategory; +import mezz.jei.api.recipe.IRecipeWrapper; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +import javax.annotation.Nonnull; +import java.util.Collection; +import java.util.List; + +public class BreweryRecipeCategory implements IRecipeCategory { + + private final IDrawableStatic background; + private final String localizedName; + + private static final int slotContainerInput = 0; + private static final int slotIngredient1 = 1; + private static final int slotIngredient2 = 2; + private static final int slotIngredient3 = 3; + private static final int slotIngredient4 = 4; + private static final int slotIngredient5 = 5; + private static final int slotIngredient6 = 6; + private static final int slotOutput = 7; + + public BreweryRecipeCategory(IGuiHelper guiHelper) { + ResourceLocation location = new ResourceLocation("botania", "textures/gui/neiBrewery.png"); + background = guiHelper.createDrawable(location, 0, 0, 166, 65, 0, 0, 0, 0); + localizedName = StatCollector.translateToLocal("botania.nei.brewery"); + } + + @Nonnull + @Override + public String getUid() { + return "botania.brewery"; + } + + @Nonnull + @Override + public String getTitle() { + return localizedName; + } + + @Nonnull + @Override + public IDrawable getBackground() { + return background; + } + + @Override + public void drawExtras(Minecraft minecraft) {} + + @Override + public void drawAnimations(Minecraft minecraft) {} + + @Override + public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapper recipeWrapper) { + recipeLayout.getItemStacks().init(slotContainerInput, true, 39, 41); + recipeLayout.getItemStacks().init(slotIngredient1, true, 64, 6); + recipeLayout.getItemStacks().init(slotIngredient2, true, 80, 6); + recipeLayout.getItemStacks().init(slotIngredient3, true, 96, 6); + recipeLayout.getItemStacks().init(slotIngredient4, true, 112, 6); + recipeLayout.getItemStacks().init(slotIngredient5, true, 128, 6); + recipeLayout.getItemStacks().init(slotIngredient6, true, 144, 6); + recipeLayout.getItemStacks().init(slotOutput, false, 87, 41); // todo coords + + BreweryRecipeWrapper wrapper = ((BreweryRecipeWrapper) recipeWrapper); + List inputs = wrapper.getInputs(); + for (int i = 0; i < inputs.size(); i++) { + if (i > slotOutput) { + break; + } + if (inputs.get(i) instanceof ItemStack) { + recipeLayout.getItemStacks().set(i, ((ItemStack) inputs.get(i))); + } else if (inputs.get(i) instanceof Collection) { + recipeLayout.getItemStacks().set(i, ((Collection) inputs.get(i))); + } + } + recipeLayout.getItemStacks().set(slotOutput, wrapper.getOutputs().get(0)); + } +} diff --git a/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeHandler.java b/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeHandler.java new file mode 100644 index 000000000..ea218cfa7 --- /dev/null +++ b/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeHandler.java @@ -0,0 +1,34 @@ +package vazkii.botania.client.integration.jei.brewery; + +import mezz.jei.api.recipe.IRecipeHandler; +import mezz.jei.api.recipe.IRecipeWrapper; +import vazkii.botania.api.recipe.RecipeBrew; + +import javax.annotation.Nonnull; + +public class BreweryRecipeHandler implements IRecipeHandler { + + @Nonnull + @Override + public Class getRecipeClass() { + return RecipeBrew.class; + } + + @Nonnull + @Override + public String getRecipeCategoryUid() { + return "botania.brewery"; + } + + @Nonnull + @Override + public IRecipeWrapper getRecipeWrapper(@Nonnull RecipeBrew recipe) { + return new BreweryRecipeWrapper(recipe); + } + + @Override + public boolean isRecipeValid(@Nonnull RecipeBrew recipe) { + return recipe.getInputs().size() <= 6; + } + +} diff --git a/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeWrapper.java b/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeWrapper.java new file mode 100644 index 000000000..f52973a3a --- /dev/null +++ b/src/main/java/vazkii/botania/client/integration/jei/brewery/BreweryRecipeWrapper.java @@ -0,0 +1,58 @@ +package vazkii.botania.client.integration.jei.brewery; + +import com.google.common.collect.ImmutableList; +import mezz.jei.api.recipe.IRecipeWrapper; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; +import vazkii.botania.api.recipe.RecipeBrew; +import vazkii.botania.common.block.ModBlocks; +import vazkii.botania.common.item.ModItems; + +import javax.annotation.Nonnull; +import java.util.List; + +public class BreweryRecipeWrapper implements IRecipeWrapper { + + private final List input; + private final List output; + + public BreweryRecipeWrapper(RecipeBrew recipeBrew) { + ImmutableList.Builder builder = ImmutableList.builder(); + builder.add(new ItemStack(ModItems.vial)); + for (Object o : recipeBrew.getInputs()) { + if (o instanceof ItemStack) { + builder.add(o); + } + if (o instanceof String) { + builder.add(OreDictionary.getOres(((String) o))); + } + } + + input = builder.build(); + output = ImmutableList.of(recipeBrew.getOutput(new ItemStack(ModItems.vial)).copy(), new ItemStack(ModBlocks.brewery)); + } + + @Override + public List getInputs() { + return input; + } + + @Override + public List getOutputs() { + return output; + } + + @Override + public List getFluidInputs() { return ImmutableList.of(); } + + @Override + public List getFluidOutputs() { return ImmutableList.of(); } + + @Override + public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight) {} + + @Override + public void drawAnimations(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight) {} +}