diff --git a/src/main/java/binnie/extratrees/alcohol/ModuleAlcohol.java b/src/main/java/binnie/extratrees/alcohol/ModuleAlcohol.java index 7aed95d9..e4dd0c61 100644 --- a/src/main/java/binnie/extratrees/alcohol/ModuleAlcohol.java +++ b/src/main/java/binnie/extratrees/alcohol/ModuleAlcohol.java @@ -13,6 +13,7 @@ import binnie.extratrees.item.ExtraTreeItems; import binnie.extratrees.item.Food; import binnie.extratrees.machines.brewery.BrewedGrainRecipe; import binnie.extratrees.machines.brewery.BreweryRecipes; +import binnie.extratrees.machines.distillery.DistilleryLogic; import binnie.extratrees.machines.distillery.DistilleryRecipes; import binnie.extratrees.machines.fruitpress.FruitPressRecipes; import forestry.api.recipes.ISqueezerRecipe; @@ -133,13 +134,18 @@ public class ModuleAlcohol implements IInitializable { } private void addDistillery(final IFluidType source, final IFluidType singleDistilled, final IFluidType doubleDistilled, final IFluidType tripleDistilled) { - DistilleryRecipes.addRecipe(source.get(5), singleDistilled.get(4), 0); - DistilleryRecipes.addRecipe(source.get(5), doubleDistilled.get(2), 1); - DistilleryRecipes.addRecipe(source.get(5), tripleDistilled.get(1), 2); + final int inAmount = DistilleryLogic.INPUT_FLUID_AMOUNT; + final int outAmount1 = inAmount * 4 / 5; + final int outAmount2 = inAmount * 2 / 5; + final int outAmount3 = inAmount / 5; - DistilleryRecipes.addRecipe(singleDistilled.get(5), doubleDistilled.get(2), 0); - DistilleryRecipes.addRecipe(singleDistilled.get(5), tripleDistilled.get(1), 1); + DistilleryRecipes.addRecipe(source.get(inAmount), singleDistilled.get(outAmount1), 0); + DistilleryRecipes.addRecipe(source.get(inAmount), doubleDistilled.get(outAmount2), 1); + DistilleryRecipes.addRecipe(source.get(inAmount), tripleDistilled.get(outAmount3), 2); - DistilleryRecipes.addRecipe(doubleDistilled.get(5), tripleDistilled.get(2), 0); + DistilleryRecipes.addRecipe(singleDistilled.get(inAmount), doubleDistilled.get(outAmount2), 0); + DistilleryRecipes.addRecipe(singleDistilled.get(inAmount), tripleDistilled.get(outAmount3), 1); + + DistilleryRecipes.addRecipe(doubleDistilled.get(inAmount), tripleDistilled.get(outAmount2), 0); } } diff --git a/src/main/java/binnie/extratrees/integration/jei/ExtraTreesJeiPlugin.java b/src/main/java/binnie/extratrees/integration/jei/ExtraTreesJeiPlugin.java index e3a7a179..c17d7a23 100644 --- a/src/main/java/binnie/extratrees/integration/jei/ExtraTreesJeiPlugin.java +++ b/src/main/java/binnie/extratrees/integration/jei/ExtraTreesJeiPlugin.java @@ -5,6 +5,9 @@ import binnie.core.integration.jei.SimpleRecipeHandler; import binnie.extratrees.integration.jei.brewery.BreweryRecipeCategory; import binnie.extratrees.integration.jei.brewery.BreweryRecipeMaker; import binnie.extratrees.integration.jei.brewery.BreweryRecipeWrapper; +import binnie.extratrees.integration.jei.distillery.brewery.DistilleryRecipeCategory; +import binnie.extratrees.integration.jei.distillery.brewery.DistilleryRecipeMaker; +import binnie.extratrees.integration.jei.distillery.brewery.DistilleryRecipeWrapper; import binnie.extratrees.integration.jei.fruitpress.FruitPressRecipeCategory; import binnie.extratrees.integration.jei.fruitpress.FruitPressRecipeMaker; import binnie.extratrees.integration.jei.fruitpress.FruitPressRecipeWrapper; @@ -39,21 +42,25 @@ public class ExtraTreesJeiPlugin extends BlankModPlugin { registry.addRecipeCategories( new LumbermillRecipeCategory(), new FruitPressRecipeCategory(), - new BreweryRecipeCategory() + new BreweryRecipeCategory(), + new DistilleryRecipeCategory() ); registry.addRecipeHandlers( new SimpleRecipeHandler<>(LumbermillRecipeWrapper.class, RecipeUids.LUMBERMILL), new SimpleRecipeHandler<>(FruitPressRecipeWrapper.class, RecipeUids.FRUIT_PRESS), - new SimpleRecipeHandler<>(BreweryRecipeWrapper.class, RecipeUids.BREWING) + new SimpleRecipeHandler<>(BreweryRecipeWrapper.class, RecipeUids.BREWING), + new SimpleRecipeHandler<>(DistilleryRecipeWrapper.class, RecipeUids.DISTILLING) ); registry.addRecipeCategoryCraftingItem(ExtraTreeMachine.Lumbermill.get(1), RecipeUids.LUMBERMILL); registry.addRecipeCategoryCraftingItem(ExtraTreeMachine.Press.get(1), RecipeUids.FRUIT_PRESS); registry.addRecipeCategoryCraftingItem(ExtraTreeMachine.Brewery.get(1), RecipeUids.BREWING); + registry.addRecipeCategoryCraftingItem(ExtraTreeMachine.Distillery.get(1), RecipeUids.DISTILLING); registry.addRecipes(LumbermillRecipeMaker.create()); registry.addRecipes(FruitPressRecipeMaker.create()); registry.addRecipes(BreweryRecipeMaker.create()); + registry.addRecipes(DistilleryRecipeMaker.create()); } } diff --git a/src/main/java/binnie/extratrees/integration/jei/RecipeUids.java b/src/main/java/binnie/extratrees/integration/jei/RecipeUids.java index 8b931fbf..a81a401c 100644 --- a/src/main/java/binnie/extratrees/integration/jei/RecipeUids.java +++ b/src/main/java/binnie/extratrees/integration/jei/RecipeUids.java @@ -4,4 +4,5 @@ public class RecipeUids { public static final String LUMBERMILL = "binnie.extratrees.lumbermill"; public static final String FRUIT_PRESS = "binnie.extratrees.fruitpress"; public static final String BREWING = "binnie.extratrees.brewing"; + public static final String DISTILLING = "binnie.extratrees.distilling"; } diff --git a/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeCategory.java b/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeCategory.java new file mode 100644 index 00000000..0f15b1a2 --- /dev/null +++ b/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeCategory.java @@ -0,0 +1,70 @@ +package binnie.extratrees.integration.jei.distillery.brewery; + +import binnie.craftgui.core.CraftGUI; +import binnie.craftgui.core.geometry.IArea; +import binnie.craftgui.core.geometry.IPoint; +import binnie.craftgui.core.geometry.Position; +import binnie.craftgui.extratrees.dictionary.ControlDistilleryProgress; +import binnie.craftgui.resource.Texture; +import binnie.craftgui.resource.minecraft.StandardTexture; +import binnie.extratrees.core.ExtraTreeTexture; +import binnie.extratrees.integration.jei.ExtraTreesJeiPlugin; +import binnie.extratrees.integration.jei.RecipeUids; +import binnie.extratrees.machines.brewery.BreweryMachine; +import binnie.extratrees.machines.distillery.DistilleryLogic; +import binnie.extratrees.machines.distillery.DistilleryMachine; +import forestry.core.tiles.ITitled; +import mezz.jei.api.gui.IDrawable; +import mezz.jei.api.gui.IDrawableAnimated; +import mezz.jei.api.gui.IGuiFluidStackGroup; +import mezz.jei.api.gui.IGuiItemStackGroup; +import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.gui.ITickTimer; +import mezz.jei.api.ingredients.IIngredients; +import mezz.jei.api.recipe.BlankRecipeCategory; +import net.minecraft.client.Minecraft; + +public class DistilleryRecipeCategory extends BlankRecipeCategory { + private static final Texture DISTILLERY_BASE = new StandardTexture(43, 0, 58, 60, ExtraTreeTexture.Gui); + private static final Texture LIQUID_FLOW = new StandardTexture(101, 0, 38, 60, ExtraTreeTexture.Gui); + + private final ITickTimer progress; + + public DistilleryRecipeCategory() { + this.progress = ExtraTreesJeiPlugin.guiHelper.createTickTimer(200, 100, false); + } + + @Override + public String getUid() { + return RecipeUids.DISTILLING; + } + + @Override + public String getTitle() { + return "Distilling"; + } + + @Override + public IDrawable getBackground() { + return ExtraTreesJeiPlugin.guiHelper.createBlankDrawable(84, 60); + } + + @Override + public void drawExtras(Minecraft minecraft) { + CraftGUI.Render.texture(DISTILLERY_BASE, new IPoint(0.0f, 0.0f)); + CraftGUI.Render.texturePercentage(LIQUID_FLOW, new IArea(18.0f, 0.0f, 38.0f, 60.0f), Position.Left, progress.getValue() / 100f); + + IDrawable tank = ExtraTreesJeiPlugin.drawables.getTank(); + tank.draw(minecraft, 0, 0); + tank.draw(minecraft, 64, 0); + } + + @Override + public void setRecipe(IRecipeLayout recipeLayout, DistilleryRecipeWrapper recipeWrapper, IIngredients ingredients) { + IDrawable tankOverlay = ExtraTreesJeiPlugin.drawables.getTankOverlay(); + IGuiFluidStackGroup fluidStacks = recipeLayout.getFluidStacks(); + fluidStacks.init(DistilleryMachine.TANK_INPUT, true, 1, 1, 16, 58, DistilleryLogic.INPUT_FLUID_AMOUNT, false, tankOverlay); + fluidStacks.init(DistilleryMachine.TANK_OUTPUT, false, 65, 1, 16, 58, DistilleryLogic.INPUT_FLUID_AMOUNT, false, tankOverlay); + fluidStacks.set(ingredients); + } +} diff --git a/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeMaker.java b/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeMaker.java new file mode 100644 index 00000000..8265fd2f --- /dev/null +++ b/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeMaker.java @@ -0,0 +1,24 @@ +package binnie.extratrees.integration.jei.distillery.brewery; + +import binnie.extratrees.machines.distillery.DistilleryRecipes; +import net.minecraftforge.fluids.FluidStack; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.ArrayList; +import java.util.List; + +public class DistilleryRecipeMaker { + public static List create() { + List recipes = new ArrayList<>(); + + for (int level = 0; level < 3; level++) { + for (Pair entry : DistilleryRecipes.getRecipes(level)) { + FluidStack input = entry.getKey(); + FluidStack output = entry.getValue(); + recipes.add(new DistilleryRecipeWrapper(level, input, output)); + } + } + + return recipes; + } +} diff --git a/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeWrapper.java b/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeWrapper.java new file mode 100644 index 00000000..906c9f3a --- /dev/null +++ b/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/DistilleryRecipeWrapper.java @@ -0,0 +1,34 @@ +package binnie.extratrees.integration.jei.distillery.brewery; + +import binnie.craftgui.core.CraftGUI; +import binnie.craftgui.core.geometry.IPoint; +import binnie.craftgui.extratrees.dictionary.ControlDistilleryProgress; +import mezz.jei.api.ingredients.IIngredients; +import mezz.jei.api.recipe.BlankRecipeWrapper; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fluids.FluidStack; + +public class DistilleryRecipeWrapper extends BlankRecipeWrapper { + private final int level; + private final FluidStack input; + private final FluidStack output; + + public DistilleryRecipeWrapper(int level, FluidStack input, FluidStack output) { + this.level = level; + this.input = input; + this.output = output; + } + + @Override + public void getIngredients(IIngredients ingredients) { + ingredients.setInput(FluidStack.class, input); + ingredients.setOutput(FluidStack.class, output); + } + + @Override + public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { + super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY); + + CraftGUI.Render.texture(ControlDistilleryProgress.OUTPUT, new IPoint(47.0f, 14 + level * 15)); + } +} diff --git a/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/package-info.java b/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/package-info.java new file mode 100644 index 00000000..e9672d76 --- /dev/null +++ b/src/main/java/binnie/extratrees/integration/jei/distillery/brewery/package-info.java @@ -0,0 +1,9 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package binnie.extratrees.integration.jei.distillery.brewery; + +import binnie.core.util.FieldsAreNonnullByDefault; +import mcp.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/binnie/extratrees/machines/distillery/DistilleryLogic.java b/src/main/java/binnie/extratrees/machines/distillery/DistilleryLogic.java index 5e3532d7..aaac2398 100644 --- a/src/main/java/binnie/extratrees/machines/distillery/DistilleryLogic.java +++ b/src/main/java/binnie/extratrees/machines/distillery/DistilleryLogic.java @@ -13,6 +13,8 @@ import net.minecraftforge.fml.relauncher.Side; import java.util.Map; public class DistilleryLogic extends ComponentProcessSetCost implements IProcess, INetwork.SendGuiNBT, INetwork.RecieveGuiNBT { + public static final int INPUT_FLUID_AMOUNT = 1000; + public FluidStack currentFluid; public int level; @@ -73,8 +75,7 @@ public class DistilleryLogic extends ComponentProcessSetCost implements IProcess @Override protected void onFinishTask() { - final FluidStack output = DistilleryRecipes.getOutput(this.currentFluid, this.level).copy(); - output.amount = 1000; + final FluidStack output = DistilleryRecipes.getOutput(this.currentFluid, this.level); this.getUtil().fillTank(DistilleryMachine.TANK_OUTPUT, output); } @@ -113,8 +114,8 @@ public class DistilleryLogic extends ComponentProcessSetCost implements IProcess @Override public void onUpdate() { super.onUpdate(); - if (this.canWork() == null && this.currentFluid == null && this.getUtil().getTank(DistilleryMachine.TANK_INPUT).getFluidAmount() >= 1000) { - this.currentFluid = this.getUtil().drainTank(DistilleryMachine.TANK_INPUT, 1000); + if (this.canWork() == null && this.currentFluid == null && this.getUtil().getTank(DistilleryMachine.TANK_INPUT).getFluidAmount() >= INPUT_FLUID_AMOUNT) { + this.currentFluid = this.getUtil().drainTank(DistilleryMachine.TANK_INPUT, INPUT_FLUID_AMOUNT); } } @@ -123,6 +124,10 @@ public class DistilleryLogic extends ComponentProcessSetCost implements IProcess if (this.currentFluid == null) { return "Empty"; } - return "Creating " + DistilleryRecipes.getOutput(this.currentFluid, this.level).getFluid().getLocalizedName(this.currentFluid); + FluidStack output = DistilleryRecipes.getOutput(this.currentFluid, this.level); + if (output == null) { + return "Empty"; + } + return "Creating " + output.getLocalizedName(); } } diff --git a/src/main/java/binnie/extratrees/machines/distillery/DistilleryRecipes.java b/src/main/java/binnie/extratrees/machines/distillery/DistilleryRecipes.java index acdae16a..708301c4 100644 --- a/src/main/java/binnie/extratrees/machines/distillery/DistilleryRecipes.java +++ b/src/main/java/binnie/extratrees/machines/distillery/DistilleryRecipes.java @@ -2,15 +2,18 @@ package binnie.extratrees.machines.distillery; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import org.apache.commons.lang3.tuple.Pair; import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; public class DistilleryRecipes { - private static final List> recipes = new ArrayList<>(); + private static final List>> recipes = new ArrayList<>(); static { recipes.add(new HashMap<>()); @@ -18,16 +21,23 @@ public class DistilleryRecipes { recipes.add(new HashMap<>()); } + @Nullable public static FluidStack getOutput(@Nullable final FluidStack fluid, final int level) { - if (fluid == null) { - return null; + if (fluid != null) { + Map> recipesForLevel = recipes.get(level); + Pair recipe = recipesForLevel.get(fluid.getFluid()); + if (recipe != null) { + return recipe.getValue().copy(); + } } - return recipes.get(level).get(fluid.getFluid()); + return null; } public static boolean isValidInputLiquid(final FluidStack fluid) { for (int i = 0; i < 3; ++i) { - if (recipes.get(i).containsKey(fluid.getFluid())) { + Map> recipesForLevel = recipes.get(i); + Pair recipe = recipesForLevel.get(fluid.getFluid()); + if (recipe.getKey().isFluidEqual(fluid)) { return true; } } @@ -36,8 +46,9 @@ public class DistilleryRecipes { public static boolean isValidOutputLiquid(final FluidStack fluid) { for (int i = 0; i < 3; ++i) { - for (final Map.Entry entry : recipes.get(i).entrySet()) { - if (entry.getValue().isFluidEqual(fluid)) { + Map> recipesForLevel = recipes.get(i); + for (final Pair recipe : recipesForLevel.values()) { + if (recipe.getValue().isFluidEqual(fluid)) { return true; } } @@ -46,6 +57,12 @@ public class DistilleryRecipes { } public static void addRecipe(final FluidStack input, final FluidStack output, final int level) { - recipes.get(level).put(input.getFluid(), output); + Map> recipesForLevel = recipes.get(level); + recipesForLevel.put(input.getFluid(), Pair.of(input, output)); + } + + public static Collection> getRecipes(int level) { + Map> recipesForLevel = recipes.get(level); + return Collections.unmodifiableCollection(recipesForLevel.values()); } } diff --git a/src/main/resources/assets/extratrees/textures/gui/gui.png b/src/main/resources/assets/extratrees/textures/gui/gui.png index 18542808..30d41e58 100644 Binary files a/src/main/resources/assets/extratrees/textures/gui/gui.png and b/src/main/resources/assets/extratrees/textures/gui/gui.png differ