Fixes
This commit is contained in:
@@ -5,8 +5,6 @@ import net.minecraft.world.World;
|
|||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a crafting task.
|
* Represents a crafting task.
|
||||||
*/
|
*/
|
||||||
@@ -17,9 +15,14 @@ public interface ICraftingTask {
|
|||||||
ICraftingPattern getPattern();
|
ICraftingPattern getPattern();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The child tasks
|
* @return The child task
|
||||||
*/
|
*/
|
||||||
List<ICraftingTask> getChildren();
|
ICraftingTask getChild();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param child The child task
|
||||||
|
*/
|
||||||
|
void setChild(ICraftingTask child);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world The world
|
* @param world The world
|
||||||
|
|||||||
@@ -1,33 +1,24 @@
|
|||||||
package refinedstorage.apiimpl.autocrafting.task;
|
package refinedstorage.apiimpl.autocrafting.task;
|
||||||
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class CraftingTask implements ICraftingTask {
|
public abstract class CraftingTask implements ICraftingTask {
|
||||||
protected List<ICraftingTask> children;
|
protected ICraftingTask child;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ICraftingTask> getChildren() {
|
public ICraftingTask getChild() {
|
||||||
return children;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateChildren(World world, INetworkMaster network) {
|
@Override
|
||||||
Iterator<ICraftingTask> childrenIterator = children.iterator();
|
public void setChild(ICraftingTask child) {
|
||||||
|
this.child = child;
|
||||||
while (childrenIterator.hasNext()) {
|
|
||||||
if (childrenIterator.next().update(world, network)) {
|
|
||||||
childrenIterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled(INetworkMaster network) {
|
public void onCancelled(INetworkMaster network) {
|
||||||
for (ICraftingTask child : children) {
|
if (child != null) {
|
||||||
child.onCancelled(network);
|
child.onCancelled(network);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,8 +47,6 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(World world, INetworkMaster network) {
|
public boolean update(World world, INetworkMaster network) {
|
||||||
updateChildren(world, network);
|
|
||||||
|
|
||||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||||
ItemStack input = pattern.getInputs()[i];
|
ItemStack input = pattern.getInputs()[i];
|
||||||
|
|
||||||
@@ -63,9 +61,11 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, input);
|
ICraftingPattern pattern = NetworkUtils.getPattern(network, input);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
children.add(network.createCraftingTask(pattern));
|
child = network.createCraftingTask(pattern);
|
||||||
|
|
||||||
childrenCreated[i] = true;
|
childrenCreated[i] = true;
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,21 +77,19 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (children.isEmpty()) {
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
for (ItemStack output : pattern.getOutputs()) {
|
// @TODO: Handle remainder
|
||||||
// @TODO: Handle remainder
|
network.insertItem(output, output.stackSize, false);
|
||||||
network.insertItem(output, output.stackSize, false);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (pattern.getByproducts() != null) {
|
||||||
for (ItemStack byproduct : pattern.getByproducts()) {
|
for (ItemStack byproduct : pattern.getByproducts()) {
|
||||||
// @TODO: Handle remainder
|
// @TODO: Handle remainder
|
||||||
network.insertItem(byproduct, byproduct.stackSize, false);
|
network.insertItem(byproduct, byproduct.stackSize, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -251,4 +251,4 @@ public abstract class ItemStorageNBT implements IItemStorage {
|
|||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,16 +261,18 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
Iterator<ICraftingTask> craftingTaskIterator = craftingTasks.iterator();
|
Iterator<ICraftingTask> craftingTaskIterator = craftingTasks.iterator();
|
||||||
|
|
||||||
while (craftingTaskIterator.hasNext()) {
|
while (craftingTaskIterator.hasNext()) {
|
||||||
|
craftingTasksChanged = true;
|
||||||
|
|
||||||
ICraftingTask task = craftingTaskIterator.next();
|
ICraftingTask task = craftingTaskIterator.next();
|
||||||
|
|
||||||
markDirty();
|
if (task.getChild() != null) {
|
||||||
|
if (updateCraftingTask(task.getChild())) {
|
||||||
ICraftingPatternContainer container = task.getPattern().getContainer(worldObj);
|
task.setChild(null);
|
||||||
|
}
|
||||||
if (container != null && ticks % container.getSpeed() == 0 && task.update(worldObj, this)) {
|
} else {
|
||||||
craftingTaskIterator.remove();
|
if (updateCraftingTask(task)) {
|
||||||
|
craftingTaskIterator.remove();
|
||||||
craftingTasksChanged = true;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +317,15 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
super.update();
|
super.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean updateCraftingTask(ICraftingTask task) {
|
||||||
|
ICraftingPatternContainer container = task.getPattern().getContainer(worldObj);
|
||||||
|
|
||||||
|
return container != null && ticks % container.getSpeed() == 0 && task.update(worldObj, this);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateCraftingTasks() {
|
private void updateCraftingTasks() {
|
||||||
|
markDirty();
|
||||||
|
|
||||||
for (INetworkNode node : nodeGraph.all()) {
|
for (INetworkNode node : nodeGraph.all()) {
|
||||||
if (node instanceof TileCraftingMonitor) {
|
if (node instanceof TileCraftingMonitor) {
|
||||||
((TileCraftingMonitor) node).dataManager.sendParameterToWatchers(TileCraftingMonitor.TASKS);
|
((TileCraftingMonitor) node).dataManager.sendParameterToWatchers(TileCraftingMonitor.TASKS);
|
||||||
@@ -541,22 +551,22 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@TODO: Processing crafting tasks
|
// @TODO: Processing crafting tasks
|
||||||
|
|
||||||
int inserted = remainder != null ? (orginalSize - remainder.stackSize) : orginalSize;
|
int inserted = remainder != null ? (orginalSize - remainder.stackSize) : orginalSize;
|
||||||
|
|
||||||
if (!simulate && inserted > 0) {
|
if (!simulate && inserted > 0) {
|
||||||
for (int i = 0; i < inserted; ++i) {
|
/*for (int i = 0; i < inserted; ++i) {
|
||||||
if (!craftingTasks.empty() && craftingTasks.peek() instanceof ProcessingCraftingTask) {
|
if (!craftingTasks.empty() && craftingTasks.peek() instanceof ProcessingCraftingTask) {
|
||||||
if (((ProcessingCraftingTask) craftingTasks.peek()).onInserted(stack)) {
|
if (((ProcessingCraftingTask) craftingTasks.peek()).onInserted(stack)) {
|
||||||
updateTopCraftingTask(false);
|
updateTopCraftingTask(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
itemStorage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted), false);
|
itemStorage.add(ItemHandlerHelper.copyStackWithSize(stack, inserted), false);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
return remainder;
|
return remainder;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user