Package net.minecraft.inventory

Examples of net.minecraft.inventory.InventoryCrafting


       
        // 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);
          }
        }
View Full Code Here


  @Override
  public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    if (!tileRollingMachineClass.isInstance(tile))
      return false;

    InventoryCrafting craftMatrix = getCraftMatrix(tile);
    if (craftMatrix == null)
      return false;

    ItemStack result = getResult(craftMatrix, tile.getWorldObj());

    if (result == null)
      return false;

    inventory.setInventorySlotContents(9, result);

    // Import
    for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
      if (i >= inventory.getSizeInventory() - 2) {
        break;
      }
      final ItemStack newStack = craftMatrix.getStackInSlot(i) == null ? null : craftMatrix.getStackInSlot(i).copy();
      inventory.setInventorySlotContents(i, newStack);
    }

    inventory.compact_first(9);
   
View Full Code Here

    getAndUpdateOutput();
  }

  public ItemStack getAndUpdateOutput()
  {
    InventoryCrafting ic = new InventoryCrafting( this, 3, 3 );
    for (int x = 0; x < ic.getSizeInventory(); x++)
      ic.setInventorySlotContents( x, crafting.getStackInSlot( x ) );

    ItemStack is = CraftingManager.getInstance().findMatchingRecipe( ic, this.getPlayerInv().player.worldObj );
    cOut.setInventorySlotContents( 0, is );
    return is;
  }
