Java Code Examples for net.minecraftforge.fluids.FluidTank#drain()

The following examples show how to use net.minecraftforge.fluids.FluidTank#drain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiffuserHelper.java    From EmergingTechnology with MIT License 5 votes vote down vote up
private static boolean growBlock(World world, IBlockState blockState, Block block, BlockPos position,
        FluidTank gasHandler, int probability) {
    boolean isValidPlant = false;
    if (!PlantHelper.isCropAtPositionReadyForHarvest(world, position)) {
        isValidPlant = true;
        if (rollForGrow(probability) == true) {
            block.updateTick(world, position, blockState, new Random());
            gasHandler.drain(EmergingTechnologyConfig.HYDROPONICS_MODULE.DIFFUSER.diffuserGasBaseUsage, true);
        }
    }

    return isValidPlant;
}
 
Example 2
Source File: FluidPipeFluidHandler.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
    FluidTank fluidTank = getNetFluidTank();
    return fluidTank == null ? null : fluidTank.drain(resource, doDrain);
}
 
Example 3
Source File: FluidPipeFluidHandler.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
    FluidTank fluidTank = getNetFluidTank();
    return fluidTank == null ? null : fluidTank.drain(maxDrain, doDrain);
}
 
Example 4
Source File: BarrelModeFluid.java    From ExNihiloAdscensio with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void update(TileBarrel barrel) {
	// Fluids on top.
	if (barrel.getTank().getFluid() != null) {
		FluidTank tank = barrel.getTank();
		if (tank.getFluid().amount != tank.getCapacity())
			return;

		Fluid fluidInBarrel = tank.getFluid().getFluid();

		BlockPos barrelPos = barrel.getPos();
		BlockPos pos = new BlockPos(barrelPos.getX(), barrelPos.getY() + 1, barrelPos.getZ());
		Block onTop = barrel.getWorld().getBlockState(pos).getBlock();

		Fluid fluidOnTop = null;
		if (onTop instanceof BlockLiquid) {
			fluidOnTop = onTop.getMaterial(barrel.getWorld().getBlockState(pos)) == Material.WATER
					? FluidRegistry.WATER : FluidRegistry.LAVA;
		}

		if (onTop != null && onTop instanceof IFluidBlock) {
			fluidOnTop = ((BlockFluidBase) onTop).getFluid();
		}

		if (FluidOnTopRegistry.isValidRecipe(fluidInBarrel, fluidOnTop)) {
			ItemInfo info = FluidOnTopRegistry.getTransformedBlock(fluidInBarrel, fluidOnTop);
			tank.drain(tank.getCapacity(), true);
			barrel.setMode("block");
			PacketHandler.sendToAllAround(new MessageBarrelModeUpdate("block", barrel.getPos()), barrel);

			barrel.getMode().addItem(info.getItemStack(), barrel);

			return;
		}

		// Fluid transforming time!
		if (FluidTransformRegistry.containsKey(barrel.getTank().getFluid().getFluid().getName())) {
			List<FluidTransformer> transformers = FluidTransformRegistry
					.getFluidTransformers(barrel.getTank().getFluid().getFluid().getName());

			boolean found = false;
			for (int radius = 0; radius <= 2; radius++) {
				for (FluidTransformer transformer : transformers) {
					if (!BarrelLiquidBlacklistRegistry.isBlacklisted(barrel.getTier(), transformer.getOutputFluid())
							&& (Util.isSurroundingBlocksAtLeastOneOf(transformer.getTransformingBlocks(),
									barrel.getPos().add(0, -1, 0), barrel.getWorld(), radius)
									|| Util.isSurroundingBlocksAtLeastOneOf(transformer.getTransformingBlocks(),
											barrel.getPos(), barrel.getWorld(), radius))) {
						// Time to start the process.
						FluidStack fstack = tank.getFluid();
						tank.setFluid(null);

						barrel.setMode("fluidTransform");
						BarrelModeFluidTransform mode = (BarrelModeFluidTransform) barrel.getMode();

						mode.setTransformer(transformer);
						mode.setInputStack(fstack);
						mode.setOutputStack(FluidRegistry.getFluidStack(transformer.getOutputFluid(), 1000));

						PacketHandler.sendNBTUpdate(barrel);
						found = true;
					}
				}
				if (found) break;
			}
		}
	}
}