Search in sources :

Example 31 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project SpongeCommon by SpongePowered.

the class IMixinSingleBlockCarrier method getInventory.

static Inventory getInventory(Direction from, BlockCarrier thisThing) {
    if (thisThing instanceof ISidedInventory) {
        EnumFacing facing = DirectionFacingProvider.getInstance().get(from).get();
        int[] slots = ((ISidedInventory) thisThing).getSlotsForFace(facing);
        QueryOperation<?>[] indices = new QueryOperation[slots.length];
        for (int i = 0; i < slots.length; i++) {
            indices[i] = QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(slots[i]));
        }
        return thisThing.getInventory().query(indices);
    }
    return thisThing.getInventory();
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) EnumFacing(net.minecraft.util.EnumFacing) QueryOperation(org.spongepowered.api.item.inventory.query.QueryOperation)

Example 32 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project RebornCore by TechReborn.

the class InventoryHelper method insertItemIntoInventory.

public static void insertItemIntoInventory(IInventory inventory, ItemStack stack, EnumFacing side, int intoSlot, boolean doMove, boolean canStack) {
    if (stack.isEmpty())
        return;
    IInventory targetInventory = inventory;
    if (!doMove) {
        targetInventory = new GenericInventory("temporary.inventory", false, targetInventory.getSizeInventory());
        ((GenericInventory) targetInventory).copyFrom(inventory);
    }
    int i = 0;
    int[] attemptSlots = new int[0];
    if (inventory instanceof ISidedInventory && side != null) {
        attemptSlots = ((ISidedInventory) inventory).getSlotsForFace(side);
        if (attemptSlots == null)
            attemptSlots = new int[0];
    } else {
        attemptSlots = new int[inventory.getSizeInventory()];
        for (int a = 0; a < inventory.getSizeInventory(); a++) attemptSlots[a] = a;
    }
    if (intoSlot > -1) {
        Set<Integer> x = new HashSet<Integer>();
        for (int attemptedSlot : attemptSlots) x.add(attemptedSlot);
        if (x.contains(intoSlot))
            attemptSlots = new int[] { intoSlot };
        else
            attemptSlots = new int[0];
    }
    while (stack.getCount() > 0 && i < attemptSlots.length) {
        if (side != null && inventory instanceof ISidedInventory)
            if (!((ISidedInventory) inventory).canInsertItem(attemptSlots[i], stack, side.getOpposite())) {
                i++;
                continue;
            }
        tryInsertStack(targetInventory, attemptSlots[i], stack, canStack);
        i++;
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) HashSet(java.util.HashSet)

Example 33 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project Solar by ArekkuusuJerii.

the class TileGravityHopper method update.

@Override
@SuppressWarnings("ConstantConditions")
public void update() {
    if (!world.isRemote) {
        if (cooldown <= 0) {
            EnumFacing facing = getFacing();
            traceBlock(facing).ifPresent(out -> {
                traceBlock(facing.getOpposite()).ifPresent(in -> {
                    Pair<IItemHandler, ISidedInventory> invOut = getInventory(out, facing.getOpposite());
                    Pair<IItemHandler, ISidedInventory> invIn;
                    ItemStack stack = transferOut(invOut, true);
                    if (!stack.isEmpty() && transferIn(invIn = getInventory(in, facing), stack, true)) {
                        if (transferIn(invIn, transferOut(invOut, false), false))
                            cooldown = 5;
                    }
                });
            });
        } else
            cooldown--;
    } else {
        spawnParticles();
    }
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) IItemHandler(net.minecraftforge.items.IItemHandler) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack)

Example 34 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project Solar by ArekkuusuJerii.

the class TileVacuumConveyor method dropItems.

