List of usage examples for net.minecraftforge.fluids IFluidTank getFluid
@Nonnull FluidStack getFluid();
From source file:com.builtbroken.atomic.content.machines.processing.TileEntityProcessingMachine.java
/** * Outputs fluids to container in slot/*from w ww .jav a2 s . c om*/ * * @param slot - slot with container * @param outputTank - tank to drain */ protected void outputFluids(final int slot, final IFluidTank outputTank) { final ItemStack itemStack = getStackInSlot(slot); if (itemStack != null && outputTank.getFluid() != null) { if (itemStack.getItem() instanceof IFluidContainerItem) { //Copy stack (fix for containers that can stack when empty) final ItemStack fluidContainer = itemStack.copy(); fluidContainer.stackSize = 1; IFluidContainerItem fluidContainerItem = (IFluidContainerItem) fluidContainer.getItem(); FluidStack fluidStack = fluidContainerItem.getFluid(fluidContainer); if (fluidStack == null || fluidStack.getFluid() == outputTank.getFluid().getFluid()) { int filled = fluidContainerItem.fill(fluidContainer, outputTank.getFluid(), true); outputTank.drain(filled, true); if (itemStack.stackSize == 1) { setInventorySlotContents(slot, fluidContainer); } else { decrStackSize(slot, 1); //TODO add fluid container output slot EntityItem item = new EntityItem(worldObj); item.setPosition(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); item.setEntityItemStack(fluidContainer); worldObj.spawnEntityInWorld(item); } } } else if (FluidContainerRegistry.isEmptyContainer(itemStack)) { ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(outputTank.getFluid(), itemStack); if (filledContainer != null) { FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(filledContainer); if (fluidStack.getFluid() == outputTank.getFluid().getFluid() && fluidStack.amount <= outputTank.getFluidAmount()) { outputTank.drain(fluidStack.amount, true); decrStackSize(slot, 1); if (getStackInSlot(slot) == null) { setInventorySlotContents(slot, filledContainer); } else { //TODO add fluid container output slot EntityItem item = new EntityItem(worldObj); item.setPosition(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); item.setEntityItemStack(filledContainer); worldObj.spawnEntityInWorld(item); } } } } } }
From source file:com.builtbroken.atomic.content.machines.processing.TileEntityProcessingMachine.java
/** * Outputs fluids to connected tiles/* w w w .j a v a 2s . com*/ * * @param outputTank - tank to drain */ protected void outputFluidToTiles(IFluidTank outputTank, Function<ForgeDirection, Boolean> canUseSideFunction) { if (outputTank.getFluid() != null) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { if (canUseSideFunction == null || canUseSideFunction.apply(direction)) { int x = xCoord + direction.offsetX; int y = yCoord + direction.offsetY; int z = zCoord + direction.offsetZ; if (worldObj.blockExists(x, y, z)) { TileEntity tile = worldObj.getTileEntity(x, y, z); if (tile instanceof IFluidHandler && outputTank.getFluid() != null && ((IFluidHandler) tile) .canFill(direction.getOpposite(), outputTank.getFluid().getFluid())) { int fill = ((IFluidHandler) tile).fill(direction.getOpposite(), outputTank.getFluid(), true); outputTank.drain(fill, true); } } } } } }
From source file:com.builtbroken.atomic.content.machines.processing.TileEntityProcessingMachine.java
/** * Checks if the tank has fluids// www. j a va 2 s .c o m * * @param tank - tank to check * @param fluid - fluid to match * @param amount - fluid volume to match >= * @return true if enough fluid exists */ public boolean hasInputFluid(IFluidTank tank, Fluid fluid, int amount) { FluidStack inputFluidStack = tank.getFluid(); return inputFluidStack != null && inputFluidStack.getFluid() == fluid && inputFluidStack.amount >= amount; }
From source file:com.builtbroken.atomic.content.machines.processing.TileEntityProcessingMachine.java
/** * Checks if there is enough fluid to output * * @param tank - tank to drain/*from w w w . ja va 2 s.co m*/ * @param fluid - fluid to drain * @param amount - amount to drain * @return true if enough fluid */ public boolean canOutputFluid(IFluidTank tank, Fluid fluid, int amount) { if (fluid != null && amount > 0) { if (tank.getFluid() != null) { //Space left in tank final int room = tank.getCapacity() - tank.getFluid().amount; return room >= amount && fluid == tank.getFluid().getFluid(); } else { return tank.getCapacity() >= amount; } } return false; }
From source file:com.builtbroken.atomic.content.machines.processing.TileEntityProcessingMachine.java
public boolean tankMatch(IFluidTank tank, FluidStack fluidStack) { if (fluidStack != null) { return tank.getFluid() != null && tank.getFluid().getFluid() == fluidStack.getFluid(); }/* www . j a va 2s . c om*/ return false; }
From source file:com.builtbroken.atomic.content.machines.processing.TileEntityProcessingMachine.java
public boolean tankMatch(IFluidTank tank, Fluid fluid) { return tank.getFluid() != null && tank.getFluid().getFluid() == fluid; }
From source file:com.buuz135.industrial.utils.ItemStackUtils.java
License:Open Source License
public static void fillItemFromTank(ItemStackHandler fluidItems, IFluidTank tank) { if (tank.getFluid() == null) return;// w w w . j ava 2s.co m ItemStack stack = fluidItems.getStackInSlot(0).copy(); if (!stack.isEmpty()) { if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { FluidActionResult result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null, false); if (result.isSuccess() && (fluidItems.getStackInSlot(1).isEmpty() || (ItemHandlerHelper.canItemStacksStack(result.getResult(), fluidItems.getStackInSlot(1)) && result.getResult().getCount() + fluidItems.getStackInSlot(1).getCount() <= result .getResult().getMaxStackSize()))) { result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null, true); if (fluidItems.getStackInSlot(1).isEmpty()) { fluidItems.setStackInSlot(1, result.getResult()); } else { fluidItems.getStackInSlot(1).grow(1); } fluidItems.getStackInSlot(0).shrink(1); } } } }
From source file:mods.railcraft.client.render.carts.CartContentRendererTank.java
License:Open Source License
@Override public void render(RenderCart renderer, EntityMinecart cart, float light, float time) { super.render(renderer, cart, light, time); EntityCartTank cartTank = (EntityCartTank) cart; GL11.glPushMatrix();//from www . j a va 2 s . co m GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glTranslatef(0.0F, 0.3125F, 0.0F); GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F); GL11.glDisable(2896 /*GL_LIGHTING*/); int x = (int) (Math.floor(cart.posX)); int y = (int) (Math.floor(cart.posY)); int z = (int) (Math.floor(cart.posZ)); IFluidTank tank = cartTank.getTankManager().get(0); FluidStack fluidStack = tank.getFluid(); if (fluidStack != null && fluidStack.amount > 0) { Fluid fluid = fluidStack.getFluid(); int[] displayLists = FluidRenderer.getLiquidDisplayLists(fluidStack); if (fluid != null && displayLists != null) { GL11.glPushMatrix(); GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glEnable(GL11.GL_BLEND); GL11.glTranslatef(0, 0.0625f, 0); float cap = tank.getCapacity(); float level = (float) Math.min(fluidStack.amount, cap) / cap; renderer.bindTex(FluidRenderer.getFluidSheet(fluidStack)); FluidRenderer.setColorForFluidStack(fluidStack); GL11.glCallList(displayLists[(int) (level * (float) (FluidRenderer.DISPLAY_STAGES - 1))]); if (cartTank.isFilling()) { ResourceLocation texSheet = FluidRenderer.setupFlowingLiquidTexture(fluidStack, fillBlock.texture); if (texSheet != null) { renderer.bindTex(texSheet); RenderFakeBlock.renderBlockForEntity(fillBlock, cart.worldObj, x, y, z, false, true); } } GL11.glPopAttrib(); GL11.glPopMatrix(); } } ItemStack bucket = cartTank.getFilterItem(); if (bucket != null && bucket.getItem() != null) { GL11.glPushMatrix(); GL11.glScalef(FILTER_SCALE_X, FILTER_SCALE_Y, FILTER_SCALE_Z); GL11.glTranslatef(0, -0.4f, 0); renderer.bindTex(TextureMap.locationItemsTexture); int meta = bucket.getItemDamage(); for (int pass = 0; pass < bucket.getItem().getRenderPasses(meta); ++pass) { IIcon texture = bucket.getItem().getIconFromDamageForRenderPass(meta, pass); if (texture == null) continue; int color = bucket.getItem().getColorFromItemStack(bucket, pass); float c1 = (float) (color >> 16 & 255) / 255.0F; float c2 = (float) (color >> 8 & 255) / 255.0F; float c3 = (float) (color & 255) / 255.0F; float dim = 0.7f; GL11.glColor4f(c1 * light * dim, c2 * light * dim, c3 * light * dim, 1.0F); Tessellator tess = Tessellator.instance; tess.setBrightness(bucketSign.template.getMixedBrightnessForBlock(cart.worldObj, x, y, z)); bucketSign.texture[0] = texture; RenderFakeBlock.renderBlockForEntity(bucketSign, cart.worldObj, x, y, z, false, true); } GL11.glPopMatrix(); } GL11.glPopAttrib(); GL11.glPopMatrix(); }
From source file:mods.railcraft.client.render.RenderFluidLoader.java
License:Open Source License
@Override public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) { TileLoaderFluidBase base = (TileLoaderFluidBase) tile; GL11.glPushMatrix();/*from www . ja v a 2s . com*/ GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_BLEND); // GL11.glEnable(GL11.GL_CULL_FACE); backDrop.texture[0] = base.getMachineType().getTexture(7); bindTexture(TextureMap.locationBlocksTexture); RenderFakeBlock.renderBlock(backDrop, base.getWorld(), x, y, z, false, true); GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F); GL11.glScalef(1f, 0.6f, 1f); IFluidTank tank = base.getTankManager().get(0); FluidStack fluidStack = tank.getFluid(); if (fluidStack != null && fluidStack.amount > 0) { int[] displayLists = FluidRenderer.getLiquidDisplayLists(fluidStack); if (displayLists != null) { GL11.glPushMatrix(); if (FluidRenderer.getFluidTexture(fluidStack, false) != null) { float cap = tank.getCapacity(); float level = (float) Math.min(fluidStack.amount, cap) / cap; bindTexture(FluidRenderer.getFluidSheet(fluidStack)); FluidRenderer.setColorForFluidStack(fluidStack); GL11.glCallList(displayLists[(int) (level * (float) (FluidRenderer.DISPLAY_STAGES - 1))]); } GL11.glPopMatrix(); } } // GL11.glScalef(0.994f, 1.05f, 0.994f); GL11.glPopAttrib(); GL11.glPopMatrix(); if (tile.getClass() == TileFluidLoader.class) { TileFluidLoader loader = (TileFluidLoader) tile; pipe.minY = RenderTools.PIXEL - loader.getPipeLenght(); RenderFakeBlock.renderBlock(pipe, loader.getWorld(), x, y, z, false, true); } }
From source file:mods.railcraft.client.render.RenderLiquidLoader.java
License:Open Source License
@Override public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) { TileLoaderLiquidBase base = (TileLoaderLiquidBase) tile; GL11.glPushMatrix();//from w w w . jav a 2 s . c o m GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_BLEND); // GL11.glEnable(GL11.GL_CULL_FACE); backDrop.texture[0] = base.getMachineType().getTexture(7); bindTexture(TextureMap.locationBlocksTexture); RenderFakeBlock.renderBlock(backDrop, base.getWorld(), x, y, z, false, true); GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F); GL11.glScalef(1f, 0.6f, 1f); IFluidTank tank = base.getTankManager().get(0); FluidStack fluidStack = tank.getFluid(); if (fluidStack != null && fluidStack.amount > 0) { int[] displayLists = FluidRenderer.getLiquidDisplayLists(fluidStack); if (displayLists != null) { GL11.glPushMatrix(); if (FluidRenderer.getFluidTexture(fluidStack, false) != null) { float cap = tank.getCapacity(); float level = (float) Math.min(fluidStack.amount, cap) / cap; bindTexture(FluidRenderer.getFluidSheet(fluidStack)); FluidRenderer.setColorForFluidStack(fluidStack); GL11.glCallList(displayLists[(int) (level * (float) (FluidRenderer.DISPLAY_STAGES - 1))]); } GL11.glPopMatrix(); } } // GL11.glScalef(0.994f, 1.05f, 0.994f); GL11.glPopAttrib(); GL11.glPopMatrix(); if (tile.getClass() == TileLiquidLoader.class) { TileLiquidLoader loader = (TileLiquidLoader) tile; pipe.minY = RenderTools.PIXEL - loader.getPipeLenght(); RenderFakeBlock.renderBlock(pipe, loader.getWorld(), x, y, z, false, true); } }