Worked on Fluid Recipe system more
This commit is contained in:
parent
b1b8e30617
commit
ca73318c78
3 changed files with 84 additions and 11 deletions
|
@ -4,19 +4,20 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
import dark.api.parts.ITileConnector;
|
||||
|
||||
/** Think of this in the same way as an electrical device from UE. getforce methods are designed to
|
||||
* get the idea amount of foce that a side should be outputing at the time. Apply force is the input
|
||||
* for force for the tile, and should return the actually force the machine is using. Supply is when
|
||||
* the code asks for your tile to output force on the side, just return the force value don't try to
|
||||
* apply the force to other machines.
|
||||
*
|
||||
* Tip Supply should never equal load as everything will stop moving since the load equals the
|
||||
* amount of force. The supply of force should be greater
|
||||
*
|
||||
* get the idea amount of force that a side should be outputting at the time. Apply force is the
|
||||
* input for force for the tile, and should return the actually force the machine is using. Supply
|
||||
* is when the code asks for your tile to output force on the side, just return the force value
|
||||
* don't try to apply the force to other machines.
|
||||
*
|
||||
* Tip Supply should never equal load as everything will stop moving since your need more force to
|
||||
* move an object than it creates as a load, 100Power - 100Load = 0Force/0Movement. The supply of
|
||||
* force should be greater than the load required to do the work
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IForceDevice extends ITileConnector
|
||||
{
|
||||
/** Applies force to this tile
|
||||
*
|
||||
*
|
||||
* @param side - side its coming from
|
||||
* @param force - amount of force
|
||||
* @return amount of force actually loaded down */
|
||||
|
@ -26,9 +27,9 @@ public interface IForceDevice extends ITileConnector
|
|||
* @return force to apply in direction */
|
||||
public float supplyForce(ForgeDirection side);
|
||||
|
||||
/** Idea force to output on the side */
|
||||
/** Idea force to output on the given side. */
|
||||
public float getForceOut(ForgeDirection side);
|
||||
|
||||
/** Idea force to load down on the side */
|
||||
/** Idea force to load down on the given side */
|
||||
public float getForceLoad(ForgeDirection side);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
@ -29,6 +30,9 @@ public class FluidCraftingHandler
|
|||
registerRecipe(FluidRegistry.WATER, FluidRegistry.LAVA, Block.cobblestone);
|
||||
}
|
||||
|
||||
/** Creates a very basic A + B = C result for mixing two objects together. Suggest that the use
|
||||
* of a SimpleFluidRecipe i used instead to create a more refined fluid mixing that takes into
|
||||
* account ratios, and fluid volumes */
|
||||
public static void registerRecipe(Object a, Object b, Object c)
|
||||
{
|
||||
if (a != null && b != null && c != null)
|
||||
|
@ -60,6 +64,56 @@ public class FluidCraftingHandler
|
|||
//TODO load the process by which a potion would be created threw fliud crafting
|
||||
}
|
||||
|
||||
/** Does the fluid recipe crafting for the crafter object. Requires that the object fully use all
|
||||
* methods from the #IFluidRecipeCrafter
|
||||
*
|
||||
* @param crafter - crafting object, recommend it be a tile but can be anything as long as the
|
||||
* method are used correctly. In some recipe cases when the setRecipeObjectContent nothing will
|
||||
* be used. If result is null assume not crafting was performed. If there is a result the
|
||||
* crafter couldn't use the output to reduce the input values. From here the IFluidRecipeCrafter
|
||||
* will need to process the output and decress the input values correctly */
|
||||
public static void craft(IFluidRecipeCrafter crafter)
|
||||
{
|
||||
Object received = crafter.getReceivingObjectStack();
|
||||
int receivedVolume = 0;
|
||||
Object input = crafter.getInputObjectStack();
|
||||
int inputVolume = 0;
|
||||
if (crafter != null && received != null && input != null)
|
||||
{
|
||||
//Trip input values so they will match the correct mapped values
|
||||
if (received instanceof FluidStack)
|
||||
{
|
||||
receivedVolume = ((FluidStack) received).amount;
|
||||
received = FluidHelper.getStack((FluidStack) received, 1);
|
||||
}
|
||||
if (received instanceof ItemStack)
|
||||
{
|
||||
receivedVolume = ((ItemStack) received).stackSize;
|
||||
((ItemStack) received).stackSize = 1;
|
||||
}
|
||||
if (input instanceof FluidStack)
|
||||
{
|
||||
inputVolume = ((FluidStack) input).amount;
|
||||
input = FluidHelper.getStack((FluidStack) input, 1);
|
||||
}
|
||||
if (input instanceof ItemStack)
|
||||
{
|
||||
receivedVolume = ((ItemStack) input).stackSize;
|
||||
((ItemStack) input).stackSize = 1;
|
||||
}
|
||||
Object result = fluidMergeResults.containsKey(new Pair<Object, Object>(crafter.getReceivingObjectStack(), crafter.getInputObjectStack()));
|
||||
if (result != null)
|
||||
{
|
||||
if (result instanceof SimpleFluidRecipe)
|
||||
{
|
||||
Triple<Integer, Integer, Pair<Object, Integer>> re = ((SimpleFluidRecipe) result).mix(crafter.getInputObjectStack(), crafter.getInputObjectStack());
|
||||
crafter.setRecipeObjectContent(received, re.getA(), input, re.getB(), re.getC().getKey(), re.getC().getValue());
|
||||
}
|
||||
}
|
||||
crafter.setRecipeObjectContent(received, 0, input, 0, result, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Merges two fluids together that don't result in damage to the network */
|
||||
public static FluidStack mergeFluidStacks(FluidStack stackOne, FluidStack stackTwo)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package dark.core.prefab.tilenetwork.fluid;
|
||||
|
||||
/** Use this if you want to take advantage of the {@link #FluidCraftingHandler} 's auto crafting
|
||||
* methods to do as little as work as possible to create recipe results
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IFluidRecipeCrafter
|
||||
{
|
||||
/** After calling {@link #FluidCraftingHandler} 's crafting method this will be called to setup
|
||||
* the end result of all 3 objects. That is if crafting was not called for calculations only */
|
||||
public void setRecipeObjectContent(Object receivingObject, int usedReceivingVolume, Object inputObject, int usedInputVolume, Object resultObject, int resultCreatedVolume);
|
||||
|
||||
/** Stack that is receiving the input object (ItemStack & FluidStack are best) */
|
||||
public Object getReceivingObjectStack();
|
||||
|
||||
/** Stack that will be received by the receiving object (ItemStack & FluidStack are best) */
|
||||
public Object getInputObjectStack();
|
||||
}
|
Loading…
Add table
Reference in a new issue