use of buildcraft.lib.tile.item.StackInsertionFunction.InsertionResult in project BuildCraft by BuildCraft.
the class ItemHandlerSimple method insertItem.
@Override
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (badSlotIndex(slot)) {
return stack;
}
if (canSet(slot, stack)) {
ItemStack current = stacks.get(slot);
if (!canSet(slot, current)) {
// A bit odd, but can happen if the filter changed
return stack;
}
InsertionResult result = inserter.modifyForInsertion(slot, asValid(current.copy()), asValid(stack.copy()));
if (!canSet(slot, result.toSet)) {
// We have a bad inserter or checker, as they should not be conflicting
CrashReport report = new CrashReport("Inserting an item (buildcraft:ItemHandlerSimple)", new IllegalStateException("Conflicting Insertion!"));
CrashReportCategory cat = report.makeCategory("Inventory details");
cat.addCrashSection("Existing Item", current);
cat.addCrashSection("Inserting Item", stack);
cat.addCrashSection("To Set", result.toSet);
cat.addCrashSection("To Return", result.toReturn);
cat.addCrashSection("Slot", slot);
cat.addCrashSection("Checker", checker.getClass());
cat.addCrashSection("Inserter", inserter.getClass());
throw new ReportedException(report);
} else if (!simulate) {
setStackInternal(slot, result.toSet);
if (callback != null) {
callback.onStackChange(this, slot, current, result.toSet);
}
}
return asValid(result.toReturn);
} else {
return stack;
}
}
Aggregations