private void dropItems() {
    if (cooldown <= 0) {
        IItemHandler handler = from.getKey();
        ISidedInventory sidedInv = from.getValue();
        for (int slot = 0; slot < handler.getSlots(); slot++) {
            ItemStack inSlot = handler.getStackInSlot(slot);
            if (!inSlot.isEmpty() && (lookup.isEmpty() || ItemHandlerHelper.canItemStacksStack(lookup, inSlot)) && (sidedInv == null || sidedInv.canExtractItem(slot, inSlot, getFacingLazy()))) {
                BlockPos offset = pos.offset(getFacingLazy());
                Vector3 spawn = Vector3.apply(offset.getX(), offset.getY(), offset.getZ()).add(0.5D);
                ItemStack out = handler.extractItem(slot, Integer.MAX_VALUE, false);
                EntityTemporalItem entity = new EntityTemporalItem(world, spawn.x(), spawn.y(), spawn.z(), out);
                impulseEntityItem(spawn, entity);
                world.spawnEntity(entity);
                break;
            }
        }
        cooldown = 5;
    } else
        cooldown--;
    applyGravity(repulse, -1.25D);
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) IItemHandler(net.minecraftforge.items.IItemHandler) BlockPos(net.minecraft.util.math.BlockPos) Vector3(net.katsstuff.mirror.data.Vector3) EntityTemporalItem(arekkuusu.solar.common.entity.EntityTemporalItem) ItemStack(net.minecraft.item.ItemStack)

Example 35 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BloodMagic by WayofTime.

the class Utils method insertStackIntoInventory.

/**
 * Inserts the desired stack into the inventory up to a limit for the
 * inventory.
 *
 * @param stack
 * @param inventory
 * @param dir
 * @param limit
 * @return
 */
public static ItemStack insertStackIntoInventory(ItemStack stack, IInventory inventory, EnumFacing dir, int limit) {
    if (stack.isEmpty()) {
        return ItemStack.EMPTY;
    }
    boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
    if (inventory instanceof ISidedInventory) {
        int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
        for (int in : array) {
            canBeInserted[in] = ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
        }
    } else {
        for (int i = 0; i < canBeInserted.length; i++) {
            canBeInserted[i] = true;
        }
    }
    int numberMatching = 0;
    for (int i = 0; i < inventory.getSizeInventory(); i++) {
        if (!canBeInserted[i]) {
            continue;
        }
        ItemStack invStack = inventory.getStackInSlot(i);
        if (!invStack.isEmpty() && canCombine(stack, invStack)) {
            numberMatching += invStack.getCount();
        }
    }
    if (numberMatching >= limit) {
        return stack;
    }
    int newLimit = limit - numberMatching;
    for (int i = 0; i < inventory.getSizeInventory(); i++) {
        if (!canBeInserted[i]) {
            continue;
        }
        int prevStackSize = stack.getCount();
        ItemStack[] combinedStacks = combineStacks(stack, inventory.getStackInSlot(i), newLimit);
        stack = combinedStacks[0];
        // TODO
        inventory.setInventorySlotContents(i, combinedStacks[1]);
        newLimit -= (prevStackSize - stack.getCount());
        if (newLimit <= 0 || stack.isEmpty()) {
            return stack;
        }
    }
    return stack;
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ISidedInventory (net.minecraft.inventory.ISidedInventory)53 ItemStack (net.minecraft.item.ItemStack)36 IInventory (net.minecraft.inventory.IInventory)24 TileEntity (net.minecraft.tileentity.TileEntity)9 IItemHandler (net.minecraftforge.items.IItemHandler)7 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)5 ArrayList (java.util.ArrayList)3 World (net.minecraft.world.World)3 Pos (com.builtbroken.mc.lib.transform.vector.Pos)2 IBee (forestry.api.apiculture.IBee)2 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)2 ISlotUpgradeManager (logisticspipes.interfaces.ISlotUpgradeManager)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 EnumFacing (net.minecraft.util.EnumFacing)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 SidedInvWrapper (net.minecraftforge.items.wrapper.SidedInvWrapper)2 Int3 (WayofTime.alchemicalWizardry.api.Int3)1 RoutingFocusParadigm (WayofTime.alchemicalWizardry.api.RoutingFocusParadigm)1 RoutingFocusPosAndFacing (WayofTime.alchemicalWizardry.api.RoutingFocusPosAndFacing)1 IBloodAltar (WayofTime.alchemicalWizardry.api.tile.IBloodAltar)1