Search in sources :

Example 66 with IInventory

use of net.minecraft.inventory.IInventory in project SecurityCraft by Geforce132.

the class BlockKeypadFurnace method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity tileentity = worldIn.getTileEntity(pos);
    if (tileentity instanceof IInventory) {
        InventoryHelper.dropInventoryItems(worldIn, pos, (IInventory) tileentity);
        worldIn.updateComparatorOutputLevel(pos, this);
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory)

Example 67 with IInventory

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

the class FlickerOperatorItemTransport method FindOutput.

/**
	 * Will try to find a place to move the item stack
	 *
	 * @param stack The item stack to move
	 * @return Returns true if the item can be moved, returns false otherwise
	 */
private boolean FindOutput(World worldObj, TileEntityFlickerHabitat attuner, ItemStack stack, IInventory source) {
    HashMap<Integer, ArrayList<AMVector3>> removeFromOutList = new HashMap<Integer, ArrayList<AMVector3>>();
    boolean itemMoved = false;
    for (int priority = 0; priority <= TileEntityFlickerHabitat.PRIORITY_FINAL; ++priority) {
        if (attuner.getOutListPosition(priority) >= attuner.getOutListSize(priority)) {
            //if the out list position has gone outside the list size reset it to 0
            attuner.setOutListPosition(priority, 0);
        }
        int start = attuner.getOutListPosition(priority);
        int pos = start;
        boolean fullLoop = false;
        while (!fullLoop) {
            //get the crystal marker tile entity for the specified position
            AMVector3 vector = attuner.getOutListAt(priority, pos);
            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
                if (!removeFromOutList.containsKey(priority))
                    removeFromOutList.put(priority, new ArrayList<AMVector3>());
                removeFromOutList.get(priority).add(vector);
                break;
            }
            te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
            int markerType = worldObj.getBlockMetadata((int) vector.x, (int) vector.y, (int) vector.z);
            if (te != null && te instanceof IInventory) {
                IInventory inventory = (IInventory) te;
                itemMoved = outputItem(markerType, new IInventory[] { inventory }, stack, crystalMarkerTE, new IInventory[] { source });
                if (itemMoved) {
                    attuner.setOutListPosition(priority, pos + 1);
                }
            }
            if (!itemMoved && te instanceof TileEntityChest) {
                //This handles the special case of double chests
                TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
                if (adjacent != null) {
                    IInventory inventory = adjacent;
                    itemMoved = outputItem(markerType, new IInventory[] { inventory, (IInventory) te }, stack, crystalMarkerTE, new IInventory[] { source });
                    if (itemMoved) {
                        attuner.setOutListPosition(priority, pos + 1);
                    }
                }
            }
            if (itemMoved)
                break;
            pos++;
            pos %= attuner.getOutListSize(priority);
            if (pos == start)
                fullLoop = true;
        }
        for (int i : removeFromOutList.keySet()) {
            for (AMVector3 vector : removeFromOutList.get(i)) {
                attuner.removeOutListAt(i, vector);
            }
        }
        if (!itemMoved) {
            attuner.setOutListPosition(priority, 0);
        } else {
            break;
        }
    }
    return itemMoved;
}
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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 68 with IInventory

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

the class FlickerOperatorPackedEarth method DoOperation.

