Search in sources :

Example 26 with IInventory

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

the class DroneAIExternalProgram method doBlockInteraction.

@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
    IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
    if (inv == null)
        return false;
    if (curProgramTag != null) {
        if (curSlot < inv.getSizeInventory()) {
            ItemStack stack = inv.getStackInSlot(curSlot);
            if (stack != null && curProgramTag.equals(stack.getTagCompound())) {
                subAI.onUpdateTasks();
                if (subAI.isIdling() || isRunningSameProgram(subAI.getCurrentAI())) {
                    curProgramTag = null;
                    curSlot++;
                }
            } else {
                curProgramTag = null;
                subAI.setWidgets(new ArrayList<IProgWidget>());
            }
        }
        return true;
    } else {
        while (curSlot < inv.getSizeInventory()) {
            ItemStack stack = inv.getStackInSlot(curSlot);
            if (stack != null && stack.getItem() instanceof IProgrammable) {
                IProgrammable programmable = (IProgrammable) stack.getItem();
                if (programmable.canProgram(stack) && programmable.usesPieces(stack)) {
                    List<IProgWidget> widgets = TileEntityProgrammer.getProgWidgets(stack);
                    boolean areWidgetsValid = true;
                    for (IProgWidget widget : widgets) {
                        if (!drone.isProgramApplicable(widget)) {
                            areWidgetsValid = false;
                            break;
                        }
                    }
                    if (areWidgetsValid) {
                        if (widget.shareVariables)
                            mainAI.connectVariables(subAI);
                        subAI.getDrone().getAIManager().setLabel("Main");
                        subAI.setWidgets(widgets);
                        curProgramTag = stack.getTagCompound();
                        if (!subAI.isIdling()) {
                            return true;
                        }
                    }
                }
            }
            curSlot++;
        }
        return false;
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) IProgrammable(pneumaticCraft.api.item.IProgrammable) ItemStack(net.minecraft.item.ItemStack)

Example 27 with IInventory

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

the class DroneAIExternalProgram method isValidPosition.

