Fixed stirling gen typo and fused quartz recipe now allows inputs in any slots.

This commit is contained in:
brad-c committed 2013-08-16 17:11:49 +08:00
1 parent cb5f833675
commit 5051506de0
7 files changed
+160 -18

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ public enum ModObject {
blockFusedQuartz(++Config.BID, CATEGORY_BLOCK, "Fused Quartz"),
// Stirling Gen
blockStirlingGenerator(++Config.BID, CATEGORY_BLOCK, "Strirling Generator"),
blockStirlingGenerator(++Config.BID, CATEGORY_BLOCK, "Stirling Generator"),
blockReservoir(++Config.BID, CATEGORY_BLOCK, "Reservoir"),
blockAlloySmelter(++Config.BID, CATEGORY_BLOCK, "Alloy Smelter"),
@@ -158,10 +158,13 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity im
if (hasPower() && nextRecipe.isRecipe(getInputs())) {
// then get our recipe and take away the source items
currentTask = new PoweredTask(nextRecipe, getInputs());
for(RecipeInput input : getInputs()) {
int consumed = nextRecipe.getQuantityConsumed(input);
decrStackSize(input.slotNumber, consumed);
}
RecipeInput[] consumed = nextRecipe.getQuantitiesConsumed(getInputs());
for(RecipeInput item : consumed) {
if(item != null && item.item != null && item.item.stackSize > 0) {
decrStackSize(item.slotNumber, item.item.stackSize);
}
}
return true;
}
return false;
@@ -16,6 +16,6 @@ public interface IMachineRecipe {
String getMachineName();
int getQuantityConsumed(RecipeInput input);
RecipeInput[] getQuantitiesConsumed(RecipeInput[] inputs);
}
@@ -1,8 +1,12 @@
package crazypants.enderio.machine.alloy;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.*;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.IMachineRecipe;
import crazypants.enderio.machine.RecipeInput;
public class BasicAlloyRecipe implements IMachineRecipe {
@@ -21,7 +25,11 @@ public class BasicAlloyRecipe implements IMachineRecipe {
this.uid = uid;
inputs = new ItemStack[recipeInputs.length];
for(int i=0;i<inputs.length;i++) {
inputs[i] = recipeInputs[i].copy();
if(recipeInputs[i] != null) {
inputs[i] = recipeInputs[i].copy();
} else {
inputs[i] = null;
}
}
}
@@ -83,12 +91,11 @@ public class BasicAlloyRecipe implements IMachineRecipe {
return ModObject.blockAlloySmelter.unlocalisedName;
}
@Override
public int getQuantityConsumed(RecipeInput input) {
ItemStack ing = getIngrediantForInput(input.item);
return ing == null ? 0 : ing.stackSize;
}
private ItemStack getIngrediantForInput(ItemStack input) {
if(input == null) {
return null;
@@ -101,4 +108,21 @@ public class BasicAlloyRecipe implements IMachineRecipe {
return null;
}
@Override
public RecipeInput[] getQuantitiesConsumed(RecipeInput[] inputs) {
List<RecipeInput> result = new ArrayList<RecipeInput>();
for(RecipeInput input : inputs) {
int numConsumed = getQuantityConsumed(input);
if(numConsumed > 0) {
ItemStack consumed = input.item.copy();
consumed.stackSize = numConsumed;
result.add(new RecipeInput(input.slotNumber, consumed));
}
}
if(result.isEmpty()) {
return null;
}
return result.toArray(new RecipeInput[result.size()]);
}
}
@@ -110,10 +110,27 @@ public class BasicPainterTemplate implements IMachineRecipe {
protected int getResultId(ItemStack target) {
return target.itemID;
}
@Override
public int getQuantityConsumed(RecipeInput input) {
return input.slotNumber == 0 ? 1 : 0;
}
@Override
public RecipeInput[] getQuantitiesConsumed(RecipeInput[] inputs) {
RecipeInput consume = null;
for(RecipeInput input : inputs) {
if(input != null && input.slotNumber == 0 && input.item != null) {
ItemStack consumed = input.item.copy();
consumed.stackSize = 1;
consume = new RecipeInput(input.slotNumber, consumed);
}
}
if(consume != null) {
return new RecipeInput[] {consume};
}
return null;
}
}
@@ -0,0 +1,101 @@
package crazypants.enderio.material;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.IMachineRecipe;
import crazypants.enderio.machine.RecipeInput;
import crazypants.enderio.machine.alloy.BasicAlloyRecipe;
public class FusedQuartzRecipe implements IMachineRecipe {
private static final int NUM_QUARTZ = 4;
@Override
public String getUid() {
return ModObject.blockFusedQuartz.unlocalisedName;
}
@Override
public float getEnergyRequired(RecipeInput... inputs) {
return BasicAlloyRecipe.DEFAULT_ENERGY_USE;
}
@Override
public boolean isRecipe(RecipeInput... inputs) {
int numQuartz = 0;
for (RecipeInput input : inputs) {
if (input != null && input.item != null && input.item.itemID == Item.netherQuartz.itemID) {
numQuartz += input.item.stackSize;
}
}
return numQuartz >= NUM_QUARTZ;
}
@Override
public ItemStack[] getCompletedResult(RecipeInput... inputs) {
return new ItemStack[] { new ItemStack(ModObject.blockFusedQuartz.actualId, 1, 0) };
}
@Override
public boolean isValidInput(int slotNumber, ItemStack item) {
if (item != null && item.itemID == Item.netherQuartz.itemID) {
return true;
}
return false;
}
@Override
public String getMachineName() {
return ModObject.blockFusedQuartz.unlocalisedName;
}
@Override
public RecipeInput[] getQuantitiesConsumed(RecipeInput[] inputs) {
int[] numPerInput = new int[inputs.length];
int numFound = 0;
for (int i = 0; i < inputs.length; i++) {
numPerInput[i] = getQuartzQuanity(inputs[i]);
}
int total = 0;
int[] consumedPerInput = new int[inputs.length];
for (int i = 0; i < NUM_QUARTZ; i++) {
for (int j = 0; j < consumedPerInput.length; j++) {
if (total < NUM_QUARTZ && numPerInput[j] - consumedPerInput[j] > 0) {
total++;
consumedPerInput[j]++;
}
}
}
if (total < NUM_QUARTZ) {
System.out.println("FusedQuartzRecipe.getQuantitiesConsumed: Error!! No QuartzConsumed Consumed.");
return new RecipeInput[0];
}
if (total > NUM_QUARTZ) {
System.out.println("FusedQuartzRecipe.getQuantitiesConsumed: Error!! Consumed more than we should have.");
}
List<RecipeInput> res = new ArrayList<RecipeInput>();
for (int i = 0; i < consumedPerInput.length; i++) {
if (consumedPerInput[i] > 0) {
RecipeInput consumed = new RecipeInput(inputs[i].slotNumber, new ItemStack(Item.netherQuartz, consumedPerInput[i]));
res.add(consumed);
}
}
return res.toArray(new RecipeInput[res.size()]);
}
private int getQuartzQuanity(RecipeInput ri) {
if (ri != null && ri.item != null && ri.item.itemID == Item.netherQuartz.itemID) {
return ri.item.stackSize;
}
return 0;
}
}
@@ -30,12 +30,9 @@ public class MaterialRecipes {
meta++;
}
ItemStack fusedQuartz = new ItemStack(ModObject.blockFusedQuartz.actualId, 1, 0);
IMachineRecipe recipe = new BasicAlloyRecipe(fusedQuartz, ModObject.blockFusedQuartz.unlocalisedName, new ItemStack(Item.netherQuartz,4,0));
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockAlloySmelter.unlocalisedName, recipe);
ItemStack fusedQuartzFrame = new ItemStack(ModObject.itemFusedQuartzFrame.actualId,1,0);
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockAlloySmelter.unlocalisedName, new FusedQuartzRecipe());
ItemStack fusedQuartzFrame = new ItemStack(ModObject.itemFusedQuartzFrame.actualId,1,0);
GameRegistry.addShapedRecipe(fusedQuartzFrame, "bsb", "s s", "bsb", 'b', industialBinder, 's', new ItemStack(Item.stick));
}