Assembly Table: prevent planning recipies multiple times

This commit is contained in:
Player 2013-06-19 10:27:43 +02:00
parent acae574f26
commit 4f740be088

View file

@ -1,6 +1,8 @@
package buildcraft.silicon; package buildcraft.silicon;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
@ -28,7 +30,7 @@ import buildcraft.core.utils.Utils;
public class TileAssemblyTable extends TileEntity implements IMachine, IInventory, IPipeConnection, ILaserTarget { public class TileAssemblyTable extends TileEntity implements IMachine, IInventory, IPipeConnection, ILaserTarget {
ItemStack[] items = new ItemStack[12]; ItemStack[] items = new ItemStack[12];
LinkedList<AssemblyRecipe> plannedOutput = new LinkedList<AssemblyRecipe>(); LinkedHashSet<AssemblyRecipe> plannedOutput = new LinkedHashSet<AssemblyRecipe>();
public AssemblyRecipe currentRecipe; public AssemblyRecipe currentRecipe;
private float currentRequiredEnergy = 0; private float currentRequiredEnergy = 0;
private float energyStored = 0; private float energyStored = 0;
@ -237,6 +239,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
for (AssemblyRecipe r : AssemblyRecipe.assemblyRecipes) { for (AssemblyRecipe r : AssemblyRecipe.assemblyRecipes) {
if (r.output.itemID == stack.itemID && r.output.getItemDamage() == stack.getItemDamage()) { if (r.output.itemID == stack.itemID && r.output.getItemDamage() == stack.getItemDamage()) {
plannedOutput.add(r); plannedOutput.add(r);
break;
} }
} }
} }
@ -278,20 +281,11 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
} }
} }
public void cleanPlannedOutput() {
plannedOutput.clear();
}
public boolean isPlanned(AssemblyRecipe recipe) { public boolean isPlanned(AssemblyRecipe recipe) {
if (recipe == null) if (recipe == null)
return false; return false;
for (AssemblyRecipe r : plannedOutput) { return plannedOutput.contains(recipe);
if (r == recipe)
return true;
}
return false;
} }
public boolean isAssembling(AssemblyRecipe recipe) { public boolean isAssembling(AssemblyRecipe recipe) {
@ -324,8 +318,8 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
plannedOutput.remove(recipe); plannedOutput.remove(recipe);
if (plannedOutput.size() != 0) { if (!plannedOutput.isEmpty()) {
setCurrentRecipe(plannedOutput.getFirst()); setCurrentRecipe(plannedOutput.iterator().next());
} }
} }