Merge branch 'master-MC1.10.2' of https://github.com/ForestryMC/Binnie into master-MC1.10.2

This commit is contained in:
Nedelosk committed 2017-01-23 15:49:21 +01:00
commit 9ba257dec5
42 files changed
+1389 -922

No files matched your search

@@ -36,14 +36,12 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
private Map<Class<? extends MachineComponent>, MachineComponent> componentMap;
private TileEntity tile;
private boolean queuedInventoryUpdate;
private int nextProgressBarID;
private GameProfile owner;
public Machine(final MachinePackage pack, final TileEntity tile) {
this.componentInterfaceMap = new LinkedHashMap<>();
this.componentMap = new LinkedHashMap<>();
this.queuedInventoryUpdate = false;
this.nextProgressBarID = 0;
this.owner = null;
this.tile = tile;
pack.createMachine(this);
@@ -248,10 +246,6 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
}
}
public int getUniqueProgressBarID() {
return this.nextProgressBarID++;
}
@Override
public GameProfile getOwner() {
return this.owner;
@@ -12,6 +12,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidTank;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -108,6 +109,7 @@ public class MachineUtil {
return this.getTank(tankInput).getFluidAmount() == 0;
}
@Nullable
public FluidStack getFluid(final int tankInput) {
return (this.getTank(tankInput).getFluid() == null) ? null : this.getTank(tankInput).getFluid();
}
@@ -2,9 +2,14 @@ package binnie.core.network;
import binnie.core.AbstractMod;
import binnie.core.network.packet.MessageBinnie;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class BinniePacketHandler implements IMessageHandler<MessageBinnie, IMessage> {
private IPacketProvider provider;
@@ -19,17 +24,33 @@ public abstract class BinniePacketHandler implements IMessageHandler<MessageBinn
@Override
public IMessage onMessage(final MessageBinnie message, final MessageContext ctx) {
try {
final int packetId = message.id;
for (final IPacketID id : this.provider.getPacketIDs()) {
if (id.ordinal() == packetId) {
id.onMessage(message, ctx);
return null;
final int packetId = message.id;
for (final IPacketID id : this.provider.getPacketIDs()) {
if (id.ordinal() == packetId) {
if (ctx.side == Side.CLIENT) {
onClientMessage(id, message, ctx);
} else {
onServerMessage(id, message, ctx);
}
return null;
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return null;
}
@SideOnly(Side.CLIENT)
private static void onClientMessage(final IPacketID id, final MessageBinnie message, final MessageContext ctx) {
checkThreadAndEnqueue(id, message, ctx, Minecraft.getMinecraft());
}
private static void onServerMessage(final IPacketID id, final MessageBinnie message, final MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
checkThreadAndEnqueue(id, message, ctx, player.getServerWorld());
}
private static void checkThreadAndEnqueue(final IPacketID id, final MessageBinnie message, final MessageContext ctx, IThreadListener threadListener) {
if (!threadListener.isCallingFromMinecraftThread()) {
threadListener.addScheduledTask(() -> id.onMessage(message, ctx));
}
}
}
@@ -0,0 +1,39 @@
package binnie.core.util;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
public class OreDictionaryUtil {
private OreDictionaryUtil() {
}
public static List<ItemStack> getOres(int oreId) {
String oreName = OreDictionary.getOreName(oreId);
if (OreDictionary.doesOreNameExist(oreName)) {
return OreDictionary.getOres(oreName);
} else {
return Collections.emptyList();
}
}
public static boolean hasOreId(@Nonnull ItemStack itemStack, int oreId) {
int[] oreIds = OreDictionary.getOreIDs(itemStack);
return contains(oreIds, oreId);
}
private static boolean contains(int[] array, int value) {
for (int arrayValue : array) {
if (arrayValue == value) {
return true;
}
}
return false;
}
}
@@ -12,9 +12,8 @@ import binnie.craftgui.minecraft.control.ControlProgressBase;
import binnie.craftgui.resource.Texture;
import binnie.craftgui.resource.minecraft.StandardTexture;
import binnie.extratrees.core.ExtraTreeTexture;
import binnie.extratrees.machines.Brewery;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import binnie.extratrees.machines.brewery.BreweryLogic;
import binnie.extratrees.machines.brewery.BreweryRecipes;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
@@ -28,28 +27,28 @@ public class ControlBreweryProgress extends ControlProgressBase {
@Override
public void onRenderBackground() {
CraftGUI.render.texture(ControlBreweryProgress.Brewery, new IPoint(0.0f, 0.0f));
final Brewery.ComponentBreweryLogic logic = Machine.getInterface(Brewery.ComponentBreweryLogic.class, Window.get(this).getInventory());
if (logic == null || logic.currentCrafting == null || logic.currentCrafting.currentInput == null) {
final BreweryLogic logic = Machine.getInterface(BreweryLogic.class, Window.get(this).getInventory());
if (logic == null || logic.currentCrafting == null || logic.currentCrafting.inputFluid == null) {
return;
}
final int fermentedHeight = (int) (32.0f * logic.getProgress() / 100.0f);
CraftGUI.render.limitArea(new IArea(new IPoint(1.0f, 6.0f).add(this.getAbsolutePosition()), new IPoint(32.0f, 32 - fermentedHeight)));
GL11.glEnable(3089);
CraftGUI.render.fluid(new IPoint(1.0f, 6.0f), logic.currentCrafting.currentInput);
CraftGUI.render.fluid(new IPoint(17.0f, 6.0f), logic.currentCrafting.currentInput);
CraftGUI.render.fluid(new IPoint(1.0f, 22.0f), logic.currentCrafting.currentInput);
CraftGUI.render.fluid(new IPoint(17.0f, 22.0f), logic.currentCrafting.currentInput);
CraftGUI.render.fluid(new IPoint(1.0f, 6.0f), logic.currentCrafting.inputFluid);
CraftGUI.render.fluid(new IPoint(17.0f, 6.0f), logic.currentCrafting.inputFluid);
CraftGUI.render.fluid(new IPoint(1.0f, 22.0f), logic.currentCrafting.inputFluid);
CraftGUI.render.fluid(new IPoint(17.0f, 22.0f), logic.currentCrafting.inputFluid);
GL11.glDisable(3089);
CraftGUI.render.limitArea(new IArea(new IPoint(1.0f, 38 - fermentedHeight).add(this.getAbsolutePosition()), new IPoint(32.0f, fermentedHeight)));
GL11.glEnable(3089);
CraftGUI.render.fluid(new IPoint(1.0f, 6.0f), binnie.extratrees.machines.Brewery.getOutput(logic.currentCrafting));
CraftGUI.render.fluid(new IPoint(17.0f, 6.0f), binnie.extratrees.machines.Brewery.getOutput(logic.currentCrafting));
CraftGUI.render.fluid(new IPoint(1.0f, 22.0f), binnie.extratrees.machines.Brewery.getOutput(logic.currentCrafting));
CraftGUI.render.fluid(new IPoint(17.0f, 22.0f), binnie.extratrees.machines.Brewery.getOutput(logic.currentCrafting));
CraftGUI.render.fluid(new IPoint(1.0f, 6.0f), BreweryRecipes.getOutput(logic.currentCrafting));
CraftGUI.render.fluid(new IPoint(17.0f, 6.0f), BreweryRecipes.getOutput(logic.currentCrafting));
CraftGUI.render.fluid(new IPoint(1.0f, 22.0f), BreweryRecipes.getOutput(logic.currentCrafting));
CraftGUI.render.fluid(new IPoint(17.0f, 22.0f), BreweryRecipes.getOutput(logic.currentCrafting));
GL11.glDisable(3089);
final ItemStackSet stacks = new ItemStackSet();
Collections.addAll(stacks, logic.currentCrafting.inputs);
stacks.add(logic.currentCrafting.ingr);
Collections.addAll(stacks, logic.currentCrafting.inputGrains);
stacks.add(logic.currentCrafting.ingredient);
int x = 1;
int y = 6;
for (final ItemStack stack : stacks) {
@@ -12,24 +12,22 @@ import binnie.craftgui.minecraft.control.ControlProgressBase;
import binnie.craftgui.resource.Texture;
import binnie.craftgui.resource.minecraft.StandardTexture;
import binnie.extratrees.core.ExtraTreeTexture;
import binnie.extratrees.machines.Distillery;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import binnie.extratrees.machines.distillery.DistilleryLogic;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
public class ControlDistilleryProgress extends ControlProgressBase {
static Texture DistilleryBase = new StandardTexture(43, 0, 58, 66, ExtraTreeTexture.Gui);
static Texture DistilleryOverlay = new StandardTexture(139, 0, 18, 66, ExtraTreeTexture.Gui);
static Texture LiquidFlow = new StandardTexture(101, 0, 38, 66, ExtraTreeTexture.Gui);
static Texture Output = new StandardTexture(68, 66, 17, 7, ExtraTreeTexture.Gui);
public static final Texture DISTILLERY_BASE = new StandardTexture(43, 0, 58, 66, ExtraTreeTexture.Gui);
public static final Texture DISTILLERY_OVERLAY = new StandardTexture(139, 0, 18, 66, ExtraTreeTexture.Gui);
public static final Texture LIQUID_FLOW = new StandardTexture(101, 0, 38, 66, ExtraTreeTexture.Gui);
public static final Texture OUTPUT = new StandardTexture(68, 66, 17, 7, ExtraTreeTexture.Gui);
@Override
public void onRenderBackground() {
CraftGUI.render.texture(ControlDistilleryProgress.DistilleryBase, new IPoint(0.0f, 0.0f));
CraftGUI.render.texturePercentage(ControlDistilleryProgress.LiquidFlow, new IArea(18.0f, 0.0f, 38.0f, 66.0f), Position.Left, this.progress);
final Distillery.ComponentDistilleryLogic component = Machine.getInterface(Distillery.ComponentDistilleryLogic.class, Window.get(this).getInventory());
CraftGUI.render.texture(DISTILLERY_BASE, new IPoint(0.0f, 0.0f));
CraftGUI.render.texturePercentage(LIQUID_FLOW, new IArea(18.0f, 0.0f, 38.0f, 66.0f), Position.Left, this.progress);
final DistilleryLogic component = Machine.getInterface(DistilleryLogic.class, Window.get(this).getInventory());
FluidStack stack = null;
if (component != null) {
stack = component.currentFluid;
@@ -43,11 +41,11 @@ public class ControlDistilleryProgress extends ControlProgressBase {
@Override
public void onRenderForeground() {
Distillery.ComponentDistilleryLogic distilleryLogic = Machine.getInterface(Distillery.ComponentDistilleryLogic.class, Window.get(this).getInventory());
DistilleryLogic distilleryLogic = Machine.getInterface(DistilleryLogic.class, Window.get(this).getInventory());
if (distilleryLogic != null) {
final int level = distilleryLogic.level;
CraftGUI.render.texture(ControlDistilleryProgress.Output, new IPoint(47.0f, 14 + level * 15));
CraftGUI.render.texture(ControlDistilleryProgress.DistilleryOverlay, new IPoint(0.0f, 0.0f));
CraftGUI.render.texture(OUTPUT, new IPoint(47.0f, 14 + level * 15));
CraftGUI.render.texture(DISTILLERY_OVERLAY, new IPoint(0.0f, 0.0f));
}
}
@@ -11,7 +11,7 @@ import binnie.craftgui.minecraft.control.ControlPlayerInventory;
import binnie.craftgui.minecraft.control.ControlSlot;
import binnie.craftgui.minecraft.control.ControlSlotArray;
import binnie.extratrees.ExtraTrees;
import binnie.extratrees.machines.Brewery;
import binnie.extratrees.machines.brewery.BreweryMachine;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.fml.relauncher.Side;
@@ -34,14 +34,14 @@ public class WindowBrewery extends Window {
@Override
public void initialiseClient() {
this.setTitle(Machine.getMachine(this.getInventory()).getPackage().getDisplayName());
new ControlSlotArray(this, 42, 32, 1, 3).create(Brewery.slotRecipeGrains);
new ControlSlot(this, 16.0f, 41.0f).assign(Brewery.slotRecipeInput);
new ControlSlot(this, 105.0f, 77.0f).assign(Brewery.slotRecipeYeast);
new ControlLiquidTank(this, 76, 32).setTankID(Brewery.tankInput);
new ControlLiquidTank(this, 162, 32).setTankID(Brewery.tankOutput);
new ControlSlotArray(this, 42, 32, 1, 3).create(BreweryMachine.SLOT_RECIPE_GRAINS);
new ControlSlot(this, 16.0f, 41.0f).assign(BreweryMachine.SLOT_RECIPE_INPUT);
new ControlSlot(this, 105.0f, 77.0f).assign(BreweryMachine.SLOT_YEAST);
new ControlLiquidTank(this, 76, 32).setTankID(BreweryMachine.TANK_INPUT);
new ControlLiquidTank(this, 162, 32).setTankID(BreweryMachine.TANK_OUTPUT);
new ControlEnergyBar(this, 196, 32, 16, 60, Position.Bottom);
new ControlBreweryProgress(this, 110.0f, 32.0f);
new ControlSlotArray(this, (int) (this.getSize().x() / 2.0f - 81.0f), 104, 9, 1).create(Brewery.slotInventory);
new ControlSlotArray(this, (int) (this.getSize().x() / 2.0f - 81.0f), 104, 9, 1).create(BreweryMachine.SLOTS_INVENTORY);
new ControlPlayerInventory(this);
new ControlErrorState(this, 133.0f, 79.0f);
}
@@ -9,7 +9,7 @@ import binnie.craftgui.minecraft.control.ControlErrorState;
import binnie.craftgui.minecraft.control.ControlLiquidTank;
import binnie.craftgui.minecraft.control.ControlPlayerInventory;
import binnie.extratrees.ExtraTrees;
import binnie.extratrees.machines.Distillery;
import binnie.extratrees.machines.distillery.DistilleryMachine;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.fml.relauncher.Side;
@@ -33,11 +33,11 @@ public class WindowDistillery extends Window {
public void initialiseClient() {
this.setTitle(Machine.getMachine(this.getInventory()).getPackage().getDisplayName());
int x = 16;
new ControlLiquidTank(this, x, 35).setTankID(Distillery.tankInput);
new ControlLiquidTank(this, x, 35).setTankID(DistilleryMachine.TANK_INPUT);
x += 34;
new ControlDistilleryProgress(this, x, 32.0f);
x += 64;
new ControlLiquidTank(this, x, 35).setTankID(Distillery.tankOutput);
new ControlLiquidTank(this, x, 35).setTankID(DistilleryMachine.TANK_OUTPUT);
x += 34;
new ControlEnergyBar(this, x, 36, 60, 16, Position.Left);
new ControlPlayerInventory(this);
@@ -9,9 +9,12 @@ import binnie.extratrees.ExtraTrees;
import binnie.extratrees.alcohol.drink.DrinkLiquid;
import binnie.extratrees.alcohol.drink.DrinkManager;
import binnie.extratrees.alcohol.drink.ItemDrink;
import binnie.extratrees.item.ExtraTreeItems;
import binnie.extratrees.item.Food;
import binnie.extratrees.machines.Brewery;
import binnie.extratrees.machines.Distillery;
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;
import forestry.api.recipes.RecipeManagers;
@@ -69,19 +72,16 @@ public class ModuleAlcohol implements IInitializable {
}
for (final ItemStack stack : ores) {
for (final ISqueezerRecipe entry : RecipeManagers.squeezerManager.recipes()) {
try {
final ItemStack input = entry.getResources()[0];
final FluidStack output = entry.getFluidOutput();
if (!ItemStack.areItemStacksEqual(stack, input) && !OreDictionary.itemMatches(input, stack, true)) {
continue;
}
int amount = output.amount;
if (Objects.equals(output.getFluid().getName(), "seedoil")) {
amount *= 2;
}
FruitPressRecipes.addRecipe(stack, juice.get(amount));
} catch (Exception ex) {
final ItemStack input = entry.getResources()[0];
final FluidStack output = entry.getFluidOutput();
if (!ItemStack.areItemStacksEqual(stack, input) && !OreDictionary.itemMatches(input, stack, true)) {
continue;
}
int amount = output.amount;
if (Objects.equals(output.getFluid().getName(), "seedoil")) {
amount *= 2;
}
FruitPressRecipes.addRecipe(stack, juice.get(amount));
}
}
}
@@ -89,11 +89,25 @@ public class ModuleAlcohol implements IInitializable {
for (final String fermentLiquid : alcohol.fermentationLiquid) {
final FluidStack fluid = Binnie.Liquid.getFluidStack(fermentLiquid, 5);
if (fluid != null) {
Brewery.addRecipe(fluid, alcohol.get(5));
BreweryRecipes.addRecipe(fluid, alcohol.get(5));
}
}
}
Brewery.addBeerAndMashRecipes();
BreweryRecipes.addRecipes(
new BrewedGrainRecipe(Alcohol.Ale, BreweryRecipes.GRAIN_BARLEY, BreweryRecipes.HOPS),
new BrewedGrainRecipe(Alcohol.Lager, BreweryRecipes.GRAIN_BARLEY, BreweryRecipes.HOPS, ExtraTreeItems.LagerYeast.get(1)),
new BrewedGrainRecipe(Alcohol.Stout, BreweryRecipes.GRAIN_ROASTED, BreweryRecipes.HOPS),
new BrewedGrainRecipe(Alcohol.CornBeer, BreweryRecipes.GRAIN_CORN, BreweryRecipes.HOPS),
new BrewedGrainRecipe(Alcohol.RyeBeer, BreweryRecipes.GRAIN_RYE, BreweryRecipes.HOPS),
new BrewedGrainRecipe(Alcohol.WheatBeer, BreweryRecipes.GRAIN_WHEAT, BreweryRecipes.HOPS),
new BrewedGrainRecipe(Alcohol.Barley, BreweryRecipes.GRAIN_BARLEY),
new BrewedGrainRecipe(Alcohol.Corn, BreweryRecipes.GRAIN_CORN),
new BrewedGrainRecipe(Alcohol.Rye, BreweryRecipes.GRAIN_RYE),
new BrewedGrainRecipe(Alcohol.Wheat, BreweryRecipes.GRAIN_WHEAT)
);
this.addDistillery(Alcohol.Apple, Spirit.AppleBrandy, Spirit.AppleLiquor, Spirit.NeutralSpirit);
this.addDistillery(Alcohol.Pear, Spirit.PearBrandy, Spirit.PearLiquor, Spirit.NeutralSpirit);
this.addDistillery(Alcohol.Apricot, Spirit.ApricotBrandy, Spirit.ApricotLiquor, Spirit.NeutralSpirit);
@@ -119,12 +133,19 @@ public class ModuleAlcohol implements IInitializable {
this.addDistillery(Alcohol.Corn, Spirit.CornWhiskey, Spirit.Vodka, Spirit.NeutralSpirit);
}
private void addDistillery(final IFluidType source, final IFluidType a, final IFluidType b, final IFluidType c) {
Distillery.addRecipe(source.get(5), a.get(4), 0);
Distillery.addRecipe(source.get(5), b.get(2), 1);
Distillery.addRecipe(source.get(5), c.get(1), 2);
Distillery.addRecipe(a.get(5), b.get(2), 0);
Distillery.addRecipe(a.get(5), b.get(1), 1);
Distillery.addRecipe(b.get(5), c.get(2), 0);
private void addDistillery(final IFluidType source, final IFluidType singleDistilled, final IFluidType doubleDistilled, final IFluidType tripleDistilled) {
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(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(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);
}
}
@@ -2,6 +2,12 @@ package binnie.extratrees.integration.jei;
import binnie.core.integration.jei.Drawables;
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;
@@ -35,18 +41,26 @@ public class ExtraTreesJeiPlugin extends BlankModPlugin {
registry.addRecipeCategories(
new LumbermillRecipeCategory(),
new FruitPressRecipeCategory()
new FruitPressRecipeCategory(),
new BreweryRecipeCategory(),
new DistilleryRecipeCategory()
);
registry.addRecipeHandlers(
new SimpleRecipeHandler<>(LumbermillRecipeWrapper.class, RecipeUids.LUMBERMILL),
new SimpleRecipeHandler<>(FruitPressRecipeWrapper.class, RecipeUids.FRUIT_PRESS)
new SimpleRecipeHandler<>(FruitPressRecipeWrapper.class, RecipeUids.FRUIT_PRESS),
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());
}
}
@@ -3,4 +3,6 @@ package binnie.extratrees.integration.jei;
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";
}
@@ -0,0 +1,69 @@
package binnie.extratrees.integration.jei.brewery;
import binnie.extratrees.integration.jei.ExtraTreesJeiPlugin;
import binnie.extratrees.integration.jei.RecipeUids;
import binnie.extratrees.machines.brewery.BreweryMachine;
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.ingredients.IIngredients;
import mezz.jei.api.recipe.BlankRecipeCategory;
import net.minecraft.client.Minecraft;
public class BreweryRecipeCategory extends BlankRecipeCategory<BreweryRecipeWrapper> {
private final IDrawableAnimated arrowAnimated;
public BreweryRecipeCategory() {
this.arrowAnimated = ExtraTreesJeiPlugin.drawables.createArrowAnimated(56);
}
@Override
public String getUid() {
return RecipeUids.BREWING;
}
@Override
public String getTitle() {
return "Brewing";
}
@Override
public IDrawable getBackground() {
return ExtraTreesJeiPlugin.guiHelper.createBlankDrawable(130, 60);
}
@Override
public void drawExtras(Minecraft minecraft) {
IDrawable tank = ExtraTreesJeiPlugin.drawables.getTank();
tank.draw(minecraft, 0, 0);
tank.draw(minecraft, 112, 0);
IDrawable arrow = ExtraTreesJeiPlugin.drawables.getArrow();
arrow.draw(minecraft, 69, 25);
arrowAnimated.draw(minecraft, 69, 25);
IDrawable slot = ExtraTreesJeiPlugin.guiHelper.getSlotDrawable();
slot.draw(minecraft, 42, 0);
slot.draw(minecraft, 42, 21);
slot.draw(minecraft, 42, 42);
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, BreweryRecipeWrapper recipeWrapper, IIngredients ingredients) {
IDrawable tankOverlay = ExtraTreesJeiPlugin.drawables.getTankOverlay();
IGuiFluidStackGroup fluidStacks = recipeLayout.getFluidStacks();
fluidStacks.init(BreweryMachine.TANK_INPUT, true, 1, 1, 16, 58, 10, false, tankOverlay);
fluidStacks.init(BreweryMachine.TANK_OUTPUT, false, 113, 1, 16, 58, 10, false, tankOverlay);
fluidStacks.set(ingredients);
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init(0, true, 42, 0);
itemStacks.init(1, true, 42, 21);
itemStacks.init(2, true, 42, 42);
itemStacks.set(ingredients);
}
}
@@ -0,0 +1,23 @@
package binnie.extratrees.integration.jei.brewery;
import binnie.extratrees.machines.brewery.BreweryRecipes;
import binnie.extratrees.machines.brewery.IBreweryRecipe;
import binnie.extratrees.machines.lumbermill.LumbermillRecipes;
import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class BreweryRecipeMaker {
public static List<BreweryRecipeWrapper> create() {
List<BreweryRecipeWrapper> recipes = new ArrayList<>();
for (IBreweryRecipe breweryRecipe : BreweryRecipes.getRecipes()) {
recipes.add(new BreweryRecipeWrapper(breweryRecipe));
}
return recipes;
}
}
@@ -0,0 +1,31 @@
package binnie.extratrees.integration.jei.brewery;
import binnie.extratrees.machines.brewery.IBreweryRecipe;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.BlankRecipeWrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class BreweryRecipeWrapper extends BlankRecipeWrapper {
private final IBreweryRecipe recipe;
public BreweryRecipeWrapper(IBreweryRecipe recipe) {
this.recipe = recipe;
}
@Override
public void getIngredients(IIngredients ingredients) {
List<List<ItemStack>> inputs = new ArrayList<>();
inputs.add(recipe.getIngredients());
inputs.add(recipe.getGrains());
inputs.add(Collections.singletonList(recipe.getYeast()));
ingredients.setInputLists(ItemStack.class, inputs);
ingredients.setInput(FluidStack.class, recipe.getInput());
ingredients.setOutput(FluidStack.class, recipe.getOutput());
}
}
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package binnie.extratrees.integration.jei.brewery;
import binnie.core.util.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -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<DistilleryRecipeWrapper> {
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);
}
}
@@ -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<DistilleryRecipeWrapper> create() {
List<DistilleryRecipeWrapper> recipes = new ArrayList<>();
for (int level = 0; level < 3; level++) {
for (Pair<FluidStack, FluidStack> entry : DistilleryRecipes.getRecipes(level)) {
FluidStack input = entry.getKey();
FluidStack output = entry.getValue();
recipes.add(new DistilleryRecipeWrapper(level, input, output));
}
}
return recipes;
}
}
@@ -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));
}
}
@@ -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;
@@ -1,583 +0,0 @@
package binnie.extratrees.machines;
import binnie.Binnie;
import binnie.core.liquid.IFluidType;
import binnie.core.machines.Machine;
import binnie.core.machines.TileEntityMachine;
import binnie.core.machines.inventory.ComponentInventorySlots;
import binnie.core.machines.inventory.ComponentTankContainer;
import binnie.core.machines.inventory.InventorySlot;
import binnie.core.machines.inventory.MachineSide;
import binnie.core.machines.inventory.SlotValidator;
import binnie.core.machines.inventory.TankValidator;
import binnie.core.machines.network.INetwork;
import binnie.core.machines.power.ComponentPowerReceptor;
import binnie.core.machines.power.ComponentProcessSetCost;
import binnie.core.machines.power.ErrorState;
import binnie.core.machines.power.IProcess;
import binnie.craftgui.minecraft.IMachineInformation;
import binnie.extratrees.alcohol.Alcohol;
import binnie.extratrees.core.ExtraTreeTexture;
import binnie.extratrees.core.ExtraTreesGUID;
import binnie.extratrees.item.ExtraTreeItems;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Brewery {
public static int[] slotRecipeGrains = new int[]{0, 1, 2};
public static int slotRecipeInput = 3;
public static int slotRecipeYeast = 4;
public static int[] slotInventory = new int[]{5, 6, 7, 8, 9, 10, 11, 12, 13};
public static int tankInput = 0;
public static int tankOutput = 1;
private static List<IBreweryRecipe> recipes = new ArrayList<>();
public static boolean isValidGrain(final ItemStack itemstack) {
for (final IBreweryRecipe recipe : Brewery.recipes) {
for (final ItemStack ingredient : recipe.getGrains()) {
if (ingredient.isItemEqual(itemstack)) {
return true;
}
}
}
return false;
}
public static boolean isValidYeast(final ItemStack itemstack) {
for (final IBreweryRecipe recipe : Brewery.recipes) {
for (final ItemStack ingredient : recipe.getYeasts()) {
if (ingredient.isItemEqual(itemstack)) {
return true;
}
}
}
return false;
}
public static FluidStack getOutput(final FluidStack stack) {
final BreweryCrafting crafting = new BreweryCrafting(stack, null, null, null);
for (final IBreweryRecipe recipe : Brewery.recipes) {
if (recipe.getOutput(crafting) != null) {
return recipe.getOutput(crafting);
}
}
return null;
}
@Nullable
public static FluidStack getOutput(final BreweryCrafting crafting) {
if (crafting.currentInput != null && crafting.yeast != null) {
for (final IBreweryRecipe recipe : Brewery.recipes) {
if (recipe.getOutput(crafting) != null) {
return recipe.getOutput(crafting);
}
}
}
return null;
}
public static boolean isValidIngredient(final ItemStack itemstack) {
for (final IBreweryRecipe recipe : Brewery.recipes) {
for (final ItemStack ingr : recipe.getIngredient()) {
if (ingr.isItemEqual(itemstack)) {
return true;
}
}
}
return false;
}
public static boolean isValidInputLiquid(final FluidStack fluid) {
for (final IBreweryRecipe recipe : Brewery.recipes) {
for (final FluidStack ingr : recipe.getInput()) {
if (ingr.isFluidEqual(fluid)) {
return true;
}
}
}
return false;
}
public static boolean isValidOutputLiquid(final FluidStack fluid) {
for (final IBreweryRecipe recipe : Brewery.recipes) {
for (final FluidStack ingr : recipe.getOutput()) {
if (ingr.isFluidEqual(fluid)) {
return true;
}
}
}
return false;
}
public static void addRecipe(final FluidStack input, final FluidStack output) {
Brewery.recipes.add(new BreweryRecipe(input, output));
}
public static void addBeerAndMashRecipes() {
Brewery.recipes.add(new BeerRecipe());
}
public static class PackageBrewery extends ExtraTreeMachine.PackageExtraTreeMachine implements IMachineInformation {
public PackageBrewery() {
super("brewery", ExtraTreeTexture.breweryTexture, true);
}
@Override
public void createMachine(final Machine machine) {
new ExtraTreeMachine.ComponentExtraTreeGUI(machine, ExtraTreesGUID.Brewery);
final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
inventory.addSlotArray(Brewery.slotRecipeGrains, "grain");
for (final InventorySlot slot : inventory.getSlots(Brewery.slotRecipeGrains)) {
slot.setValidator(new SlotValidatorBreweryGrain());
slot.setType(InventorySlot.Type.Recipe);
}
inventory.addSlotArray(Brewery.slotInventory, "inventory");
for (final InventorySlot slot : inventory.getSlots(Brewery.slotInventory)) {
slot.forbidExtraction();
}
inventory.addSlot(Brewery.slotRecipeYeast, "yeast");
inventory.getSlot(Brewery.slotRecipeYeast).setValidator(new SlotValidatorYeast());
inventory.getSlot(Brewery.slotRecipeYeast).setType(InventorySlot.Type.Recipe);
inventory.addSlot(Brewery.slotRecipeInput, "ingredient");
inventory.getSlot(Brewery.slotRecipeInput).setValidator(new SlotValidatorBreweryIngredient());
inventory.getSlot(Brewery.slotRecipeInput).setType(InventorySlot.Type.Recipe);
final ComponentTankContainer tanks = new ComponentTankContainer(machine);
tanks.addTank(Brewery.tankInput, "input", 5000);
tanks.getTankSlot(Brewery.tankInput).setValidator(new TankValidatorFermentInput());
tanks.getTankSlot(Brewery.tankInput).setOutputSides(MachineSide.TopAndBottom);
tanks.addTank(Brewery.tankOutput, "output", 5000);
tanks.getTankSlot(Brewery.tankOutput).setValidator(new TankValidatorFermentOutput());
tanks.getTankSlot(Brewery.tankOutput).forbidInsertion();
tanks.getTankSlot(Brewery.tankOutput).setOutputSides(MachineSide.Sides);
new ComponentPowerReceptor(machine);
new ComponentBreweryLogic(machine);
}
@Override
public TileEntity createTileEntity() {
return new TileEntityMachine(this);
}
@Override
public void register() {
}
}
public static class BreweryCrafting implements INbtWritable, INbtReadable {
public FluidStack currentInput;
public ItemStack[] inputs;
public ItemStack ingr;
public ItemStack yeast;
public BreweryCrafting(final FluidStack currentInput, final ItemStack ingr, final ItemStack[] inputs, final ItemStack yeast) {
this.currentInput = currentInput;
this.inputs = ((inputs == null) ? new ItemStack[3] : inputs);
this.ingr = ingr;
this.yeast = yeast;
}
public BreweryCrafting(final NBTTagCompound nbt) {
this.readFromNBT(nbt);
}
@Override
public void readFromNBT(final NBTTagCompound nbt) {
this.currentInput = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("fluid"));
this.ingr = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("ingr"));
(this.inputs = new ItemStack[3])[0] = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("in1"));
this.inputs[1] = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("in2"));
this.inputs[2] = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("in3"));
this.yeast = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("yeast"));
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound nbt) {
final NBTTagCompound fluidTag = new NBTTagCompound();
this.currentInput.writeToNBT(fluidTag);
nbt.setTag("fluid", fluidTag);
nbt.setTag("ingr", this.getNBT(this.ingr));
nbt.setTag("in1", this.getNBT(this.inputs[0]));
nbt.setTag("in2", this.getNBT(this.inputs[1]));
nbt.setTag("in3", this.getNBT(this.inputs[2]));
nbt.setTag("yeast", this.getNBT(this.yeast));
return nbt;
}
private NBTTagCompound getNBT(final ItemStack ingr) {
if (ingr == null) {
return new NBTTagCompound();
}
final NBTTagCompound nbt = new NBTTagCompound();
ingr.writeToNBT(nbt);
return nbt;
}
}
public static class ComponentBreweryLogic extends ComponentProcessSetCost implements IProcess, INetwork.GuiNBT {
public BreweryCrafting currentCrafting;
public ComponentBreweryLogic(final Machine machine) {
super(machine, 16000, 800);
this.currentCrafting = null;
}
@Override
public ErrorState canWork() {
if (this.getUtil().isTankEmpty(Brewery.tankInput) && this.currentCrafting == null) {
return new ErrorState.InsufficientLiquid("No Input Liquid", Brewery.tankInput);
}
if (Brewery.getOutput(this.getInputCrafting()) == null && this.currentCrafting == null) {
return new ErrorState("No Recipe", "Brewing cannot occur with these ingredients");
}
if (!this.getUtil().hasIngredients(new int[]{0, 1, 2, 3, 4}, Brewery.slotInventory) && this.currentCrafting == null) {
return new ErrorState("Insufficient Ingredients", "Not enough ingredients for Brewing");
}
return super.canWork();
}
private BreweryCrafting getInputCrafting() {
return new BreweryCrafting(this.getUtil().getFluid(Brewery.tankInput), this.getUtil().getStack(Brewery.slotRecipeInput), this.getUtil().getStacks(Brewery.slotRecipeGrains), this.getUtil().getStack(Brewery.slotRecipeYeast));
}
@Override
public ErrorState canProgress() {
if (this.currentCrafting == null) {
return new ErrorState("Brewery Empty", "No liquid in Brewery");
}
if (!this.getUtil().spaceInTank(Brewery.tankOutput, 1000)) {
return new ErrorState.TankSpace("No Space for Fermented Liquid", Brewery.tankOutput);
}
if (this.getUtil().getFluid(Brewery.tankOutput) != null && !this.getUtil().getFluid(Brewery.tankOutput).isFluidEqual(Brewery.getOutput(this.currentCrafting))) {
return new ErrorState.TankSpace("Different fluid in tank", Brewery.tankOutput);
}
return super.canProgress();
}
@Override
protected void onFinishTask() {
FluidStack output = Brewery.getOutput(this.currentCrafting);
if (output != null) {
output = output.copy();
output.amount = 1000;
this.getUtil().fillTank(Brewery.tankOutput, output);
}
}
@Override
public void onUpdate() {
super.onUpdate();
if (this.canWork() == null && this.currentCrafting == null && this.getUtil().getTank(Brewery.tankInput).getFluidAmount() >= 1000) {
final FluidStack stack = this.getUtil().drainTank(Brewery.tankInput, 1000);
this.currentCrafting = this.getInputCrafting();
this.currentCrafting.currentInput = stack;
}
}
@Override
public void sendGuiNBT(final Map<String, NBTTagCompound> data) {
final NBTTagCompound nbt = new NBTTagCompound();
if (this.currentCrafting == null) {
nbt.setBoolean("null", true);
} else {
this.currentCrafting.writeToNBT(nbt);
}
data.put("brewery-recipe", nbt);
}
@Override
public void recieveGuiNBT(final Side side, final EntityPlayer player, final String name, final NBTTagCompound nbt) {
if (name.equals("brewery-recipe")) {
if (nbt.getBoolean("null")) {
this.currentCrafting = null;
} else {
this.currentCrafting = new BreweryCrafting(nbt);
}
}
}
@Override
public String getTooltip() {
if (this.currentCrafting == null) {
return "Empty";
}
FluidStack output = Brewery.getOutput(this.currentCrafting);
if (output == null) {
return "Empty";
}
return "Creating " + output.getFluid().getLocalizedName(output);
}
}
public static class SlotValidatorBreweryGrain extends SlotValidator {
public SlotValidatorBreweryGrain() {
super(SlotValidator.IconBlock);
}
@Override
public boolean isValid(final ItemStack itemStack) {
return Brewery.isValidGrain(itemStack);
}
@Override
public String getTooltip() {
return "Brewing Grains";
}
}
public static class SlotValidatorBreweryIngredient extends SlotValidator {
public SlotValidatorBreweryIngredient() {
super(SlotValidator.IconBlock);
}
@Override
public boolean isValid(final ItemStack itemStack) {
return Brewery.isValidIngredient(itemStack);
}
@Override
public String getTooltip() {
return "Brewing Ingredient";
}
}
public static class SlotValidatorYeast extends SlotValidator {
public SlotValidatorYeast() {
super(SlotValidator.IconBlock);
}
@Override
public boolean isValid(final ItemStack itemStack) {
return Brewery.isValidYeast(itemStack);
}
@Override
public String getTooltip() {
return "Yeast";
}
}
public static class TankValidatorFermentInput extends TankValidator {
@Override
public boolean isValid(final FluidStack itemStack) {
return Brewery.isValidInputLiquid(itemStack);
}
@Override
public String getTooltip() {
return "Fermentable Liquids";
}
}
public static class TankValidatorFermentOutput extends TankValidator {
@Override
public boolean isValid(final FluidStack itemStack) {
return Brewery.isValidOutputLiquid(itemStack);
}
@Override
public String getTooltip() {
return "Fermented Liquids";
}
}
public static class BreweryRecipe implements IBreweryRecipe {
FluidStack input;
ItemStack specificYeast;
FluidStack output;
public BreweryRecipe(final FluidStack input, final FluidStack output) {
this(input, null, output);
}
public BreweryRecipe(final FluidStack input, final ItemStack specificYeast, final FluidStack output) {
this.input = input;
this.specificYeast = specificYeast;
this.output = output;
}
@Override
public FluidStack getOutput(final BreweryCrafting crafting) {
if (this.specificYeast != null && !this.specificYeast.isItemEqual(crafting.yeast)) {
return null;
}
if (this.input.isFluidEqual(crafting.currentInput)) {
return this.output;
}
return null;
}
@Override
public FluidStack[] getInput() {
return new FluidStack[]{this.input};
}
@Override
public FluidStack[] getOutput() {
return new FluidStack[0];
}
@Override
public ItemStack[] getGrains() {
return new ItemStack[0];
}
@Override
public ItemStack[] getIngredient() {
return new ItemStack[0];
}
@Override
public ItemStack[] getYeasts() {
return new ItemStack[]{ExtraTreeItems.Yeast.get(1)};
}
}
public static class BeerRecipe implements IBreweryRecipe {
Map<ItemStack, String> grainCrops;
List<FluidStack> outputs;
static String barley = "seedBarley";
static String wheat = "seedWheat";
static String rye = "seedRye";
static String corn = "seedCorn";
static String roasted = "seedRoasted";
String[] grains;
FluidStack water;
ItemStack hops;
public BeerRecipe() {
this.grainCrops = new HashMap<>();
this.outputs = new ArrayList<>();
this.grains = new String[]{BeerRecipe.barley, BeerRecipe.wheat, BeerRecipe.rye, BeerRecipe.corn, BeerRecipe.roasted};
for (final String grainType : this.grains) {
for (final ItemStack stack : OreDictionary.getOres(grainType)) {
this.grainCrops.put(stack, grainType);
}
}
this.water = Binnie.Liquid.getFluidStack("water", 5);
this.hops = OreDictionary.getOres("cropHops").get(0);
this.add(Alcohol.Ale);
this.add(Alcohol.Lager);
this.add(Alcohol.Stout);
this.add(Alcohol.CornBeer);
this.add(Alcohol.RyeBeer);
this.add(Alcohol.WheatBeer);
this.add(Alcohol.Barley);
this.add(Alcohol.Corn);
this.add(Alcohol.Rye);
this.add(Alcohol.Wheat);
}
private void add(final IFluidType fluid) {
this.outputs.add(fluid.get(1));
}
@Override
public FluidStack getOutput(final BreweryCrafting crafting) {
if (!crafting.currentInput.isFluidEqual(this.water)) {
return null;
}
int roasted = 0;
int barley = 0;
int wheat = 0;
int rye = 0;
int corn = 0;
for (final ItemStack stack : crafting.inputs) {
if (stack == null) {
return null;
}
String name = "";
for (final Map.Entry<ItemStack, String> entry : this.grainCrops.entrySet()) {
if (entry.getKey().isItemEqual(stack)) {
name = entry.getValue();
break;
}
}
if (name.isEmpty()) {
return null;
}
if (name.equals(BeerRecipe.roasted)) {
++roasted;
}
if (name.equals(BeerRecipe.barley)) {
++barley;
}
if (name.equals(BeerRecipe.wheat)) {
++wheat;
}
if (name.equals(BeerRecipe.rye)) {
++rye;
}
if (name.equals(BeerRecipe.corn)) {
++corn;
}
}
final boolean isBeer = crafting.ingr != null;
final boolean isLager = crafting.yeast.isItemEqual(ExtraTreeItems.LagerYeast.get(1));
if (roasted >= 2 && isBeer) {
return Alcohol.Stout.get(5);
}
if (wheat >= 2) {
return isBeer ? Alcohol.WheatBeer.get(5) : Alcohol.Wheat.get(5);
}
if (rye >= 2) {
return isBeer ? Alcohol.RyeBeer.get(5) : Alcohol.Rye.get(5);
}
if (corn >= 2) {
return isBeer ? Alcohol.CornBeer.get(5) : Alcohol.Corn.get(5);
}
return isBeer ? (isLager ? Alcohol.Lager.get(5) : Alcohol.Ale.get(5)) : Alcohol.Barley.get(5);
}
@Override
public FluidStack[] getInput() {
return new FluidStack[]{this.water};
}
@Override
public FluidStack[] getOutput() {
return this.outputs.toArray(new FluidStack[0]);
}
@Override
public ItemStack[] getGrains() {
return this.grainCrops.keySet().toArray(new ItemStack[0]);
}
@Override
public ItemStack[] getIngredient() {
return new ItemStack[]{this.hops};
}
@Override
public ItemStack[] getYeasts() {
return new ItemStack[]{ExtraTreeItems.Yeast.get(1), ExtraTreeItems.LagerYeast.get(1)};
}
}
private interface IBreweryRecipe {
FluidStack getOutput(final BreweryCrafting p0);
FluidStack[] getInput();
FluidStack[] getOutput();
ItemStack[] getGrains();
ItemStack[] getIngredient();
ItemStack[] getYeasts();
}
}
@@ -1,243 +0,0 @@
package binnie.extratrees.machines;
import binnie.core.machines.Machine;
import binnie.core.machines.TileEntityMachine;
import binnie.core.machines.inventory.ComponentInventorySlots;
import binnie.core.machines.inventory.ComponentTankContainer;
import binnie.core.machines.inventory.MachineSide;
import binnie.core.machines.inventory.TankValidator;
import binnie.core.machines.network.INetwork;
import binnie.core.machines.power.ComponentPowerReceptor;
import binnie.core.machines.power.ComponentProcessSetCost;
import binnie.core.machines.power.ErrorState;
import binnie.core.machines.power.IProcess;
import binnie.craftgui.minecraft.IMachineInformation;
import binnie.extratrees.core.ExtraTreeTexture;
import binnie.extratrees.core.ExtraTreesGUID;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Distillery {
public static int tankInput = 0;
public static int tankOutput = 1;
static List<Map<Fluid, FluidStack>> recipes;
public static FluidStack getOutput(final FluidStack fluid, final int level) {
if (fluid == null) {
return null;
}
return Distillery.recipes.get(level).get(fluid.getFluid());
}
public static boolean isValidInputLiquid(final FluidStack fluid) {
for (int i = 0; i < 3; ++i) {
if (Distillery.recipes.get(i).containsKey(fluid.getFluid())) {
return true;
}
}
return false;
}
public static boolean isValidOutputLiquid(final FluidStack fluid) {
for (int i = 0; i < 3; ++i) {
for (final Map.Entry<Fluid, FluidStack> entry : Distillery.recipes.get(i).entrySet()) {
if (entry.getValue().isFluidEqual(fluid)) {
return true;
}
}
}
return false;
}
public static void addRecipe(final FluidStack input, final FluidStack output, final int level) {
Distillery.recipes.get(level).put(input.getFluid(), output);
}
static {
(Distillery.recipes = new ArrayList<>()).add(new HashMap<>());
Distillery.recipes.add(new HashMap<>());
Distillery.recipes.add(new HashMap<>());
}
public static class PackageDistillery extends ExtraTreeMachine.PackageExtraTreeMachine implements IMachineInformation {
public PackageDistillery() {
super("distillery", ExtraTreeTexture.distilleryTexture, true);
}
@Override
public void createMachine(final Machine machine) {
new ExtraTreeMachine.ComponentExtraTreeGUI(machine, ExtraTreesGUID.Distillery);
final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
final ComponentTankContainer tanks = new ComponentTankContainer(machine);
tanks.addTank(Distillery.tankInput, "input", 5000);
tanks.getTankSlot(Distillery.tankInput).setValidator(new TankValidatorDistilleryInput());
tanks.getTankSlot(Distillery.tankInput).setOutputSides(MachineSide.TopAndBottom);
tanks.addTank(Distillery.tankOutput, "output", 5000);
tanks.getTankSlot(Distillery.tankOutput).setValidator(new TankValidatorDistilleryOutput());
tanks.getTankSlot(Distillery.tankOutput).setReadOnly();
tanks.getTankSlot(Distillery.tankOutput).setOutputSides(MachineSide.Sides);
new ComponentPowerReceptor(machine);
new ComponentDistilleryLogic(machine);
}
@Override
public TileEntity createTileEntity() {
return new TileEntityMachine(this);
}
@Override
public void register() {
}
}
public static class ComponentDistilleryLogic extends ComponentProcessSetCost implements IProcess, INetwork.SendGuiNBT, INetwork.RecieveGuiNBT {
public FluidStack currentFluid;
public int level;
int guiLevel;
public ComponentDistilleryLogic(final Machine machine) {
super(machine, 16000, 800);
this.currentFluid = null;
this.level = 0;
this.guiLevel = machine.getUniqueProgressBarID();
}
@Override
public float getEnergyPerTick() {
return 2.0f;
}
@Override
public int getProcessLength() {
return 2000 + 800 * this.level;
}
@Override
public void readFromNBT(final NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.level = nbt.getByte("dlevel");
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound nbt2) {
NBTTagCompound nbt = super.writeToNBT(nbt2);
nbt.setByte("dlevel", (byte) this.level);
return nbt;
}
@Override
public ErrorState canWork() {
if (this.getUtil().isTankEmpty(Distillery.tankInput) && this.currentFluid == null) {
return new ErrorState.InsufficientLiquid("No Input Liquid", Distillery.tankInput);
}
return super.canWork();
}
@Override
public ErrorState canProgress() {
if (this.currentFluid == null) {
return new ErrorState("Distillery Empty", "No liquid in Distillery");
}
if (!this.getUtil().isTankEmpty(Distillery.tankOutput) && this.getOutput() != null && !this.getOutput().isFluidEqual(this.getUtil().getFluid(Distillery.tankOutput))) {
return new ErrorState.Tank("No Room", "No room for liquid", new int[]{Distillery.tankOutput});
}
if (this.getUtil().getFluid(Distillery.tankOutput) != null && !this.getUtil().getFluid(Distillery.tankOutput).isFluidEqual(Distillery.getOutput(this.getUtil().getFluid(Distillery.tankInput), this.level))) {
return new ErrorState.TankSpace("Different fluid in tank", Distillery.tankOutput);
}
return super.canProgress();
}
private FluidStack getOutput() {
return Distillery.getOutput(this.getUtil().getFluid(Distillery.tankInput), this.level);
}
@Override
protected void onFinishTask() {
final FluidStack output = Distillery.getOutput(this.currentFluid, this.level).copy();
output.amount = 1000;
this.getUtil().fillTank(Distillery.tankOutput, output);
}
@Override
protected void onTickTask() {
}
@Override
public void recieveGuiNBT(final Side side, final EntityPlayer player, final String name, final NBTTagCompound nbt) {
if (name.equals("still-level")) {
this.level = nbt.getByte("i");
}
if (name.equals("still-recipe")) {
if (nbt.getBoolean("null")) {
this.currentFluid = null;
} else {
this.currentFluid = FluidStack.loadFluidStackFromNBT(nbt);
}
}
}
@Override
public void sendGuiNBT(final Map<String, NBTTagCompound> data) {
final NBTTagCompound nbt = new NBTTagCompound();
if (this.currentFluid == null) {
nbt.setBoolean("null", true);
} else {
this.currentFluid.writeToNBT(nbt);
}
data.put("still-recipe", nbt);
final NBTTagCompound nbt2 = new NBTTagCompound();
nbt.setByte("i", (byte) this.level);
data.put("still-level", nbt);
}
@Override
public void onUpdate() {
super.onUpdate();
if (this.canWork() == null && this.currentFluid == null && this.getUtil().getTank(Distillery.tankInput).getFluidAmount() >= 1000) {
final FluidStack stack = this.getUtil().drainTank(Distillery.tankInput, 1000);
this.currentFluid = stack;
}
}
@Override
public String getTooltip() {
if (this.currentFluid == null) {
return "Empty";
}
return "Creating " + Distillery.getOutput(this.currentFluid, this.level).getFluid().getLocalizedName(this.currentFluid);
}
}
public static class TankValidatorDistilleryInput extends TankValidator {
@Override
public boolean isValid(final FluidStack itemStack) {
return Distillery.isValidInputLiquid(itemStack);
}
@Override
public String getTooltip() {
return "Distillable Liquids";
}
}
public static class TankValidatorDistilleryOutput extends TankValidator {
@Override
public boolean isValid(final FluidStack itemStack) {
return Distillery.isValidOutputLiquid(itemStack);
}
@Override
public String getTooltip() {
return "Distilled Liquids";
}
}
}
@@ -12,6 +12,8 @@ import binnie.core.resource.BinnieResource;
import binnie.core.resource.ResourceType;
import binnie.extratrees.ExtraTrees;
import binnie.extratrees.core.ExtraTreesGUID;
import binnie.extratrees.machines.brewery.BreweryMachine;
import binnie.extratrees.machines.distillery.DistilleryMachine;
import binnie.extratrees.machines.lumbermill.LumbermillMachine;
import binnie.extratrees.machines.fruitpress.FruitPressMachine;
import net.minecraft.entity.player.EntityPlayer;
@@ -26,8 +28,8 @@ public enum ExtraTreeMachine implements IMachineType {
Panelworker(Designer.PackagePanelworker.class),
Nursery(Nursery.PackageNursery.class),
Press(FruitPressMachine.class),
Brewery(Brewery.PackageBrewery.class),
Distillery(Distillery.PackageDistillery.class),
Brewery(BreweryMachine.class),
Distillery(DistilleryMachine.class),
Glassworker(Designer.PackageGlassworker.class),
Tileworker(Designer.PackageTileworker.class);
@@ -0,0 +1,113 @@
package binnie.extratrees.machines.brewery;
import binnie.Binnie;
import binnie.core.util.OreDictionaryUtil;
import binnie.extratrees.alcohol.Alcohol;
import binnie.extratrees.item.ExtraTreeItems;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
public class BrewedGrainRecipe implements IBreweryRecipe {
public static final FluidStack WATER = Binnie.Liquid.getFluidStack("water", 5);
private final FluidStack output;
private final int grainOreId;
@Nullable
private final Integer ingredientOreId;
private final ItemStack yeast;
public BrewedGrainRecipe(Alcohol output, int grainOreId) {
this(output, grainOreId, null, null);
}
public BrewedGrainRecipe(Alcohol output, int grainOreId, Integer ingredientOreId) {
this(output, grainOreId, ingredientOreId, null);
}
public BrewedGrainRecipe(Alcohol output, int grainOreId, @Nullable Integer ingredientOreId, @Nullable ItemStack specificYeast) {
this.output = output.get(5);
this.grainOreId = grainOreId;
this.ingredientOreId = ingredientOreId;
if (specificYeast != null) {
this.yeast = specificYeast;
} else {
this.yeast = ExtraTreeItems.Yeast.get(1);
}
}
@Override
public FluidStack getOutput(final BreweryCrafting crafting) {
if (!WATER.isFluidEqual(crafting.inputFluid)) {
return null;
}
if (!isIngredient(crafting.ingredient)) {
return null;
}
if (!yeast.isItemEqual(crafting.yeast)) {
return null;
}
int grainCount = 0;
for (final ItemStack stack : crafting.inputGrains) {
if (stack == null) {
return null;
}
if (isGrain(stack)) {
grainCount++;
}
}
if (grainCount >= 2) {
return output.copy();
} else {
return null;
}
}
@Override
public FluidStack getInput() {
return WATER;
}
@Override
public FluidStack getOutput() {
return this.output;
}
@Override
public boolean isIngredient(@Nullable ItemStack itemstack) {
if (itemstack == null) {
return ingredientOreId == null;
}
return ingredientOreId != null && OreDictionaryUtil.hasOreId(itemstack, ingredientOreId);
}
public List<ItemStack> getIngredients() {
if (ingredientOreId == null) {
return Collections.emptyList();
}
return OreDictionaryUtil.getOres(ingredientOreId);
}
@Override
public boolean isGrain(@Nonnull ItemStack itemStack) {
return OreDictionaryUtil.hasOreId(itemStack, grainOreId);
}
@Override
public List<ItemStack> getGrains() {
return OreDictionaryUtil.getOres(grainOreId);
}
@Override
public ItemStack getYeast() {
return yeast;
}
}
@@ -0,0 +1,66 @@
package binnie.extratrees.machines.brewery;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nullable;
public class BreweryCrafting implements INbtWritable, INbtReadable {
@Nullable
public FluidStack inputFluid;
public ItemStack[] inputGrains;
@Nullable
public ItemStack ingredient;
@Nullable
public ItemStack yeast;
public BreweryCrafting(@Nullable final FluidStack inputFluid, @Nullable final ItemStack ingredient, @Nullable final ItemStack[] inputGrains, final @Nullable ItemStack yeast) {
this.inputFluid = inputFluid;
this.inputGrains = ((inputGrains == null) ? new ItemStack[3] : inputGrains);
this.ingredient = ingredient;
this.yeast = yeast;
}
public BreweryCrafting(final NBTTagCompound nbt) {
this.readFromNBT(nbt);
}
@Override
public void readFromNBT(final NBTTagCompound nbt) {
this.inputFluid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("fluid"));
this.ingredient = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("ingr"));
this.inputGrains = new ItemStack[] {
ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("in1")),
ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("in2")),
ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("in3"))
};
this.yeast = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("yeast"));
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound nbt) {
if (this.inputFluid != null) {
final NBTTagCompound fluidTag = new NBTTagCompound();
this.inputFluid.writeToNBT(fluidTag);
nbt.setTag("fluid", fluidTag);
}
nbt.setTag("ingr", this.getNBT(this.ingredient));
nbt.setTag("in1", this.getNBT(this.inputGrains[0]));
nbt.setTag("in2", this.getNBT(this.inputGrains[1]));
nbt.setTag("in3", this.getNBT(this.inputGrains[2]));
nbt.setTag("yeast", this.getNBT(this.yeast));
return nbt;
}
private NBTTagCompound getNBT(final ItemStack ingr) {
if (ingr == null) {
return new NBTTagCompound();
}
final NBTTagCompound nbt = new NBTTagCompound();
ingr.writeToNBT(nbt);
return nbt;
}
}
@@ -0,0 +1,114 @@
package binnie.extratrees.machines.brewery;
import binnie.core.machines.Machine;
import binnie.core.machines.network.INetwork;
import binnie.core.machines.power.ComponentProcessSetCost;
import binnie.core.machines.power.ErrorState;
import binnie.core.machines.power.IProcess;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import java.util.Map;
public class BreweryLogic extends ComponentProcessSetCost implements IProcess, INetwork.GuiNBT {
public BreweryCrafting currentCrafting;
public BreweryLogic(final Machine machine) {
super(machine, 16000, 800);
this.currentCrafting = null;
}
@Override
public ErrorState canWork() {
if (this.getUtil().isTankEmpty(BreweryMachine.TANK_INPUT) && this.currentCrafting == null) {
return new ErrorState.InsufficientLiquid("No Input Liquid", BreweryMachine.TANK_INPUT);
}
if (BreweryRecipes.getOutput(this.getInputCrafting()) == null && this.currentCrafting == null) {
return new ErrorState("No Recipe", "Brewing cannot occur with these ingredients");
}
if (!this.getUtil().hasIngredients(new int[]{0, 1, 2, 3, 4}, BreweryMachine.SLOTS_INVENTORY) && this.currentCrafting == null) {
return new ErrorState("Insufficient Ingredients", "Not enough ingredients for Brewing");
}
return super.canWork();
}
private BreweryCrafting getInputCrafting() {
FluidStack inputFluid = this.getUtil().getFluid(BreweryMachine.TANK_INPUT);
ItemStack inputIngredient = this.getUtil().getStack(BreweryMachine.SLOT_RECIPE_INPUT);
ItemStack[] inputGrains = this.getUtil().getStacks(BreweryMachine.SLOT_RECIPE_GRAINS);
ItemStack inputYeast = this.getUtil().getStack(BreweryMachine.SLOT_YEAST);
return new BreweryCrafting(inputFluid, inputIngredient, inputGrains, inputYeast);
}
@Override
public ErrorState canProgress() {
if (this.currentCrafting == null) {
return new ErrorState("Brewery Empty", "No liquid in Brewery");
}
if (!this.getUtil().spaceInTank(BreweryMachine.TANK_OUTPUT, 1000)) {
return new ErrorState.TankSpace("No Space for Fermented Liquid", BreweryMachine.TANK_OUTPUT);
}
FluidStack outputFluid = this.getUtil().getFluid(BreweryMachine.TANK_OUTPUT);
if (outputFluid != null && !outputFluid.isFluidEqual(BreweryRecipes.getOutput(this.currentCrafting))) {
return new ErrorState.TankSpace("Different fluid in tank", BreweryMachine.TANK_OUTPUT);
}
return super.canProgress();
}
@Override
protected void onFinishTask() {
FluidStack output = BreweryRecipes.getOutput(this.currentCrafting);
if (output != null) {
output = output.copy();
output.amount = 1000;
this.getUtil().fillTank(BreweryMachine.TANK_OUTPUT, output);
}
}
@Override
public void onUpdate() {
super.onUpdate();
if (this.canWork() == null && this.currentCrafting == null && this.getUtil().getTank(BreweryMachine.TANK_INPUT).getFluidAmount() >= 1000) {
final FluidStack stack = this.getUtil().drainTank(BreweryMachine.TANK_INPUT, 1000);
this.currentCrafting = this.getInputCrafting();
this.currentCrafting.inputFluid = stack;
}
}
@Override
public void sendGuiNBT(final Map<String, NBTTagCompound> data) {
final NBTTagCompound nbt = new NBTTagCompound();
if (this.currentCrafting == null) {
nbt.setBoolean("null", true);
} else {
this.currentCrafting.writeToNBT(nbt);
}
data.put("brewery-recipe", nbt);
}
@Override
public void recieveGuiNBT(final Side side, final EntityPlayer player, final String name, final NBTTagCompound nbt) {
if (name.equals("brewery-recipe")) {
if (nbt.getBoolean("null")) {
this.currentCrafting = null;
} else {
this.currentCrafting = new BreweryCrafting(nbt);
}
}
}
@Override
public String getTooltip() {
if (this.currentCrafting == null) {
return "Empty";
}
FluidStack output = BreweryRecipes.getOutput(this.currentCrafting);
if (output == null) {
return "Empty";
}
return "Creating " + output.getFluid().getLocalizedName(output);
}
}
@@ -0,0 +1,68 @@
package binnie.extratrees.machines.brewery;
import binnie.core.machines.Machine;
import binnie.core.machines.TileEntityMachine;
import binnie.core.machines.inventory.ComponentInventorySlots;
import binnie.core.machines.inventory.ComponentTankContainer;
import binnie.core.machines.inventory.InventorySlot;
import binnie.core.machines.inventory.MachineSide;
import binnie.core.machines.power.ComponentPowerReceptor;
import binnie.craftgui.minecraft.IMachineInformation;
import binnie.extratrees.core.ExtraTreeTexture;
import binnie.extratrees.core.ExtraTreesGUID;
import binnie.extratrees.machines.ExtraTreeMachine;
import net.minecraft.tileentity.TileEntity;
public class BreweryMachine extends ExtraTreeMachine.PackageExtraTreeMachine implements IMachineInformation {
public static final int TANK_INPUT = 0;
public static final int TANK_OUTPUT = 1;
public static final int[] SLOT_RECIPE_GRAINS = new int[]{0, 1, 2};
public static final int SLOT_RECIPE_INPUT = 3;
public static final int SLOT_YEAST = 4;
public static final int[] SLOTS_INVENTORY = new int[]{5, 6, 7, 8, 9, 10, 11, 12, 13};
public BreweryMachine() {
super("brewery", ExtraTreeTexture.breweryTexture, true);
}
@Override
public void createMachine(final Machine machine) {
new ExtraTreeMachine.ComponentExtraTreeGUI(machine, ExtraTreesGUID.Brewery);
final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
inventory.addSlotArray(SLOT_RECIPE_GRAINS, "grain");
for (final InventorySlot slot : inventory.getSlots(SLOT_RECIPE_GRAINS)) {
slot.setValidator(new SlotValidatorBreweryGrain());
slot.setType(InventorySlot.Type.Recipe);
}
inventory.addSlotArray(SLOTS_INVENTORY, "inventory");
for (final InventorySlot slot : inventory.getSlots(SLOTS_INVENTORY)) {
slot.forbidExtraction();
}
inventory.addSlot(SLOT_YEAST, "yeast");
inventory.getSlot(SLOT_YEAST).setValidator(new SlotValidatorBreweryYeast());
inventory.getSlot(SLOT_YEAST).setType(InventorySlot.Type.Recipe);
inventory.addSlot(SLOT_RECIPE_INPUT, "ingredient");
inventory.getSlot(SLOT_RECIPE_INPUT).setValidator(new SlotValidatorBreweryIngredient());
inventory.getSlot(SLOT_RECIPE_INPUT).setType(InventorySlot.Type.Recipe);
final ComponentTankContainer tanks = new ComponentTankContainer(machine);
tanks.addTank(TANK_INPUT, "input", 5000);
tanks.getTankSlot(TANK_INPUT).setValidator(new TankValidatorFermentInput());
tanks.getTankSlot(TANK_INPUT).setOutputSides(MachineSide.TopAndBottom);
tanks.addTank(TANK_OUTPUT, "output", 5000);
tanks.getTankSlot(TANK_OUTPUT).setValidator(new TankValidatorFermentOutput());
tanks.getTankSlot(TANK_OUTPUT).forbidInsertion();
tanks.getTankSlot(TANK_OUTPUT).setOutputSides(MachineSide.Sides);
new ComponentPowerReceptor(machine);
new BreweryLogic(machine);
}
@Override
public TileEntity createTileEntity() {
return new TileEntityMachine(this);
}
@Override
public void register() {
}
}
@@ -0,0 +1,76 @@
package binnie.extratrees.machines.brewery;
import binnie.extratrees.item.ExtraTreeItems;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
public class BreweryRecipe implements IBreweryRecipe {
private final FluidStack input;
private final FluidStack output;
private final ItemStack yeast;
public BreweryRecipe(final FluidStack input, final FluidStack output) {
this(input, output, null);
}
public BreweryRecipe(final FluidStack input, final FluidStack output, @Nullable final ItemStack specificYeast) {
this.input = input;
this.output = output;
if (specificYeast != null) {
this.yeast = specificYeast;
} else {
this.yeast = ExtraTreeItems.Yeast.get(1);
}
}
@Override
public FluidStack getOutput(final BreweryCrafting crafting) {
if (!this.yeast.isItemEqual(crafting.yeast)) {
return null;
}
if (this.input.isFluidEqual(crafting.inputFluid)) {
return this.output;
}
return null;
}
@Override
public FluidStack getInput() {
return this.input;
}
@Override
public FluidStack getOutput() {
return output;
}
@Override
public boolean isGrain(@Nonnull ItemStack itemStack) {
return false;
}
@Override
public List<ItemStack> getGrains() {
return Collections.emptyList();
}
@Override
public boolean isIngredient(@Nonnull ItemStack itemstack) {
return false;
}
@Override
public List<ItemStack> getIngredients() {
return Collections.emptyList();
}
@Override
public ItemStack getYeast() {
return yeast;
}
}
@@ -0,0 +1,107 @@
package binnie.extratrees.machines.brewery;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class BreweryRecipes {
public static final int GRAIN_BARLEY = OreDictionary.getOreID("seedBarley");
public static final int GRAIN_WHEAT = OreDictionary.getOreID("seedWheat");
public static final int GRAIN_RYE = OreDictionary.getOreID("seedRye");
public static final int GRAIN_CORN = OreDictionary.getOreID("seedCorn");
public static final int GRAIN_ROASTED = OreDictionary.getOreID("seedRoasted");
public static final int HOPS = OreDictionary.getOreID("cropHops");
private static List<IBreweryRecipe> recipes = new ArrayList<>();
public static boolean isValidGrain(final ItemStack itemstack) {
for (final IBreweryRecipe recipe : recipes) {
if (recipe.isGrain(itemstack)) {
return true;
}
}
return false;
}
public static boolean isValidYeast(final ItemStack itemstack) {
for (final IBreweryRecipe recipe : recipes) {
ItemStack yeast = recipe.getYeast();
if (yeast.isItemEqual(itemstack)) {
return true;
}
}
return false;
}
public static FluidStack getOutput(final FluidStack stack) {
final BreweryCrafting crafting = new BreweryCrafting(stack, null, null, null);
for (final IBreweryRecipe recipe : recipes) {
if (recipe.getOutput(crafting) != null) {
return recipe.getOutput(crafting);
}
}
return null;
}
@Nullable
public static FluidStack getOutput(final BreweryCrafting crafting) {
if (crafting.inputFluid != null && crafting.yeast != null) {
for (final IBreweryRecipe recipe : recipes) {
if (recipe.getOutput(crafting) != null) {
return recipe.getOutput(crafting);
}
}
}
return null;
}
public static boolean isValidIngredient(final ItemStack itemstack) {
for (final IBreweryRecipe recipe : recipes) {
if (recipe.isIngredient(itemstack)) {
return true;
}
}
return false;
}
public static boolean isValidInputLiquid(final FluidStack fluid) {
for (final IBreweryRecipe recipe : recipes) {
FluidStack input = recipe.getInput();
if (input.isFluidEqual(fluid)) {
return true;
}
}
return false;
}
public static boolean isValidOutputLiquid(final FluidStack fluid) {
for (final IBreweryRecipe recipe : recipes) {
FluidStack output = recipe.getOutput();
if (output.isFluidEqual(fluid)) {
return true;
}
}
return false;
}
public static void addRecipe(final FluidStack input, final FluidStack output) {
recipes.add(new BreweryRecipe(input, output));
}
public static void addRecipe(IBreweryRecipe recipe) {
recipes.add(recipe);
}
public static void addRecipes(IBreweryRecipe... recipes) {
Collections.addAll(BreweryRecipes.recipes, recipes);
}
public static List<IBreweryRecipe> getRecipes() {
return Collections.unmodifiableList(recipes);
}
}
@@ -0,0 +1,25 @@
package binnie.extratrees.machines.brewery;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import java.util.List;
public interface IBreweryRecipe {
FluidStack getOutput(final BreweryCrafting crafting);
FluidStack getInput();
FluidStack getOutput();
boolean isIngredient(@Nonnull ItemStack itemstack);
List<ItemStack> getIngredients();
boolean isGrain(@Nonnull ItemStack itemStack);
List<ItemStack> getGrains();
ItemStack getYeast();
}
@@ -0,0 +1,20 @@
package binnie.extratrees.machines.brewery;
import binnie.core.machines.inventory.SlotValidator;
import net.minecraft.item.ItemStack;
public class SlotValidatorBreweryGrain extends SlotValidator {
public SlotValidatorBreweryGrain() {
super(SlotValidator.IconBlock);
}
@Override
public boolean isValid(final ItemStack itemStack) {
return BreweryRecipes.isValidGrain(itemStack);
}
@Override
public String getTooltip() {
return "Brewing Grains";
}
}
@@ -0,0 +1,20 @@
package binnie.extratrees.machines.brewery;
import binnie.core.machines.inventory.SlotValidator;
import net.minecraft.item.ItemStack;
public class SlotValidatorBreweryIngredient extends SlotValidator {
public SlotValidatorBreweryIngredient() {
super(SlotValidator.IconBlock);
}
@Override
public boolean isValid(final ItemStack itemStack) {
return BreweryRecipes.isValidIngredient(itemStack);
}
@Override
public String getTooltip() {
return "Brewing Ingredient";
}
}
@@ -0,0 +1,20 @@
package binnie.extratrees.machines.brewery;
import binnie.core.machines.inventory.SlotValidator;
import net.minecraft.item.ItemStack;
public class SlotValidatorBreweryYeast extends SlotValidator {
public SlotValidatorBreweryYeast() {
super(SlotValidator.IconBlock);
}
@Override
public boolean isValid(final ItemStack itemStack) {
return BreweryRecipes.isValidYeast(itemStack);
}
@Override
public String getTooltip() {
return "Yeast";
}
}
@@ -0,0 +1,16 @@
package binnie.extratrees.machines.brewery;
import binnie.core.machines.inventory.TankValidator;
import net.minecraftforge.fluids.FluidStack;
public class TankValidatorFermentInput extends TankValidator {
@Override
public boolean isValid(final FluidStack itemStack) {
return BreweryRecipes.isValidInputLiquid(itemStack);
}
@Override
public String getTooltip() {
return "Fermentable Liquids";
}
}
@@ -0,0 +1,16 @@
package binnie.extratrees.machines.brewery;
import binnie.core.machines.inventory.TankValidator;
import net.minecraftforge.fluids.FluidStack;
public class TankValidatorFermentOutput extends TankValidator {
@Override
public boolean isValid(final FluidStack itemStack) {
return BreweryRecipes.isValidOutputLiquid(itemStack);
}
@Override
public String getTooltip() {
return "Fermented Liquids";
}
}
@@ -0,0 +1,133 @@
package binnie.extratrees.machines.distillery;
import binnie.core.machines.Machine;
import binnie.core.machines.network.INetwork;
import binnie.core.machines.power.ComponentProcessSetCost;
import binnie.core.machines.power.ErrorState;
import binnie.core.machines.power.IProcess;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
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;
public DistilleryLogic(final Machine machine) {
super(machine, 16000, 800);
this.currentFluid = null;
this.level = 0;
}
@Override
public float getEnergyPerTick() {
return 2.0f;
}
@Override
public int getProcessLength() {
return 2000 + 800 * this.level;
}
@Override
public void readFromNBT(final NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.level = nbt.getByte("dlevel");
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound nbt2) {
NBTTagCompound nbt = super.writeToNBT(nbt2);
nbt.setByte("dlevel", (byte) this.level);
return nbt;
}
@Override
public ErrorState canWork() {
if (this.getUtil().isTankEmpty(DistilleryMachine.TANK_INPUT) && this.currentFluid == null) {
return new ErrorState.InsufficientLiquid("No Input Liquid", DistilleryMachine.TANK_INPUT);
}
return super.canWork();
}
@Override
public ErrorState canProgress() {
if (this.currentFluid == null) {
return new ErrorState("Distillery Empty", "No liquid in Distillery");
}
FluidStack fluidInOutputTank = this.getUtil().getFluid(DistilleryMachine.TANK_OUTPUT);
if (fluidInOutputTank != null) {
FluidStack inputFluid = this.getUtil().getFluid(DistilleryMachine.TANK_INPUT);
FluidStack recipeOutput = DistilleryRecipes.getOutput(inputFluid, this.level);
if (recipeOutput != null && !recipeOutput.isFluidEqual(fluidInOutputTank)) {
return new ErrorState.TankSpace("Different fluid in tank", DistilleryMachine.TANK_OUTPUT);
}
}
return super.canProgress();
}
@Override
protected void onFinishTask() {
final FluidStack output = DistilleryRecipes.getOutput(this.currentFluid, this.level);
this.getUtil().fillTank(DistilleryMachine.TANK_OUTPUT, output);
}
@Override
protected void onTickTask() {
}
@Override
public void recieveGuiNBT(final Side side, final EntityPlayer player, final String name, final NBTTagCompound nbt) {
if (name.equals("still-level")) {
this.level = nbt.getByte("i");
this.setProgress(0);
}
if (name.equals("still-recipe")) {
if (nbt.getBoolean("null")) {
this.currentFluid = null;
} else {
this.currentFluid = FluidStack.loadFluidStackFromNBT(nbt);
}
}
}
@Override
public void sendGuiNBT(final Map<String, NBTTagCompound> data) {
final NBTTagCompound nbt = new NBTTagCompound();
if (this.currentFluid == null) {
nbt.setBoolean("null", true);
} else {
this.currentFluid.writeToNBT(nbt);
}
data.put("still-recipe", nbt);
nbt.setByte("i", (byte) this.level);
data.put("still-level", nbt);
}
@Override
public void onUpdate() {
super.onUpdate();
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);
}
}
@Override
public String getTooltip() {
if (this.currentFluid == null) {
return "Empty";
}
FluidStack output = DistilleryRecipes.getOutput(this.currentFluid, this.level);
if (output == null) {
return "Empty";
}
return "Creating " + output.getLocalizedName();
}
}
@@ -0,0 +1,47 @@
package binnie.extratrees.machines.distillery;
import binnie.core.machines.Machine;
import binnie.core.machines.TileEntityMachine;
import binnie.core.machines.inventory.ComponentInventorySlots;
import binnie.core.machines.inventory.ComponentTankContainer;
import binnie.core.machines.inventory.MachineSide;
import binnie.core.machines.power.ComponentPowerReceptor;
import binnie.craftgui.minecraft.IMachineInformation;
import binnie.extratrees.core.ExtraTreeTexture;
import binnie.extratrees.core.ExtraTreesGUID;
import binnie.extratrees.machines.ExtraTreeMachine;
import net.minecraft.tileentity.TileEntity;
public class DistilleryMachine extends ExtraTreeMachine.PackageExtraTreeMachine implements IMachineInformation {
public static final int TANK_INPUT = 0;
public static final int TANK_OUTPUT = 1;
public DistilleryMachine() {
super("distillery", ExtraTreeTexture.distilleryTexture, true);
}
@Override
public void createMachine(final Machine machine) {
new ExtraTreeMachine.ComponentExtraTreeGUI(machine, ExtraTreesGUID.Distillery);
final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
final ComponentTankContainer tanks = new ComponentTankContainer(machine);
tanks.addTank(TANK_INPUT, "input", 5000);
tanks.getTankSlot(TANK_INPUT).setValidator(new TankValidatorDistilleryInput());
tanks.getTankSlot(TANK_INPUT).setOutputSides(MachineSide.TopAndBottom);
tanks.addTank(TANK_OUTPUT, "output", 5000);
tanks.getTankSlot(TANK_OUTPUT).setValidator(new TankValidatorDistilleryOutput());
tanks.getTankSlot(TANK_OUTPUT).setReadOnly();
tanks.getTankSlot(TANK_OUTPUT).setOutputSides(MachineSide.Sides);
new ComponentPowerReceptor(machine);
new DistilleryLogic(machine);
}
@Override
public TileEntity createTileEntity() {
return new TileEntityMachine(this);
}
@Override
public void register() {
}
}
@@ -0,0 +1,68 @@
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<Map<Fluid, Pair<FluidStack, FluidStack>>> recipes = new ArrayList<>();
static {
recipes.add(new HashMap<>());
recipes.add(new HashMap<>());
recipes.add(new HashMap<>());
}
@Nullable
public static FluidStack getOutput(@Nullable final FluidStack fluid, final int level) {
if (fluid != null) {
Map<Fluid, Pair<FluidStack, FluidStack>> recipesForLevel = recipes.get(level);
Pair<FluidStack, FluidStack> recipe = recipesForLevel.get(fluid.getFluid());
if (recipe != null) {
return recipe.getValue().copy();
}
}
return null;
}
public static boolean isValidInputLiquid(final FluidStack fluid) {
for (int i = 0; i < 3; ++i) {
Map<Fluid, Pair<FluidStack, FluidStack>> recipesForLevel = recipes.get(i);
Pair<FluidStack, FluidStack> recipe = recipesForLevel.get(fluid.getFluid());
if (recipe.getKey().isFluidEqual(fluid)) {
return true;
}
}
return false;
}
public static boolean isValidOutputLiquid(final FluidStack fluid) {
for (int i = 0; i < 3; ++i) {
Map<Fluid, Pair<FluidStack, FluidStack>> recipesForLevel = recipes.get(i);
for (final Pair<FluidStack, FluidStack> recipe : recipesForLevel.values()) {
if (recipe.getValue().isFluidEqual(fluid)) {
return true;
}
}
}
return false;
}
public static void addRecipe(final FluidStack input, final FluidStack output, final int level) {
Map<Fluid, Pair<FluidStack, FluidStack>> recipesForLevel = recipes.get(level);
recipesForLevel.put(input.getFluid(), Pair.of(input, output));
}
public static Collection<Pair<FluidStack, FluidStack>> getRecipes(int level) {
Map<Fluid, Pair<FluidStack, FluidStack>> recipesForLevel = recipes.get(level);
return Collections.unmodifiableCollection(recipesForLevel.values());
}
}
@@ -0,0 +1,16 @@
package binnie.extratrees.machines.distillery;
import binnie.core.machines.inventory.TankValidator;
import net.minecraftforge.fluids.FluidStack;
public class TankValidatorDistilleryInput extends TankValidator {
@Override
public boolean isValid(final FluidStack itemStack) {
return DistilleryRecipes.isValidInputLiquid(itemStack);
}
@Override
public String getTooltip() {
return "Distillable Liquids";
}
}
@@ -0,0 +1,16 @@
package binnie.extratrees.machines.distillery;
import binnie.core.machines.inventory.TankValidator;
import net.minecraftforge.fluids.FluidStack;
public class TankValidatorDistilleryOutput extends TankValidator {
@Override
public boolean isValid(final FluidStack itemStack) {
return DistilleryRecipes.isValidOutputLiquid(itemStack);
}
@Override
public String getTooltip() {
return "Distilled Liquids";
}
}
@@ -1,5 +1,6 @@
package binnie.extratrees.machines.lumbermill;
import binnie.core.util.OreDictionaryUtil;
import binnie.core.util.FakeCraftingWorld;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
@@ -66,8 +67,7 @@ public class LumbermillRecipes {
try {
ItemStack recipeOutput = craftingManager.findMatchingRecipe(fakeCraftingInventory, FakeCraftingWorld.getInstance());
if (recipeOutput != null) {
int[] outputOreIds = OreDictionary.getOreIDs(recipeOutput);
if (contains(outputOreIds, plankOreId)) {
if (OreDictionaryUtil.hasOreId(recipeOutput, plankOreId)) {
Item logItem = logCopy.getItem();
ItemStack outputCopy = recipeOutput.copy();
outputCopy.stackSize = (int) Math.ceil(outputCopy.stackSize * 1.5f); // turns stack of 4 up to 6
@@ -80,15 +80,6 @@ public class LumbermillRecipes {
}
}
private static boolean contains(int[] array, int value) {
for (int arrayValue : array) {
if (arrayValue == value) {
return true;
}
}
return false;
}
private static class FakeCraftingHandler extends Container {
@Override
public void onCraftMatrixChanged(IInventory inventoryIn) {
@@ -6,8 +6,8 @@ import binnie.craftgui.controls.ControlTextCentered;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.minecraft.control.ControlItemDisplay;
import binnie.extratrees.machines.Brewery;
import binnie.extratrees.machines.Distillery;
import binnie.extratrees.machines.brewery.BreweryRecipes;
import binnie.extratrees.machines.distillery.DistilleryRecipes;
import binnie.extratrees.machines.fruitpress.FruitPressRecipes;
import forestry.api.recipes.ICentrifugeRecipe;
import forestry.api.recipes.ISqueezerRecipe;
@@ -149,10 +149,10 @@ public abstract class AnalystPageProduce extends ControlAnalystPage {
protected Collection<? extends FluidStack> getAllProducts(final FluidStack stack) {
final Collection<FluidStack> fluids = new UniqueFluidStackSet();
fluids.add(Brewery.getOutput(stack));
fluids.add(Distillery.getOutput(stack, 0));
fluids.add(Distillery.getOutput(stack, 1));
fluids.add(Distillery.getOutput(stack, 2));
fluids.add(BreweryRecipes.getOutput(stack));
fluids.add(DistilleryRecipes.getOutput(stack, 0));
fluids.add(DistilleryRecipes.getOutput(stack, 1));
fluids.add(DistilleryRecipes.getOutput(stack, 2));
return fluids;
}