@Override
protected boolean isValidPosition(ChunkPosition pos) {
    if (traversedPositions.add(pos)) {
        curSlot = 0;
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        return te instanceof IInventory;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory)

Example 28 with IInventory

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

the class DroneEntityAIInventoryExport method export.

private boolean export(ChunkPosition pos, boolean simulate) {
    IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
    if (inv != null) {
        for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
            ItemStack droneStack = drone.getInventory().getStackInSlot(i);
            if (droneStack != null) {
                if (widget.isItemValidForFilters(droneStack)) {
                    for (int side = 0; side < 6; side++) {
                        droneStack = drone.getInventory().getStackInSlot(i);
                        if (((ISidedWidget) widget).getSides()[side] && droneStack != null) {
                            droneStack = droneStack.copy();
                            int oldCount = droneStack.stackSize;
                            if (((ICountWidget) widget).useCount())
                                droneStack.stackSize = Math.min(droneStack.stackSize, getRemainingCount());
                            ItemStack remainder = IOHelper.insert(inv, droneStack.copy(), side, simulate);
                            int stackSize = drone.getInventory().getStackInSlot(i).stackSize - (remainder == null ? droneStack.stackSize : droneStack.stackSize - remainder.stackSize);
                            droneStack.stackSize = stackSize;
                            int exportedItems = oldCount - stackSize;
                            if (!simulate) {
                                drone.getInventory().setInventorySlotContents(i, stackSize > 0 ? droneStack : null);
                                decreaseCount(exportedItems);
                            }
                            if (simulate && exportedItems > 0)
                                return true;
                            //doing it for every side for no side sensitive inventories would be a waste.
                            if (!(inv instanceof ISidedInventory))
                                break;
                        }
                    }
                    if (droneStack == null && !simulate)
                        drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
                    else
                        drone.addDebugEntry("gui.progWidget.inventoryExport.debug.filledToMax", pos);
                } else {
                    drone.addDebugEntry("gui.progWidget.inventoryExport.debug.stackdoesntPassFilter", pos);
                }
            }
        }
    } else {
        drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ISidedWidget(pneumaticCraft.common.progwidgets.ISidedWidget) ICountWidget(pneumaticCraft.common.progwidgets.ICountWidget) ItemStack(net.minecraft.item.ItemStack)

Example 29 with IInventory

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

the class DroneEntityAIInventoryImport method importItems.

private boolean importItems(ChunkPosition pos, boolean simulate) {
    IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
    if (inv != null) {
        Set<Integer> accessibleSlots = PneumaticCraftUtils.getAccessibleSlotsForInventoryAndSides(inv, ((ISidedWidget) widget).getSides());
        for (Integer i : accessibleSlots) {
            ItemStack stack = inv.getStackInSlot(i);
            if (stack != null && IOHelper.canExtractItemFromInventory(inv, stack, i, ((ISidedWidget) widget).getSides())) {
                if (widget.isItemValidForFilters(stack)) {
                    ItemStack importedStack = stack.copy();
                    if (((ICountWidget) widget).useCount())
                        importedStack.stackSize = Math.min(importedStack.stackSize, getRemainingCount());
                    ItemStack remainder = IOHelper.insert(drone.getInventory(), importedStack.copy(), 0, simulate);
                    int removedItems = importedStack.stackSize - (remainder != null ? remainder.stackSize : 0);
                    if (!simulate) {
                        ItemStack newStack = stack.copy();
                        newStack.stackSize = stack.stackSize - removedItems;
                        inv.setInventorySlotContents(i, newStack.stackSize > 0 ? newStack : null);
                        decreaseCount(removedItems);
                        drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
                        if (((ICountWidget) widget).useCount() && getRemainingCount() <= 0)
                            return false;
                    } else if (removedItems > 0) {
                        return true;
                    } else {
                        drone.addDebugEntry("gui.progWidget.inventoryImport.debug.filledToMax", pos);
                    }
                } else {
                    drone.addDebugEntry("gui.progWidget.inventoryImport.debug.stackdoesntPassFilter", pos);
                }
            }
        }
    } else {
        drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedWidget(pneumaticCraft.common.progwidgets.ISidedWidget) ICountWidget(pneumaticCraft.common.progwidgets.ICountWidget) ItemStack(net.minecraft.item.ItemStack)

Example 30 with IInventory

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

the class ModuleAirGrate method update.

@Override
public void update() {
    super.update();
    World worldObj = pressureTube.world();
    int xCoord = pressureTube.x();
    int yCoord = pressureTube.y();
    int zCoord = pressureTube.z();
    Vec3 tileVec = Vec3.createVectorHelper(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D);
    if (!worldObj.isRemote) {
        int oldGrateRange = grateRange;
        grateRange = getRange();
        pressureTube.getAirHandler().addAir((vacuum ? 1 : -1) * grateRange * PneumaticValues.USAGE_AIR_GRATE, ForgeDirection.UNKNOWN);
        if (oldGrateRange != grateRange)
            sendDescriptionPacket();
        checkForPlantsAndFarm(worldObj, xCoord, yCoord, zCoord, grateRange);
        coolHeatSinks(worldObj, xCoord, yCoord, zCoord, grateRange);
    } else {
        rangeLineRenderer.update();
    /*  updateParticleTargets(tileVec, grateRange);
              for(Vec3 particleVec : particleTargets) {

                  //if(worldObj.rand.nextInt(10) == 0) {
                  Vec3 motionVec = particleVec.subtract(tileVec);
                  double force = 0.1D;
                  motionVec.xCoord *= force;
                  motionVec.yCoord *= force;
                  motionVec.zCoord *= force;
                  if(vacuum) {
                      worldObj.spawnParticle("smoke", particleVec.xCoord, particleVec.yCoord, particleVec.zCoord, -motionVec.xCoord, -motionVec.yCoord, -motionVec.zCoord);
                  } else {
                      worldObj.spawnParticle("smoke", tileVec.xCoord, tileVec.yCoord, tileVec.zCoord, motionVec.xCoord, motionVec.yCoord, motionVec.zCoord);
                  }
                  //   }

              }*/
    }
    AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(xCoord - grateRange, yCoord - grateRange, zCoord - grateRange, xCoord + grateRange + 1, yCoord + grateRange + 1, zCoord + grateRange + 1);
    List<Entity> entities = worldObj.selectEntitiesWithinAABB(Entity.class, bbBox, new StringFilterEntitySelector().setFilter(entityFilter));
    double d0 = grateRange + 0.5D;
    for (Entity entity : entities) {
        if (!entity.worldObj.isRemote && entity.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) < 0.6D && entity instanceof EntityItem && !entity.isDead) {
            List<IInventory> inventories = new ArrayList<IInventory>();
            List<Integer> sides = new ArrayList<Integer>();
            for (int i = 0; i < 6; i++) {
                IInventory inventory = TileEntityHopper.func_145893_b(worldObj, xCoord + Facing.offsetsXForSide[i], yCoord + Facing.offsetsYForSide[i], zCoord + Facing.offsetsZForSide[i]);
                if (inventory != null) {
                    inventories.add(inventory);
                    sides.add(i);
                }
            }
            // if there isn't a
            if (inventories.size() == 0)
                continue;
            // inventory attached,
            // stop handling.
            int inventoryIndexSelected = new Random().nextInt(inventories.size());
            IInventory inventory = inventories.get(inventoryIndexSelected);
            int side = sides.get(inventoryIndexSelected);
            side = Facing.oppositeSide[side];
            ItemStack leftoverStack = TileEntityHopper.func_145889_a(inventory, ((EntityItem) entity).getEntityItem(), side);
            if (leftoverStack == null || leftoverStack.stackSize == 0) {
                entity.setDead();
            }
        } else {
            if (!(entity instanceof EntityPlayer) || !((EntityPlayer) entity).capabilities.isCreativeMode) {
                Vec3 entityVec = Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ);
                MovingObjectPosition trace = worldObj.rayTraceBlocks(entityVec, tileVec);
                if (trace != null && trace.blockX == xCoord && trace.blockY == yCoord && trace.blockZ == zCoord) {
                    double d1 = (entity.posX - xCoord - 0.5D) / d0;
                    double d2 = (entity.posY - yCoord - 0.5D) / d0;
                    double d3 = (entity.posZ - zCoord - 0.5D) / d0;
                    double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
                    double d5 = 1.0D - d4;
                    if (d5 > 0.0D) {
                        d5 *= d5;
                        if (!vacuum)
                            d5 *= -1;
                        entity.motionX -= d1 / d4 * d5 * 0.1D;
                        entity.motionY -= d2 / d4 * d5 * 0.1D;
                        entity.motionZ -= d3 / d4 * d5 * 0.1D;
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IInventory(net.minecraft.inventory.IInventory) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) StringFilterEntitySelector(pneumaticCraft.common.ai.StringFilterEntitySelector) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Random(java.util.Random) Vec3(net.minecraft.util.Vec3) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

IInventory (net.minecraft.inventory.IInventory)123 ItemStack (net.minecraft.item.ItemStack)78 TileEntity (net.minecraft.tileentity.TileEntity)53 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