Allow crafting upgrade for fluids in constructor and exporter. #461
This commit is contained in:
@@ -86,6 +86,16 @@ public interface ICraftingManager {
|
||||
@Nullable
|
||||
ICraftingTask request(ItemStack stack, int amount);
|
||||
|
||||
/**
|
||||
* Schedules a crafting task if the task isn't scheduled yet.
|
||||
*
|
||||
* @param stack the stack
|
||||
* @param amount the mB of the fluid to request
|
||||
* @return the crafting task created, or null if no task is created
|
||||
*/
|
||||
@Nullable
|
||||
ICraftingTask request(FluidStack stack, int amount);
|
||||
|
||||
/**
|
||||
* Tracks an incoming stack.
|
||||
*
|
||||
|
||||
@@ -218,14 +218,41 @@ public class CraftingManager implements ICraftingManager {
|
||||
listeners.forEach(ICraftingMonitorListener::onChanged);
|
||||
}
|
||||
|
||||
//TODO: Make fluid version
|
||||
@Override
|
||||
@Nullable
|
||||
public ICraftingTask request(ItemStack stack, int amount) {
|
||||
for (ICraftingTask task : getTasks()) {
|
||||
if (task.getRequested().getItem() != null) {
|
||||
if (API.instance().getComparer().isEqualNoQuantity(task.getRequested().getItem(), stack)) {
|
||||
amount -= task.getQuantity() * task.getQuantityPerCraft();
|
||||
amount -= task.getQuantity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (amount > 0) {
|
||||
ICraftingTask task = create(stack, amount);
|
||||
|
||||
if (task != null) {
|
||||
ICraftingTaskError error = task.calculate();
|
||||
|
||||
if (error == null) {
|
||||
this.add(task);
|
||||
|
||||
return task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICraftingTask request(FluidStack stack, int amount) {
|
||||
for (ICraftingTask task : getTasks()) {
|
||||
if (task.getRequested().getFluid() != null) {
|
||||
if (API.instance().getComparer().isEqual(task.getRequested().getFluid(), stack, IComparer.COMPARE_NBT)) {
|
||||
amount -= task.getQuantity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
// TODO: Crafting upgrade for fluids.
|
||||
public class NetworkNodeConstructor extends NetworkNode implements IComparable, IType, ICoverable {
|
||||
public static final String ID = "constructor";
|
||||
|
||||
@@ -135,6 +134,8 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
|
||||
|
||||
world.setBlockState(front, state, 1 | 2);
|
||||
}
|
||||
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
|
||||
network.getCraftingManager().request(stack, Fluid.BUCKET_VOLUME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
// TODO: Crafting upgrade for fluids
|
||||
public class NetworkNodeExporter extends NetworkNode implements IComparable, IType, ICoverable {
|
||||
public static final String ID = "exporter";
|
||||
|
||||
@@ -122,10 +121,12 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
|
||||
FluidStack stack = fluids[filterSlot];
|
||||
|
||||
if (stack != null) {
|
||||
int toExtract = Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount();
|
||||
|
||||
FluidStack stackInStorage = network.getFluidStorageCache().getList().get(stack, compare);
|
||||
|
||||
if (stackInStorage != null) {
|
||||
int toExtract = Math.min(Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount(), stackInStorage.amount);
|
||||
toExtract = Math.min(toExtract, stackInStorage.amount);
|
||||
|
||||
FluidStack took = network.extractFluid(stack, toExtract, compare, Action.SIMULATE);
|
||||
|
||||
@@ -138,6 +139,8 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
|
||||
handler.fill(took, true);
|
||||
}
|
||||
}
|
||||
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
|
||||
network.getCraftingManager().request(stack, toExtract);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user