Search in sources :

Example 46 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.

the class IOHelper method insert.

public static ItemStack insert(IInventory inventory, ItemStack itemStack, int side, boolean simulate) {
    if (inventory instanceof ISidedInventory && side > -1) {
        ISidedInventory isidedinventory = (ISidedInventory) inventory;
        int[] aint = isidedinventory.getSlotsForFace(Direction.from3DDataValue(side));
        for (int j = 0; j < aint.length && !itemStack.isEmpty() && itemStack.getCount() > 0; ++j) {
            itemStack = insert(inventory, itemStack, aint[j], side, simulate);
        }
    } else {
        int k = inventory.getContainerSize();
        for (int l = 0; l < k && !itemStack.isEmpty() && itemStack.getCount() > 0; ++l) {
            itemStack = insert(inventory, itemStack, l, side, simulate);
        }
    }
    if (!itemStack.isEmpty() && itemStack.getCount() == 0) {
        itemStack = ItemStack.EMPTY;
    }
    return itemStack;
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory)

Example 47 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.

the class IOHelper method extractOneItem.

public static ItemStack extractOneItem(TileEntity tile, Direction dir) {
    IInventory inv = getInventoryForTE(tile);
    if (inv != null && !inv.isEmpty()) {
        int[] accessibleSlots;
        if (inv instanceof ISidedInventory) {
            accessibleSlots = ((ISidedInventory) inv).getSlotsForFace(dir);
        } else {
            accessibleSlots = new int[inv.getContainerSize()];
            for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
        }
        for (int slot : accessibleSlots) {
            ItemStack stack = inv.getItem(slot);
            ItemStack retrievingStack = stack.isEmpty() ? ItemStack.EMPTY : stack.copy().split(1);
            if (!stack.isEmpty() && IOHelper.canTakeItemThroughFaceFromInventory(inv, retrievingStack, slot, dir.ordinal())) {
                ItemStack ret = stack.split(1);
                if (stack.getCount() == 0)
                    inv.setItem(slot, ItemStack.EMPTY);
                tile.setChanged();
                return ret;
            }
        }
    }
    return ItemStack.EMPTY;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 48 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.

the class TileRegulator method isSatisfied.

/**
 * Returns true if the supplying inventory has the items stated in the output filter.
 *
 * @return
 */
private boolean isSatisfied() {
    IInventory inv = IOHelper.getInventoryForTE(getTileCache(getOutputDirection()));
    if (inv != null) {
        int[] accessibleSlots;
        if (inv instanceof ISidedInventory) {
            accessibleSlots = ((ISidedInventory) inv).getSlotsForFace(getFacingDirection());
        } else {
            accessibleSlots = new int[inv.getContainerSize()];
            for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
        }
        boolean everythingNull = true;
        for (int i = 18; i < 27; i++) {
            if (!inventory.get(i).isEmpty()) {
                everythingNull = false;
                int outputFilterItems = getItemsInSection(inventory.get(i), EnumSection.OUTPUT_FILTER);
                int supplyingInvCount = 0;
                for (int slot : accessibleSlots) {
                    ItemStack stackInSlot = inv.getItem(slot);
                    if (!stackInSlot.isEmpty() && ItemStackHelper.areStacksEqual(stackInSlot, inventory.get(i), fuzzySetting) && IOHelper.canPlaceItemThroughFaceToInventory(inv, inventory.get(i), slot, getFacingDirection().ordinal())) {
                        supplyingInvCount += stackInSlot.getCount();
                    }
                }
                if (supplyingInvCount < outputFilterItems)
                    return false;
            }
        }
        return !everythingNull;
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 49 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project ForestryMC by ForestryMC.

the class TileAlvearyPlain method updateServerSide.

@Override
protected void updateServerSide() {
    if (beekeepingLogic == null) {
        return;
    }
    if (!isMaster()) {
        return;
    }
    beekeepingLogic.update();
    // Equalize humidity and temperature
    equalizeTemperature();
    equalizeHumidity();
    IBee queen = beekeepingLogic.getQueen();
    if (queen == null) {
        return;
    }
    // Add swarm effects
    if (updateOnInterval(200)) {
        ISidedInventory inventory = getStructureInventory();
        if (inventory != null) {
            onQueenChange(inventory.getStackInSlot(SLOT_QUEEN));
        }
    }
    if (getErrorState() == EnumErrorCode.OK) {
        queen.doFX(beekeepingLogic.getEffectData(), this);
    }
    if (getErrorState() == EnumErrorCode.OK && updateOnInterval(50)) {
        float f = xCoord + 0.5F;
        float f1 = yCoord + 0.0F + (worldObj.rand.nextFloat() * 6F) / 16F;
        float f2 = zCoord + 0.5F;
        float f3 = 0.52F;
        float f4 = worldObj.rand.nextFloat() * 0.6F - 0.3F;
        Proxies.common.addEntitySwarmFX(worldObj, (f - f3), f1, (f2 + f4), 0F, 0F, 0F);
        Proxies.common.addEntitySwarmFX(worldObj, (f + f3), f1, (f2 + f4), 0F, 0F, 0F);
        Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 - f3), 0F, 0F, 0F);
        Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 + f3), 0F, 0F, 0F);
    }
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) IBee(forestry.api.apiculture.IBee)

Example 50 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project ForestryMC by ForestryMC.

the class TileAlvearyPlain method updateClientSide.

@Override
protected void updateClientSide() {
    if (!isMaster()) {
        return;
    }
    ISidedInventory inventory = getStructureInventory();
    if (inventory == null) {
        return;
    }
    // / Multiplayer FX
    ItemStack queenStack = inventory.getStackInSlot(SLOT_QUEEN);
    if (PluginApiculture.beeInterface.isMated(queenStack)) {
        if (getErrorState() == EnumErrorCode.OK && updateOnInterval(2)) {
            IBee displayQueen = PluginApiculture.beeInterface.getMember(queenStack);
            displayQueen.doFX(beekeepingLogic.getEffectData(), this);
        }
    }
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) IBee(forestry.api.apiculture.IBee) 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