Search in sources :

Example 1 with InsertionResult

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;
    }
}
Also used : CrashReport(net.minecraft.crash.CrashReport) ItemStack(net.minecraft.item.ItemStack) CrashReportCategory(net.minecraft.crash.CrashReportCategory) InsertionResult(buildcraft.lib.tile.item.StackInsertionFunction.InsertionResult) ReportedException(net.minecraft.util.ReportedException) Nonnull(javax.annotation.Nonnull)

Aggregations

InsertionResult (buildcraft.lib.tile.item.StackInsertionFunction.InsertionResult)1 Nonnull (javax.annotation.Nonnull)1 CrashReport (net.minecraft.crash.CrashReport)1 CrashReportCategory (net.minecraft.crash.CrashReportCategory)1 ItemStack (net.minecraft.item.ItemStack)1 ReportedException (net.minecraft.util.ReportedException)1