allow SAG-Mill recipes to disable main output bonus per recipe

This commit is contained in:
Matthias Mann committed 2014-12-30 23:19:26 +01:00
1 parent a75bcd1855
commit ff0d28df4a
21 files changed
+162 -22

No files matched your search

@@ -1,6 +1,7 @@
package crazypants.enderio.machine;
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
import crazypants.enderio.machine.recipe.RecipeBonusType;
import net.minecraft.nbt.NBTTagCompound;
public class ContinuousTask implements IPoweredTask {
@@ -49,8 +50,13 @@ public class ContinuousTask implements IPoweredTask {
return 1;
}
@Override
public RecipeBonusType getBonusType() {
return RecipeBonusType.NONE;
}
@Override
public MachineRecipeInput[] getInputs() {
return new MachineRecipeInput[0];
}
}
}
@@ -5,6 +5,8 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.machine.recipe.RecipeBonusType;
/**
* A MachineRecipe implementation must be stateless, always returning the same
* values given the same parameters. The 'in progress' recipe for a machine is
@@ -34,6 +36,11 @@ public interface IMachineRecipe {
*/
int getEnergyRequired(MachineRecipeInput... inputs);
/**
* Returns the how bonus should be handled for this input
**/
RecipeBonusType getBonusType(MachineRecipeInput... inputs);
/**
* Only returns true if output can be generated using these inputs. If
* partially complete inputs are provided (for example only one of two
@@ -2,6 +2,7 @@ package crazypants.enderio.machine;
import net.minecraft.nbt.NBTTagCompound;
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
import crazypants.enderio.machine.recipe.RecipeBonusType;
public interface IPoweredTask {
@@ -17,10 +18,12 @@ public interface IPoweredTask {
float getChance();
RecipeBonusType getBonusType();
void writeToNBT(NBTTagCompound nbtRoot);
IMachineRecipe getRecipe();
public abstract MachineRecipeInput[] getInputs();
}
}
@@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.MathHelper;
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
import crazypants.enderio.machine.recipe.RecipeBonusType;
public class PoweredTask implements IPoweredTask {
@@ -22,6 +23,8 @@ public class PoweredTask implements IPoweredTask {
private float requiredEnergy;
private RecipeBonusType bonusType;
private IMachineRecipe recipe;
private float chance;
@@ -57,6 +60,7 @@ public class PoweredTask implements IPoweredTask {
this.usedEnergy = usedEnergy;
this.chance = MathHelper.clamp_float(chance, 0, 1);
requiredEnergy = recipe.getEnergyRequired(inputsIn);
bonusType = recipe.getBonusType(inputsIn);
}
@@ -115,6 +119,11 @@ public class PoweredTask implements IPoweredTask {
this.chance = chance;
}
@Override
public RecipeBonusType getBonusType() {
return bonusType;
}
/* (non-Javadoc)
* @see crazypants.enderio.machine.IPoweredTask#writeToNBT(net.minecraft.nbt.NBTTagCompound)
*/
@@ -2,6 +2,7 @@ package crazypants.enderio.machine;
import net.minecraft.nbt.NBTTagCompound;
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
import crazypants.enderio.machine.recipe.RecipeBonusType;
/**
* Client side stub for reporting progress.
@@ -47,6 +48,11 @@ public class PoweredTaskProgress implements IPoweredTask {
return 0;
}
@Override
public RecipeBonusType getBonusType() {
return RecipeBonusType.NONE;
}
@Override
public void writeToNBT(NBTTagCompound nbtRoot) {
}
@@ -17,6 +17,7 @@ import crazypants.enderio.machine.recipe.IRecipe;
import crazypants.enderio.machine.recipe.Recipe;
import crazypants.enderio.machine.recipe.RecipeInput;
import crazypants.enderio.machine.recipe.RecipeOutput;
import crazypants.enderio.machine.recipe.RecipeBonusType;
import crazypants.enderio.material.OreDictionaryPreferences;
public class VanillaSmeltingRecipe implements IMachineRecipe {
@@ -49,6 +50,11 @@ public class VanillaSmeltingRecipe implements IMachineRecipe {
return numInputs * RF_PER_ITEM;
}
@Override
public RecipeBonusType getBonusType(MachineRecipeInput... inputs) {
return RecipeBonusType.NONE;
}
private int getNumInputs(MachineRecipeInput[] inputs) {
int numInputs = 0;
for (MachineRecipeInput input : inputs) {
@@ -171,7 +177,7 @@ public class VanillaSmeltingRecipe implements IMachineRecipe {
for (Entry<ItemStack, ItemStack> entry : metaList.entrySet()) {
ItemStack output = entry.getValue();
output = OreDictionaryPreferences.instance.getPreferred(output);
result.add(new Recipe(new RecipeInput(entry.getKey()), RF_PER_ITEM, new RecipeOutput(output)));
result.add(new Recipe(new RecipeInput(entry.getKey()), RF_PER_ITEM, RecipeBonusType.NONE, new RecipeOutput(output)));
}
return result;
}
@@ -19,6 +19,7 @@ import crazypants.enderio.machine.recipe.RecipeConfig;
import crazypants.enderio.machine.recipe.RecipeConfigParser;
import crazypants.enderio.machine.recipe.RecipeInput;
import crazypants.enderio.machine.recipe.RecipeOutput;
import crazypants.enderio.machine.recipe.RecipeBonusType;
import crazypants.util.Util;
public class CrusherRecipeManager {
@@ -178,7 +179,7 @@ public class CrusherRecipeManager {
if(input == null || output == null) {
return;
}
addRecipe(new Recipe(new RecipeInput(input, false), energyCost, output));
addRecipe(new Recipe(new RecipeInput(input, false), energyCost, RecipeBonusType.MULTIPLY_OUTPUT, output));
}
public void addRecipe(Recipe recipe) {
@@ -9,6 +9,7 @@ import crazypants.enderio.machine.IPoweredTask;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.PoweredTask;
import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.machine.recipe.RecipeBonusType;
import crazypants.enderio.network.PacketHandler;
public class TileCrusher extends AbstractPoweredTaskEntity {
@@ -85,15 +86,17 @@ public class TileCrusher extends AbstractPoweredTaskEntity {
IPoweredTask ct = currentTask;
super.taskComplete();
//run it again if the ball says so
if(gb != null && useGrindingBall) {
float chance = random.nextFloat();
float mul = gb.getGrindingMultiplier() - 1;
while (mul > 0) {
if(chance <= mul) {
currentTask = ct;
super.taskComplete();
if(gb != null && useGrindingBall && ct != null) {
if(ct.getBonusType() == RecipeBonusType.MULTIPLY_OUTPUT) {
float chance = random.nextFloat();
float mul = gb.getGrindingMultiplier() - 1;
while (mul > 0) {
if(chance <= mul) {
currentTask = ct;
super.taskComplete();
}
mul--;
}
mul--;
}
}
}
@@ -12,6 +12,7 @@ import crazypants.enderio.ModObject;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.IMachineRecipe;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.recipe.RecipeBonusType;
import crazypants.util.Util;
public abstract class BasicPainterTemplate implements IMachineRecipe {
@@ -29,6 +30,11 @@ public abstract class BasicPainterTemplate implements IMachineRecipe {
return DEFAULT_ENERGY_PER_TASK;
}
@Override
public RecipeBonusType getBonusType(MachineRecipeInput... inputs) {
return RecipeBonusType.NONE;
}
@Override
public boolean isRecipe(MachineRecipeInput... inputs) {
return isValidTarget(getTarget(inputs)) && isValidPaintSource(getPaintSource(inputs));
@@ -6,6 +6,7 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.IMachineRecipe;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.recipe.RecipeBonusType;
public abstract class AbstractMachineRecipe implements IMachineRecipe {
@@ -18,6 +19,14 @@ public abstract class AbstractMachineRecipe implements IMachineRecipe {
return recipe == null ? 0 : recipe.getEnergyRequired();
}
public RecipeBonusType getBonusType(MachineRecipeInput... inputs) {
if(inputs == null || inputs.length <= 0) {
return RecipeBonusType.NONE;
}
IRecipe recipe = getRecipeForInputs(inputs);
return recipe == null ? RecipeBonusType.NONE : recipe.getBonusType();
}
public abstract IRecipe getRecipeForInputs(MachineRecipeInput[] inputs);
@Override
@@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.recipe.RecipeBonusType;
public class BasicManyToOneRecipe implements IManyToOneRecipe {
@@ -17,6 +18,8 @@ public class BasicManyToOneRecipe implements IManyToOneRecipe {
private final float expPerItem;
private final RecipeBonusType bonusType;
private final Recipe recipe;
public BasicManyToOneRecipe(Recipe recipe) {
@@ -24,6 +27,7 @@ public class BasicManyToOneRecipe implements IManyToOneRecipe {
this.output = recipe.getOutputs()[0].getOutput().copy();
expPerItem = recipe.getOutputs()[0].getExperiance();
energyRequired = recipe.getEnergyRequired();
bonusType = recipe.getBonusType();
}
@Override
@@ -77,6 +81,11 @@ public class BasicManyToOneRecipe implements IManyToOneRecipe {
return energyRequired;
}
@Override
public RecipeBonusType getBonusType() {
return bonusType;
}
@Override
public RecipeOutput[] getOutputs() {
return recipe.getOutputs();
@@ -20,6 +20,8 @@ public interface IRecipe {
List<FluidStack> getInputFluidStacks();
RecipeBonusType getBonusType();
// boolean isInputForRecipe(List<ItemStack> test);
//
// boolean isInputForRecipe(List<ItemStack> test, List<FluidStack> testFluids);
@@ -14,19 +14,21 @@ public class Recipe implements IRecipe {
private final RecipeInput[] inputs;
private final RecipeOutput[] outputs;
private final int energyRequired;
private final RecipeBonusType bonusType;
public Recipe(RecipeOutput output, int energyRequired, RecipeInput... input) {
this(input, new RecipeOutput[] { output }, energyRequired);
public Recipe(RecipeOutput output, int energyRequired, RecipeBonusType bonusType, RecipeInput... input) {
this(input, new RecipeOutput[] { output }, energyRequired, bonusType);
}
public Recipe(RecipeInput input, int energyRequired, RecipeOutput... output) {
this(new RecipeInput[] { input }, output, energyRequired);
public Recipe(RecipeInput input, int energyRequired, RecipeBonusType bonusType, RecipeOutput... output) {
this(new RecipeInput[] { input }, output, energyRequired, bonusType);
}
public Recipe(RecipeInput[] input, RecipeOutput[] output, int energyRequired) {
public Recipe(RecipeInput[] input, RecipeOutput[] output, int energyRequired, RecipeBonusType bonusType) {
this.inputs = input;
this.outputs = output;
this.energyRequired = energyRequired;
this.bonusType = bonusType;
}
@Override
@@ -145,6 +147,11 @@ public class Recipe implements IRecipe {
return outputs;
}
@Override
public RecipeBonusType getBonusType() {
return bonusType;
}
public boolean hasOuput(ItemStack result) {
if(result == null) {
return false;
@@ -0,0 +1,7 @@
package crazypants.enderio.machine.recipe;
public enum RecipeBonusType {
NONE,
MULTIPLY_OUTPUT,
CHANCE_ONLY
}
@@ -284,6 +284,8 @@ public class RecipeConfig {
private int energyRequired;
private RecipeBonusType bonusType = RecipeBonusType.MULTIPLY_OUTPUT;
private String name;
private RecipeElement(String name) {
@@ -309,11 +311,11 @@ public class RecipeConfig {
List<Recipe> result = new ArrayList<Recipe>();
if(isRecipePerInput) {
for (RecipeInput input : inputs) {
result.add(new Recipe(input, energyRequired, outputArr));
result.add(new Recipe(input, energyRequired, bonusType, outputArr));
}
} else {
for (RecipeOutput output : outputs) {
result.add(new Recipe(output, energyRequired, inputArr));
result.add(new Recipe(output, energyRequired, bonusType, inputArr));
}
}
return result;
@@ -331,9 +333,17 @@ public class RecipeConfig {
this.energyRequired = energyRequired;
}
public RecipeBonusType getBonusType() {
return bonusType;
}
public void setBonusType(RecipeBonusType bonusType) {
this.bonusType = bonusType;
}
@Override
public String toString() {
return "Recipe [input=" + inputs + ", outputs=" + outputs + ", energyRequired=" + energyRequired + "]";
return "Recipe [input=" + inputs + ", outputs=" + outputs + ", energyRequired=" + energyRequired + ", bonusType=" + bonusType + "]";
}
}
@@ -5,6 +5,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.StringReader;
import java.util.Locale;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@@ -48,6 +50,7 @@ public class RecipeConfigParser extends DefaultHandler {
public static final String AT_DUMP_ITEMS = "modObjects";
public static final String AT_ORE_DICT = "oreDictionary";
public static final String AT_ENERGY_COST = "energyCost";
public static final String AT_BONUS_TYPE = "bonusType";
public static final String AT_ITEM_META = "itemMeta";
public static final String AT_ITEM_NAME = "itemName";
public static final String AT_MOD_ID = "modID";
@@ -250,6 +253,7 @@ public class RecipeConfigParser extends DefaultHandler {
}
recipe = recipeGroup.createRecipe(name);
recipe.setEnergyRequired(getIntValue(AT_ENERGY_COST, attributes, CrusherRecipeManager.ORE_ENERGY_COST));
recipe.setBonusType(getEnumValue(AT_BONUS_TYPE, attributes, RecipeBonusType.class, RecipeBonusType.MULTIPLY_OUTPUT));
return;
}
@@ -464,6 +468,23 @@ public class RecipeConfigParser extends DefaultHandler {
return val;
}
public static <E extends Enum<E>> E getEnumValue(String qName, Attributes attributes, Class<E> clazz, E def) {
String val = attributes.getValue(qName);
if(val == null) {
return def;
}
val = val.trim();
if(val.length() <= 0) {
return def;
}
val = val.toUpperCase(Locale.ENGLISH);
try {
return Enum.valueOf(clazz, val);
} catch(IllegalArgumentException ex) {
return def;
}
}
public static boolean hasAttribute(String att, Attributes attributes) {
return attributes.getValue(att) != null;
}
@@ -13,6 +13,7 @@ import crazypants.enderio.config.Config;
import crazypants.enderio.machine.IMachineRecipe;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
import crazypants.enderio.machine.recipe.RecipeBonusType;
import crazypants.enderio.material.FrankenSkull;
public abstract class AbstractSoulBinderRecipe implements IMachineRecipe, ISoulBinderRecipe {
@@ -54,6 +55,11 @@ public abstract class AbstractSoulBinderRecipe implements IMachineRecipe, ISoulB
return getEnergyRequired();
}
@Override
public RecipeBonusType getBonusType(MachineRecipeInput... inputs) {
return RecipeBonusType.NONE;
}
@Override
public boolean isRecipe(MachineRecipeInput... inputs) {
int validCount = 0;
@@ -10,6 +10,7 @@ import crazypants.enderio.config.Config;
import crazypants.enderio.machine.IMachineRecipe;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.spawner.PoweredSpawnerConfig;
import crazypants.enderio.machine.recipe.RecipeBonusType;
import crazypants.util.EntityUtil;
public class SoulBinderSpawnerRecipe implements IMachineRecipe, ISoulBinderRecipe {
@@ -26,6 +27,11 @@ public class SoulBinderSpawnerRecipe implements IMachineRecipe, ISoulBinderRecip
return Config.soulBinderBrokenSpawnerRF;
}
@Override
public RecipeBonusType getBonusType(MachineRecipeInput... inputs) {
return RecipeBonusType.NONE;
}
@Override
public int getExperienceRequired() {
return Config.soulBinderBrokenSpawnerLevels;
@@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.IMachineRecipe;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.recipe.RecipeBonusType;
public class DummyRecipe implements IMachineRecipe {
@@ -31,6 +32,11 @@ public class DummyRecipe implements IMachineRecipe {
return new ResultStack[0];
}
@Override
public RecipeBonusType getBonusType(MachineRecipeInput... inputs) {
return RecipeBonusType.NONE;
}
@Override
public float getExperienceForOutput(ItemStack output) {
return 0;
@@ -51,4 +57,4 @@ public class DummyRecipe implements IMachineRecipe {
return Collections.emptyList();
}
}
}
@@ -10,6 +10,7 @@ import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.recipe.IRecipe;
import crazypants.enderio.machine.recipe.RecipeInput;
import crazypants.enderio.machine.recipe.RecipeOutput;
import crazypants.enderio.machine.recipe.RecipeBonusType;
public class VatRecipe implements IRecipe {
@@ -79,6 +80,11 @@ public class VatRecipe implements IRecipe {
return inputStacks;
}
@Override
public RecipeBonusType getBonusType() {
return RecipeBonusType.NONE;
}
@Override
public boolean isValidInput(int slot, ItemStack item) {
if(item == null) {