Search in sources :

Example 56 with IInventory

use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.

the class ItemMagicBroom method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, true);
        if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
            TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (te instanceof IInventory) {
                EntityBroom broom = new EntityBroom(world);
                broom.setPosition(player.posX, player.posY, player.posZ);
                broom.setChestLocation(new AMVector3(mop.blockX, mop.blockY, mop.blockZ));
                world.spawnEntityInWorld(broom);
                stack.stackSize--;
                if (stack.stackSize == 0) {
                    player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityBroom(am2.entities.EntityBroom)

Example 57 with IInventory

use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.

the class FlickerOperatorItemTransport method DoOperation.

@Override
public boolean DoOperation(World worldObj, IFlickerController controller, boolean powered, Affinity[] flickers) {
    if (worldObj.isRemote) {
        return false;
    }
    //Gets the habitat running this operation
    TileEntityFlickerHabitat habitat = null;
    if (controller instanceof TileEntityFlickerHabitat) {
        habitat = (TileEntityFlickerHabitat) controller;
    } else {
        //if the habitat couldn't be found, bail
        return false;
    }
    int toMove = 0;
    //if(powered){
    for (int i = 0; i < 6; i++) {
        if (flickers[i] == Affinity.ARCANE) {
            toMove += 32;
        }
    }
    //}
    //ensure toMove is at least 1
    toMove = Math.max(toMove, 1);
    //initiate the arrays for any input crystals
    ArrayList<ItemStack> itemsToTransfer = new ArrayList<ItemStack>();
    ArrayList<AMVector3> removeFromInList = new ArrayList<AMVector3>();
    boolean itemFound = false;
    //if the in list position has exceeded the size of the list reset it
    if (habitat.getInListPosition() >= habitat.getInListSize()) {
        habitat.setInListPosition(0);
    }
    for (int inIterator = habitat.getInListPosition(); inIterator < habitat.getInListSize(); ++inIterator) {
        //Gets the tile entity for the attached crystal marker at the specified location
        AMVector3 vector = habitat.getInListAt(inIterator);
        TileEntity te = null;
        TileEntityCrystalMarker crystalMarkerTE = GetCrystalMarkerTileEntity(worldObj, (int) vector.x, (int) vector.y, (int) vector.z);
        if (crystalMarkerTE == null) {
            //crystal marker no longer exists, remove it from the list
            removeFromInList.add(vector);
            break;
        }
        te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
        if (te != null && te instanceof IInventory) {
            //if the crystal is attached to an inventory
            itemFound = moveItem(worldObj, (IInventory) te, crystalMarkerTE, habitat, toMove);
            if (itemFound) {
                //if an item was found the break out of the current loop
                habitat.setInListPosition(inIterator + 1);
                break;
            } else if (te instanceof TileEntityChest) {
                //This is to handle the special case of double chests
                TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
                if (adjacent != null) {
                    itemFound = moveItem(worldObj, adjacent, crystalMarkerTE, habitat, toMove);
                    if (itemFound) {
                        habitat.setInListPosition(inIterator + 1);
                    }
                }
            }
        }
    }
    if (itemFound == false) {
        //if no items were found to move then reset the input list position
        habitat.setInListPosition(0);
    }
    for (AMVector3 vector : removeFromInList) {
        //remove the invalid in list positions from the maintained in list
        habitat.removeInListAt(vector);
    }
    return itemFound;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityChest(net.minecraft.tileentity.TileEntityChest) TileEntityCrystalMarker(am2.blocks.tileentities.TileEntityCrystalMarker) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 58 with IInventory

use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.

the class FlickerOperatorFelledOak method getSaplingFromNearbyChest.

/**
	 * Gets a single sapling from an adjacent chest
	 *
	 * @return
	 */
private ItemStack getSaplingFromNearbyChest(World worldObj, IFlickerController habitat) {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        IInventory inv = getOffsetInventory(worldObj, habitat, dir);
        if (inv == null)
            continue;
        int index = InventoryUtilities.getInventorySlotIndexFor(inv, new ItemStack(Blocks.sapling, 1, Short.MAX_VALUE));
        if (index > -1) {
            ItemStack stack = inv.getStackInSlot(index).copy();
            stack.stackSize = 1;
            return stack;
        }
    }
    return null;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack)

Example 59 with IInventory

use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.

the class FlickerOperatorFelledOak method deductSaplingFromNearbyChest.

private void deductSaplingFromNearbyChest(World worldObj, IFlickerController habitat) {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        IInventory inv = getOffsetInventory(worldObj, habitat, dir);
        if (inv == null)
            continue;
        int index = InventoryUtilities.getInventorySlotIndexFor(inv, new ItemStack(Blocks.sapling, 1, Short.MAX_VALUE));
        if (index > -1) {
            InventoryUtilities.decrementStackQuantity(inv, index, 1);
            return;
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack)

Example 60 with IInventory

use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.

the class FlickerOperatorFelledOak method getOffsetInventory.

/**
	 * Gets an instance of the adjacent IInventory at direction offset.  Returns null if not found or invalid type adjacent.
	 */
private IInventory getOffsetInventory(World worldObj, IFlickerController habitat, ForgeDirection direction) {
    TileEntity te = (TileEntity) habitat;
    TileEntity adjacent = worldObj.getTileEntity(te.xCoord + direction.offsetX, te.yCoord + direction.offsetY, te.zCoord + direction.offsetZ);
    if (adjacent != null && adjacent instanceof IInventory)
        return (IInventory) adjacent;
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory)

Aggregations

IInventory (net.minecraft.inventory.IInventory)129 ItemStack (net.minecraft.item.ItemStack)80 TileEntity (net.minecraft.tileentity.TileEntity)59 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)21 ArrayList (java.util.ArrayList)18 ISidedInventory (net.minecraft.inventory.ISidedInventory)13 EntityItem (net.minecraft.entity.item.EntityItem)12 EntityPlayer (net.minecraft.entity.player.EntityPlayer)12 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)9 AMVector3 (am2.api.math.AMVector3)8 List (java.util.List)8 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)8 SinkReply (logisticspipes.utils.SinkReply)8 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)8 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 ConnectionPipeType (logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType)7