Search in sources :

Example 76 with IInventory

use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.

the class InventoryCraftingStation method craft.

/** Called when an item is removed from the output slot while it doesn't
	 *  store any real items. Returns if the recipe can be crafted again.*/
private boolean craft(EntityPlayer player, boolean simulate) {
    ItemStack[] contents = (simulate ? this.contents.clone() : this.contents);
    ItemStack[] crafting = (simulate ? this.crafting.clone() : this.crafting);
    if (simulate)
        for (int i = 0; i < crafting.length; i++) crafting[i] = ItemStack.copyItemStack(crafting[i]);
    if (currentCrafting instanceof VanillaStationCrafting) {
        boolean unset = false;
        if (player == null) {
            player = FakePlayer.get(entity);
            unset = true;
        }
        ItemStack craftOutput = (simulate ? output[4].copy() : output[4]);
        IInventory craftMatrix = new InventoryStacks(crafting);
        FMLCommonHandler.instance().firePlayerCraftingEvent(player, craftOutput, craftMatrix);
        new CustomSlotCrafting(player, craftOutput);
        if (unset) {
            FakePlayer.unset();
            player = null;
        }
    }
    ICraftingSource source = new CraftingSourceTileEntity(entity, player);
    currentCrafting.craft(source);
    IRecipeInput[] requiredInput = currentCrafting.getCraftRequirements();
    for (int i = 0; i < crafting.length; i++) if (crafting[i] != null)
        crafting[i] = craftSlot(crafting[i], requiredInput[i], player, simulate);
    boolean pulled = pullRequired(contents, crafting, requiredInput);
    if (!simulate) {
        int requiredExperience = currentCrafting.getRequiredExperience();
        if ((requiredExperience != 0) && (player != null) && !player.capabilities.isCreativeMode)
            player.experienceLevel -= requiredExperience;
        outputIsReal = !outputEmpty();
        progress = 0;
        inputChanged();
        checkHasRequirements = true;
    }
    return pulled;
}
Also used : VanillaStationCrafting(net.mcft.copy.betterstorage.item.recipe.VanillaStationCrafting) IInventory(net.minecraft.inventory.IInventory) ICraftingSource(net.mcft.copy.betterstorage.api.crafting.ICraftingSource) CraftingSourceTileEntity(net.mcft.copy.betterstorage.api.crafting.CraftingSourceTileEntity) IRecipeInput(net.mcft.copy.betterstorage.api.crafting.IRecipeInput) ItemStack(net.minecraft.item.ItemStack)

Example 77 with IInventory

use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.

the class ItemBackpack method openBackpack.

/** Opens the carrier's equipped backpack for the player.
	 *  Returns if it was successfully opened. */
