Stuff
This commit is contained in:
@@ -59,6 +59,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
private List<ClientSideMachine> clientSideMachines = new ArrayList<ClientSideMachine>();
|
||||
|
||||
private List<CraftingTask> craftingTasks = new ArrayList<CraftingTask>();
|
||||
private List<CraftingTask> craftingTasksToAdd = new ArrayList<CraftingTask>();
|
||||
|
||||
private List<BlockPos> visited = new ArrayList<BlockPos>();
|
||||
|
||||
@@ -142,6 +143,9 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
}
|
||||
}
|
||||
|
||||
craftingTasks.addAll(craftingTasksToAdd);
|
||||
craftingTasksToAdd.clear();
|
||||
|
||||
Iterator<CraftingTask> it = craftingTasks.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
@@ -219,6 +223,10 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
return craftingTasks;
|
||||
}
|
||||
|
||||
public void addCraftingTask(CraftingTask task) {
|
||||
craftingTasksToAdd.add(task);
|
||||
}
|
||||
|
||||
private void syncItems() {
|
||||
itemGroups.clear();
|
||||
|
||||
@@ -628,7 +636,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
for (int i = 0; i < quantity; ++i) {
|
||||
ItemStack toCraft = itemGroups.get(id).toItemStack();
|
||||
toCraft.stackSize = 1;
|
||||
craftingTasks.add(CraftingTask.create(toCraft));
|
||||
addCraftingTask(CraftingTask.create(toCraft));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import net.minecraft.item.ItemStack;
|
||||
public class CraftingIngredient {
|
||||
private ItemStack stack;
|
||||
private boolean satisfied;
|
||||
private boolean subtaskCreated;
|
||||
|
||||
public CraftingIngredient(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
@@ -21,4 +22,12 @@ public class CraftingIngredient {
|
||||
public void setSatisfied() {
|
||||
this.satisfied = true;
|
||||
}
|
||||
|
||||
public boolean isSubtaskCreated() {
|
||||
return subtaskCreated;
|
||||
}
|
||||
|
||||
public void setSubtaskCreated() {
|
||||
subtaskCreated = true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package refinedstorage.tile.autocrafting;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import refinedstorage.container.ContainerDummy;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import refinedstorage.tile.TileController;
|
||||
import refinedstorage.util.InventoryUtils;
|
||||
|
||||
@@ -14,7 +13,6 @@ import java.util.List;
|
||||
public class CraftingTask {
|
||||
private ItemStack result;
|
||||
private List<CraftingIngredient> ingredients;
|
||||
private CraftingTask parentTask;
|
||||
|
||||
public CraftingTask(ItemStack result, List<CraftingIngredient> ingredients) {
|
||||
this.result = result;
|
||||
@@ -25,14 +23,6 @@ public class CraftingTask {
|
||||
return result;
|
||||
}
|
||||
|
||||
public CraftingTask getParentTask() {
|
||||
return parentTask;
|
||||
}
|
||||
|
||||
public void setParentTask(CraftingTask parentTask) {
|
||||
this.parentTask = parentTask;
|
||||
}
|
||||
|
||||
public boolean attemptCraft(TileController controller) {
|
||||
for (CraftingIngredient ingredient : ingredients) {
|
||||
if (!ingredient.isSatisfied()) {
|
||||
@@ -40,17 +30,10 @@ public class CraftingTask {
|
||||
|
||||
if (took != null) {
|
||||
ingredient.setSatisfied();
|
||||
} else {
|
||||
// schedule a crafting task, if it doesn't exist yet
|
||||
for (CraftingTask task : controller.getCraftingTasks()) {
|
||||
if (InventoryUtils.compareStack(task.getResult(), result) & task.getParentTask() == this) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (!ingredient.isSubtaskCreated()) {
|
||||
CraftingTask subTask = CraftingTask.create(ingredient.getStack());
|
||||
subTask.setParentTask(this);
|
||||
controller.getCraftingTasks().add(subTask);
|
||||
ingredient.setSubtaskCreated();
|
||||
controller.addCraftingTask(subTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,26 +55,22 @@ public class CraftingTask {
|
||||
return new CraftingTask(result, ingredients);
|
||||
}
|
||||
|
||||
private static void addCraftingIngredients(List<CraftingIngredient> ingredients, ItemStack stack) {
|
||||
private static void addCraftingIngredients(List<CraftingIngredient> ingredients, ItemStack result) {
|
||||
for (IRecipe recipe : CraftingManager.getInstance().getRecipeList()) {
|
||||
ItemStack output = recipe.getRecipeOutput();
|
||||
// this may seem unnecessary but keep it, some horrible mods return a null itemstack
|
||||
if (output != null && output.getItem() != null) {
|
||||
boolean hasIngredients = false;
|
||||
|
||||
// first check if the output is the stack we're adding the ingredients for
|
||||
if (InventoryUtils.compareStack(output, stack)) {
|
||||
// now get all the ingredients from that recipe
|
||||
for (ItemStack ingredient : recipe.getRemainingItems(new InventoryCrafting(new ContainerDummy(), 3, 3))) {
|
||||
ingredients.add(new CraftingIngredient(ingredient));
|
||||
hasIngredients = true;
|
||||
break;
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
ItemStack output = recipe.getRecipeOutput();
|
||||
// this may seem unnecessary but keep it, some mods return a null itemstack
|
||||
if (output != null && output.getItem() != null) {
|
||||
// first check if the output is the stack we're adding the ingredients for
|
||||
if (InventoryUtils.compareStack(output, result)) {
|
||||
// now get all the ingredients from that recipe
|
||||
for (ItemStack ingredient : ((ShapedRecipes) recipe).recipeItems) {
|
||||
if (ingredient != null) {
|
||||
ingredients.add(new CraftingIngredient(ingredient));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasIngredients) {
|
||||
ingredients.add(new CraftingIngredient(stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user