Add the unified FluidGenerator recipe system + Restructure FluidGenerators tiles

They should all be pretty now
This commit is contained in:
Ourten 2016-12-17 01:25:32 +01:00
parent 3bf346f39a
commit 97192ee3f4
12 changed files with 442 additions and 607 deletions

View file

@ -0,0 +1,5 @@
package techreborn.api.generator;
public enum EFluidGenerator {
THERMAL, GAS, DIESEL, SEMIFLUID
}

View file

@ -0,0 +1,63 @@
package techreborn.api.generator;
import net.minecraftforge.fluids.Fluid;
public class FluidGeneratorRecipe {
private Fluid fluid;
private int energyPerMb;
public FluidGeneratorRecipe(Fluid fluid, int energyPerMb)
{
this.fluid = fluid;
this.energyPerMb = energyPerMb;
}
public Fluid getFluid() {
return fluid;
}
public void setFluid(Fluid fluid) {
this.fluid = fluid;
}
public int getEnergyPerMb() {
return energyPerMb;
}
public void setEnergyPerMb(int energyPerMb) {
this.energyPerMb = energyPerMb;
}
@Override
public String toString() {
return "FluidGeneratorRecipe [fluid=" + fluid + ", energyPerMb=" + energyPerMb + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + energyPerMb;
result = prime * result + ((fluid == null) ? 0 : fluid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FluidGeneratorRecipe other = (FluidGeneratorRecipe) obj;
if (energyPerMb != other.energyPerMb)
return false;
if (fluid == null) {
if (other.fluid != null)
return false;
} else if (!fluid.equals(other.fluid))
return false;
return true;
}
}

View file

@ -0,0 +1,71 @@
package techreborn.api.generator;
import com.google.common.collect.Sets;
import java.util.HashSet;
import java.util.Optional;
import net.minecraftforge.fluids.Fluid;
public class FluidGeneratorRecipeList {
private HashSet<FluidGeneratorRecipe> recipes;
public FluidGeneratorRecipeList(FluidGeneratorRecipe... recipes)
{
this.recipes = Sets.newHashSet(recipes);
}
public boolean addRecipe(FluidGeneratorRecipe fluidGeneratorRecipe) {
if(!this.getRecipeForFluid(fluidGeneratorRecipe.getFluid()).isPresent())
return this.getRecipes().add(fluidGeneratorRecipe);
return false;
}
public boolean removeRecipe(FluidGeneratorRecipe fluidGeneratorRecipe)
{
return this.getRecipes().remove(fluidGeneratorRecipe);
}
public Optional<FluidGeneratorRecipe> getRecipeForFluid(Fluid fluid)
{
return this.recipes.stream().filter(recipe -> recipe.getFluid().equals(fluid)).findAny();
}
public HashSet<FluidGeneratorRecipe> getRecipes() {
return recipes;
}
public void setRecipes(HashSet<FluidGeneratorRecipe> recipes) {
this.recipes = recipes;
}
@Override
public String toString() {
return "FluidGeneratorRecipeList [recipes=" + recipes + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((recipes == null) ? 0 : recipes.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FluidGeneratorRecipeList other = (FluidGeneratorRecipeList) obj;
if (recipes == null) {
if (other.recipes != null)
return false;
} else if (!recipes.equals(other.recipes))
return false;
return true;
}
}

View file

@ -0,0 +1,45 @@
package techreborn.api.generator;
import java.util.EnumMap;
import net.minecraftforge.fluids.Fluid;
public class GeneratorRecipeHelper {
/**
* This EnumMap store all the energy recipes for the fluid generators. Each
* value of the EFluidGenerator enum is linked to an object holding a set of
* FluidGeneratorRecipe.
*/
public static EnumMap<EFluidGenerator, FluidGeneratorRecipeList> fluidRecipes = new EnumMap<>(
EFluidGenerator.class);
/**
* Register a Fluid energy recipe.
*
* @param generatorType
* A value of the EFluidGenerator type in which the fluid is
* allowed to be consumed.
* @param fluidType
* @param energyPerMb
* Represent the energy / MILLI_BUCKET the fluid will produce.
* Some generators use this value to alter their fluid decay
* speed to match their maximum energy output.
*/
public static void registerFluidRecipe(EFluidGenerator generatorType, Fluid fluidType, int energyPerMb) {
fluidRecipes.putIfAbsent(generatorType, new FluidGeneratorRecipeList());
fluidRecipes.get(generatorType).addRecipe(new FluidGeneratorRecipe(fluidType, energyPerMb));
}
/**
*
* @param generatorType
* A value of the EFluidGenerator type in which the fluid is
* allowed to be consumed.
* @return An object holding a set of availables recipes for this type of
* FluidGenerator.
*/
public static FluidGeneratorRecipeList getFluidRecipesForGenerator(EFluidGenerator generatorType) {
return fluidRecipes.get(generatorType);
}
}

View file

@ -0,0 +1,4 @@
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI")
package techreborn.api.generator;
import net.minecraftforge.fml.common.API;