Allow crafting upgrade for fluids in constructor and exporter. #461

This commit is contained in:
raoulvdberge
2018-07-23 12:41:31 +02:00
parent b3f4109ffa
commit edb66464ae
4 changed files with 46 additions and 5 deletions

View File

@@ -86,6 +86,16 @@ public interface ICraftingManager {
@Nullable @Nullable
ICraftingTask request(ItemStack stack, int amount); 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. * Tracks an incoming stack.
* *

View File

@@ -218,14 +218,41 @@ public class CraftingManager implements ICraftingManager {
listeners.forEach(ICraftingMonitorListener::onChanged); listeners.forEach(ICraftingMonitorListener::onChanged);
} }
//TODO: Make fluid version
@Override @Override
@Nullable @Nullable
public ICraftingTask request(ItemStack stack, int amount) { public ICraftingTask request(ItemStack stack, int amount) {
for (ICraftingTask task : getTasks()) { for (ICraftingTask task : getTasks()) {
if (task.getRequested().getItem() != null) { if (task.getRequested().getItem() != null) {
if (API.instance().getComparer().isEqualNoQuantity(task.getRequested().getItem(), stack)) { 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();
} }
} }
} }

View File

@@ -48,7 +48,6 @@ import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
// TODO: Crafting upgrade for fluids.
public class NetworkNodeConstructor extends NetworkNode implements IComparable, IType, ICoverable { public class NetworkNodeConstructor extends NetworkNode implements IComparable, IType, ICoverable {
public static final String ID = "constructor"; public static final String ID = "constructor";
@@ -135,6 +134,8 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
world.setBlockState(front, state, 1 | 2); world.setBlockState(front, state, 1 | 2);
} }
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
network.getCraftingManager().request(stack, Fluid.BUCKET_VOLUME);
} }
} }
} }

View File

@@ -29,7 +29,6 @@ import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
// TODO: Crafting upgrade for fluids
public class NetworkNodeExporter extends NetworkNode implements IComparable, IType, ICoverable { public class NetworkNodeExporter extends NetworkNode implements IComparable, IType, ICoverable {
public static final String ID = "exporter"; public static final String ID = "exporter";
@@ -122,10 +121,12 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
FluidStack stack = fluids[filterSlot]; FluidStack stack = fluids[filterSlot];
if (stack != null) { if (stack != null) {
int toExtract = Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount();
FluidStack stackInStorage = network.getFluidStorageCache().getList().get(stack, compare); FluidStack stackInStorage = network.getFluidStorageCache().getList().get(stack, compare);
if (stackInStorage != null) { 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); 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); handler.fill(took, true);
} }
} }
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
network.getCraftingManager().request(stack, toExtract);
} }
} }