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