use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class TileEntityAssemblyIOUnit method getItemFromCurrentDirection.
private boolean getItemFromCurrentDirection() {
TileEntity tile = getTileEntityForCurrentDirection();
boolean extracted = false;
if (isImportUnit()) {
if (searchedItemStack == null) {
// we don't know what we're supposed to pick up
reset();
} else if (tile instanceof IInventory) {
IInventory inv = (IInventory) tile;
int oldStackSize = inventory[0] == null ? 0 : inventory[0].stackSize;
for (int i = 0; i < inv.getSizeInventory(); i++) {
if (inv.getStackInSlot(i) != null) {
if (inventory[0] == null) {
if (inv.getStackInSlot(i).isItemEqual(searchedItemStack)) {
inventory[0] = inv.decrStackSize(i, 1);
}
} else if (inv.getStackInSlot(i).isItemEqual(inventory[0])) {
inv.decrStackSize(i, 1);
inventory[0].stackSize++;
}
// we might need to pickup more than 1 item
extracted = (inventory[0] == null ? 0 : inventory[0].stackSize) == searchedItemStack.stackSize;
if (extracted)
break;
}
}
if (// nothing picked up, search for different inventory
oldStackSize == (inventory[0] == null ? 0 : inventory[0].stackSize))
state = STATE_SEARCH_SRC;
} else
// inventory gone
state = STATE_SEARCH_SRC;
} else {
if (tile instanceof TileEntityAssemblyPlatform) {
TileEntityAssemblyPlatform plat = (TileEntityAssemblyPlatform) tile;
if (plat.openClaw()) {
inventory[0] = plat.getHeldStack();
plat.setHeldStack(null);
extracted = inventory[0] != null;
if (// something went wrong - either the platform is gone altogether, or the item is not there anymore
!extracted)
state = STATE_SEARCH_SRC;
}
}
}
return extracted;
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class IOHelper method dropInventory.
public static void dropInventory(World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory)) {
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0) {
spawnItemInWorld(world, itemStack, x, y, z);
}
}
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class IOHelper method insert.
/**
* Inserts on all sides
* @param tile
* @param itemStack
* @param simulate
* @return
*/
public static ItemStack insert(TileEntity tile, ItemStack itemStack, boolean simulate) {
IInventory inv = getInventoryForTE(tile);
ItemStack insertingStack = itemStack.copy();
for (int i = 0; i < 6; i++) {
insertingStack = insert(inv, insertingStack, i, simulate);
if (insertingStack == null || insertingStack.stackSize != itemStack.stackSize)
return insertingStack;
}
return insertingStack;
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class IOHelper method getInventoryForTE.
public static IInventory getInventoryForTE(TileEntity te) {
if (te instanceof IInventory) {
IInventory inv = (IInventory) te;
Block block = te.getBlockType();
if (block instanceof BlockChest) {
inv = ((BlockChest) block).func_149951_m(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
}
return inv;
} else {
return null;
}
}
use of net.minecraft.inventory.IInventory in project LogisticsPipes by RS485.
the class PipeItemsBasicLogistics method getPointedInventory.
@Override
public IInventoryUtil getPointedInventory(boolean forExtraction) {
IInventoryUtil inv = super.getPointedInventory(forExtraction);
if (inv == null) {
Optional<Pair<IInventory, ForgeDirection>> first = new WorldCoordinatesWrapper(container).getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacentInventory -> new Pair<>(InventoryHelper.getInventory((IInventory) adjacentInventory.tileEntity), adjacentInventory.direction)).filter(inventoryDirectionPair -> inventoryDirectionPair.getValue1() != null).findFirst();
if (first.isPresent()) {
Pair<IInventory, ForgeDirection> p = first.get();
inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(p.getValue1(), p.getValue2().getOpposite());
}
}
return inv;
}
Aggregations