@Override
public boolean DoOperation(World worldObj, IFlickerController habitat, boolean powered) {
    int searchesPerLoop = 12;
    int radius = 6;
    int diameter = radius * 2 + 1;
    if (!worldObj.isRemote) {
        boolean actionPerformed = false;
        for (int i = 0; i < searchesPerLoop && !actionPerformed; ++i) {
            TileEntity te = worldObj.getTileEntity(((TileEntity) habitat).xCoord, ((TileEntity) habitat).yCoord - 1, ((TileEntity) habitat).zCoord);
            if (te == null || !(te instanceof IInventory)) {
                return false;
            }
            int effectX = ((TileEntity) habitat).xCoord - radius + (worldObj.rand.nextInt(diameter));
            int effectZ = ((TileEntity) habitat).zCoord - radius + (worldObj.rand.nextInt(diameter));
            int effectY = ((TileEntity) habitat).yCoord - 1 - worldObj.rand.nextInt(radius);
            if (effectY < 3)
                effectY = 3;
            Block block = worldObj.getBlock(effectX, effectY, effectZ);
            if (worldObj.isAirBlock(effectX, effectY, effectZ) || block.isReplaceable(worldObj, effectX, effectY, effectZ)) {
                int inventoryIndex = InventoryUtilities.getFirstBlockInInventory((IInventory) te);
                if (inventoryIndex > -1) {
                    ItemStack stack = ((IInventory) te).getStackInSlot(inventoryIndex);
                    InventoryUtilities.decrementStackQuantity((IInventory) te, inventoryIndex, 1);
                    worldObj.setBlock(effectX, effectY, effectZ, Block.getBlockFromItem(stack.getItem()), stack.getItemDamage(), 2);
                    actionPerformed = true;
                }
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 69 with IInventory

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

the class FlickerOperatorFishing method transferOrEjectItem.

private void transferOrEjectItem(World worldObj, ItemStack stack, int xCoord, int yCoord, int zCoord) {
    if (worldObj.isRemote)
        return;
    boolean eject = false;
    for (int i = -1; i <= 1; ++i) {
        for (int j = -1; j <= 1; ++j) {
            for (int k = -1; k <= 1; ++k) {
                if (i == 0 && j == 0 && k == 0)
                    continue;
                TileEntity te = worldObj.getTileEntity(xCoord + i, yCoord + j, zCoord + k);
                if (te != null && te instanceof IInventory) {
                    for (int side = 0; side < 6; ++side) {
                        if (InventoryUtilities.mergeIntoInventory((IInventory) te, stack, stack.stackSize, side))
                            return;
                    }
                }
            }
        }
    }
    //eject the remainder
    EntityItem item = new EntityItem(worldObj);
    item.setPosition(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5);
    item.setEntityItemStack(stack);
    worldObj.spawnEntityInWorld(item);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) EntityItem(net.minecraft.entity.item.EntityItem)

Example 70 with IInventory

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

the class EntityAISpellmaking method updateTask.

@Override
public void updateTask() {
    AMVector3 targetLocation = host.getSearchLocation();
    AMVector3 dropLocation = host.getDropLocation();
    AMVector3 hostLocation = new AMVector3(host);
    ItemStack searchItem = host.getSearchItem();
    if (searchItem.getItem() == ItemsCommonProxy.essence && searchItem.getItemDamage() > ItemsCommonProxy.essence.META_MAX) {
        TileEntityCraftingAltar altar = host.getAltarTarget();
        if (altar.switchIsOn())
            return;
        BlockCoord bc = altar.getSwitchLocation();
        if (action_state == 0 && host.getNavigator().noPath()) {
            host.getNavigator().tryMoveToXYZ(altar.xCoord + bc.x, altar.yCoord + bc.y, altar.zCoord + bc.z, MOVE_SPEED);
        } else if (action_state == 0 && hostLocation.distanceSqTo(new AMVector3(altar.xCoord + bc.x, altar.yCoord + bc.y, altar.zCoord + bc.z)) < DISTANCE_THRESHOLD) {
            action_state = 1;
            altar.flipSwitch();
            wait_counter = 0;
        } else if (action_state == 1 && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 1 && wait_counter >= WAIT_TIME) {
            resetTask();
        }
    } else {
        if (action_state == 0 && host.getNavigator().noPath()) {
            //no item and too far away to grab			
            host.getNavigator().tryMoveToXYZ(targetLocation.x, targetLocation.y, targetLocation.z, MOVE_SPEED);
        } else if (action_state == 0 && hostLocation.distanceSqTo(targetLocation) < DISTANCE_THRESHOLD) {
            host.getNavigator().clearPathEntity();
            TileEntity te = host.worldObj.getTileEntity((int) targetLocation.x, (int) targetLocation.y, (int) targetLocation.z);
            if (te == null || !(te instanceof IInventory)) {
                resetTask();
                return;
            }
            ((IInventory) te).openInventory();
            if (!host.worldObj.isRemote)
                InventoryUtilities.deductFromInventory(((IInventory) te), host.getSearchItem(), 1);
            host.setHeldItem(host.getSearchItem());
            action_state = 1;
        } else if (action_state == 1 && host.getNavigator().noPath() && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 1 && host.getNavigator().noPath() && wait_counter >= WAIT_TIME) {
            wait_counter = 0;
            TileEntity te = host.worldObj.getTileEntity((int) targetLocation.x, (int) targetLocation.y, (int) targetLocation.z);
            if (te == null || !(te instanceof IInventory)) {
                resetTask();
                return;
            }
            ((IInventory) te).closeInventory();
            host.getNavigator().tryMoveToXYZ(dropLocation.x, dropLocation.y, dropLocation.z, MOVE_SPEED);
        } else if (action_state == 1 && hostLocation.distanceSqTo(dropLocation) < DISTANCE_THRESHOLD) {
            host.getNavigator().clearPathEntity();
            if (!host.worldObj.isRemote) {
                EntityItem droppedItem = host.entityDropItem(host.getSearchItem(), 0f);
                host.setHeldItem(new ItemStack(Items.paper));
            }
            action_state = 2;
        } else if (action_state == 2 && wait_counter < WAIT_TIME) {
            wait_counter++;
        } else if (action_state == 2 && wait_counter >= WAIT_TIME) {
            resetTask();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityCraftingAltar(am2.blocks.tileentities.TileEntityCraftingAltar) ItemStack(net.minecraft.item.ItemStack) BlockCoord(am2.api.blocks.MultiblockStructureDefinition.BlockCoord) EntityItem(net.minecraft.entity.item.EntityItem)

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