private final boolean equalsSlot( int slot ) { final IAEFluidStack stackA = this.inv.getFluidInSlot( slot ); final IAEFluidStack stackB = this.cache.getFluidInSlot( slot ); if( !Objects.equals( stackA, stackB ) ) { return false; } return stackA == null || stackA.getStackSize() == stackB.getStackSize(); } }
public FluidStack drain( final int slot, final int maxDrain, boolean doDrain ) { final IAEFluidStack fluid = this.fluids[slot]; if( fluid == null || maxDrain <= 0 ) { return null; } int drained = maxDrain; if( fluid.getStackSize() < drained ) { drained = (int) fluid.getStackSize(); } FluidStack stack = new FluidStack( fluid.getFluid(), drained ); if( doDrain ) { fluid.setStackSize( fluid.getStackSize() - drained ); if( fluid.getStackSize() <= 0 ) { this.fluids[slot] = null; } this.onContentChanged( slot ); } return stack; }
@Override public String getMessage() { final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot ); if( fluid != null && fluid.getStackSize() > 0 ) { String desc = fluid.getFluid().getLocalizedName( fluid.getFluidStack() ); String amountToText = fluid.getStackSize() + "mB"; return desc + "\n" + amountToText; } return null; }
private void handleFluidChanged( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes ) { // Completely different fluid this.cachedAeStacks[slot] = AEFluidStack.fromFluidStack( newFS ); // If we had a stack previously in this slot, notify the network about its disappearance if( oldAeFS != null ) { oldAeFS.setStackSize( -oldAeFS.getStackSize() ); changes.add( oldAeFS ); } // Notify the network about the new stack. Note that this is null if newFS was null if( this.cachedAeStacks[slot] != null ) { changes.add( this.cachedAeStacks[slot] ); } } }
@Override public void setFluidInSlot( final int slot, final IAEFluidStack fluid ) { if( slot >= 0 && slot < this.getSlots() ) { if( Objects.equals( this.fluids[slot], fluid ) ) { if( fluid != null && fluid.getStackSize() != this.fluids[slot].getStackSize() ) { this.fluids[slot].setStackSize( Math.min( fluid.getStackSize(), this.capacity ) ); this.onContentChanged( slot ); } } else { if( fluid == null ) { this.fluids[slot] = null; } else { this.fluids[slot] = fluid.copy(); this.fluids[slot].setStackSize( Math.min( fluid.getStackSize(), this.capacity ) ); } this.onContentChanged( slot ); } } }
amountToStore -= fluid.getStackSize(); fluid.setStackSize( fluid.getStackSize() + amountToStore ); this.onContentChanged( slot );
final IAEFluidStack stored = this.tanks.getFluidInSlot( slot ); if( req == null && ( stored != null && stored.getStackSize() > 0 ) ) this.requireWork[slot] = work.setStackSize( -work.getStackSize() ); return; if( stored == null || stored.getStackSize() == 0 ) // need to add stuff! if( stored.getStackSize() < TANK_CAPACITY ) this.requireWork[slot].setStackSize( TANK_CAPACITY - stored.getStackSize() ); return; this.requireWork[slot] = work.setStackSize( -work.getStackSize() ); return;
private void handleStackSizeChanged( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes ) { // Still the same fluid, but amount might have changed final long diff = newFS.amount - oldAeFS.getStackSize(); if( diff != 0 ) { final IAEFluidStack stack = oldAeFS.copy(); stack.setStackSize( newFS.amount ); this.cachedAeStacks[slot] = stack; final IAEFluidStack a = stack.copy(); a.setStackSize( diff ); changes.add( a ); } }
private void updateReportingValue( final IMEMonitor<IAEFluidStack> monitor ) { final IAEFluidStack myStack = this.config.getFluidInSlot( 0 ); if( myStack == null ) { this.lastReportedValue = 0; for( final IAEFluidStack st : monitor.getStorageList() ) { this.lastReportedValue += st.getStackSize(); } } else { final IAEFluidStack r = monitor.getStorageList().findPrecise( myStack ); if( r == null ) { this.lastReportedValue = 0; } else { this.lastReportedValue = r.getStackSize(); } } this.updateState(); }
a.setStackSize( -a.getStackSize() ); changes.add( a );
@Override public IAEFluidStack injectItems( final IAEFluidStack input, final Actionable type, final IActionSource src ) { final int filled = this.handler.fill( input.getFluidStack(), type == Actionable.MODULATE ); if( filled == 0 ) { return input.copy(); } if( type == Actionable.MODULATE ) { this.onTick(); } if( filled == input.getStackSize() ) { return null; } final IAEFluidStack o = input.copy(); o.setStackSize( input.getStackSize() - filled ); return o; }
@Override public void addStorage( final IAEFluidStack option ) { if( option == null ) { return; } final IAEFluidStack st = this.getFluidRecord( option ); if( st != null ) { st.incStackSize( option.getStackSize() ); return; } final IAEFluidStack opt = option.copy(); this.putFluidRecord( opt ); }
@Override protected void renderHoveredToolTip( int mouseX, int mouseY ) { final Slot slot = this.getSlot( mouseX, mouseY ); if( slot != null && slot instanceof IMEFluidSlot && slot.isEnabled() ) { final IMEFluidSlot fluidSlot = (IMEFluidSlot) slot; if( fluidSlot.getAEFluidStack() != null && fluidSlot.shouldRenderAsFluid() ) { final IAEFluidStack fluidStack = fluidSlot.getAEFluidStack(); final String formattedAmount = NumberFormat.getNumberInstance( Locale.US ).format( fluidStack.getStackSize() / 1000.0 ) + " B"; final String modName = "" + TextFormatting.BLUE + TextFormatting.ITALIC + Loader.instance() .getIndexedModList() .get( Platform.getModId( fluidStack ) ) .getName(); final List<String> list = new ArrayList<>(); list.add( fluidStack.getFluidStack().getLocalizedName() ); list.add( formattedAmount ); list.add( modName ); this.drawHoveringText( list, mouseX, mouseY ); return; } } super.renderHoveredToolTip( mouseX, mouseY ); }
@Override public void add( final IAEFluidStack option ) { if( option == null ) { return; } this.incStackSize( option.getStackSize() ); this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() ); this.setCraftable( this.isCraftable() || option.isCraftable() ); }
@Override public int fill( final FluidStack resource, final boolean doFill ) { TileChest.this.updateHandler(); if( TileChest.this.cellHandler != null && TileChest.this.cellHandler .getChannel() == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ) { final IAEFluidStack results = Platform.poweredInsert( TileChest.this, TileChest.this.cellHandler, AEFluidStack.fromFluidStack( resource ), TileChest.this.mySrc, doFill ? Actionable.MODULATE : Actionable.SIMULATE ); if( results == null ) { return resource.amount; } return resource.amount - (int) results.getStackSize(); } return 0; }
@Override public IAEFluidStack injectItems( IAEFluidStack input, Actionable type, IActionSource src ) if( this.blocked || input == null || input.getStackSize() < Fluid.BUCKET_VOLUME ) ret.setStackSize( input.getStackSize() - Fluid.BUCKET_VOLUME ); return ret.getStackSize() == 0 ? null : ret;
private boolean storeFluid( IAEFluidStack stack, boolean modulate ) { try { final IStorageGrid storage = this.getProxy().getStorage(); final IMEInventory<IAEFluidStack> inv = storage.getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ); if( modulate ) { final IEnergyGrid energy = this.getProxy().getEnergy(); return Platform.poweredInsert( energy, inv, stack, this.mySrc ) == null; } else { final float requiredPower = stack.getStackSize() / Math.min( 1.0f, stack.getChannel().transferFactor() ); final IEnergyGrid energy = this.getProxy().getEnergy(); if( energy.extractAEPower( requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG ) < requiredPower ) { return false; } final IAEFluidStack leftOver = inv.injectItems( stack, Actionable.SIMULATE, this.mySrc ); return leftOver == null || leftOver.getStackSize() == 0; } } catch( final GridAccessException e ) { // :P } return false; }
@Override protected void handleMouseClick( Slot slot, int slotIdx, int mouseButton, ClickType clickType ) { if( slot instanceof SlotFluidME ) { final SlotFluidME meSlot = (SlotFluidME) slot; if( clickType == ClickType.PICKUP ) { // TODO: Allow more options if( mouseButton == 0 && meSlot.getHasStack() ) { this.container.setTargetStack( meSlot.getAEFluidStack() ); AELog.debug( "mouse0 GUI STACK SIZE %s", meSlot.getAEFluidStack().getStackSize() ); NetworkHandler.instance().sendToServer( new PacketInventoryAction( InventoryAction.FILL_ITEM, slot.slotNumber, 0 ) ); } else { this.container.setTargetStack( meSlot.getAEFluidStack() ); if( meSlot.getAEFluidStack() != null ) { AELog.debug( "mouse1 GUI STACK SIZE %s", meSlot.getAEFluidStack().getStackSize() ); } NetworkHandler.instance().sendToServer( new PacketInventoryAction( InventoryAction.EMPTY_ITEM, slot.slotNumber, 0 ) ); } } return; } super.handleMouseClick( slot, slotIdx, mouseButton, clickType ); }
public void renderStackSize( FontRenderer fontRenderer, IAEFluidStack aeStack, int xPos, int yPos ) { if( aeStack != null ) { final float scaleFactor = AEConfig.instance().useTerminalUseLargeFont() ? 0.85f : 0.5f; final float inverseScaleFactor = 1.0f / scaleFactor; final int offset = AEConfig.instance().useTerminalUseLargeFont() ? 0 : -1; final boolean unicodeFlag = fontRenderer.getUnicodeFlag(); fontRenderer.setUnicodeFlag( false ); if( aeStack.getStackSize() > 0 ) { final String stackSize = this.getToBeRenderedStackSize( aeStack.getStackSize() ); GlStateManager.disableLighting(); GlStateManager.disableDepth(); GlStateManager.disableBlend(); GlStateManager.pushMatrix(); GlStateManager.scale( scaleFactor, scaleFactor, scaleFactor ); final int X = (int) ( ( (float) xPos + offset + 16.0f - fontRenderer.getStringWidth( stackSize ) * scaleFactor ) * inverseScaleFactor ); final int Y = (int) ( ( (float) yPos + offset + 16.0f - 7.0f * scaleFactor ) * inverseScaleFactor ); fontRenderer.drawStringWithShadow( stackSize, X, Y, 16777215 ); GlStateManager.popMatrix(); GlStateManager.enableLighting(); GlStateManager.enableDepth(); GlStateManager.enableBlend(); } fontRenderer.setUnicodeFlag( unicodeFlag ); } }
@Override public void drawButton( final Minecraft mc, final int mouseX, final int mouseY, final float partialTicks ) { if( this.visible ) { GlStateManager.disableBlend(); GlStateManager.disableLighting(); drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 ); final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot ); if( fluid != null && fluid.getStackSize() > 0 ) { mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE ); float red = ( fluid.getFluid().getColor() >> 16 & 255 ) / 255.0F; float green = ( fluid.getFluid().getColor() >> 8 & 255 ) / 255.0F; float blue = ( fluid.getFluid().getColor() & 255 ) / 255.0F; GlStateManager.color( red, green, blue ); TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getFluid().getStill().toString() ); final int scaledHeight = (int) ( this.height * ( (float) fluid.getStackSize() / this.tank.getTankProperties()[this.slot].getCapacity() ) ); int iconHeightRemainder = scaledHeight % 16; if( iconHeightRemainder > 0 ) { this.drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder, sprite, 16, iconHeightRemainder ); } for( int i = 0; i < scaledHeight / 16; i++ ) { this.drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder - ( i + 1 ) * 16, sprite, 16, 16 ); } } } }