View Full Code Here

          updateHeld( (EntityPlayerMP) p );
        detectAndSendChanges();
        return;
      }

      InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
      InventoryCrafting real = new InventoryCrafting( new ContainerNull(), 3, 3 );
      for (int x = 0; x < 9; x++)
      {
        ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? null : packetPatternSlot.pattern[x].getItemStack() );
      }

      IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj );

      if ( r == null )
        return;

      IMEMonitor<IAEItemStack> storage = ct.getItemInventory();
      IItemList<IAEItemStack> all = storage.getStorageList();

      ItemStack is = r.getCraftingResult( ic );

      for (int x = 0; x < ic.getSizeInventory(); x++)
      {
        if ( ic.getStackInSlot( x ) != null )
        {
          ItemStack pulled = Platform.extractItemsByRecipe( powerSrc, mySrc, storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all,
              Actionable.MODULATE, ItemViewCell.createFilter( getViewCells() ) );
          real.setInventorySlotContents( x, pulled );
        }
      }

      IRecipe rr = Platform.findMatchingRecipe( real, p.worldObj );

      if ( rr == r && Platform.isSameItemPrecise( rr.getCraftingResult( real ), is ) )
      {
        SlotCrafting sc = new SlotCrafting( p, real, cOut, 0, 0, 0 );
        sc.onPickupFromSlot( p, is );

        for (int x = 0; x < real.getSizeInventory(); x++)
        {
          ItemStack failed = playerInv.addItems( real.getStackInSlot( x ) );
          if ( failed != null )
            p.dropPlayerItemWithRandomChoice( failed, false );
        }

        inv.addItems( is );
        if ( p instanceof EntityPlayerMP )
          updateHeld( (EntityPlayerMP) p );
        detectAndSendChanges();
      }
      else
      {
        for (int x = 0; x < real.getSizeInventory(); x++)
        {
          ItemStack failed = real.getStackInSlot( x );
          if ( failed != null )
          {
            cellInv.injectItems( AEItemStack.create( failed ), Actionable.MODULATE, new MachineSource( ct ) );
          }
        }
View Full Code Here

  {
    job.handlePausing();

    if ( fullSimulation )
    {
      InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );

      for (Entry<CraftingTreeNode, Long> entry : nodes.entrySet())
      {
        IAEItemStack item = entry.getKey().getStack( entry.getValue() );
        IAEItemStack stack = entry.getKey().request( inv, item.getStackSize(), src );

        ic.setInventorySlotContents( entry.getKey().slot, stack.getItemStack() );
      }

      FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic );

      for (int x = 0; x < ic.getSizeInventory(); x++)
      {
        ItemStack is = ic.getStackInSlot( x );
        is = Platform.getContainerItem( is );

        IAEItemStack o = AEApi.instance().storage().createItemStack( is );
        if ( o != null )
        {
View Full Code Here

    if ( details.isCraftable() )
    {
      IAEItemStack list[] = details.getInputs();

      InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
      IAEItemStack[] is = details.getInputs();
      for (int x = 0; x < ic.getSizeInventory(); x++)
        ic.setInventorySlotContents( x, is[x] == null ? null : is[x].getItemStack() );

      FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) world ), details.getOutput( ic, world ), ic );

      for (int x = 0; x < ic.getSizeInventory(); x++)
      {
        ItemStack g = ic.getStackInSlot( x );
        if ( g != null && g.stackSize > 1 )
          fullSimulation = true;
      }

      for ( IAEItemStack part : details.getCondensedInputs() )
View Full Code Here

   */
  @Override
  public void onCraftMatrixChanged(IInventory par1IInventory)
  {
    ContainerNull cn = new ContainerNull();
    InventoryCrafting ic = new InventoryCrafting( cn, 3, 3 );

    for (int x = 0; x < 9; x++)
      ic.setInventorySlotContents( x, craftingSlots[x].getStack() );

    outputSlot.putStack( CraftingManager.getInstance().findMatchingRecipe( ic, getPlayerInv().player.worldObj ) );
  }
View Full Code Here

      ItemStack[] set = new ItemStack[pattern.getSizeInventory()];

      // add one of each item to the items on the board...
      if ( Platform.isServer() )
      {
        InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
        for ( int x = 0; x < 9; x++ )
          ic.setInventorySlotContents( x, pattern.getStackInSlot( x ) );

        IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj );

        if ( r == null )
        {
          Item target = request.getItem();
          if ( target.isDamageable() && target.isRepairable() )
          {
            boolean isBad = false;
            for ( int x = 0; x < ic.getSizeInventory(); x++ )
            {
              ItemStack pis = ic.getStackInSlot( x );
              if ( pis == null )
                continue;
              if ( pis.getItem() != target )
                isBad = true;
            }
            if ( !isBad )
            {
              super.onPickupFromSlot( p, is );
              // actually necessary to cleanup this case...
              p.openContainer.onCraftMatrixChanged( getCraftingMatrix() );
              return request;
            }
          }
          return null;
        }

        is = r.getCraftingResult( ic );

        if ( inv != null )
        {
          for ( int x = 0; x < pattern.getSizeInventory(); x++ )
          {
            if ( pattern.getStackInSlot( x ) != null )
            {
              set[x] = Platform.extractItemsByRecipe( energySrc, mySrc, inv, p.worldObj, r, is, ic, pattern.getStackInSlot( x ), x, all,
                  Actionable.MODULATE, ItemViewCell.createFilter( container.getViewCells() ) );
              ic.setInventorySlotContents( x, set[x] );
            }
          }
        }
      }
