Fix wrong quantity stuff
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package refinedstorage.api.autocrafting.registry;
|
package refinedstorage.api.autocrafting.registry;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
@@ -19,11 +20,12 @@ public interface ICraftingTaskFactory {
|
|||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world
|
||||||
* @param network the network
|
* @param network the network
|
||||||
|
* @param stack the stack to create task for
|
||||||
* @param pattern the pattern
|
* @param pattern the pattern
|
||||||
* @param quantity the quantity
|
* @param quantity the quantity
|
||||||
* @param tag the NBT tag, if this is null it isn't reading from disk but is used for making a task on demand
|
* @param tag the NBT tag, if this is null it isn't reading from disk but is used for making a task on demand
|
||||||
* @return the crafting task
|
* @return the crafting task
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
ICraftingTask create(World world, INetworkMaster network, ICraftingPattern pattern, int quantity, @Nullable NBTTagCompound tag);
|
ICraftingTask create(World world, INetworkMaster network, @Nullable ItemStack stack, ICraftingPattern pattern, int quantity, @Nullable NBTTagCompound tag);
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,8 @@ import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
|||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for network manipulation.
|
* Utilities for network manipulation.
|
||||||
*/
|
*/
|
||||||
@@ -34,8 +36,8 @@ public final class NetworkUtils {
|
|||||||
return network.getPattern(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
|
return network.getPattern(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ICraftingTask createCraftingTask(INetworkMaster network, ICraftingPattern pattern, int quantity) {
|
public static ICraftingTask createCraftingTask(INetworkMaster network, @Nullable ItemStack stack, ICraftingPattern pattern, int quantity) {
|
||||||
return RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(pattern.getId()).create(network.getNetworkWorld(), network, pattern, quantity, null);
|
return RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(pattern.getId()).create(network.getNetworkWorld(), network, stack, pattern, quantity, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
|
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
|
||||||
@@ -69,7 +71,7 @@ public final class NetworkUtils {
|
|||||||
ICraftingPattern pattern = network.getPattern(stack, compare);
|
ICraftingPattern pattern = network.getPattern(stack, compare);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
network.addCraftingTask(createCraftingTask(network, pattern, 1));
|
network.addCraftingTask(createCraftingTask(network, stack, pattern, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +88,7 @@ public final class NetworkUtils {
|
|||||||
ICraftingTaskFactory factory = RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(tag.getString(ICraftingTask.NBT_PATTERN_ID));
|
ICraftingTaskFactory factory = RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(tag.getString(ICraftingTask.NBT_PATTERN_ID));
|
||||||
|
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
return factory.create(world, network, pattern, tag.getInteger(ICraftingTask.NBT_QUANTITY), tag);
|
return factory.create(world, network, null, pattern, tag.getInteger(ICraftingTask.NBT_QUANTITY), tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package refinedstorage.apiimpl.autocrafting.registry;
|
package refinedstorage.apiimpl.autocrafting.registry;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
@@ -16,7 +17,7 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public ICraftingTask create(World world, INetworkMaster network, ICraftingPattern pattern, int quantity, @Nullable NBTTagCompound tag) {
|
public ICraftingTask create(World world, INetworkMaster network, @Nullable ItemStack stack, ICraftingPattern pattern, int quantity, @Nullable NBTTagCompound tag) {
|
||||||
return new CraftingTaskNormal(network, pattern, quantity);
|
return new CraftingTaskNormal(network, stack, pattern, quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CraftingTaskNormal implements ICraftingTask {
|
public class CraftingTaskNormal implements ICraftingTask {
|
||||||
private INetworkMaster network;
|
private INetworkMaster network;
|
||||||
|
private ItemStack requested;
|
||||||
private ICraftingPattern pattern;
|
private ICraftingPattern pattern;
|
||||||
private int quantity;
|
private int quantity;
|
||||||
private Deque<ItemStack> toTake = new ArrayDeque<>();
|
private Deque<ItemStack> toTake = new ArrayDeque<>();
|
||||||
@@ -32,22 +33,24 @@ public class CraftingTaskNormal implements ICraftingTask {
|
|||||||
private Multimap<Item, ItemStack> missing = ArrayListMultimap.create();
|
private Multimap<Item, ItemStack> missing = ArrayListMultimap.create();
|
||||||
private Multimap<Item, ItemStack> extras = ArrayListMultimap.create();
|
private Multimap<Item, ItemStack> extras = ArrayListMultimap.create();
|
||||||
|
|
||||||
public CraftingTaskNormal(INetworkMaster network, ICraftingPattern pattern, int quantity) {
|
public CraftingTaskNormal(INetworkMaster network, ItemStack requested, ICraftingPattern pattern, int quantity) {
|
||||||
this.network = network;
|
this.network = network;
|
||||||
|
this.requested = requested;
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculate() {
|
public void calculate() {
|
||||||
calculate(network.getItemStorage().copy(), pattern, true);
|
int newQuantity = quantity;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
while (newQuantity > 0) {
|
||||||
public void onCancelled() {
|
calculate(network.getItemStorage().copy(), pattern, true);
|
||||||
|
|
||||||
|
newQuantity -= requested == null ? newQuantity : pattern.getQuantityPerRequest(requested);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculate(IGroupedItemStorage storage, ICraftingPattern pattern, boolean basePattern) {
|
private void calculate(IGroupedItemStorage storage, ICraftingPattern pattern, boolean basePattern) {
|
||||||
for (int i = 0; i < quantity; ++i) {
|
|
||||||
if (pattern.isProcessing()) {
|
if (pattern.isProcessing()) {
|
||||||
toProcess.add(new Processable(pattern));
|
toProcess.add(new Processable(pattern));
|
||||||
}
|
}
|
||||||
@@ -84,6 +87,9 @@ public class CraftingTaskNormal implements ICraftingTask {
|
|||||||
addExtras(pattern);
|
addExtras(pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -174,6 +180,7 @@ public class CraftingTaskNormal implements ICraftingTask {
|
|||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IProcessable> getToProcess() {
|
public List<IProcessable> getToProcess() {
|
||||||
return toProcess;
|
return toProcess;
|
||||||
|
@@ -123,7 +123,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
ItemStack stack = network.getItemStorage().get(hash);
|
ItemStack stack = network.getItemStorage().get(hash);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
CraftingTaskNormal task = new CraftingTaskNormal(network, NetworkUtils.getPattern(network, stack), quantity);
|
CraftingTaskNormal task = new CraftingTaskNormal(network, stack, NetworkUtils.getPattern(network, stack), quantity);
|
||||||
|
|
||||||
task.calculate();
|
task.calculate();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user