@Override public ItemStack getStackInSlot( final int var1 ) { if( this.inv[var1] == null ) { return ItemStack.EMPTY; } return this.inv[var1].createItemStack(); }
public ItemStack getItemStack() { return this.itemStack .isEmpty() ? ( this.aeItemStack == null ? ItemStack.EMPTY : ( this.itemStack = this.aeItemStack.createItemStack() ) ) : this.itemStack; }
@Override public ItemStack addItems( final ItemStack toBeAdded ) { final IAEItemStack in = AEItemStack.fromItemStack( toBeAdded ); if( in != null ) { final IAEItemStack out = this.target.injectItems( in, Actionable.MODULATE, this.src ); if( out != null ) { return out.createItemStack(); } } return ItemStack.EMPTY; }
@Override public ItemStack simulateAdd( final ItemStack toBeSimulated ) { final IAEItemStack in = AEItemStack.fromItemStack( toBeSimulated ); if( in != null ) { final IAEItemStack out = this.target.injectItems( in, Actionable.SIMULATE, this.src ); if( out != null ) { return out.createItemStack(); } } return ItemStack.EMPTY; }
public ItemStack getOutput( final ItemStack item ) { ItemStack out = SIMPLE_CACHE.get( item ); if( out != null ) { return out; } final World w = AppEng.proxy.getWorld(); if( w == null ) { return ItemStack.EMPTY; } final ICraftingPatternDetails details = this.getPatternForItem( item, w ); out = details != null ? details.getOutputs()[0].createItemStack() : ItemStack.EMPTY; SIMPLE_CACHE.put( item, out ); return out; } }
@Override public void clientPacketData( final INetworkInfo network, final AppEngPacket packet, final EntityPlayer player ) { if( this.action == InventoryAction.UPDATE_HAND ) { if( this.slotItem == null ) { AppEng.proxy.getPlayers().get( 0 ).inventory.setItemStack( ItemStack.EMPTY ); } else { AppEng.proxy.getPlayers().get( 0 ).inventory.setItemStack( this.slotItem.createItemStack() ); } } } }
@Override public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops ) { if( !ItemHandlerUtil.isEmpty( this.getConfigSlot() ) ) { drops.add( this.getConfigSlot().getStackInSlot( 0 ) ); } for( final IAEItemStack ais : this.inventory.getStoredItems() ) { drops.add( ais.createItemStack() ); } }
@Override public ItemStack getOutput( final InventoryCrafting craftingInv, final World w ) { if( !this.isCrafting ) { throw new IllegalStateException( "Only crafting recipes supported." ); } for( int x = 0; x < craftingInv.getSizeInventory(); x++ ) { if( !this.isValidItemForSlot( x, craftingInv.getStackInSlot( x ), w ) ) { return ItemStack.EMPTY; } } if( this.outputs != null && this.outputs.length > 0 ) { return this.outputs[0].createItemStack(); } return ItemStack.EMPTY; }
public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack acquired, final Actionable mode ) { final int slot = this.craftingTracker.getSlot( link ); if( acquired != null && slot >= 0 && slot <= this.requireWork.length ) { final InventoryAdaptor adaptor = this.getAdaptor( slot ); if( mode == Actionable.SIMULATE ) { return AEItemStack.fromItemStack( adaptor.simulateAdd( acquired.createItemStack() ) ); } else { final IAEItemStack is = AEItemStack.fromItemStack( adaptor.addItems( acquired.createItemStack() ) ); this.updatePlan( slot ); return is; } } return acquired; }
@Override protected boolean readFromStream( final ByteBuf data ) throws IOException { final boolean c = super.readFromStream( data ); try { final IAEItemStack item = AEItemStack.fromPacket( data ); final ItemStack is = item.createItemStack(); this.inv.setStackInSlot( 0, is ); } catch( final Throwable t ) { this.inv.setStackInSlot( 0, ItemStack.EMPTY ); } return c; // TESR doesn't need updates! }
private ItemStack doRemoveItemsFuzzy( final int amount, final ItemStack filter, final IInventoryDestination destination, final Actionable type, final FuzzyMode fuzzyMode ) { final IAEItemStack reqFilter = AEItemStack.fromItemStack( filter ); if( reqFilter == null ) { return ItemStack.EMPTY; } IAEItemStack out = null; for( final IAEItemStack req : ImmutableList.copyOf( this.getList().findFuzzy( reqFilter, fuzzyMode ) ) ) { if( req != null ) { req.setStackSize( amount ); out = this.target.extractItems( req, type, this.src ); if( out != null ) { return out.createItemStack(); } } } return ItemStack.EMPTY; }
@Override public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src ) { ItemStack out = ItemStack.EMPTY; if( type == Actionable.SIMULATE ) { out = this.adaptor.simulateAdd( input.createItemStack() ); } else { out = this.adaptor.addItems( input.createItemStack() ); } if( type == Actionable.MODULATE ) { this.onTick(); } if( out.isEmpty() ) { return null; } // better then doing construction from scratch :3 final IAEItemStack o = input.copy(); o.setStackSize( out.getCount() ); return o; }
@Override public boolean isBlackListed( final ItemStack cellItem, final IAEItemStack requestedAddition ) { final float pen = AEApi.instance().registries().matterCannon().getPenetration( requestedAddition.createItemStack() ); if( pen > 0 ) { return false; } if( requestedAddition.getItem() instanceof ItemPaintBall ) { return false; } return true; }
@Override public void readPermissions( final Map<Integer, EnumSet<SecurityPermissions>> playerPerms ) { final IPlayerRegistry pr = AEApi.instance().registries().players(); // read permissions for( final IAEItemStack ais : this.inventory.getStoredItems() ) { final ItemStack is = ais.createItemStack(); final Item i = is.getItem(); if( i instanceof IBiometricCard ) { final IBiometricCard bc = (IBiometricCard) i; bc.registerPermissions( new PlayerSecurityWrapper( playerPerms ), pr, is ); } } // make sure thea admin is Boss. playerPerms.put( this.getProxy().getNode().getPlayerID(), EnumSet.allOf( SecurityPermissions.class ) ); }
@Override public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack items, final Actionable mode ) { final InventoryAdaptor d = this.getHandler(); try { if( d != null && this.getProxy().isActive() ) { final IEnergyGrid energy = this.getProxy().getEnergy(); final double power = items.getStackSize(); if( energy.extractAEPower( power, mode, PowerMultiplier.CONFIG ) > power - 0.01 ) { if( mode == Actionable.MODULATE ) { return AEItemStack.fromItemStack( d.addItems( items.createItemStack() ) ); } return AEItemStack.fromItemStack( d.simulateAdd( items.createItemStack() ) ); } } } catch( final GridAccessException e ) { AELog.debug( e ); } return items; }
private void pushItemIntoTarget( final InventoryAdaptor d, final IEnergyGrid energy, final IMEInventory<IAEItemStack> inv, IAEItemStack ais ) { final ItemStack is = ais.createItemStack(); is.setCount( (int) this.itemToSend ); final ItemStack o = d.simulateAdd( is ); final long canFit = o.isEmpty() ? this.itemToSend : this.itemToSend - o.getCount(); if( canFit > 0 ) { ais = ais.copy(); ais.setStackSize( canFit ); final IAEItemStack itemsToAdd = Platform.poweredExtraction( energy, inv, ais, this.mySrc ); if( itemsToAdd != null ) { this.itemToSend -= itemsToAdd.getStackSize(); final ItemStack failed = d.addItems( itemsToAdd.createItemStack() ); if( !failed.isEmpty() ) { ais.setStackSize( failed.getCount() ); inv.injectItems( ais, Actionable.MODULATE, this.mySrc ); } else { this.didSomething = true; } } } }
private ItemStack shiftStoreItem( final ItemStack input ) { if( this.getPowerSource() == null || this.getCellInventory() == null ) { return input; } final IAEItemStack ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( input ), this.getActionSource() ); if( ais == null ) { return ItemStack.EMPTY; } return ais.createItemStack(); }
@Override public NBTTagCompound writeToNBT( final NBTTagCompound data ) { super.writeToNBT( data ); this.cm.writeToNBT( data ); data.setByte( "paintedColor", (byte) this.paintedColor.ordinal() ); data.setLong( "securityKey", this.securityKey ); this.getConfigSlot().writeToNBT( data, "config" ); final NBTTagCompound storedItems = new NBTTagCompound(); int offset = 0; for( final IAEItemStack ais : this.inventory.getStoredItems() ) { final NBTTagCompound it = new NBTTagCompound(); ais.createItemStack().writeToNBT( it ); storedItems.setTag( String.valueOf( offset ), it ); offset++; } data.setTag( "storedItems", storedItems ); return data; }
@Override public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src ) { if( this.hasPermission( src ) ) { if( AEApi.instance().definitions().items().biometricCard().isSameAs( input.createItemStack() ) ) { if( this.canAccept( input ) ) { if( type == Actionable.SIMULATE ) { return null; } this.getStoredItems().add( input ); this.securityTile.inventoryChanged(); return null; } } } return input; }
private void tryToStoreContents() { if( !ItemHandlerUtil.isEmpty( this.inputInventory ) ) { this.updateHandler(); if( this.cellHandler != null && this.cellHandler.getChannel() == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) { final IAEItemStack returns = Platform.poweredInsert( this, this.cellHandler, AEItemStack.fromItemStack( this.inputInventory.getStackInSlot( 0 ) ), this.mySrc ); if( returns == null ) { this.inputInventory.setStackInSlot( 0, ItemStack.EMPTY ); } else { this.inputInventory.setStackInSlot( 0, returns.createItemStack() ); } } } }