Search in sources :

Example 1 with IItemHandlerSimpleInserter

use of net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter in project SophisticatedBackpacks by P3pp3rF1y.

the class InventoryModificationHandler method initializeWrappedInventory.

private void initializeWrappedInventory(IItemHandlerSimpleInserter inventoryHandler) {
    List<IInventoryWrapperUpgrade> inventoryWrapperUpgrades = backpackWrapper.getUpgradeHandler().getWrappersThatImplement(IInventoryWrapperUpgrade.class);
    IItemHandlerSimpleInserter wrappedHandler = inventoryHandler;
    for (IInventoryWrapperUpgrade inventoryWrapperUpgrade : inventoryWrapperUpgrades) {
        wrappedHandler = inventoryWrapperUpgrade.wrapInventory(wrappedHandler);
    }
    modifiedInventoryHandler = wrappedHandler;
}
Also used : IItemHandlerSimpleInserter(net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter) IInventoryWrapperUpgrade(net.p3pp3rf1y.sophisticatedbackpacks.api.IInventoryWrapperUpgrade)

Example 2 with IItemHandlerSimpleInserter

use of net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter in project SophisticatedBackpacks by P3pp3rF1y.

the class AutoCookingUpgradeWrapper method tryPushingOutput.

private void tryPushingOutput() {
    if (outputCooldown > 0) {
        outputCooldown--;
        return;
    }
    ItemStack output = cookingLogic.getCookOutput();
    IItemHandlerSimpleInserter inventory = backpackWrapper.getInventoryForUpgradeProcessing();
    if (!output.isEmpty() && inventory.insertItem(output, true).getCount() < output.getCount()) {
        ItemStack ret = inventory.insertItem(output, false);
        cookingLogic.getCookingInventory().extractItem(CookingLogic.COOK_OUTPUT_SLOT, output.getCount() - ret.getCount(), false);
    } else {
        outputCooldown = NO_INVENTORY_SPACE_COOLDOWN;
    }
    ItemStack fuel = cookingLogic.getFuel();
    if (!fuel.isEmpty() && ForgeHooks.getBurnTime(fuel, recipeType) <= 0 && inventory.insertItem(fuel, true).getCount() < fuel.getCount()) {
        ItemStack ret = inventory.insertItem(fuel, false);
        cookingLogic.getCookingInventory().extractItem(CookingLogic.FUEL_SLOT, fuel.getCount() - ret.getCount(), false);
    }
}
Also used : IItemHandlerSimpleInserter(net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IItemHandlerSimpleInserter

use of net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter in project SophisticatedBackpacks by P3pp3rF1y.

the class ToolSwapperUpgradeWrapper method tryToSwapTool.

private boolean tryToSwapTool(PlayerEntity player, BlockState state, Block block, ItemStack mainHandItem) {
    AtomicReference<ItemStack> selectedTool = new AtomicReference<>(ItemStack.EMPTY);
    AtomicInteger selectedSlot = new AtomicInteger(-1);
    AtomicBoolean finished = new AtomicBoolean(false);
    IItemHandlerSimpleInserter backpackInventory = backpackWrapper.getInventoryHandler();
    InventoryHelper.iterate(backpackInventory, (slot, stack) -> {
        if (stack.isEmpty()) {
            return;
        }
        if (isAllowedAndGoodAtBreakingBlock(state, block, stack)) {
            selectedSlot.set(slot);
            selectedTool.set(stack);
            if (!(block instanceof LeavesBlock) || !getToolTypes(stack).contains(ToolType.HOE)) {
                finished.set(true);
            }
        }
    }, finished::get);
    ItemStack tool = selectedTool.get();
    if (!tool.isEmpty() && hasSpaceInBackpackOrCanPlaceInTheSlotOfSwappedTool(backpackInventory, mainHandItem, tool, selectedSlot.get())) {
        player.setItemInHand(Hand.MAIN_HAND, backpackInventory.extractItem(selectedSlot.get(), 1, false));
        backpackInventory.insertItem(mainHandItem, false);
        return true;
    }
    return false;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IItemHandlerSimpleInserter(net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter) AtomicReference(java.util.concurrent.atomic.AtomicReference) ItemStack(net.minecraft.item.ItemStack) LeavesBlock(net.minecraft.block.LeavesBlock)

Example 4 with IItemHandlerSimpleInserter

use of net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter in project SophisticatedBackpacks by P3pp3rF1y.

the class ToolSwapperUpgradeWrapper method tryToSwapInWeapon.

private boolean tryToSwapInWeapon(PlayerEntity player, ItemStack mainHandItem) {
    AtomicReference<ItemStack> bestAxe = new AtomicReference<>(ItemStack.EMPTY);
    AtomicDouble bestAxeDamage = new AtomicDouble(0);
    AtomicReference<ItemStack> bestSword = new AtomicReference<>(ItemStack.EMPTY);
    AtomicDouble bestSwordDamage = new AtomicDouble(0);
    updateBestWeapons(bestAxe, bestAxeDamage, bestSword, bestSwordDamage, mainHandItem);
    IItemHandlerSimpleInserter backpackInventory = backpackWrapper.getInventoryForUpgradeProcessing();
    InventoryHelper.iterate(backpackInventory, (slot, stack) -> {
        if (filterLogic.matchesWeaponFilter(stack)) {
            updateBestWeapons(bestAxe, bestAxeDamage, bestSword, bestSwordDamage, stack);
        }
    });
    if (!bestSword.get().isEmpty()) {
        return swapWeapon(player, mainHandItem, backpackInventory, bestSword.get());
    } else if (!bestAxe.get().isEmpty()) {
        return swapWeapon(player, mainHandItem, backpackInventory, bestAxe.get());
    }
    return false;
}
Also used : AtomicDouble(com.google.common.util.concurrent.AtomicDouble) IItemHandlerSimpleInserter(net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter) AtomicReference(java.util.concurrent.atomic.AtomicReference) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IItemHandlerSimpleInserter

use of net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter in project SophisticatedBackpacks by P3pp3rF1y.

the class MagnetUpgradeWrapper method tryToInsertItem.

private boolean tryToInsertItem(ItemEntity itemEntity) {
    ItemStack stack = itemEntity.getItem();
    IItemHandlerSimpleInserter inventory = backpackWrapper.getInventoryForUpgradeProcessing();
    ItemStack remaining = inventory.insertItem(stack, true);
    boolean insertedSomething = false;
    if (remaining.getCount() != stack.getCount()) {
        insertedSomething = true;
        remaining = inventory.insertItem(stack, false);
        itemEntity.setItem(remaining);
    }
    return insertedSomething;
}
Also used : IItemHandlerSimpleInserter(net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)5 IItemHandlerSimpleInserter (net.p3pp3rf1y.sophisticatedbackpacks.util.IItemHandlerSimpleInserter)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 LeavesBlock (net.minecraft.block.LeavesBlock)2 Multimap (com.google.common.collect.Multimap)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Optional (java.util.Optional)1 Queue (java.util.Queue)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Nullable (javax.annotation.Nullable)1 BeehiveBlock (net.minecraft.block.BeehiveBlock)1 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1