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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations