Search in sources :

Example 16 with IInventory

use of net.minecraft.inventory.IInventory in project LogisticsPipes by RS485.

the class PipeLogisticsChassi method getConnectedRawInventories.

@Override
protected List<IInventory> getConnectedRawInventories() {
    if (_cachedAdjacentInventories != null) {
        return _cachedAdjacentInventories;
    }
    List<IInventory> adjacent = new ArrayList<>(1);
    IInventory adjinv = getRealInventory();
    if (adjinv != null) {
        adjacent.add(adjinv);
    }
    _cachedAdjacentInventories = adjacent;
    return _cachedAdjacentInventories;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ArrayList(java.util.ArrayList)

Example 17 with IInventory

use of net.minecraft.inventory.IInventory in project LogisticsPipes by RS485.

the class PipeItemsSatelliteLogistics method updateInv.

private void updateInv(boolean force) {
    itemList.clear();
    for (ForgeDirection ori : ForgeDirection.VALID_DIRECTIONS) {
        if (!this.container.isPipeConnected(ori))
            continue;
        IInventory inv = getInventory(ori);
        if (inv != null) {
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                if (inv.getStackInSlot(i) != null) {
                    addToList(ItemIdentifierStack.getFromStack(inv.getStackInSlot(i)));
                }
            }
        }
    }
    if (!itemList.equals(oldList) || force) {
        oldList.clear();
        oldList.addAll(itemList);
        MainProxy.sendToPlayerList(PacketHandler.getPacket(ChestContent.class).setIdentList(itemList).setPosX(getX()).setPosY(getY()).setPosZ(getZ()), localModeWatchers);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ChestContent(logisticspipes.network.packets.hud.ChestContent)

Example 18 with IInventory

use of net.minecraft.inventory.IInventory in project LogisticsPipes by RS485.

the class PipeItemsInvSysConnector method inventoryConnected.

private boolean inventoryConnected() {
    for (int i = 0; i < 6; i++) {
        ForgeDirection dir = ForgeDirection.values()[i];
        DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(this), dir);
        TileEntity tile = p.getTileEntity(getWorld());
        if (tile instanceof IInventory && this.container.canPipeConnect(tile, dir)) {
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 19 with IInventory

use of net.minecraft.inventory.IInventory in project LogisticsPipes by RS485.

the class ImmibisCraftingTableMk2 method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    try {
        if (tileAutoCraftingMk2.isInstance(tile)) {
            // Import recipeInputs
            ItemStack[][] recipe = (ItemStack[][]) tileAutoCraftingMk2.getField("recipeInputs").get(tile);
            // Not really a AutoCraftingInventory, but same content
            InventoryCrafting tempCraftingInv = new InventoryCrafting(new Container() {

                @Override
                public boolean canInteractWith(EntityPlayer entityplayer) {
                    return false;
                }

                @Override
                public void onCraftMatrixChanged(IInventory par1iInventory) {
                }
            }, 3, 3);
            for (int i = 0; i < 9; i++) {
                if (recipe[i].length > 0) {
                    tempCraftingInv.setInventorySlotContents(i, recipe[i][0]);
                    inventory.setInventorySlotContents(i, recipe[i][0]);
                } else {
                    inventory.clearInventorySlotContents(i);
                }
            }
            // Compact
            int slotCount = 0;
            for (int i = 0; i < 9; i++) {
                ItemStack slotStack = inventory.getStackInSlot(i);
                inventory.clearInventorySlotContents(i);
                if (slotStack != null && slotStack.getItem() != null) {
                    int count = 1;
                    for (int j = i + 1; j < 9; j++) {
                        ItemStack tempStack = inventory.getStackInSlot(j);
                        if (tempStack != null && ItemIdentifier.get(slotStack).equals(ItemIdentifier.get(tempStack))) {
                            inventory.clearInventorySlotContents(j);
                            count++;
                        }
                    }
                    slotStack.stackSize = count;
                    inventory.setInventorySlotContents(slotCount, slotStack);
                    slotCount++;
                }
            }
            ItemStack result = null;
            for (IRecipe r : CraftingUtil.getRecipeList()) {
                if (r.matches(tempCraftingInv, tile.getWorldObj())) {
                    result = r.getCraftingResult(tempCraftingInv);
                    break;
                }
            }
            inventory.setInventorySlotContents(9, result);
            return true;
        }
    } catch (IllegalArgumentException | NoSuchFieldException e) {
        LogisticsPipes.log.fatal("Error while importing recipe from Tubestuff's AutoCraftingMk2");
        e.printStackTrace();
    } catch (Exception e) {
        LogisticsPipes.log.error("Got a problem on ImmibisCraftingTableMk2 CraftingRecipeProvider:");
        LogisticsPipes.log.error(e.getMessage());
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IRecipe(net.minecraft.item.crafting.IRecipe) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) Container(net.minecraft.inventory.Container) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 20 with IInventory

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

the class BlockTrackUpgradeHandler method update.

@Override
public void update(EntityPlayer player, int rangeUpgrades) {
    ticksExisted++;
    SearchUpgradeHandler searchHandler = HUDHandler.instance().getSpecificRenderer(SearchUpgradeHandler.class);
    if (ticksExisted % updateInterval == 0) {
        int timeTaken = (int) accTime / updateInterval;
        updateInterval = updateInterval * timeTaken / MAX_TIME;
        if (updateInterval <= 1)
            updateInterval = 2;
        accTime = 0;
        ticksExisted = 0;
    }
    accTime -= System.currentTimeMillis();
    int blockTrackRange = BLOCK_TRACKING_RANGE + Math.min(rangeUpgrades, 5) * PneumaticValues.RANGE_UPGRADE_HELMET_RANGE_INCREASE;
    int baseX = (int) Math.floor(player.posX) - blockTrackRange;
    int baseY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval) / (updateInterval / 2);
    int maxY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval + 1) / (updateInterval / 2);
    baseY = MathHelper.clamp_int(baseY, 0, 255);
    maxY = MathHelper.clamp_int(maxY, 0, 255);
    int baseZ = (int) Math.floor(player.posZ) - blockTrackRange;
    IBlockAccess chunkCache = new ChunkCache(player.worldObj, baseX, baseY, baseZ, baseX + 2 * blockTrackRange, maxY, baseZ + 2 * blockTrackRange, 0);
    for (int i = baseX; i <= baseX + 2 * blockTrackRange; i++) {
        for (int j = baseY; j < maxY; j++) {
            for (int k = baseZ; k <= baseZ + 2 * blockTrackRange; k++) {
                if (player.getDistance(i, j, k) > blockTrackRange)
                    continue;
                TileEntity te = chunkCache.getTileEntity(i, j, k);
                if (MinecraftForge.EVENT_BUS.post(new BlockTrackEvent(player.worldObj, i, j, k, te)))
                    continue;
                if (searchHandler != null && te instanceof IInventory) {
                    searchHandler.checkInventoryForItems(te);
                }
                List<IBlockTrackEntry> entries = BlockTrackEntryList.instance.getEntriesForCoordinate(chunkCache, i, j, k, te);
                if (entries.isEmpty())
                    continue;
                boolean inList = false;
                for (int l = 0; l < blockTargets.size(); l++) {
                    if (blockTargets.get(l).isSameTarget(player.worldObj, i, j, k)) {
                        inList = true;
                        // cancel lost targets
                        blockTargets.get(l).ticksExisted = Math.abs(blockTargets.get(l).ticksExisted);
                        blockTargets.get(l).setTileEntity(te);
                        break;
                    }
                }
                if (!inList) {
                    boolean sentUpdate = false;
                    for (IBlockTrackEntry entry : entries) {
                        if (entry.shouldBeUpdatedFromServer(te)) {
                            if (!sentUpdate) {
                                NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(i, j, k));
                                sentUpdate = true;
                            }
                        }
                    }
                    addBlockTarget(new RenderBlockTarget(player.worldObj, player, i, j, k, te, this));
                    for (IBlockTrackEntry entry : entries) {
                        if (countBlockTrackersOfType(entry) == entry.spamThreshold() + 1) {
                            HUDHandler.instance().addMessage(new ArmorMessage(I18n.format("blockTracker.message.stopSpam", I18n.format(entry.getEntryName())), new ArrayList<String>(), 60, 0x7700AA00));
                        }
                    }
                }
            }
        }
    }
    accTime += System.currentTimeMillis();
    for (int i = 0; i < blockTargets.size(); i++) {
        RenderBlockTarget blockTarget = blockTargets.get(i);
        boolean wasNegative = blockTarget.ticksExisted < 0;
        blockTarget.ticksExisted += CommonHUDHandler.getHandlerForPlayer(player).getSpeedFromUpgrades();
        if (blockTarget.ticksExisted >= 0 && wasNegative)
            blockTarget.ticksExisted = -1;
        blockTarget.update();
        if (blockTarget.getDistanceToEntity(player) > blockTrackRange + 5 || !blockTarget.isTargetStillValid()) {
            if (blockTarget.ticksExisted > 0) {
                blockTarget.ticksExisted = -60;
            } else if (blockTarget.ticksExisted == -1) {
                removeBlockTarget(i);
                i--;
            }
        }
    }
    List<String> textList = new ArrayList<String>();
    RenderBlockTarget focusedTarget = null;
    for (RenderBlockTarget blockTarget : blockTargets) {
        if (blockTarget.isInitialized() && blockTarget.isPlayerLooking()) {
            focusedTarget = blockTarget;
            break;
        }
    }
    if (focusedTarget != null) {
        blockTrackInfo.setTitle(focusedTarget.stat.getTitle());
        textList.addAll(focusedTarget.textList);
    } else {
        blockTrackInfo.setTitle("Current tracked blocks:");
        if (blockTypeCount == null || ticksExisted % 40 == 0) {
            blockTypeCount = new int[BlockTrackEntryList.instance.trackList.size()];
            for (RenderBlockTarget target : blockTargets) {
                for (IBlockTrackEntry validEntry : target.getApplicableEntries()) {
                    blockTypeCount[BlockTrackEntryList.instance.trackList.indexOf(validEntry)]++;
                }
            }
        }
        for (int i = 0; i < blockTypeCount.length; i++) {
            if (blockTypeCount[i] > 0) {
                textList.add(blockTypeCount[i] + " " + I18n.format(BlockTrackEntryList.instance.trackList.get(i).getEntryName()));
            }
        }
        if (textList.size() == 0)
            textList.add("Tracking no blocks currently.");
    }
    blockTrackInfo.setText(textList);
}
Also used : IInventory(net.minecraft.inventory.IInventory) ChunkCache(net.minecraft.world.ChunkCache) ArrayList(java.util.ArrayList) IBlockAccess(net.minecraft.world.IBlockAccess) TileEntity(net.minecraft.tileentity.TileEntity) IBlockTrackEntry(pneumaticCraft.api.client.pneumaticHelmet.IBlockTrackEntry) PacketDescriptionPacketRequest(pneumaticCraft.common.network.PacketDescriptionPacketRequest) BlockTrackEvent(pneumaticCraft.api.client.pneumaticHelmet.BlockTrackEvent)

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