View Full Code Here

        Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE;

        if ( inv != null && recipe != null && security != null )
        {
          InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
          for (int x = 0; x < 9; x++)
          {
            if ( recipe[x] != null && recipe[x].length > 0 )
            {
              ic.setInventorySlotContents( x, recipe[x][0] );
            }
          }

          IRecipe r = Platform.findMatchingRecipe( ic, pmp.worldObj );

          if ( r != null && security.hasPermission( player, SecurityPermissions.EXTRACT ) )
          {
            ItemStack is = r.getCraftingResult( ic );

            if ( is != null )
            {
              IMEMonitor<IAEItemStack> storage = inv.getItemInventory();
              IItemList all = storage.getStorageList();
              IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter( cct.getViewCells() );

              for (int x = 0; x < craftMatrix.getSizeInventory(); x++)
              {
                ItemStack PatternItem = ic.getStackInSlot( x );

                ItemStack currentItem = craftMatrix.getStackInSlot( x );
                if ( currentItem != null )
                {
                  ic.setInventorySlotContents( x, currentItem );
                  ItemStack newItemStack = r.matches( ic, pmp.worldObj ) ? r.getCraftingResult( ic ) : null;
                  ic.setInventorySlotContents( x, PatternItem );

                  if ( newItemStack == null || !Platform.isSameItemPrecise( newItemStack, is ) )
                  {
                    IAEItemStack in = AEItemStack.create( currentItem );
                    if ( in != null )
View Full Code Here

      }

      ICraftingPatternDetails details = e.getKey();
      if ( canCraft( details, details.getCondensedInputs() ) )
      {
        InventoryCrafting ic = null;

        for (ICraftingMedium m : cc.getMediums( e.getKey() ))
        {
          if ( e.getValue().value <= 0 )
            continue;

          if ( !m.isBusy() )
          {
            if ( ic == null )
            {
              IAEItemStack[] input = details.getInputs();

              double sum = 0;
              for (IAEItemStack anInput : input)
              {
                if ( anInput != null )
                {
                  sum += anInput.getStackSize();
                }
              }

              // power...
              if ( eg.extractAEPower( sum, Actionable.MODULATE, PowerMultiplier.CONFIG ) < sum - 0.01 )
                continue;

              ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
              boolean found = false;

              for (int x = 0; x < input.length; x++)
              {

                if ( input[x] != null )
                {
                  found = false;
                  if ( details.isCraftable() )
                  {
                    for (IAEItemStack fuzz : inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL ))
                    {
                      fuzz = fuzz.copy();
                      fuzz.setStackSize( input[x].getStackSize() );

                      if ( details.isValidItemForSlot( x, fuzz.getItemStack(), getWorld() ) )
                      {
                        IAEItemStack ais = inventory.extractItems( fuzz, Actionable.MODULATE, machineSrc );
                        ItemStack is = ais == null ? null : ais.getItemStack();

                        if ( is != null )
                        {
                          postChange( AEItemStack.create( is ), machineSrc );
                          ic.setInventorySlotContents( x, is );
                          found = true;
                          break;
                        }
                      }
                    }
                  }
                  else
                  {
                    IAEItemStack ais = inventory.extractItems( input[x].copy(), Actionable.MODULATE, machineSrc );
                    ItemStack is = ais == null ? null : ais.getItemStack();

                    if ( is != null )
                    {
                      postChange( input[x], machineSrc );
                      ic.setInventorySlotContents( x, is );
                      if ( is.stackSize == input[x].getStackSize() )
                      {
                        found = true;
                        continue;
                      }
                    }
                  }

                  if ( !found )
                    break;
                }

              }

              if ( !found )
              {
                // put stuff back..
                for (int x = 0; x < ic.getSizeInventory(); x++)
                {
                  ItemStack is = ic.getStackInSlot( x );
                  if ( is != null )
                    inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, machineSrc );
                }
                ic = null;
                break;
              }
            }

            if ( m.pushPattern( details, ic ) )
            {
              somethingChanged = true;
              remainingOperations--;

              for (IAEItemStack out : details.getCondensedOutputs())
              {
                postChange( out, machineSrc );
                waitingFor.add( out.copy() );
                postCraftingStatusChange( out.copy() );
              }

              if ( details.isCraftable() )
              {
                FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) getWorld() ),
                    details.getOutput( ic, getWorld() ), ic );

                for (int x = 0; x < ic.getSizeInventory(); x++)
                {
                  ItemStack output = Platform.getContainerItem( ic.getStackInSlot( x ) );
                  if ( output != null )
                  {
                    IAEItemStack cItem = AEItemStack.create( output );
                    postChange( cItem, machineSrc );
                    waitingFor.add( cItem );
                    postCraftingStatusChange( cItem );
                  }
                }
              }

              ic = null; // hand off complete!
              markDirty();

              e.getValue().value--;
              if ( e.getValue().value <= 0 )
                continue;

              if ( remainingOperations == 0 )
                return;
            }
          }
        }

        if ( ic != null )
        {
          // put stuff back..
          for (int x = 0; x < ic.getSizeInventory(); x++)
          {
            ItemStack is = ic.getStackInSlot( x );
            if ( is != null )
            {
              inventory.injectItems( AEItemStack.create( is ), Actionable.MODULATE, machineSrc );
            }
          }
View Full Code Here

TOP

Related Classes of net.minecraft.inventory.InventoryCrafting

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.