public static boolean openBackpack(EntityPlayer player, EntityLivingBase carrier) {
    ItemStack backpack = ItemBackpack.getBackpack(carrier);
    if (backpack == null)
        return false;
    ItemBackpack backpackType = (ItemBackpack) backpack.getItem();
    IInventory inventory = ItemBackpack.getBackpackItems(carrier, player);
    inventory = new InventoryBackpackEquipped(carrier, player, inventory);
    if (!inventory.isUseableByPlayer(player))
        return false;
    int columns = backpackType.getBackpackColumns();
    int rows = backpackType.getBackpackRows();
    Container container = new ContainerBetterStorage(player, inventory, columns, rows);
    String title = StackUtils.get(backpack, "", "display", "Name");
    PlayerUtils.openGui(player, inventory.getInventoryName(), columns, rows, title, container);
    return true;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ContainerBetterStorage(net.mcft.copy.betterstorage.container.ContainerBetterStorage) Container(net.minecraft.inventory.Container) InventoryBackpackEquipped(net.mcft.copy.betterstorage.inventory.InventoryBackpackEquipped) ItemStack(net.minecraft.item.ItemStack)

Example 78 with IInventory

use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.

the class WorldUtils method syncPlayersUsing.

/** Counts and returns the number of players who're accessing a tile entity. */
public static int syncPlayersUsing(TileEntity te, int playersUsing, IInventory playerInventory) {
    if (!te.getWorldObj().isRemote && (playersUsing != 0)) {
        playersUsing = 0;
        List<EntityPlayer> players = te.getWorldObj().getEntitiesWithinAABB(EntityPlayer.class, getAABB(te, 5));
        for (EntityPlayer player : players) {
            if (player.openContainer instanceof ContainerBetterStorage) {
                IInventory inventory = ((ContainerBetterStorage) player.openContainer).inventory;
                if (inventory == playerInventory)
                    playersUsing++;
                else if (inventory instanceof InventoryTileEntity)
                    if (((InventoryTileEntity) inventory).mainTileEntity == te)
                        playersUsing++;
            }
        }
    }
    return playersUsing;
}
Also used : ContainerBetterStorage(net.mcft.copy.betterstorage.container.ContainerBetterStorage) IInventory(net.minecraft.inventory.IInventory) InventoryTileEntity(net.mcft.copy.betterstorage.inventory.InventoryTileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 79 with IInventory

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

the class GuiPneumaticContainerBase method drawGuiContainerForegroundLayer.

@Override
protected void drawGuiContainerForegroundLayer(int x, int y) {
    if (getInvNameOffset() != null && te instanceof IInventory) {
        IInventory inv = (IInventory) te;
        String containerName = inv.hasCustomInventoryName() ? inv.getInventoryName() : StatCollector.translateToLocal(inv.getInventoryName() + ".name");
        fontRendererObj.drawString(containerName, xSize / 2 - fontRendererObj.getStringWidth(containerName) / 2 + getInvNameOffset().x, 6 + getInvNameOffset().y, 4210752);
    }
    if (getInvTextOffset() != null)
        fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8 + getInvTextOffset().x, ySize - 94 + getInvTextOffset().y, 4210752);
}
Also used : IInventory(net.minecraft.inventory.IInventory)

Example 80 with IInventory

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

the class GuiPneumaticContainerBase method initGui.

@Override
public void initGui() {
    super.initGui();
    lastLeftStat = lastRightStat = null;
    if (shouldAddPressureTab() && te instanceof TileEntityPneumaticBase) {
        pressureStat = this.addAnimatedStat("gui.tab.pressure", new ItemStack(Blockss.pressureTube), 0xFF00AA00, false);
    }
    if (shouldAddProblemTab()) {
        problemTab = addAnimatedStat("gui.tab.problems", Textures.GUI_PROBLEMS_TEXTURE, 0xFFFF0000, false);
    }
    if (shouldAddRedstoneTab() && te instanceof IRedstoneControl) {
        redstoneTab = addAnimatedStat("gui.tab.redstoneBehaviour", new ItemStack(Items.redstone), 0xFFCC0000, true);
        List<String> curInfo = new ArrayList<String>();
        curInfo.add(I18n.format(getRedstoneString()));
        for (int i = 0; i < 3; i++) // create some space for the button
        curInfo.add("                                      ");
        redstoneTab.setTextWithoutCuttingString(curInfo);
        Rectangle buttonRect = redstoneTab.getButtonScaledRectangle(-170, 24, 170, 20);
        //getButtonFromRectangle(0, buttonRect, "-");
        redstoneButton = new GuiButtonSpecial(0, buttonRect.x, buttonRect.y, buttonRect.width, buttonRect.height, "-");
        redstoneTab.addWidget(redstoneButton);
    }
    if (te instanceof IInventory) {
        if (shouldAddInfoTab()) {
            String info = "gui.tab.info." + ((IInventory) te).getInventoryName();
            String translatedInfo = I18n.format(info);
            if (!translatedInfo.equals(info)) {
                addInfoTab(translatedInfo);
            }
        }
        if (te instanceof IHeatExchanger) {
            addAnimatedStat("gui.tab.info.heat.title", new ItemStack(Blocks.fire), 0xFFFF5500, false).setText("gui.tab.info.heat");
        }
        if (shouldAddUpgradeTab()) {
            String upgrades = "gui.tab.upgrades." + ((IInventory) te).getInventoryName();
            String translatedUpgrades = I18n.format(upgrades);
            List<String> upgradeText = new ArrayList<String>();
            if (te instanceof TileEntityPneumaticBase) {
                upgradeText.add("gui.tab.upgrades.volume");
                upgradeText.add("gui.tab.upgrades.security");
            }
            if (te instanceof IHeatExchanger) {
                upgradeText.add("gui.tab.upgrades.volumeCapacity");
            }
            if (!translatedUpgrades.equals(upgrades))
                upgradeText.add(upgrades);
            if (upgradeText.size() > 0)
                addAnimatedStat("gui.tab.upgrades", Textures.GUI_UPGRADES_LOCATION, 0xFF0000FF, true).setText(upgradeText);
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) IHeatExchanger(pneumaticCraft.api.tileentity.IHeatExchanger) IRedstoneControl(pneumaticCraft.common.tileentity.IRedstoneControl) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) ItemStack(net.minecraft.item.ItemStack) Point(java.awt.Point) TileEntityPneumaticBase(pneumaticCraft.common.tileentity.TileEntityPneumaticBase)

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