Search in sources :

Example 86 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class TileEntityAirCannon method updateTrackedItems.

private void updateTrackedItems() {
    if (trackedItemIds != null) {
        trackedItems.clear();
        for (Entity entity : (List<Entity>) worldObj.loadedEntityList) {
            if (trackedItemIds.contains(entity.getUniqueID()) && entity instanceof EntityItem) {
                trackedItems.add((EntityItem) entity);
            }
        }
        trackedItemIds = null;
    }
    Iterator<EntityItem> iterator = trackedItems.iterator();
    while (iterator.hasNext()) {
        EntityItem item = iterator.next();
        if (item.worldObj != worldObj || item.isDead) {
            iterator.remove();
        } else {
            Map<ChunkPosition, ForgeDirection> positions = new HashMap<ChunkPosition, ForgeDirection>();
            double range = 0.2;
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                double posX = item.posX + d.offsetX * range;
                double posY = item.posY + d.offsetY * range;
                double posZ = item.posZ + d.offsetZ * range;
                positions.put(new ChunkPosition((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)), d.getOpposite());
            }
            for (Entry<ChunkPosition, ForgeDirection> entry : positions.entrySet()) {
                ChunkPosition pos = entry.getKey();
                TileEntity te = worldObj.getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
                IInventory inv = IOHelper.getInventoryForTE(te);
                ItemStack remainder = IOHelper.insert(inv, item.getEntityItem(), entry.getValue().ordinal(), false);
                if (remainder != null) {
                    item.setEntityItemStack(remainder);
                } else {
                    item.setDead();
                    iterator.remove();
                    lastInsertingInventory = new ChunkPosition(te.xCoord, te.yCoord, te.zCoord);
                    lastInsertingInventorySide = entry.getValue();
                    break;
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) HashMap(java.util.HashMap) ChunkPosition(net.minecraft.world.ChunkPosition) TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 87 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class TileEntityAirCannon method inventoryCanCarry.

private boolean inventoryCanCarry() {
    insertingInventoryHasSpace = true;
    if (lastInsertingInventory == null)
        return true;
    if (inventory[0] == null)
        return true;
    TileEntity te = worldObj.getTileEntity(lastInsertingInventory.chunkPosX, lastInsertingInventory.chunkPosY, lastInsertingInventory.chunkPosZ);
    IInventory inv = IOHelper.getInventoryForTE(te);
    if (inv != null) {
        ItemStack remainder = IOHelper.insert(inv, inventory[0].copy(), lastInsertingInventorySide.ordinal(), true);
        insertingInventoryHasSpace = remainder == null;
        return insertingInventoryHasSpace;
    } else {
        lastInsertingInventory = null;
        lastInsertingInventorySide = null;
        return true;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Example 88 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class TileEntityBase method getUpgrades.

protected int getUpgrades(int upgradeDamage, int... upgradeSlots) {
    int upgrades = 0;
    IInventory inv = null;
    if (this instanceof IInventory)
        inv = (IInventory) this;
    if (inv == null && this instanceof TileEntityPneumaticBase && ((TileEntityPneumaticBase) this).parentTile instanceof IInventory)
        inv = (IInventory) ((TileEntityPneumaticBase) this).parentTile;
    if (inv != null) {
        for (int i : upgradeSlots) {
            if (inv.getStackInSlot(i) != null && inv.getStackInSlot(i).getItem() == Itemss.machineUpgrade && inv.getStackInSlot(i).getItemDamage() == upgradeDamage) {
                upgrades += inv.getStackInSlot(i).stackSize;
            }
        }
    }
    return upgrades;
}
Also used : IInventory(net.minecraft.inventory.IInventory) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)

Example 89 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class TileEntityBase method processFluidItem.

protected void processFluidItem(int inputSlot, int outputSlot) {
    IInventory inv = (IInventory) this;
    IFluidHandler fluidHandler = (IFluidHandler) this;
    FluidTankInfo tankInfo = fluidHandler.getTankInfo(ForgeDirection.UNKNOWN)[0];
    if (inv.getStackInSlot(inputSlot) != null) {
        ItemStack fluidContainer = inv.getStackInSlot(inputSlot);
        if (tankInfo.fluid == null || tankInfo.fluid.isFluidEqual(fluidContainer)) {
            FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(fluidContainer);
            int amount = FluidContainerRegistry.BUCKET_VOLUME;
            if (fluid == null) {
                if (fluidContainer.getItem() instanceof IFluidContainerItem) {
                    IFluidContainerItem containerItem = (IFluidContainerItem) fluidContainer.getItem();
                    fluid = containerItem.getFluid(fluidContainer);
                    if (fluid != null && fluidHandler.canFill(ForgeDirection.UNKNOWN, fluid.getFluid())) {
                        amount = fluid != null ? fluid.amount : 0;
                        int availableSpace = tankInfo.capacity - (tankInfo.fluid != null ? tankInfo.fluid.amount : 0);
                        if (availableSpace >= amount) {
                            ItemStack singleFuelItem = fluidContainer.copy();
                            singleFuelItem.stackSize = 1;
                            FluidStack drainedStack = containerItem.drain(singleFuelItem, availableSpace, true);
                            if (fluidContainer.stackSize == 1 || inv.getStackInSlot(outputSlot) == null || canStack(singleFuelItem, inv.getStackInSlot(outputSlot))) {
                                fluidHandler.fill(ForgeDirection.UNKNOWN, drainedStack, true);
                                if (fluidContainer.stackSize == 1) {
                                    inv.setInventorySlotContents(inputSlot, singleFuelItem);
                                } else {
                                    inv.getStackInSlot(inputSlot).stackSize--;
                                    if (inv.getStackInSlot(outputSlot) == null) {
                                        inv.setInventorySlotContents(outputSlot, singleFuelItem);
                                    } else {
                                        inv.getStackInSlot(outputSlot).stackSize++;
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (fluidHandler.canFill(ForgeDirection.UNKNOWN, fluid.getFluid())) {
                if (tankInfo.capacity - (tankInfo.fluid != null ? tankInfo.fluid.amount : 0) >= amount) {
                    ItemStack returnedItem = null;
                    FluidContainerData[] allFluidData = FluidContainerRegistry.getRegisteredFluidContainerData();
                    for (FluidContainerData fluidData : allFluidData) {
                        if (fluidData.filledContainer.isItemEqual(fluidContainer)) {
                            returnedItem = fluidData.emptyContainer;
                            break;
                        }
                    }
                    if (returnedItem == null || inv.getStackInSlot(outputSlot) == null || canStack(returnedItem, inv.getStackInSlot(outputSlot))) {
                        if (returnedItem != null) {
                            if (inv.getStackInSlot(outputSlot) == null) {
                                inv.setInventorySlotContents(outputSlot, returnedItem.copy());
                            } else {
                                inv.getStackInSlot(outputSlot).stackSize += returnedItem.stackSize;
                            }
                        }
                        fluidHandler.fill(ForgeDirection.UNKNOWN, new FluidStack(fluid.getFluid(), amount, fluid.tag), true);
                        inv.getStackInSlot(inputSlot).stackSize--;
                        if (inv.getStackInSlot(inputSlot).stackSize <= 0)
                            inv.setInventorySlotContents(inputSlot, null);
                    }
                }
            }
        }
        if (fluidContainer.getItem() instanceof IFluidContainerItem) {
            if (((IFluidContainerItem) fluidContainer.getItem()).getFluid(fluidContainer) == null && (inv.getStackInSlot(outputSlot) == null || canStack(fluidContainer, inv.getStackInSlot(outputSlot)))) {
                if (inv.getStackInSlot(outputSlot) == null) {
                    inv.setInventorySlotContents(outputSlot, fluidContainer);
                } else {
                    inv.getStackInSlot(outputSlot).stackSize += fluidContainer.stackSize;
                }
                inv.setInventorySlotContents(inputSlot, null);
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) IFluidContainerItem(net.minecraftforge.fluids.IFluidContainerItem) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) FluidContainerData(net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)

Example 90 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class TileEntityAssemblyIOUnit method putItemToCurrentDirection.

private boolean putItemToCurrentDirection() {
    if (isImportUnit()) {
        TileEntity tile = getTileEntityForCurrentDirection();
        if (tile instanceof TileEntityAssemblyPlatform) {
            TileEntityAssemblyPlatform plat = (TileEntityAssemblyPlatform) tile;
            if (inventory[0] == null)
                return plat.closeClaw();
            if (plat.isIdle()) {
                plat.setHeldStack(inventory[0]);
                inventory[0] = null;
                return plat.closeClaw();
            }
        } else
            // platform gone; close claw and search new drop-off-location
            repeatDropOffSearch();
    } else {
        IInventory inv = getInventoryForCurrentDirection();
        if (// inventory gone; close claw and search new drop-off-location
        inv == null)
            // inventory gone; close claw and search new drop-off-location
            repeatDropOffSearch();
        else {
            int startSize = inventory[0].stackSize;
            for (int i = 0; i < 6; i++) {
                inventory[0] = PneumaticCraftUtils.exportStackToInventory(inv, inventory[0], ForgeDirection.getOrientation(i));
                if (inventory[0] == null)
                    break;
            }
            // TODO - is this still needed? Shouldn't @DescSynced on inventory take care of this?
            if (inventory[0] == null || startSize != inventory[0].stackSize)
                sendDescriptionPacket();
            // target-inventory full or unavailable
            if (inventory[0] != null && startSize == inventory[0].stackSize)
                repeatDropOffSearch();
        }
        return inventory[0] == null;
    }
    return false;
}
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