From c9c9f1d42213a002fdc8db69000c9208d2606c98 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Fri, 13 Sep 2013 00:12:57 -0400 Subject: [PATCH] Started working on a complex Fluid & Object mixing system Too start with i original was avoiding making such a system since it boils down to an object crafting system. Though with my future and current plans i decided to start working on it. The system, when finish, will be able to handle mixing of fluids, Items, Blocks, and anything to form a result of some kind. The idea is to used it in the pipes, tanks, brewing stand, boilers, and other machines to automated the process of mixing fluids. For pipes it will either create a new fluid, or prevent the pipe from working. Tanks will do the same but can become filled with blocks or items. Brewing stand will use the system to create new fluids, gases, potions, foods, drinks, items, and so on. Boiler will use the simple version of it to convert a fluid to another fluid without any other processing. --- .../network/fluid/FluidCraftingHandler.java | 14 ++ .../network/fluid/FluidNetworkHelper.java | 1 + .../core/network/fluid/FluidRecipeInfo.java | 171 ++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 src/dark/core/network/fluid/FluidCraftingHandler.java create mode 100644 src/dark/core/network/fluid/FluidRecipeInfo.java diff --git a/src/dark/core/network/fluid/FluidCraftingHandler.java b/src/dark/core/network/fluid/FluidCraftingHandler.java new file mode 100644 index 00000000..afe9b76d --- /dev/null +++ b/src/dark/core/network/fluid/FluidCraftingHandler.java @@ -0,0 +1,14 @@ +package dark.core.network.fluid; + +/** Handles all kinds of process involving mixing Fluids with other fluids and/or Items, Blocks, + * ItemStack, or Liquids + * + * @author DarkGuardsman */ +public class FluidCraftingHandler +{ + + public static void loadPotionRecipes() + { + //TODO load the process by which a potion would be created threw fliud crafting + } +} diff --git a/src/dark/core/network/fluid/FluidNetworkHelper.java b/src/dark/core/network/fluid/FluidNetworkHelper.java index df30d8f5..354890d7 100644 --- a/src/dark/core/network/fluid/FluidNetworkHelper.java +++ b/src/dark/core/network/fluid/FluidNetworkHelper.java @@ -183,4 +183,5 @@ public class FluidNetworkHelper } return null; } + } diff --git a/src/dark/core/network/fluid/FluidRecipeInfo.java b/src/dark/core/network/fluid/FluidRecipeInfo.java new file mode 100644 index 00000000..02b4020b --- /dev/null +++ b/src/dark/core/network/fluid/FluidRecipeInfo.java @@ -0,0 +1,171 @@ +package dark.core.network.fluid; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import dark.core.prefab.helpers.Pair; +import dark.core.prefab.helpers.Triple; + +/** Used to store more complex info, than A + B = C, on two FluidStack mixing behavior + * + * @author DarkGuardsman */ +public class FluidRecipeInfo +{ + public static class BoilingFluidRecipe + { + Object boiledObject; + Object boiledResult; + } + + /** Basic A + B = C recipe result that should involve fluids but can be used as a 2 item crafting + * system if needed */ + public static class SimpleFluidRecipe + { + Object recipeObjectA, recipeObjectB, recipeObjectC; + int ratioOfA = 1, ratioOfB = 1, ratioOfC = 1; + /** Size compared to the largest volume that the smallest volume can be */ + float mixingPercentMin = .1f; + + /** receiving & input object must be either be an instance of a class extending Item, + * ItemStack, Block, Fluid, FluidStack, or OreNames. Anything else and the mixing will never + * work + * + * @param receiving - receiving object that is waiting to be mixed + * @param input - object being added to the receiving object + * @param output - result of mixing the object together. Can be anything but not all + * machines using this will respect all output types */ + public SimpleFluidRecipe(Object receiving, Object input, Object output) + { + this.recipeObjectA = receiving; + this.recipeObjectB = input; + this.recipeObjectC = output; + } + + public Object getResult() + { + return this.recipeObjectC; + } + + /** Can the mixing be complete in anyway. Does a basic volume check but does not check for + * volume wasted in mixing + * + * @param receiving - Object stored and waiting for mixing + * @param input - Object being added to the receiving object + * @return true if the process can be completed */ + public boolean canComplete(Object receiving, Object input) + { + int countReceiving = 0; + int countInput = 0; + float percent = 0; + if (receiving != null && input != null && recipeObjectA.equals(receiving) && recipeObjectB.equals(input)) + { + countReceiving = this.getObjectVolume(receiving); + countInput = this.getObjectVolume(input); + if (countReceiving > 0 && countInput > 0) + { + float per = countInput / countReceiving; + float per2 = countReceiving / countInput; + percent = per > per2 ? per2 : per; + if (percent >= this.mixingPercentMin) + { + return true; + } + } + } + return false; + } + + public int getObjectVolume(Object object) + { + int volume = 0; + if (object instanceof Item) + { + volume = 1; + } + else if (object instanceof ItemStack) + { + volume = ((ItemStack) object).stackSize; + } + else if (object instanceof FluidStack) + { + volume = ((FluidStack) object).amount; + } + else if (object instanceof Fluid) + { + volume = 1; + } + + return volume; + } + + /** @param receiving - Object receiving an input object for mixing + * @param input - Object being added to the receiving object + * @return Triple containing values of mixing. Complex way to handle it, and may be replaced + * later, However to prevent 4 different methods be created for mixing this is the best + * output design. As well this doesn't consume the object but does the calculations of the + * recipe out at the given object volumes + * + * First value is amount of the first object used. Second value is the amount of the second + * object used. Third value Pair containing object output then amount of output */ + public Triple> mix(Object receiving, Object input) + { + if (this.canComplete(receiving, input)) + { + //Collect volume of each input object + int volumeReceiving = this.getObjectVolume(receiving); + int volumeInput = this.getObjectVolume(input); + int volAUsed, volBUsed; + + //check if there is enough to mix even once + if (volumeReceiving > this.ratioOfA && volumeInput > this.ratioOfB) + { + //Collect ratio of each + int ratioA = (volumeReceiving / this.ratioOfA); + int ratioB = (volumeInput / this.ratioOfB); + + //Take the least ratio value and multiply it by the ratio of the output + int outputVolume = ratioA > ratioB ? ratioB * this.ratioOfC : ratioA * this.ratioOfC; + + volAUsed = (outputVolume / this.ratioOfC) * this.ratioOfA; + volBUsed = (outputVolume / this.ratioOfC) * this.ratioOfB; + return new Triple>(volAUsed, volBUsed, new Pair(this.recipeObjectC, outputVolume)); + } + + } + return null; + } + } + + /** Stores the list of process need to complete a long step process of creating a complex fluid + * based mixing recipe */ + public static class ComplexFluidRecipe + { + int numberOfSteps; + SimpleFluidRecipe[] stepArray; + + public ComplexFluidRecipe(int numberOfSteps) + { + this.numberOfSteps = numberOfSteps; + this.stepArray = new SimpleFluidRecipe[this.numberOfSteps]; + } + + public ComplexFluidRecipe createStep(int step, SimpleFluidRecipe stepRecipe) + { + if (step < numberOfSteps) + { + + } + return this; + } + + public boolean canCompleteStep(int step, Object receiving, Object input) + { + if (step < numberOfSteps) + { + + } + return false; + } + } +}