Package appeng.util.inv

Examples of appeng.util.inv.AdaptorPlayerHand


  {
    if ( packetPatternSlot.slotItem != null && cellInv != null )
    {
      IAEItemStack out = packetPatternSlot.slotItem.copy();

      InventoryAdaptor inv = new AdaptorPlayerHand( getPlayerInv().player );
      InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( getPlayerInv().player, ForgeDirection.UNKNOWN );
      if ( packetPatternSlot.shift )
        inv = playerInv;

      if ( inv.simulateAdd( out.getItemStack() ) != null )
        return;

      IAEItemStack extracted = Platform.poweredExtraction( powerSrc, cellInv, out, mySrc );
      EntityPlayer p = getPlayerInv().player;

      if ( extracted != null )
      {
        inv.addItems( extracted.getItemStack() );
        if ( p instanceof EntityPlayerMP )
          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
View Full Code Here


    if ( inv != null )
    {
      ItemStack is = inv.server.getStackInSlot( slot );
      boolean hasItemInHand = player.inventory.getItemStack() != null;

      InventoryAdaptor playerHand = new AdaptorPlayerHand( player );

      WrapperInvSlot slotInv = new PatternInvSlot( inv.server );

      IInventory theSlot = slotInv.getWrapper( slot );
      InventoryAdaptor interfaceSlot = new AdaptorIInventory( theSlot );

      switch (action)
      {
      case PICKUP_OR_SET_DOWN:

        if ( hasItemInHand )
        {
          ItemStack inSlot = theSlot.getStackInSlot( 0 );
          if ( inSlot == null )
            player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) );
          else
          {
            inSlot = inSlot.copy();
            ItemStack inHand = player.inventory.getItemStack().copy();

            theSlot.setInventorySlotContents( 0, null );
            player.inventory.setItemStack( null );

            player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) );

            if ( player.inventory.getItemStack() == null )
              player.inventory.setItemStack( inSlot );
            else
            {
              player.inventory.setItemStack( inHand );
              theSlot.setInventorySlotContents( 0, inSlot );
            }
          }
        }
        else
        {
          IInventory mySlot = slotInv.getWrapper( slot );
          mySlot.setInventorySlotContents( 0, playerHand.addItems( mySlot.getStackInSlot( 0 ) ) );
        }

        break;
      case SPLIT_OR_PLACE_SINGLE:

        if ( hasItemInHand )
        {
          ItemStack extra = playerHand.removeItems( 1, null, null );
          if ( extra != null )
            extra = interfaceSlot.addItems( extra );
          if ( extra != null )
            playerHand.addItems( extra );
        }
        else if ( is != null )
        {
          ItemStack extra = interfaceSlot.removeItems( (is.stackSize + 1) / 2, null, null );
          if ( extra != null )
            extra = playerHand.addItems( extra );
          if ( extra != null )
            interfaceSlot.addItems( extra );
        }

        break;
View Full Code Here

        IAEItemStack extracted = ais.copy();

        ais = Platform.poweredInsert( powerSrc, cellInv, ais, mySrc );
        if ( ais == null )
        {
          InventoryAdaptor ia = new AdaptorPlayerHand( player );

          ItemStack fail = ia.removeItems( 1, extracted.getItemStack(), null );
          if ( fail == null )
            cellInv.extractItems( extracted, Actionable.MODULATE, mySrc );

          updateHeld( player );
        }
      }

      break;
    case ROLL_UP:
    case PICKUP_SINGLE:
      if ( powerSrc == null || cellInv == null )
        return;

      if ( slotItem != null )
      {
        int liftQty = 1;
        ItemStack item = player.inventory.getItemStack();

        if ( item != null )
        {
          if ( item.stackSize >= item.getMaxStackSize() )
            liftQty = 0;
          if ( !Platform.isSameItemPrecise( slotItem.getItemStack(), item ) )
            liftQty = 0;
        }

        if ( liftQty > 0 )
        {
          IAEItemStack ais = slotItem.copy();
          ais.setStackSize( 1 );
          ais = Platform.poweredExtraction( powerSrc, cellInv, ais, mySrc );
          if ( ais != null )
          {
            InventoryAdaptor ia = new AdaptorPlayerHand( player );

            ItemStack fail = ia.addItems( ais.getItemStack() );
            if ( fail != null )
              cellInv.injectItems( ais, Actionable.MODULATE, mySrc );

            updateHeld( player );
          }
View Full Code Here

      ia = InventoryAdaptor.getAdaptor( who, null );
      maxTimesToCraft = ( int ) Math.floor( ( double ) getStack().getMaxStackSize() / ( double ) howManyPerCraft );
    }
    else if ( action == InventoryAction.CRAFT_STACK ) // craft into hand, full stack
    {
      ia = new AdaptorPlayerHand( who );
      maxTimesToCraft = ( int ) Math.floor( ( double ) getStack().getMaxStackSize() / ( double ) howManyPerCraft );
    }
    else
    // pick up what was crafted...
    {
      ia = new AdaptorPlayerHand( who );
      maxTimesToCraft = 1;
    }

    maxTimesToCraft = CapCraftingAttempts( maxTimesToCraft );
View Full Code Here

TOP

Related Classes of appeng.util.inv.AdaptorPlayerHand

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.